Merge "Fix alternate intent flags on quick contact"
diff --git a/res/layout/contact_list_filter_item.xml b/res/layout/contact_list_filter_item.xml
index 7c09976..7814565 100644
--- a/res/layout/contact_list_filter_item.xml
+++ b/res/layout/contact_list_filter_item.xml
@@ -17,6 +17,7 @@
 <view
     xmlns:android="http://schemas.android.com/apk/res/android"
     class="com.android.contacts.list.ContactListFilterView"
+    android:descendantFocusability="blocksDescendants"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:minHeight="@dimen/contact_filter_item_min_height"
@@ -45,12 +46,21 @@
 
         <TextView
             android:id="@+id/accountUserName"
+            android:layout_marginTop="-3dip"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textAppearance="?android:attr/textAppearanceSmall"
-            android:textColor="?android:attr/textColorSecondary"
+            android:textColor="?android:attr/textColorTertiary"
             android:singleLine="true"
             android:ellipsize="end"/>
     </LinearLayout>
+
+    <RadioButton
+        android:id="@+id/radioButton"
+        android:clickable="false"
+        android:layout_marginTop="1dip"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="right|center_vertical" />
 </view>
 
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
diff --git a/src/com/android/contacts/list/ContactListFilterView.java b/src/com/android/contacts/list/ContactListFilterView.java
index 3fa20a1..020952d 100644
--- a/src/com/android/contacts/list/ContactListFilterView.java
+++ b/src/com/android/contacts/list/ContactListFilterView.java
@@ -17,15 +17,18 @@
 package com.android.contacts.list;
 
 import com.android.contacts.R;
+import com.android.contacts.editor.ContactEditorFragment;
 import com.android.contacts.model.AccountType;
 import com.android.contacts.model.AccountTypeManager;
 import com.android.contacts.util.ThemeUtils;
 
 import android.content.Context;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
+import android.widget.RadioButton;
 import android.widget.TextView;
 
 /**
@@ -33,12 +36,14 @@
  */
 public class ContactListFilterView extends LinearLayout {
 
+    private static final String TAG = ContactListFilterView.class.getSimpleName();
+
     private ImageView mIcon;
     private TextView mAccountType;
     private TextView mAccountUserName;
+    private RadioButton mRadioButton;
     private ContactListFilter mFilter;
     private boolean mSingleAccount;
-    private int mActivatedBackground;
 
     public ContactListFilterView(Context context) {
         super(context);
@@ -60,16 +65,26 @@
         this.mSingleAccount = flag;
     }
 
-    public void bindView(AccountTypeManager accountTypes) {
-        if (mActivatedBackground == 0) {
-            mActivatedBackground = ThemeUtils.getActivatedBackground(getContext().getTheme());
+    @Override
+    public void setActivated(boolean activated) {
+        super.setActivated(activated);
+        if (mRadioButton != null) {
+            mRadioButton.setChecked(activated);
+        } else {
+            // We're guarding against null-pointer exceptions,
+            // but otherwise this code is not expected to work
+            // properly if the button hasn't been initialized.
+            Log.wtf(TAG, "radio-button cannot be activated because it is null");
         }
-        setBackgroundResource(mActivatedBackground);
+    }
 
+    public void bindView(AccountTypeManager accountTypes) {
         if (mAccountType == null) {
             mIcon = (ImageView) findViewById(R.id.icon);
             mAccountType = (TextView) findViewById(R.id.accountType);
             mAccountUserName = (TextView) findViewById(R.id.accountUserName);
+            mRadioButton = (RadioButton) findViewById(R.id.radioButton);
+            mRadioButton.setChecked(isActivated());
         }
 
         if (mFilter == null) {