No longer showing empty pictures for GAL contacts in the list

There is now a flag that tells us whether
a particular contact directory supports photos
or not.  If not - we don't display a photo
placeholder for the corresponding contacts.

Change-Id: I74ce43c3490fd419a7138fa01a257d14f0b6a8b6
diff --git a/src/com/android/contacts/list/ContactEntryListAdapter.java b/src/com/android/contacts/list/ContactEntryListAdapter.java
index 1ebf3c9..ddd90d3 100644
--- a/src/com/android/contacts/list/ContactEntryListAdapter.java
+++ b/src/com/android/contacts/list/ContactEntryListAdapter.java
@@ -78,6 +78,7 @@
         partition.setDirectoryId(Directory.DEFAULT);
         partition.setDirectoryType(getContext().getString(R.string.contactsList));
         partition.setPriorityDirectory(true);
+        partition.setPhotoSupported(true);
         return partition;
     }
 
@@ -228,6 +229,7 @@
         int idColumnIndex = cursor.getColumnIndex(Directory._ID);
         int directoryTypeColumnIndex = cursor.getColumnIndex(DirectoryListLoader.DIRECTORY_TYPE);
         int displayNameColumnIndex = cursor.getColumnIndex(Directory.DISPLAY_NAME);
+        int photoSupportColumnIndex = cursor.getColumnIndex(Directory.PHOTO_SUPPORT);
 
         // TODO preserve the order of partition to match those of the cursor
         // Phase I: add new directories
@@ -240,6 +242,9 @@
                 partition.setDirectoryId(id);
                 partition.setDirectoryType(cursor.getString(directoryTypeColumnIndex));
                 partition.setDisplayName(cursor.getString(displayNameColumnIndex));
+                int photoSupport = cursor.getInt(photoSupportColumnIndex);
+                partition.setPhotoSupported(photoSupport == Directory.PHOTO_SUPPORT_THUMBNAIL_ONLY
+                        || photoSupport == Directory.PHOTO_SUPPORT_FULL);
                 addPartition(partition);
             }
         }
@@ -405,4 +410,12 @@
             return String.format(format, count);
         }
     }
+
+    public boolean isPhotoSupported(int partitionIndex) {
+        Partition partition = getPartition(partitionIndex);
+        if (partition instanceof DirectoryPartition) {
+            return ((DirectoryPartition) partition).isPhotoSupported();
+        }
+        return true;
+    }
 }
diff --git a/src/com/android/contacts/list/ContactListAdapter.java b/src/com/android/contacts/list/ContactListAdapter.java
index 4b34323..cd6e125 100644
--- a/src/com/android/contacts/list/ContactListAdapter.java
+++ b/src/com/android/contacts/list/ContactListAdapter.java
@@ -231,7 +231,12 @@
         view.setDividerVisible(!placement.lastInSection);
     }
 
