Merge "Improve appearance of "Contacts to Display"."
diff --git a/src/com/android/contacts/ContactPhotoManager.java b/src/com/android/contacts/ContactPhotoManager.java
index 3002dc3..cb0dc78 100644
--- a/src/com/android/contacts/ContactPhotoManager.java
+++ b/src/com/android/contacts/ContactPhotoManager.java
@@ -100,7 +100,7 @@
         }
     }
 
-    public static final DefaultImageProvider DEFAULT_AVATER = new AvatarDefaultImageProvider();
+    public static final DefaultImageProvider DEFAULT_AVATAR = new AvatarDefaultImageProvider();
 
     public static final DefaultImageProvider DEFAULT_BLANK = new BlankDefaultImageProvider();
 
@@ -133,10 +133,10 @@
 
     /**
      * Calls {@link #loadPhoto(ImageView, long, boolean, boolean, DefaultImageProvider)} with
-     * {@link #DEFAULT_AVATER}.
+     * {@link #DEFAULT_AVATAR}.
      */
     public final void loadPhoto(ImageView view, long photoId, boolean hires, boolean darkTheme) {
-        loadPhoto(view, photoId, hires, darkTheme, DEFAULT_AVATER);
+        loadPhoto(view, photoId, hires, darkTheme, DEFAULT_AVATAR);
     }
 
     /**
@@ -149,10 +149,10 @@
 
     /**
      * Calls {@link #loadPhoto(ImageView, Uri, boolean, boolean, DefaultImageProvider)} with
-     * {@link #DEFAULT_AVATER}.
+     * {@link #DEFAULT_AVATAR}.
      */
     public final void loadPhoto(ImageView view, Uri photoUri, boolean hires, boolean darkTheme) {
-        loadPhoto(view, photoUri, hires, darkTheme, DEFAULT_AVATER);
+        loadPhoto(view, photoUri, hires, darkTheme, DEFAULT_AVATAR);
     }
 
     /**
@@ -679,7 +679,7 @@
 
     @Override
     public void cacheBitmap(Uri photoUri, Bitmap bitmap, byte[] photoBytes) {
-        Request request = Request.createFromUri(photoUri, true, false, DEFAULT_AVATER);
+        Request request = Request.createFromUri(photoUri, true, false, DEFAULT_AVATAR);
         BitmapHolder holder = new BitmapHolder(photoBytes);
         mBitmapHolderCache.put(request.getKey(), holder);
         mBitmapCache.put(request.getKey(), bitmap);
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 2ede872..4eac313 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -55,6 +55,7 @@
 import android.content.Loader;
 import android.database.Cursor;
 import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
 import android.graphics.Rect;
 import android.net.Uri;
 import android.os.Bundle;
@@ -111,6 +112,7 @@
     private static final String KEY_STATUS = "status";
     private static final String KEY_NEW_LOCAL_PROFILE = "newLocalProfile";
     private static final String KEY_IS_USER_PROFILE = "isUserProfile";
+    private static final String KEY_UPDATED_PHOTOS = "updatedPhotos";
 
     public static final String SAVE_MODE_EXTRA_KEY = "saveMode";
 
@@ -196,7 +198,7 @@
     private Cursor mGroupMetaData;
 
     private File mCurrentPhotoFile;
-    private final Bundle mUpdatedPhotos = new Bundle();
+    private Bundle mUpdatedPhotos = new Bundle();
 
     private Context mContext;
     private String mAction;
@@ -421,6 +423,7 @@
             mStatus = savedState.getInt(KEY_STATUS);
             mNewLocalProfile = savedState.getBoolean(KEY_NEW_LOCAL_PROFILE);
             mIsUserProfile = savedState.getBoolean(KEY_IS_USER_PROFILE);
+            mUpdatedPhotos = savedState.getParcelable(KEY_UPDATED_PHOTOS);
         }
     }
 
@@ -717,6 +720,11 @@
             // Set up the photo handler.
             bindPhotoHandler(editor, type, mState);
 
+            // If a new photo was chosen but not yet saved, we need to
+            // update the thumbnail to reflect this.
+            Bitmap bitmap = updatedBitmapForRawContact(rawContactId);
+            if (bitmap != null) editor.setPhotoBitmap(bitmap);
+
             if (editor instanceof RawContactEditorView) {
                 final RawContactEditorView rawContactEditor = (RawContactEditorView) editor;
                 EditorListener listener = new EditorListener() {
@@ -764,6 +772,17 @@
         if (activity != null) activity.invalidateOptionsMenu();
     }
 
+    /**
+     * If we've stashed a temporary file containing a contact's new photo,
+     * decode it and return the bitmap.
+     * @param rawContactId identifies the raw-contact whose Bitmap we'll try to return.
+     * @return Bitmap of photo for specified raw-contact, or null
+    */
+    private Bitmap updatedBitmapForRawContact(long rawContactId) {
+        String path = mUpdatedPhotos.getString(String.valueOf(rawContactId));
+        return BitmapFactory.decodeFile(path);
+    }
+
     private void bindPhotoHandler(BaseRawContactEditorView editor, AccountType type,
             EntityDeltaList state) {
         final int mode;
@@ -1513,6 +1532,8 @@
         outState.putBoolean(KEY_NEW_LOCAL_PROFILE, mNewLocalProfile);
         outState.putBoolean(KEY_IS_USER_PROFILE, mIsUserProfile);
         outState.putInt(KEY_STATUS, mStatus);
+        outState.putParcelable(KEY_UPDATED_PHOTOS, mUpdatedPhotos);
+
         super.onSaveInstanceState(outState);
     }
 
@@ -1695,10 +1716,14 @@
      * state information in several of the listener methods.
      */
     private final class PhotoHandler extends PhotoSelectionHandler {
+
+        final long mRawContactId;
+
         public PhotoHandler(Context context, BaseRawContactEditorView editor, int photoMode,
                 EntityDeltaList state) {
             super(context, editor.getPhotoEditor(), photoMode, false, state);
             setListener(new PhotoEditorListener(editor));
+            mRawContactId = editor.getRawContactId();
         }
 
         private final class PhotoEditorListener extends PhotoSelectionHandler.PhotoActionListener
@@ -1748,6 +1773,10 @@
             @Override
             public void onRemovePictureChosen() {
                 mEditor.setPhotoBitmap(null);
+
+                // Prevent bitmap from being restored if rotate the device.
+                // (only if we first chose a new photo before removing it)
+                mUpdatedPhotos.remove(String.valueOf(mRawContactId));
             }
 
             @Override