Merge "Fix NPE in getPhotos()" into ub-contactsdialer-b-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c963506..c832e8f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -904,6 +904,12 @@
          For example: Photo from Google abc@gmail.com checked. [CHAR LIMIT=60]-->
     <string name="photo_view_description_checked">Photo from <xliff:g id="account_type">%s </xliff:g><xliff:g id="user_name">%s </xliff:g>checked</string>
 
+    <!-- Content description of photo in photo picker indicating a photo from unknown account is *not* selected.-->
+    <string name="photo_view_description_not_checked_no_info">Photo from unknown account not checked</string>
+
+    <!-- Content description of photo in photo picker indicating a photo from unknown account is selected. -->
+    <string name="photo_view_description_checked_no_info">Photo from unknown account checked</string>
+
     <!-- Text shown in the contacts app while the background process updates contacts after a locale change [CHAR LIMIT=150]-->
     <string name="locale_change_in_progress">Contact list is being updated to reflect the change of language.\n\nPlease wait...</string>
 
diff --git a/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java b/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
index fe725c0..bc9435b 100644
--- a/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
+++ b/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
@@ -28,6 +28,7 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.provider.ContactsContract;
+import android.text.TextUtils;
 import android.util.DisplayMetrics;
 import android.view.Display;
 import android.view.LayoutInflater;
@@ -96,8 +97,8 @@
         public int iconRes;
         public String syncAdapterPackageName;
 
-        public String accountType;
-        public String accountName;
+        public String contentDescription;
+        public String contentDescriptionChecked; // Talkback announcement when the photo is checked
 
         public ValuesDelta valuesDelta;
 
@@ -250,11 +251,7 @@
             final ImageView checkImageView = (ImageView) photoItemView.findViewById(R.id.check);
             checkImageView.setVisibility(photo.primary ? View.VISIBLE : View.GONE);
 
-            final String contentDescription = getString(photo.primary ?
-                    R.string.photo_view_description_checked :
-                    R.string.photo_view_description_not_checked,
-                    photo.accountType, photo.accountName == null ? "" : photo.accountName);
-            photoItemView.setContentDescription(contentDescription);
+            photoItemView.setContentDescription(photo.contentDescription);
 
             return photoItemView;
         }
@@ -343,10 +340,7 @@
             }
         });
         final ViewGroup clickedView = (ViewGroup) mGridView.getChildAt(position);
-        final String contentDescription = getString(
-                R.string.photo_view_description_checked,
-                photo.accountType, photo.accountName == null ? "" : photo.accountName);
-        clickedView.announceForAccessibility(contentDescription);
+        clickedView.announceForAccessibility(photo.contentDescriptionChecked);
     }
 
     @Override
diff --git a/src/com/android/contacts/editor/CompactRawContactsEditorView.java b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
index 43f39bf..72f1c66 100644
--- a/src/com/android/contacts/editor/CompactRawContactsEditorView.java
+++ b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
@@ -547,8 +547,6 @@
                 photo.primary = valuesDelta.isSuperPrimary();
                 photo.kindSectionDataListIndex = i;
                 photo.valuesDeltaListIndex = j;
-                photo.accountType = accountType.getDisplayLabel(getContext()).toString();
-                photo.accountName = kindSectionData.getRawContactDelta().getAccountName();
                 photo.photoId = valuesDelta.getId();
 
                 if (updatedPhotos != null) {
@@ -556,6 +554,28 @@
                             kindSectionData.getRawContactDelta().getRawContactId()));
                 }
 
+                // set content descriptions of the photo
+                final CharSequence accountTypeText = accountType.getDisplayLabel(getContext());
+                if (accountTypeText != null) {
+                    final String accountNameText =
+                            kindSectionData.getRawContactDelta().getAccountName();
+                    photo.contentDescription = getResources().getString(photo.primary ?
+                                    R.string.photo_view_description_checked :
+                                    R.string.photo_view_description_not_checked,
+                            accountTypeText,
+                            accountNameText == null ? "" : accountNameText);
+                    photo.contentDescriptionChecked = getResources().getString(
+                            R.string.photo_view_description_checked,
+                            accountTypeText,
+                            accountNameText == null ? "" : accountNameText);
+                } else {
+                    photo.contentDescription = getResources().getString(photo.primary ?
+                            R.string.photo_view_description_checked_no_info :
+                            R.string.photo_view_description_not_checked_no_info);
+                    photo.contentDescriptionChecked = getResources().getString(
+                            R.string.photo_view_description_checked_no_info);
+                }
+
                 photos.add(photo);
             }
         }