-    protected void bindPhoto(final ContactListItemView view, Cursor cursor) {
+    protected void bindPhoto(final ContactListItemView view, int partitionIndex, Cursor cursor) {
+        if (!isPhotoSupported(partitionIndex)) {
+            view.removePhotoView();
+            return;
+        }
+
         // Set the photo, if available
         long photoId = 0;
         if (!cursor.isNull(CONTACT_PHOTO_ID_COLUMN_INDEX)) {
diff --git a/src/com/android/contacts/list/ContactListItemView.java b/src/com/android/contacts/list/ContactListItemView.java
index 2c37242..2195170 100644
--- a/src/com/android/contacts/list/ContactListItemView.java
+++ b/src/com/android/contacts/list/ContactListItemView.java
@@ -580,10 +580,7 @@
     /**
      * Removes the photo view.  Should not be needed once we start handling different
      * types of views as different types of views from the List's perspective.
-     *
-     * @deprecated
      */
-    @Deprecated
     public void removePhotoView() {
         if (mPhotoView != null) {
             removeView(mPhotoView);
diff --git a/src/com/android/contacts/list/DefaultContactListAdapter.java b/src/com/android/contacts/list/DefaultContactListAdapter.java
index 92ca06e..d0cdbfd 100644
--- a/src/com/android/contacts/list/DefaultContactListAdapter.java
+++ b/src/com/android/contacts/list/DefaultContactListAdapter.java
@@ -183,7 +183,7 @@
         if (isQuickContactEnabled()) {
             bindQuickContact(view, partition, cursor);
         } else {
-            bindPhoto(view, cursor);
+            bindPhoto(view, partition, cursor);
         }
 
         bindName(view, cursor);
diff --git a/src/com/android/contacts/list/DirectoryListLoader.java b/src/com/android/contacts/list/DirectoryListLoader.java
index b8cc2c9..558d3ae 100644
--- a/src/com/android/contacts/list/DirectoryListLoader.java
+++ b/src/com/android/contacts/list/DirectoryListLoader.java
@@ -45,12 +45,14 @@
             Directory.PACKAGE_NAME,
             Directory.TYPE_RESOURCE_ID,
             Directory.DISPLAY_NAME,
+            Directory.PHOTO_SUPPORT,
         };
 
         public static final int ID = 0;
         public static final int PACKAGE_NAME = 1;
         public static final int TYPE_RESOURCE_ID = 2;
         public static final int DISPLAY_NAME = 3;
+        public static final int PHOTO_SUPPORT = 4;
     }
 
     public static final String DIRECTORY_TYPE = "directoryType";
@@ -59,6 +61,7 @@
         Directory._ID,
         DIRECTORY_TYPE,
         Directory.DISPLAY_NAME,
+        Directory.PHOTO_SUPPORT,
     };
 
     private final ContentObserver mObserver = new ContentObserver(new Handler()) {
@@ -124,7 +127,8 @@
                     }
                 }
                 String displayName = cursor.getString(DirectoryQuery.DISPLAY_NAME);
-                result.addRow(new Object[]{directoryId, directoryType, displayName});
+                int photoSupport = cursor.getInt(DirectoryQuery.PHOTO_SUPPORT);
+                result.addRow(new Object[]{directoryId, directoryType, displayName, photoSupport});
             }
         } finally {
             cursor.close();
diff --git a/src/com/android/contacts/list/DirectoryPartition.java b/src/com/android/contacts/list/DirectoryPartition.java
index 88cc879..47a1037 100644
--- a/src/com/android/contacts/list/DirectoryPartition.java
+++ b/src/com/android/contacts/list/DirectoryPartition.java
@@ -33,6 +33,7 @@
     private String mDisplayName;
     private int mStatus;
     private boolean mPriorityDirectory;
+    private boolean mPhotoSupported;
 
     public DirectoryPartition(boolean showIfEmpty, boolean hasHeader) {
         super(showIfEmpty, hasHeader);
@@ -94,4 +95,15 @@
     public void setPriorityDirectory(boolean priorityDirectory) {
         mPriorityDirectory = priorityDirectory;
     }
+
+    /**
+     * Returns true if this directory supports photos.
+     */
+    public boolean isPhotoSupported() {
+        return mPhotoSupported;
+    }
+
+    public void setPhotoSupported(boolean flag) {
+        this.mPhotoSupported = flag;
+    }
 }
diff --git a/src/com/android/contacts/list/JoinContactListAdapter.java b/src/com/android/contacts/list/JoinContactListAdapter.java
index b1bb586..c72ebcd 100644
--- a/src/com/android/contacts/list/JoinContactListAdapter.java
+++ b/src/com/android/contacts/list/JoinContactListAdapter.java
@@ -200,7 +200,7 @@
         switch (partition) {
             case PARTITION_SUGGESTIONS: {
                 final ContactListItemView view = (ContactListItemView)itemView;
-                bindPhoto(view, cursor);
+                bindPhoto(view, partition, cursor);
                 bindName(view, cursor);
                 break;
             }
@@ -210,7 +210,7 @@
             case PARTITION_ALL_CONTACTS: {
                 final ContactListItemView view = (ContactListItemView)itemView;
                 bindSectionHeaderAndDivider(view, position);
-                bindPhoto(view, cursor);
+                bindPhoto(view, partition, cursor);
                 bindName(view, cursor);
                 break;
             }
diff --git a/src/com/android/contacts/list/StrequentContactListAdapter.java b/src/com/android/contacts/list/StrequentContactListAdapter.java
index 82f9799..12c56f3 100644
--- a/src/com/android/contacts/list/StrequentContactListAdapter.java
+++ b/src/com/android/contacts/list/StrequentContactListAdapter.java
@@ -209,7 +209,7 @@
         if (isQuickContactEnabled()) {
             bindQuickContact(view, partition, cursor);
         } else {
-            bindPhoto(view, cursor);
+            bindPhoto(view, partition, cursor);
         }
         bindPresence(view, cursor);