OSDN Git Service

Fix MenuItemImpl#hasCollapsibleActionView for action providers
authorAdam Powell <adamp@google.com>
Thu, 11 Jul 2013 23:17:10 +0000 (16:17 -0700)
committerAdam Powell <adamp@google.com>
Thu, 11 Jul 2013 23:24:12 +0000 (16:24 -0700)
hasCollapsibleActionView was previously checking only that mActionView
was not null, even if the item had a valid ActionProvider that would
later lazily create an action view when prompted. Account for this and
attempt to create the action view if needed when
hasCollapsibleActionView is called.

Bug 8732876

Change-Id: Idf7b329770f686208882509b82a4cb13c70ef32c

core/java/com/android/internal/view/menu/MenuItemImpl.java

index 39078ca..3d6b116 100644 (file)
@@ -616,7 +616,7 @@ public final class MenuItemImpl implements MenuItem {
 
     @Override
     public boolean expandActionView() {
-        if ((mShowAsAction & SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW) == 0 || mActionView == null) {
+        if (hasCollapsibleActionView()) {
             return false;
         }
 
@@ -653,7 +653,13 @@ public final class MenuItemImpl implements MenuItem {
     }
 
     public boolean hasCollapsibleActionView() {
-        return (mShowAsAction & SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW) != 0 && mActionView != null;
+        if ((mShowAsAction & SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW) != 0) {
+            if (mActionView == null && mActionProvider != null) {
+                mActionView = mActionProvider.onCreateActionView(this);
+            }
+            return mActionView != null;
+        }
+        return false;
     }
 
     public void setActionViewExpanded(boolean isExpanded) {