Merge "Refactor Dialogs"
diff --git a/res/drawable-hdpi/list_item_pressed_bg.9.png b/res/drawable-hdpi/list_item_pressed_bg.9.png
new file mode 100644
index 0000000..74d8e53
--- /dev/null
+++ b/res/drawable-hdpi/list_item_pressed_bg.9.png
Binary files differ
diff --git a/res/drawable-hdpi/pinned_section_header.9.png b/res/drawable-hdpi/pinned_section_header.9.png
new file mode 100644
index 0000000..8cd231b
--- /dev/null
+++ b/res/drawable-hdpi/pinned_section_header.9.png
Binary files differ
diff --git a/res/drawable-mdpi/list_item_pressed_bg.9.png b/res/drawable-mdpi/list_item_pressed_bg.9.png
new file mode 100644
index 0000000..74d8e53
--- /dev/null
+++ b/res/drawable-mdpi/list_item_pressed_bg.9.png
Binary files differ
diff --git a/res/drawable-mdpi/pinned_section_header.9.png b/res/drawable-mdpi/pinned_section_header.9.png
new file mode 100644
index 0000000..ac906cd
--- /dev/null
+++ b/res/drawable-mdpi/pinned_section_header.9.png
Binary files differ
diff --git a/res/drawable-xlarge/divider_vertical_dark.9.png b/res/drawable-xlarge/divider_vertical_dark.9.png
new file mode 100644
index 0000000..38b794b
--- /dev/null
+++ b/res/drawable-xlarge/divider_vertical_dark.9.png
Binary files differ
diff --git a/res/drawable-xlarge/pinned_section_header.9.png b/res/drawable-xlarge/pinned_section_header.9.png
new file mode 100644
index 0000000..24a0613
--- /dev/null
+++ b/res/drawable-xlarge/pinned_section_header.9.png
Binary files differ
diff --git a/res/layout-xlarge/list_section.xml b/res/layout-xlarge/list_section.xml
index 84d6e43..5504084 100644
--- a/res/layout-xlarge/list_section.xml
+++ b/res/layout-xlarge/list_section.xml
@@ -19,7 +19,7 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="37dip"
-    android:background="@drawable/section_header"
+    android:background="@drawable/pinned_section_header"
     >
     <TextView
         android:id="@+id/header_text"
diff --git a/res/values-xlarge/dimens.xml b/res/values-xlarge/dimens.xml
index d5d86c9..300c9d9 100644
--- a/res/values-xlarge/dimens.xml
+++ b/res/values-xlarge/dimens.xml
@@ -18,8 +18,4 @@
     <!-- Size of the text in the aizy visual scroll control -->
     <dimen name="aizy_text_size">12sp</dimen>
 
-    <dimen name="list_item_padding_top">0dip</dimen>
-    <dimen name="list_item_padding_bottom">0dip</dimen>
-    <dimen name="list_item_photo_size">64dip</dimen>
-
 </resources>
diff --git a/res/values-xlarge/styles.xml b/res/values-xlarge/styles.xml
index 9281e66..48923fe 100644
--- a/res/values-xlarge/styles.xml
+++ b/res/values-xlarge/styles.xml
@@ -16,14 +16,36 @@
 
 <resources>
     <style name="ContactBrowserTheme" parent="@android:Theme.Light.Holo">
+        <item name="pressedBackground">@drawable/list_item_pressed_bg</item>
+        <item name="list_item_padding_top">0dip</item>
+        <item name="list_item_padding_right">11dip</item>
+        <item name="list_item_padding_bottom">0dip</item>
+        <item name="list_item_padding_left">4dip</item>
+        <item name="list_item_gap_between_image_and_text">8dip</item>
+        <item name="list_item_gap_between_label_and_data">5dip</item>
+        <item name="list_item_call_button_padding">14dip</item>
+        <item name="list_item_vertical_divider_margin">5dip</item>
+        <item name="list_item_presence_icon_margin">5dip</item>
+        <item name="list_item_header_text_width">56dip</item>
+        <item name="list_item_photo_size">64dip</item>
     </style>
+
     <style name="ContactPickerTheme" parent="@android:Theme.Dialog">
+        <item name="list_item_padding_top">0dip</item>
+        <item name="list_item_padding_right">11dip</item>
+        <item name="list_item_padding_bottom">0dip</item>
+        <item name="list_item_padding_left">4dip</item>
+        <item name="list_item_gap_between_image_and_text">8dip</item>
+        <item name="list_item_gap_between_label_and_data">5dip</item>
+        <item name="list_item_call_button_padding">14dip</item>
+        <item name="list_item_vertical_divider_margin">5dip</item>
+        <item name="list_item_presence_icon_margin">5dip</item>
+        <item name="list_item_header_text_width">56dip</item>
+        <item name="list_item_photo_size">64dip</item>
     </style>
