mise en cache des icones des differents status, pour ne pas refaire des acces aux resssources a chaque fois
--- a/src/com/beem/project/beem/ui/ContactList.java Fri Oct 30 19:24:39 2009 +0100
+++ b/src/com/beem/project/beem/ui/ContactList.java Fri Oct 30 19:53:51 2009 +0100
@@ -15,9 +15,10 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Typeface;
-import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -65,6 +66,7 @@
private IXmppFacade mXmppFacade;
private final ServiceConnection mServConn = new BeemServiceConnection();
private BeemBroadcastReceiver mReceiver;
+ private Map<Integer, Bitmap> mIconsMap = new HashMap<Integer, Bitmap>();
static {
SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
@@ -89,6 +91,7 @@
mHandler = new Handler();
mReceiver = new BeemBroadcastReceiver(mServConn);
this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+ prepareIconsStatus();
}
/**
@@ -158,8 +161,8 @@
@Override
protected void onDestroy() {
- super.onDestroy();
- this.unregisterReceiver(mReceiver);
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
}
/**
@@ -296,6 +299,18 @@
}
/**
+ * Prepare Bitmap Map.
+ */
+ private void prepareIconsStatus(){
+ mIconsMap.put(Status.CONTACT_STATUS_AVAILABLE, BitmapFactory.decodeResource(getResources(), R.drawable.status_available));
+ mIconsMap.put(Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT, BitmapFactory.decodeResource(getResources(), R.drawable.status_available));
+ mIconsMap.put(Status.CONTACT_STATUS_AWAY, BitmapFactory.decodeResource(getResources(), R.drawable.status_away));
+ mIconsMap.put(Status.CONTACT_STATUS_BUSY, BitmapFactory.decodeResource(getResources(), R.drawable.status_dnd));
+ mIconsMap.put(Status.CONTACT_STATUS_DISCONNECT, BitmapFactory.decodeResource(getResources(), R.drawable.status_offline));
+ mIconsMap.put(Status.CONTACT_STATUS_UNAVAILABLE, BitmapFactory.decodeResource(getResources(), R.drawable.status_requested));
+ }
+
+ /**
* Sort the contact list.
*/
private void sortBeemContactList() {
@@ -524,32 +539,7 @@
if (curContact != null) {
ImageView imgV = (ImageView) view.findViewById(R.id.contactliststatus);
TextView v = (TextView) view.findViewById(R.id.contactlistpseudo);
- Drawable imageDrawable = null;
- switch (curContact.getStatus()) {
- case Status.CONTACT_STATUS_AVAILABLE:
- imageDrawable = getResources().getDrawable(R.drawable.status_available);
- break;
- case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
- imageDrawable = getResources().getDrawable(R.drawable.status_available);
- break;
- case Status.CONTACT_STATUS_AWAY:
- imageDrawable = getResources().getDrawable(R.drawable.status_away);
- break;
- case Status.CONTACT_STATUS_BUSY:
- imageDrawable = getResources().getDrawable(R.drawable.status_dnd);
- break;
- case Status.CONTACT_STATUS_DISCONNECT:
- imageDrawable = getResources().getDrawable(R.drawable.status_offline);
- break;
- case Status.CONTACT_STATUS_UNAVAILABLE:
- imageDrawable = getResources().getDrawable(R.drawable.status_requested);
- break;
- default:
- imageDrawable = getResources().getDrawable(R.drawable.status_error);
- break;
- }
- imgV.setImageDrawable(imageDrawable);
-
+ imgV.setImageBitmap(mIconsMap.get(curContact.getStatus()));
v.setText(curContact.getName());
v.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
v.setTextColor(Color.WHITE);