Merge "Fix bug 5534667 - Action bar icons need more space on tablet" into ics-mr1
diff --git a/core/java/com/android/internal/view/menu/ActionMenuItemView.java b/core/java/com/android/internal/view/menu/ActionMenuItemView.java
index e245960..a10d241 100644
--- a/core/java/com/android/internal/view/menu/ActionMenuItemView.java
+++ b/core/java/com/android/internal/view/menu/ActionMenuItemView.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.res.Resources;
+import android.content.res.TypedArray;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.text.TextUtils;
@@ -46,8 +47,8 @@
     private ImageButton mImageButton;
     private Button mTextButton;
     private boolean mAllowTextWithIcon;
-    private boolean mShowTextAllCaps;
     private boolean mExpandedFormat;
+    private int mMinWidth;
 
     public ActionMenuItemView(Context context) {
         this(context, null);
@@ -62,7 +63,11 @@
         final Resources res = context.getResources();
         mAllowTextWithIcon = res.getBoolean(
                 com.android.internal.R.bool.config_allowActionMenuItemTextWithIcon);
-        mShowTextAllCaps = res.getBoolean(com.android.internal.R.bool.config_actionMenuItemAllCaps);
+        TypedArray a = context.obtainStyledAttributes(attrs,
+                com.android.internal.R.styleable.ActionMenuItemView, 0, 0);
+        mMinWidth = a.getDimensionPixelSize(
+                com.android.internal.R.styleable.ActionMenuItemView_minWidth, 0);
+        a.recycle();
     }
 
     @Override
@@ -228,4 +233,21 @@
         cheatSheet.show();
         return true;
     }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+
+        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
+        final int specSize = MeasureSpec.getSize(widthMeasureSpec);
+        final int oldMeasuredWidth = getMeasuredWidth();
+        final int targetWidth = widthMode == MeasureSpec.AT_MOST ? Math.min(specSize, mMinWidth)
+                : mMinWidth;
+
+        if (widthMode != MeasureSpec.EXACTLY && mMinWidth > 0 && oldMeasuredWidth < targetWidth) {
+            // Remeasure at exactly the minimum width.
+            super.onMeasure(MeasureSpec.makeMeasureSpec(targetWidth, MeasureSpec.EXACTLY),
+                    heightMeasureSpec);
+        }
+    }
 }
diff --git a/core/java/com/android/internal/view/menu/BaseMenuPresenter.java b/core/java/com/android/internal/view/menu/BaseMenuPresenter.java
index 1e06b5a..db0d6dd 100644
--- a/core/java/com/android/internal/view/menu/BaseMenuPresenter.java
+++ b/core/java/com/android/internal/view/menu/BaseMenuPresenter.java
@@ -91,7 +91,14 @@
                 MenuItemImpl item = visibleItems.get(i);
                 if (shouldIncludeItem(childIndex, item)) {
                     final View convertView = parent.getChildAt(childIndex);
+                    final MenuItemImpl oldItem = convertView instanceof MenuView.ItemView ?
+                            ((MenuView.ItemView) convertView).getItemData() : null;
                     final View itemView = getItemView(item, convertView, parent);
+                    if (item != oldItem) {
+                        // Don't let old states linger with new data.
+                        itemView.setPressed(false);
+                        itemView.jumpDrawablesToCurrentState();
+                    }
                     if (itemView != convertView) {
                         addItemView(itemView, childIndex);
                     }
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index e131242..4714be8 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -518,6 +518,7 @@
 
     public void setHomeButtonEnabled(boolean enable) {
         mHomeLayout.setEnabled(enable);
+        mHomeLayout.setFocusable(enable);
         // Make sure the home button has an accurate content description for accessibility.
         if (!enable) {
             mHomeLayout.setContentDescription(null);
diff --git a/core/res/res/values-sw600dp/dimens.xml b/core/res/res/values-sw600dp/dimens.xml
index 5dacb44..db94884 100644
--- a/core/res/res/values-sw600dp/dimens.xml
+++ b/core/res/res/values-sw600dp/dimens.xml
@@ -54,5 +54,7 @@
     <!-- Compensate for double margin : preference_screen_side_margin + 4 (frame background shadow) = -preference_screen_side_margin_negative -->
     <dimen name="preference_screen_side_margin_negative">-4dp</dimen>
 
+    <!-- Minimum width for an action button in the menu area of an action bar -->
+    <dimen name="action_button_min_width">64dip</dimen>
 </resources>
 
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 65e11b4..936482d 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -2394,6 +2394,10 @@
         <attr name="description" />
     </declare-styleable>
 
+    <declare-styleable name="ActionMenuItemView">
+        <attr name="minWidth" />
+    </declare-styleable>
+
     <!-- =============================== -->
     <!-- Widget package class attributes -->
     <!-- =============================== -->
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index dfd8306..607054a 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -189,4 +189,7 @@
     <dimen name="default_app_widget_padding_top">8dp</dimen>
     <dimen name="default_app_widget_padding_right">8dp</dimen>
     <dimen name="default_app_widget_padding_bottom">8dp</dimen>
+
+    <!-- Minimum width for an action button in the menu area of an action bar -->
+    <dimen name="action_button_min_width">56dip</dimen>
 </resources>
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index a4bdf23..9246954 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -1161,8 +1161,9 @@
         <item name="android:background">?android:attr/actionBarItemBackground</item>
         <item name="android:paddingLeft">12dip</item>
         <item name="android:paddingRight">12dip</item>
-        <item name="android:minWidth">56dip</item>
+        <item name="android:minWidth">@android:dimen/action_button_min_width</item>
         <item name="android:minHeight">?android:attr/actionBarSize</item>
+        <item name="android:gravity">center</item>
     </style>
 
     <style name="Widget.ActionButton.Overflow">
@@ -1359,7 +1360,7 @@
         <item name="android:textSize">12sp</item>
         <item name="android:textStyle">bold</item>
         <item name="android:textColor">?android:attr/actionMenuTextColor</item>
-        <item name="android:textAllCaps">true</item>
+        <item name="android:textAllCaps">@android:bool/config_actionMenuItemAllCaps</item>
     </style>
 
     <style name="TextAppearance.Holo.Widget.ActionMode">
@@ -1883,7 +1884,7 @@
     </style>
 
     <style name="Widget.Holo.ActionButton" parent="Widget.ActionButton">
-        <item name="android:minWidth">56dip</item>
+        <item name="android:minWidth">@android:dimen/action_button_min_width</item>
         <item name="android:gravity">center</item>
         <item name="android:paddingLeft">12dip</item>
         <item name="android:paddingRight">12dip</item>