Merge "fix a crash when adding a group back to the sync set in the contacts display groups UI"
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index 28c5502..fdefe36 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -1705,6 +1705,10 @@
     }
 
     private boolean deleteSelection() {
+        if ((mMode & MODE_MASK_PICKER) != 0) {
+            return false;
+        }
+
         final int position = getListView().getSelectedItemPosition();
         if (position != ListView.INVALID_POSITION) {
             Uri contactUri = getContactUri(position);
@@ -3481,7 +3485,11 @@
             } else if (isSearchAllContactsItemPosition(pos)){
                 return null;
             } else {
-                return super.getItem(getRealPosition(pos));
+                int realPosition = getRealPosition(pos);
+                if (realPosition < 0) {
+                    return null;
+                }
+                return super.getItem(realPosition);
             }
         }
 
@@ -3496,7 +3504,11 @@
             } else if (isSearchAllContactsItemPosition(pos)) {
                 return 0;
             }
-            return super.getItemId(getRealPosition(pos));
+            int realPosition = getRealPosition(pos);
+            if (realPosition < 0) {
+                return 0;
+            }
+            return super.getItemId(realPosition);
         }
 
         public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
diff --git a/src/com/android/contacts/TextHighlightingAnimation.java b/src/com/android/contacts/TextHighlightingAnimation.java
index 3bf6499..e35ae1e 100644
--- a/src/com/android/contacts/TextHighlightingAnimation.java
+++ b/src/com/android/contacts/TextHighlightingAnimation.java
@@ -39,6 +39,11 @@
 
     private final static DimmingSpan[] sEmptySpans = new DimmingSpan[0];
 
+    /**
+     * Frame rate expressed a number of millis between frames.
+     */
+    private static final long FRAME_RATE = 50;
+
     private DimmingSpan mDimmingSpan;
     private Handler mHandler;
     private boolean mAnimating;
@@ -88,6 +93,13 @@
             char[] string2 = buffer2.data;
             int count1 = buffer1.sizeCopied;
             int count2 = buffer2.sizeCopied;
+
+            // Ignore matching tails of the two buffers
+            while (count1 > 0 && count2 > 0 && string1[count1 - 1] == string2[count2 - 1]) {
+                count1--;
+                count2--;
+            }
+
             int size = count2;
             for (int i = 0; i < count1; i++) {
                 if (i + size > count1) {
@@ -284,6 +296,6 @@
         invalidate();
 
         // Repeat
-        mHandler.post(this);
+        mHandler.postDelayed(this, FRAME_RATE);
     }
-}
\ No newline at end of file
+}
diff --git a/src/com/android/contacts/ui/EditContactActivity.java b/src/com/android/contacts/ui/EditContactActivity.java
index 82aa2bd..25132fb 100644
--- a/src/com/android/contacts/ui/EditContactActivity.java
+++ b/src/com/android/contacts/ui/EditContactActivity.java
@@ -128,8 +128,8 @@
 
     private static final int ICON_SIZE = 96;
 
-    private static final File PHOTO_DIR = new File(Environment.getExternalStorageDirectory(),
-            "com.android.contacts.icon");
+    private static final File PHOTO_DIR = new File(
+            Environment.getExternalStorageDirectory() + "/DCIM/Camera");
 
     private File mCurrentPhotoFile;
 
diff --git a/tests/src/com/android/contacts/EntitySetTests.java b/tests/src/com/android/contacts/EntitySetTests.java
index 26f4184..c9fc3fa 100644
--- a/tests/src/com/android/contacts/EntitySetTests.java
+++ b/tests/src/com/android/contacts/EntitySetTests.java
@@ -480,6 +480,7 @@
         final ContentValues joePhoneInsert = buildPhone(PHONE_BLUE);
         final EntityDelta joeContact = buildAfterEntity(joePhoneInsert);
         final ContentValues joeContactInsert = joeContact.getValues().getCompleteValues();
+        joeContactInsert.put(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_SUSPENDED);
         first.add(joeContact);
         assertDiffPattern(first,
                 buildAssertVersion(VER_FIRST),
@@ -536,6 +537,7 @@
         final ContentValues phoneInsert = phone.getCompleteValues();
         final ContentValues contactInsert = first.getByRawContactId(CONTACT_MARY).getValues()
                 .getCompleteValues();
+        contactInsert.put(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_SUSPENDED);
 
         // Merge and verify that update turned into insert
         final EntitySet merged = EntitySet.mergeAfter(second, first);