+    
     <style name="ContactsPreferencesTheme" parent="@android:Theme.Dialog">
     </style>
-    <style name="JoinContactActivityTheme" parent="@android:Theme.Dialog">
-        <item name="android:windowContentOverlay">@null</item>
-    </style>
     <style name="CallDetailActivityTheme" parent="@android:Theme.Dialog">
         <item name="android:windowContentOverlay">@null</item>
     </style>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index c0ce680..e995c6e 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -28,22 +28,6 @@
     <dimen name="contact_shortcut_frame_width">50dip</dimen>    
     <dimen name="contact_shortcut_frame_height">56dip</dimen>    
     
-    <!-- Dimensions for a list item -->
-    <dimen name="list_item_padding_top">4dip</dimen>    
-    <dimen name="list_item_padding_right">11dip</dimen>    
-    <dimen name="list_item_padding_bottom">4dip</dimen>    
-    <dimen name="list_item_padding_left">4dip</dimen>    
-    <dimen name="list_item_gap_between_image_and_text">8dip</dimen>    
-    <dimen name="list_item_gap_between_label_and_data">5dip</dimen>    
-    <dimen name="list_item_call_button_padding">14dip</dimen>    
-    <dimen name="list_item_vertical_divider_margin">5dip</dimen>    
-    <dimen name="list_item_presence_icon_margin">5dip</dimen>    
-    <dimen name="list_item_header_text_width">56dip</dimen>    
-    <dimen name="list_item_header_chip_width">4dip</dimen>
-    <dimen name="list_item_header_chip_right_margin">4dip</dimen>
-    <dimen name="list_item_header_checkbox_margin">5dip</dimen>
-    <dimen name="list_item_photo_size">56dip</dimen>
-
     <dimen name="aggregation_suggestion_icon_size">40dip</dimen>
 
     <!-- Size of the text in the aizy visual scroll control -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index c52bb1f..f5256ee 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -50,9 +50,6 @@
         <item name="android:src">@drawable/ic_btn_round_less</item>
     </style>
 
-    <style name="JoinContactActivityTheme" parent="android:Theme.NoTitleBar">
-        <item name="android:windowContentOverlay">@null</item>
-    </style>
     <style name="CallDetailActivityTheme" parent="android:Theme.NoTitleBar">
         <item name="android:windowContentOverlay">@null</item>
     </style>
@@ -113,13 +110,68 @@
     <style name="DummyAnimation">
         <item name="android:windowExitAnimation">@anim/dummy_animation</item>
     </style>
-    
+
+    <declare-styleable name="ContactListItemView">
+        <!-- An attribute that specifies a custom drawable for the pressed state in the contact list-->
+        <attr name="pressedBackground" format="reference"/>
+
+        <attr name="list_item_padding_top" format="dimension"/>
+        <attr name="list_item_padding_right" format="dimension"/>
+        <attr name="list_item_padding_bottom" format="dimension"/>
+        <attr name="list_item_padding_left" format="dimension"/>
+        <attr name="list_item_gap_between_image_and_text" format="dimension"/>
+        <attr name="list_item_gap_between_label_and_data" format="dimension"/>
+        <attr name="list_item_call_button_padding" format="dimension"/>
+        <attr name="list_item_vertical_divider_margin" format="dimension"/>
+        <attr name="list_item_presence_icon_margin" format="dimension"/>
+        <attr name="list_item_header_text_width" format="dimension"/>
+        <attr name="list_item_photo_size" format="dimension"/>
+
+    </declare-styleable>
+
+    <declare-styleable name="MultiplePhonePickerItemView">
+        <attr name="list_item_header_chip_width" format="dimension"/>
+        <attr name="list_item_header_chip_right_margin" format="dimension"/>
+        <attr name="list_item_header_checkbox_margin" format="dimension"/>
+    </declare-styleable>
+
     <style name="ContactBrowserTheme" parent="@android:Theme">
