Bug 1391579 Part 1: add attribute itemType to GeckoMenuItem
MozReview-Commit-ID: CelYcXveCvO
--- a/mobile/android/app/src/main/res/values/attrs.xml
+++ b/mobile/android/app/src/main/res/values/attrs.xml
@@ -50,16 +50,19 @@
<attr name="android:orderInCategory"/>
<attr name="android:title"/>
<attr name="android:icon"/>
<attr name="android:checkable"/>
<attr name="android:checked"/>
<attr name="android:visible"/>
<attr name="android:enabled"/>
<attr name="android:showAsAction"/>
+ <attr name="itemType" type="enum">
+ <enum name="default_menu_item" value="0x00" />
+ </attr>
</declare-styleable>
<declare-styleable name="MenuItemDefault">
<attr name="state_more" format="boolean"/>
</declare-styleable>
<declare-styleable name="TabThumbnailWrapper">
<attr name="state_recording" format="boolean"/>
--- a/mobile/android/base/java/org/mozilla/gecko/menu/GeckoMenuInflater.java
+++ b/mobile/android/base/java/org/mozilla/gecko/menu/GeckoMenuInflater.java
@@ -36,16 +36,17 @@ public class GeckoMenuInflater extends M
public CharSequence title;
public int iconRes;
public boolean checkable;
public boolean checked;
public boolean visible;
public boolean enabled;
public int showAsAction;
public boolean hasSubMenu;
+ public int itemType;
}
public GeckoMenuInflater(Context context) {
super(context);
mContext = context;
}
@Override
@@ -126,29 +127,31 @@ public class GeckoMenuInflater extends M
item.title = a.getText(R.styleable.MenuItem_android_title);
item.checkable = a.getBoolean(R.styleable.MenuItem_android_checkable, false);
item.checked = a.getBoolean(R.styleable.MenuItem_android_checked, false);
item.visible = a.getBoolean(R.styleable.MenuItem_android_visible, true);
item.enabled = a.getBoolean(R.styleable.MenuItem_android_enabled, true);
item.hasSubMenu = false;
item.iconRes = a.getResourceId(R.styleable.MenuItem_android_icon, 0);
item.showAsAction = a.getInt(R.styleable.MenuItem_android_showAsAction, 0);
+ item.itemType = a.getInt(R.styleable.MenuItem_itemType, GeckoMenuItem.ITEM_TYPE_DEFAULT);
a.recycle();
}
public void setValues(ParsedItem item, MenuItem menuItem) {
// We are blocking any presenter updates during inflation.
GeckoMenuItem geckoItem = null;
if (menuItem instanceof GeckoMenuItem) {
geckoItem = (GeckoMenuItem) menuItem;
}
if (geckoItem != null) {
geckoItem.stopDispatchingChanges();
+ geckoItem.setItemType(item.itemType);
}
menuItem.setChecked(item.checked)
.setVisible(item.visible)
.setEnabled(item.enabled)
.setCheckable(item.checkable)
.setIcon(item.iconRes);
--- a/mobile/android/base/java/org/mozilla/gecko/menu/GeckoMenuItem.java
+++ b/mobile/android/base/java/org/mozilla/gecko/menu/GeckoMenuItem.java
@@ -22,32 +22,35 @@ public class GeckoMenuItem implements Me
// 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;
+ public static final int ITEM_TYPE_DEFAULT = 0x00;
+
// 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 int mItemType;
private View mActionView;
private int mActionEnum;
private CharSequence mTitle;
private CharSequence mTitleCondensed;
private boolean mCheckable;
private boolean mChecked;
private boolean mVisible = true;
private boolean mEnabled = true;
@@ -445,16 +448,24 @@ public class GeckoMenuItem implements Me
mMenu.onItemChanged(this);
} else {
mDidChange = true;
}
}
return this;
}
+ public int getItemType() {
+ return mItemType;
+ }
+
+ public void setItemType(int itemType) {
+ mItemType = itemType;
+ }
+
public boolean invoke() {
if (mMenuItemClickListener != null)
return mMenuItemClickListener.onMenuItemClick(this);
else
return false;
}
public void setOnShowAsActionChangedListener(OnShowAsActionChangedListener listener) {