GroupBanner show or not and update after sync
authorNikita Kozlov <nikita@elyzion.net>
Wed, 02 Nov 2011 18:01:06 +0100
changeset 914 391114f750f0
parent 913 46ca87505a61
child 915 3039eca6adab
GroupBanner show or not and update after sync G: --
default.properties
src/com/beem/project/beem/ui/ContactList.java
--- a/default.properties	Fri Oct 28 19:12:38 2011 +0200
+++ b/default.properties	Wed Nov 02 18:01:06 2011 +0100
@@ -1,11 +1,2 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-# 
-# This file must be checked in Version Control Systems.
-# 
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
 # Project target.
-target=android-8
+target=android-14
--- a/src/com/beem/project/beem/ui/ContactList.java	Fri Oct 28 19:12:38 2011 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Wed Nov 02 18:01:06 2011 +0100
@@ -37,9 +37,11 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.database.ContentObserver;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.Handler;
 import android.os.RemoteException;
 import android.preference.PreferenceManager;
 import android.provider.ContactsContract;
@@ -124,7 +126,7 @@
 	    ContactsContract.Groups.ACCOUNT_NAME + "=?", new String[] { mAccountName }, null);
 	mAdapterBanner = new BeemBanner(this, R.layout.contactlist_group, cursorGroup,
 	    new String[] { ContactsContract.Groups.TITLE }, new int[] { R.id.contactlist_group });
-
+	cursorGroup.registerContentObserver(new BeemGroupObserver(new Handler()));
 	// Get Contacts list
 	// TODO: Get contact list by account  -> Create Sqlite View or join
 	final Cursor cursorContact = getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI,
@@ -281,13 +283,16 @@
      * Show the groups view.
      */
     private void showGroups() {
-
 	ViewStub stub = (ViewStub) findViewById(R.id.contactlist_stub);
 	if (stub != null) {
 	    View v = stub.inflate();
 	    Gallery g = (Gallery) v.findViewById(R.id.contactlist_banner);
 	    g.setOnItemClickListener(new OnItemClickGroupName());
 	    g.setAdapter(mAdapterBanner);
+	    if (mAdapterBanner.getCount() == 0)
+		v.setVisibility(View.GONE);
+	    else
+		v.setVisibility(View.VISIBLE);
 	}
     }
 
@@ -518,4 +523,30 @@
 	}
     }
 
+    private class BeemGroupObserver extends ContentObserver {
+
+	public BeemGroupObserver(Handler handler) {
+	    super(handler);
+	}
+
+	@Override
+	public boolean deliverSelfNotifications() {
+	    return true;
+	}
+
+	@Override
+	public void onChange(boolean selfChange) {
+	    super.onChange(selfChange);
+	    View v = findViewById(R.id.contactlist_groupstub);
+	    if (v != null) {
+		if (mAdapterBanner.getCount() > 0) {
+		    v.setVisibility(View.VISIBLE);
+		} else {
+		    v.setVisibility(View.GONE);
+		}
+	    }
+	}
+
+    }
+
 }