+        <item name="pressedBackground">@*android:drawable/list_selector_background</item>
+        <item name="list_item_padding_top">4dip</item>
+        <item name="list_item_padding_right">11dip</item>
+        <item name="list_item_padding_bottom">4dip</item>
+        <item name="list_item_padding_left">4dip</item>
+        <item name="list_item_gap_between_image_and_text">8dip</item>
+        <item name="list_item_gap_between_label_and_data">5dip</item>
+        <item name="list_item_call_button_padding">14dip</item>
+        <item name="list_item_vertical_divider_margin">5dip</item>
+        <item name="list_item_presence_icon_margin">5dip</item>
+        <item name="list_item_header_text_width">56dip</item>
+        <item name="list_item_photo_size">56dip</item>
     </style>
 
     <style name="ContactPickerTheme" parent="@android:Theme">
+        <item name="list_item_padding_top">4dip</item>
+        <item name="list_item_padding_right">11dip</item>
+        <item name="list_item_padding_bottom">4dip</item>
+        <item name="list_item_padding_left">4dip</item>
+        <item name="list_item_gap_between_image_and_text">8dip</item>
+        <item name="list_item_gap_between_label_and_data">5dip</item>
+        <item name="list_item_call_button_padding">14dip</item>
+        <item name="list_item_vertical_divider_margin">5dip</item>
+        <item name="list_item_presence_icon_margin">5dip</item>
+        <item name="list_item_header_text_width">56dip</item>
+        <item name="list_item_photo_size">56dip</item>
+        <item name="list_item_header_chip_width">4dip</item>
+        <item name="list_item_header_chip_right_margin">4dip</item>
+        <item name="list_item_header_checkbox_margin">5dip</item>
     </style>
 
+    <style name="JoinContactActivityTheme" parent="ContactPickerTheme">
+        <item name="android:windowNoTitle">true</item>
+        <item name="android:windowContentOverlay">@null</item>
+    </style>
+    
     <style name="ContactsPreferencesTheme" parent="@android:Theme">
     </style>
 </resources>
diff --git a/src/com/android/contacts/ContactEntryListView.java b/src/com/android/contacts/ContactEntryListView.java
index 21ff25e..b5dfbeb 100644
--- a/src/com/android/contacts/ContactEntryListView.java
+++ b/src/com/android/contacts/ContactEntryListView.java
@@ -21,6 +21,10 @@
 import com.android.contacts.widget.TextHighlightingAnimation;
 
 import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.PixelFormat;
+import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.widget.AbsListView;
 import android.widget.ListAdapter;
@@ -37,6 +41,9 @@
             new ContactNameHighlightingAnimation(this, TEXT_HIGHLIGHTING_ANIMATION_DURATION);
 
     private boolean mHighlightNamesWhenScrolling;
+    private Drawable mDefaultSelector;
+    private boolean mSelectionVisible;
+    private ContactEntryListAdapter mAdapter;
 
     public ContactEntryListView(Context context) {
         this(context, null);
@@ -50,6 +57,7 @@
         super(context, attrs, defStyle);
         setPinnedHeaderBackgroundColor(
                 context.getResources().getColor(R.color.pinned_header_background));
+        mDefaultSelector = getSelector();
     }
 
     public TextHighlightingAnimation getTextHighlightingAnimation() {
@@ -64,6 +72,19 @@
         mHighlightNamesWhenScrolling = flag;
     }
 
+    public void setSelectionVisible(boolean selectionVisible) {
+        if (selectionVisible != mSelectionVisible) {
+            mSelectionVisible = selectionVisible;
+            if (selectionVisible) {
+                // When a persistent selection is handled by the adapter,
+                // we want to disable the standard selection drawing.
+                setSelector(new EmptyDrawable());
+            } else {
+                setSelector(mDefaultSelector);
+            }
+        }
+    }
+
     @Override
     public void setAdapter(ListAdapter adapter) {
         super.setAdapter(adapter);
@@ -84,4 +105,28 @@
             }
         }
     }
+
+    /**
+     * A drawable that is ignored.  We have to use an empty drawable instead
+     * of null, because ListView does not allow selection to be null.
+     */
+    private class EmptyDrawable extends Drawable {
+
+        @Override
+        public void draw(Canvas canvas) {
+        }
+
+        @Override
+        public int getOpacity() {
+            return PixelFormat.OPAQUE;
+        }
+
+        @Override
+        public void setAlpha(int alpha) {
+        }
+
+        @Override
+        public void setColorFilter(ColorFilter cf) {
+        }
+    }
 }
diff --git a/src/com/android/contacts/list/ContactEntryListFragment.java b/src/com/android/contacts/list/ContactEntryListFragment.java
index 29d40bb..235f8f3 100644
--- a/src/com/android/contacts/list/ContactEntryListFragment.java
+++ b/src/com/android/contacts/list/ContactEntryListFragment.java
@@ -283,6 +283,11 @@
 
         loadPreferences();
 
