Bug 1353019: fix icon creation issue in GeckoMenuItem draft
authorJulian_Chu <walkingice0204@gmail.com>
Wed, 19 Apr 2017 15:39:14 +0800
changeset 564994 3296b6b3c2e78f3ee7814839f878b74c3c596c72
parent 564706 3f9f6d6086b2d247831d1d03d530095bebd5a6b2
child 564995 f2c583315bd0b7fe21534b75e929ee3fe22efff8
push id54746
push userbmo:walkingice0204@gmail.com
push dateWed, 19 Apr 2017 09:41:41 +0000
bugs1353019
milestone55.0a1
Bug 1353019: fix icon creation issue in GeckoMenuItem If change icon via resource id, we should create mIcon as well. And method `getIcon` should return the drawable which be used currently, but not generating a new drawable via resource id. Without this patch, we cannot change icon of a GeckoMenuItem until we set the icon back. ie. Drawable icon = menuItem.getIcon(); icon.setLevel(42); // does not work, cause the icon is new instance. MozReview-Commit-ID: KxW66OgI9po
mobile/android/base/java/org/mozilla/gecko/menu/GeckoMenuItem.java
--- a/mobile/android/base/java/org/mozilla/gecko/menu/GeckoMenuItem.java
+++ b/mobile/android/base/java/org/mozilla/gecko/menu/GeckoMenuItem.java
@@ -1,46 +1,48 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.menu;
 
-import org.mozilla.gecko.R;
-import org.mozilla.gecko.util.ResourceDrawableUtils;
-import org.mozilla.gecko.widget.GeckoActionProvider;
-
 import android.content.Intent;
 import android.graphics.drawable.Drawable;
 import android.text.TextUtils;
 import android.view.ActionProvider;
 import android.view.ContextMenu;
 import android.view.MenuItem;
 import android.view.SubMenu;
 import android.view.View;
 
+import org.mozilla.gecko.R;
+import org.mozilla.gecko.util.ResourceDrawableUtils;
+import org.mozilla.gecko.widget.GeckoActionProvider;
+
 public class GeckoMenuItem implements MenuItem {
     private static final int SHARE_BAR_HISTORY_SIZE = 2;
 
     // These values mirror MenuItem values that are only available on API >= 11.
     public static final int SHOW_AS_ACTION_NEVER = 0;
     public static final int SHOW_AS_ACTION_IF_ROOM = 1;
     public static final int SHOW_AS_ACTION_ALWAYS = 2;
     public static final int SHOW_AS_ACTION_WITH_TEXT = 4;
     public static final int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW = 8;
 
     // A View that can show a MenuItem should be able to initialize from
     // the properties of the MenuItem.
     public static interface Layout {
         public void initialize(GeckoMenuItem item);
+
         public void setShowIcon(boolean show);
     }
 
     public static interface OnShowAsActionChangedListener {
         public boolean hasActionItemBar();
+
         public void onShowAsActionChanged(GeckoMenuItem item);
     }
 
     private final int mId;
     private final int mOrder;
     private View mActionView;
     private int mActionEnum;
     private CharSequence mTitle;
@@ -149,24 +151,17 @@ public class GeckoMenuItem implements Me
 
     @Override
     public int getGroupId() {
         return 0;
     }
 
     @Override
     public Drawable getIcon() {
-        if (mIcon == null) {
-            if (mIconRes != 0)
-                return ResourceDrawableUtils.getDrawable(mMenu.getContext(), mIconRes);
-            else
-                return null;
-        } else {
-            return mIcon;
-        }
+        return mIcon;
     }
 
     @Override
     public Intent getIntent() {
         return null;
     }
 
     @Override
@@ -330,21 +325,17 @@ public class GeckoMenuItem implements Me
         }
         return this;
     }
 
     @Override
     public MenuItem setIcon(int iconRes) {
         if (mIconRes != iconRes) {
             mIconRes = iconRes;
-            if (mShouldDispatchChanges) {
-                mMenu.onItemChanged(this);
-            } else {
-                mDidChange = true;
-            }
+            setIcon(ResourceDrawableUtils.getDrawable(mMenu.getContext(), mIconRes));
         }
         return this;
     }
 
     @Override
     public MenuItem setIntent(Intent intent) {
         return this;
     }