OSDN Git Service

Fix a bug where OnTouchListeners in action views could be removed
authorAdam Powell <adamp@google.com>
Fri, 10 Jan 2014 18:16:27 +0000 (10:16 -0800)
committerAdam Powell <adamp@google.com>
Fri, 10 Jan 2014 18:16:27 +0000 (10:16 -0800)
ActionMenuPresenter should only replace the touch listener when binding
a generated item view.

Bug 12470259

Change-Id: I8c4c6110065605225a20cb7ed872255282085661

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

index 4654178..fe1cf72 100644 (file)
@@ -164,8 +164,24 @@ public class ActionMenuPresenter extends BaseMenuPresenter
         }
         actionView.setVisibility(item.isActionViewExpanded() ? View.GONE : View.VISIBLE);
 
+        final ActionMenuView menuParent = (ActionMenuView) parent;
+        final ViewGroup.LayoutParams lp = actionView.getLayoutParams();
+        if (!menuParent.checkLayoutParams(lp)) {
+            actionView.setLayoutParams(menuParent.generateLayoutParams(lp));
+        }
+        return actionView;
+    }
+
+    @Override
+    public void bindItemView(final MenuItemImpl item, MenuView.ItemView itemView) {
+        itemView.initialize(item, 0);
+
+        final ActionMenuView menuView = (ActionMenuView) mMenuView;
+        final ActionMenuItemView actionItemView = (ActionMenuItemView) itemView;
+        actionItemView.setItemInvoker(menuView);
+
         if (item.hasSubMenu()) {
-            actionView.setOnTouchListener(new ForwardingListener(actionView) {
+            actionItemView.setOnTouchListener(new ForwardingListener(actionItemView) {
                 @Override
                 public ListPopupWindow getPopup() {
                     return mActionButtonPopup != null ? mActionButtonPopup.getPopup() : null;
@@ -182,24 +198,8 @@ public class ActionMenuPresenter extends BaseMenuPresenter
                 }
             });
         } else {
-            actionView.setOnTouchListener(null);
+            actionItemView.setOnTouchListener(null);
         }
-
-        final ActionMenuView menuParent = (ActionMenuView) parent;
-        final ViewGroup.LayoutParams lp = actionView.getLayoutParams();
-        if (!menuParent.checkLayoutParams(lp)) {
-            actionView.setLayoutParams(menuParent.generateLayoutParams(lp));
-        }
-        return actionView;
-    }
-
-    @Override
-    public void bindItemView(MenuItemImpl item, MenuView.ItemView itemView) {
-        itemView.initialize(item, 0);
-
-        final ActionMenuView menuView = (ActionMenuView) mMenuView;
-        ActionMenuItemView actionItemView = (ActionMenuItemView) itemView;
-        actionItemView.setItemInvoker(menuView);
     }
 
     @Override