+        if (mListView instanceof ContactEntryListView) {
+            ContactEntryListView listView = (ContactEntryListView)mListView;
+            listView.setSelectionVisible(isSelectionVisible());
+        }
+
         mForceLoad = false;
         mLoadDirectoryList = true;
         mLoadPriorityDirectoriesOnly = true;
diff --git a/src/com/android/contacts/list/ContactListItemView.java b/src/com/android/contacts/list/ContactListItemView.java
index af429e4..e3c6001 100644
--- a/src/com/android/contacts/list/ContactListItemView.java
+++ b/src/com/android/contacts/list/ContactListItemView.java
@@ -22,7 +22,6 @@
 import com.android.contacts.widget.TextWithHighlightingFactory;
 
 import android.content.Context;
-import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.database.CharArrayBuffer;
 import android.database.Cursor;
@@ -68,6 +67,7 @@
     private final int mPresenceIconMargin;
     private final int mHeaderTextWidth;
 
+    private Drawable mPressedBackgroundDrawable;
     private Drawable mSelectedBackgroundDrawable;
 
     private boolean mHorizontalDividerVisible = true;
@@ -94,6 +94,7 @@
     private TextView mSnippetView;
     private ImageView mPresenceIcon;
 
+    private int mDefaultPhotoViewSize;
     private int mPhotoViewWidth;
     private int mPhotoViewHeight;
     private int mLine1Height;
@@ -111,7 +112,6 @@
 
     private CharSequence mUnknownNameText;
 
-
     /**
      * Special class to allow the parent to be pressed without being pressed itself.
      * This way the line of a tab can be pressed, but the image itself is not.
@@ -143,27 +143,33 @@
                 a.getDimensionPixelSize(android.R.styleable.Theme_listPreferredItemHeight, 0);
         a.recycle();
 
-        Resources resources = context.getResources();
-        mVerticalDividerMargin =
-                resources.getDimensionPixelOffset(R.dimen.list_item_vertical_divider_margin);
-        mPaddingTop =
-                resources.getDimensionPixelOffset(R.dimen.list_item_padding_top);
-        mPaddingBottom =
-                resources.getDimensionPixelOffset(R.dimen.list_item_padding_bottom);
-        mPaddingLeft =
-                resources.getDimensionPixelOffset(R.dimen.list_item_padding_left);
-        mPaddingRight =
-                resources.getDimensionPixelOffset(R.dimen.list_item_padding_right);
-        mGapBetweenImageAndText =
-                resources.getDimensionPixelOffset(R.dimen.list_item_gap_between_image_and_text);
-        mGapBetweenLabelAndData =
-                resources.getDimensionPixelOffset(R.dimen.list_item_gap_between_label_and_data);
-        mCallButtonPadding =
-                resources.getDimensionPixelOffset(R.dimen.list_item_call_button_padding);
-        mPresenceIconMargin =
-                resources.getDimensionPixelOffset(R.dimen.list_item_presence_icon_margin);
-        mHeaderTextWidth =
-                resources.getDimensionPixelOffset(R.dimen.list_item_header_text_width);
+        a = getContext().obtainStyledAttributes(attrs,R.styleable.ContactListItemView);
+        mPressedBackgroundDrawable = a.getDrawable(
+                R.styleable.ContactListItemView_pressedBackground);
+        mVerticalDividerMargin = a.getDimensionPixelOffset(
+                R.styleable.ContactListItemView_list_item_vertical_divider_margin, 0);
+        mPaddingTop = a.getDimensionPixelOffset(
+                R.styleable.ContactListItemView_list_item_padding_top, 0);
+        mPaddingBottom = a.getDimensionPixelOffset(
+                R.styleable.ContactListItemView_list_item_padding_bottom, 0);
+        mPaddingLeft = a.getDimensionPixelOffset(
+                R.styleable.ContactListItemView_list_item_padding_left, 0);
+        mPaddingRight = a.getDimensionPixelOffset(
+                R.styleable.ContactListItemView_list_item_padding_right, 0);
+        mGapBetweenImageAndText = a.getDimensionPixelOffset(
+                R.styleable.ContactListItemView_list_item_gap_between_image_and_text, 0);
+        mGapBetweenLabelAndData = a.getDimensionPixelOffset(
+                R.styleable.ContactListItemView_list_item_gap_between_label_and_data, 0);
+        mCallButtonPadding = a.getDimensionPixelOffset(
+                R.styleable.ContactListItemView_list_item_call_button_padding, 0);
+        mPresenceIconMargin = a.getDimensionPixelOffset(
+                R.styleable.ContactListItemView_list_item_presence_icon_margin, 0);
+        mHeaderTextWidth = a.getDimensionPixelOffset(
+                R.styleable.ContactListItemView_list_item_header_text_width, 0);
+        mDefaultPhotoViewSize = a.getDimensionPixelOffset(
+                R.styleable.ContactListItemView_list_item_photo_size, 0);
+
+        a.recycle();
     }
 
     /**
@@ -285,10 +291,14 @@
         }
 
         if (mItemSelected) {
-            ensureCheckedBackgroundDivider();
+            ensureSelectedBackgroundDrawable();
             mSelectedBackgroundDrawable.setBounds(0, topBound, width, bottomBound);
         }
 
+        if (mPressedBackgroundDrawable != null) {
+            mPressedBackgroundDrawable.setBounds(0, topBound, width, bottomBound);
+        }
+
         topBound += mPaddingTop;
         bottomBound -= mPaddingBottom;
 
@@ -411,7 +421,7 @@
     /**
      * Loads the drawable for the item background used when the item is checked.
      */
