Improve the contact list activity code a little
authorDa Risk <darisk972@gmail.com>
Mon, 21 Dec 2009 20:40:17 +0100
changeset 596 3535cead49a1
parent 590 4fc715754de8
child 597 aa75a44fdffe
Improve the contact list activity code a little
src/com/beem/project/beem/ui/ContactList.java
--- a/src/com/beem/project/beem/ui/ContactList.java	Mon Dec 21 20:36:18 2009 +0100
+++ b/src/com/beem/project/beem/ui/ContactList.java	Mon Dec 21 20:40:17 2009 +0100
@@ -81,6 +81,7 @@
 import android.widget.AdapterView.AdapterContextMenuInfo;
 import android.widget.AdapterView.OnItemClickListener;
 import android.graphics.drawable.BitmapDrawable;
+import android.R.drawable;
 
 import com.beem.project.beem.R;
 import com.beem.project.beem.service.Contact;
@@ -95,7 +96,7 @@
 import com.beem.project.beem.utils.Status;
 
 /**
- * The contact list activity displays the roster of the user. TODO: Dismiss dialogs on destroy to avoid window leak
+ * The contact list activity displays the roster of the user.
  */
 public class ContactList extends Activity {
 
@@ -106,23 +107,23 @@
     }
 
     private static final int REQUEST_CODE = 1;
-    private BeemContactList mAdapterContactList;
-    private BeemBanner mAdapterBanner;
-    private IRoster mRoster;
-    private List<Contact> mListContact = new ArrayList<Contact>();
+    private final BeemContactList mAdapterContactList = new BeemContactList();
+    private final BeemBanner mAdapterBanner = new BeemBanner();
     private final List<String> mListGroup = new ArrayList<String>();
     private final Map<String, List<Contact>> mContactOnGroup = new HashMap<String, List<Contact>>();
+    private final Handler mHandler = new Handler();
+    private final ServiceConnection mServConn = new BeemServiceConnection();
+    private final BeemBroadcastReceiver mReceiver = new BeemBroadcastReceiver();
+    private final ComparatorContactListByStatusAndName<Contact> mComparator = new ComparatorContactListByStatusAndName<Contact>();
+    private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
+    private final Map<Integer, BitmapDrawable> mIconsMap = new HashMap<Integer, BitmapDrawable>();
+    private List<Contact> mListContact;
+    private IRoster mRoster;
     private String mCurGroup;
     private Contact mContact;
-    private Handler mHandler;
     private IXmppFacade mXmppFacade;
     private SharedPreferences mSettings;
-    private final ServiceConnection mServConn = new BeemServiceConnection();
-    private final BeemBroadcastReceiver mReceiver = new BeemBroadcastReceiver();
-    private final Map<Integer, BitmapDrawable> mIconsMap = new HashMap<Integer, BitmapDrawable>();
     private LayoutInflater mInflater;
-    private ComparatorContactListByStatusAndName<Contact> mComparator = new ComparatorContactListByStatusAndName<Contact>();
-    private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
 
     /**
      * Constructor.
@@ -132,24 +133,6 @@
     }
 
     /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onCreate(Bundle saveBundle) {
-	super.onCreate(saveBundle);
-	mSettings = PreferenceManager.getDefaultSharedPreferences(this);
-	setContentView(R.layout.contactlist);
-	mAdapterContactList = new BeemContactList(this);
-	mAdapterBanner = new BeemBanner(this);
-	mHandler = new Handler();
-
-	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
-
-	mInflater = getLayoutInflater();
-	prepareIconsStatus();
-    }
-
-    /**
      * Callback for menu creation.
      * @param menu the menu created
      * @return true on success, false otherwise
@@ -269,20 +252,52 @@
      * {@inheritDoc}
      */
     @Override
+    protected void onCreate(Bundle saveBundle) {
+	super.onCreate(saveBundle);
+	Log.v("CONTACTLIST", "onCreate");
+	mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+	setContentView(R.layout.contactlist);
+
+	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+
+	mInflater = getLayoutInflater();
+	prepareIconsStatus();
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+    @Override
     protected void onStart() {
 	super.onStart();
 	if (mXmppFacade == null)
 	    bindService(SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
     }
+*/
+    protected void onResume() {
+	super.onResume();
+	Log.d("CONTACTLIST", "onResume");
+	if (mXmppFacade == null)
+	    bindService(SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+    }
 
     /**
      * {@inheritDoc}
      */
     @Override
-    protected void onStop() {
-	super.onStop();
+    protected void onPause() {
+	super.onPause();
+	try {
+	    if (mRoster != null) {
+		mRoster.removeRosterListener(mBeemRosterListener);
+		mRoster = null;
+	    }
+	} catch (RemoteException e) {
+	    Log.d("ContactList", "Remode exception", e);
+	}
 	unbindService(mServConn);
 	mXmppFacade = null;
+	Log.e("CONTACTLIST", "onPause activity");
     }
 
     /*
@@ -292,14 +307,7 @@
     @Override
     protected void onDestroy() {
 	super.onDestroy();
-	try {
-	    if (mRoster != null)
-		mRoster.removeRosterListener(mBeemRosterListener);
-	} catch (RemoteException e) {
-	    Log.d("ContactList", "Remode exception", e);
-	}
 	this.unregisterReceiver(mReceiver);
-	mRoster = null;
 	Log.e("CONTACTLIST", "onDestroy activity");
     }
 
@@ -415,13 +423,13 @@
      */
     private void prepareIconsStatus() {
 	mIconsMap.put(Status.CONTACT_STATUS_AVAILABLE, new BitmapDrawable(BitmapFactory.decodeResource(getResources(),
-	    R.drawable.status_available)));
+	    android.R.drawable.presence_online)));
 	mIconsMap.put(Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT, new BitmapDrawable(BitmapFactory.decodeResource(getResources(),
-	    R.drawable.status_available)));
-	mIconsMap.put(Status.CONTACT_STATUS_AWAY, new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.status_away)));
-	mIconsMap.put(Status.CONTACT_STATUS_BUSY, new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.status_dnd)));
+	    android.R.drawable.presence_online)));
+	mIconsMap.put(Status.CONTACT_STATUS_AWAY, new BitmapDrawable(BitmapFactory.decodeResource(getResources(), android.R.drawable.presence_away)));
+	mIconsMap.put(Status.CONTACT_STATUS_BUSY, new BitmapDrawable(BitmapFactory.decodeResource(getResources(), android.R.drawable.presence_busy)));
 	mIconsMap.put(Status.CONTACT_STATUS_DISCONNECT, new BitmapDrawable(BitmapFactory.decodeResource(getResources(),
-	    R.drawable.status_offline)));
+	    android.R.drawable.presence_offline)));
 	mIconsMap.put(Status.CONTACT_STATUS_UNAVAILABLE, new BitmapDrawable(BitmapFactory.decodeResource(getResources(),
 	    R.drawable.status_requested)));
     }
@@ -589,9 +597,8 @@
 
 	/**
 	 * Constructor.
-	 * @param context context activity.
 	 */
-	public BeemContactList(final Context context) {
+	public BeemContactList() {
 	}
 
 	/**
@@ -700,9 +707,8 @@
     private class BeemBanner extends BaseAdapter {
 	/**
 	 * Constructor.
-	 * @param c context activity.
 	 */
-	public BeemBanner(final Context c) {
+	public BeemBanner() {
 	}
 
 	/**
@@ -815,4 +821,8 @@
 	    mContactOnGroup.clear();
 	}
     }
+
+    protected void finalize() {
+	Log.e("CONTACTLIST", "FINALIZE");
+    }
 }