-    private void ensureCheckedBackgroundDivider() {
+    private void ensureSelectedBackgroundDrawable() {
         if (mSelectedBackgroundDrawable == null) {
             mSelectedBackgroundDrawable = mContext.getResources().getDrawable(
                     R.drawable.list_item_checked_bg);
@@ -469,15 +479,25 @@
                         ViewGroup.LayoutParams.WRAP_CONTENT);
                 a.recycle();
             } else {
-                mPhotoViewWidth = mPhotoViewHeight =
-                    mContext.getResources().getDimensionPixelSize(R.dimen.list_item_photo_size);
+                mPhotoViewWidth = mPhotoViewHeight = mDefaultPhotoViewSize;
             }
         }
     }
 
     @Override
+    protected void drawableStateChanged() {
+        super.drawableStateChanged();
+        if (mPressedBackgroundDrawable != null) {
+            mPressedBackgroundDrawable.setState(getDrawableState());
+            invalidate();
+        }
+    }
+
+    @Override
     public void dispatchDraw(Canvas canvas) {
-        if (mItemSelected) {
+        if (isPressed() && mPressedBackgroundDrawable != null) {
+            mPressedBackgroundDrawable.draw(canvas);
+        } else if (mItemSelected) {
             mSelectedBackgroundDrawable.draw(canvas);
         }
         if (mHeaderVisible) {
diff --git a/src/com/android/contacts/list/MultiplePhonePickerItemView.java b/src/com/android/contacts/list/MultiplePhonePickerItemView.java
index e865c1f..87f53bf 100644
--- a/src/com/android/contacts/list/MultiplePhonePickerItemView.java
+++ b/src/com/android/contacts/list/MultiplePhonePickerItemView.java
@@ -19,7 +19,7 @@
 import com.android.contacts.R;
 
 import android.content.Context;
-import android.content.res.Resources;
+import android.content.res.TypedArray;
 import android.util.AttributeSet;
 import android.view.View;
 import android.widget.CheckBox;
@@ -44,13 +44,15 @@
 
     public MultiplePhonePickerItemView(Context context, AttributeSet attrs) {
         super(context, attrs);
-        Resources resources = context.getResources();
-        mChipWidth =
-                resources.getDimensionPixelOffset(R.dimen.list_item_header_chip_width);
-        mChipRightMargin =
-                resources.getDimensionPixelOffset(R.dimen.list_item_header_chip_right_margin);
-        mCheckBoxMargin =
-                resources.getDimensionPixelOffset(R.dimen.list_item_header_checkbox_margin);
+        TypedArray a = getContext().obtainStyledAttributes(
+                attrs, R.styleable.MultiplePhonePickerItemView);
+        mChipWidth = a.getDimensionPixelOffset(
+                R.styleable.MultiplePhonePickerItemView_list_item_header_chip_width, 0);
+        mChipRightMargin = a.getDimensionPixelOffset(
+                R.styleable.MultiplePhonePickerItemView_list_item_header_chip_right_margin, 0);
+        mCheckBoxMargin = a.getDimensionPixelOffset(
+                R.styleable.MultiplePhonePickerItemView_list_item_header_checkbox_margin, 0);
+        a.recycle();
     }
 
     @Override