mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-11 14:28:42 +00:00
Bug 940997: Support showAsAction "ifRoom" in custom menu. [r=mfinkle]
This commit is contained in:
parent
5ddba12a47
commit
7b69586592
@ -246,7 +246,8 @@ class TextSelection extends Layer implements GeckoEventListener {
|
||||
try {
|
||||
final JSONObject obj = mItems.getJSONObject(i);
|
||||
final GeckoMenuItem menuitem = (GeckoMenuItem) menu.add(0, i, 0, obj.optString("label"));
|
||||
menuitem.setShowAsAction(obj.optBoolean("showAsAction") ? 1 : 0, R.attr.menuItemActionModeStyle);
|
||||
final int actionEnum = obj.optBoolean("showAsAction") ? GeckoMenuItem.SHOW_AS_ACTION_ALWAYS : GeckoMenuItem.SHOW_AS_ACTION_NEVER;
|
||||
menuitem.setShowAsAction(actionEnum, R.attr.menuItemActionModeStyle);
|
||||
|
||||
BitmapUtils.getDrawable(mStartHandle.getContext(), obj.optString("icon"), new BitmapLoader() {
|
||||
public void onBitmapFound(Drawable d) {
|
||||
|
@ -78,8 +78,11 @@ public class GeckoMenu extends ListView
|
||||
// List of all menu items.
|
||||
private List<GeckoMenuItem> mItems;
|
||||
|
||||
// Map of items in action-bar and their views.
|
||||
private Map<GeckoMenuItem, View> mActionItems;
|
||||
// Map of "always" action-items in action-bar and their views.
|
||||
private Map<GeckoMenuItem, View> mPrimaryActionItems;
|
||||
|
||||
// Map of "ifRoom" action-items in action-bar and their views.
|
||||
private Map<GeckoMenuItem, View> mSecondaryActionItems;
|
||||
|
||||
// Reference to a callback for menu events.
|
||||
private Callback mCallback;
|
||||
@ -87,8 +90,11 @@ public class GeckoMenu extends ListView
|
||||
// Reference to menu presenter.
|
||||
private MenuPresenter mMenuPresenter;
|
||||
|
||||
// Reference to action-items bar in action-bar.
|
||||
private ActionItemBarPresenter mActionItemBarPresenter;
|
||||
// Reference to "always" action-items bar in action-bar.
|
||||
private ActionItemBarPresenter mPrimaryActionItemBar;
|
||||
|
||||
// Reference to "ifRoom" action-items bar in action-bar.
|
||||
private final ActionItemBarPresenter mSecondaryActionItemBar;
|
||||
|
||||
// Adapter to hold the list of menu items.
|
||||
private MenuItemsAdapter mAdapter;
|
||||
@ -113,9 +119,11 @@ public class GeckoMenu extends ListView
|
||||
setOnItemClickListener(this);
|
||||
|
||||
mItems = new ArrayList<GeckoMenuItem>();
|
||||
mActionItems = new HashMap<GeckoMenuItem, View>();
|
||||
mPrimaryActionItems = new HashMap<GeckoMenuItem, View>();
|
||||
mSecondaryActionItems = new HashMap<GeckoMenuItem, View>();
|
||||
|
||||
mActionItemBarPresenter = (DefaultActionItemBar) LayoutInflater.from(context).inflate(R.layout.menu_action_bar, null);
|
||||
mPrimaryActionItemBar = (DefaultActionItemBar) LayoutInflater.from(context).inflate(R.layout.menu_action_bar, null);
|
||||
mSecondaryActionItemBar = (DefaultActionItemBar) LayoutInflater.from(context).inflate(R.layout.menu_secondary_action_bar, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -155,28 +163,55 @@ public class GeckoMenu extends ListView
|
||||
private boolean addActionItem(final GeckoMenuItem menuItem) {
|
||||
menuItem.setOnShowAsActionChangedListener(this);
|
||||
|
||||
if (mActionItems.size() == 0 &&
|
||||
mActionItemBarPresenter instanceof DefaultActionItemBar) {
|
||||
// Reset the adapter before adding the header view to a list.
|
||||
setAdapter(null);
|
||||
addHeaderView((DefaultActionItemBar) mActionItemBarPresenter);
|
||||
setAdapter(mAdapter);
|
||||
}
|
||||
final View actionView = menuItem.getActionView();
|
||||
final int actionEnum = menuItem.getActionEnum();
|
||||
boolean added = false;
|
||||
|
||||
View actionView = menuItem.getActionView();
|
||||
actionView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
handleMenuItemClick(menuItem);
|
||||
if (actionEnum == GeckoMenuItem.SHOW_AS_ACTION_ALWAYS) {
|
||||
if (mPrimaryActionItems.size() == 0 &&
|
||||
mPrimaryActionItemBar instanceof DefaultActionItemBar) {
|
||||
// Reset the adapter before adding the header view to a list.
|
||||
setAdapter(null);
|
||||
addHeaderView((DefaultActionItemBar) mPrimaryActionItemBar);
|
||||
setAdapter(mAdapter);
|
||||
}
|
||||
});
|
||||
|
||||
if (mActionItemBarPresenter.addActionItem(actionView)) {
|
||||
mActionItems.put(menuItem, actionView);
|
||||
mItems.add(menuItem);
|
||||
return true;
|
||||
if (added = mPrimaryActionItemBar.addActionItem(actionView)) {
|
||||
mPrimaryActionItems.put(menuItem, actionView);
|
||||
mItems.add(menuItem);
|
||||
}
|
||||
} else if (actionEnum == GeckoMenuItem.SHOW_AS_ACTION_IF_ROOM) {
|
||||
if (mSecondaryActionItems.size() == 0) {
|
||||
// Reset the adapter before adding the header view to a list.
|
||||
setAdapter(null);
|
||||
addHeaderView((DefaultActionItemBar) mSecondaryActionItemBar);
|
||||
setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
if (added = mSecondaryActionItemBar.addActionItem(actionView)) {
|
||||
mSecondaryActionItems.put(menuItem, actionView);
|
||||
mItems.add(menuItem);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
// Set the listeners.
|
||||
if (actionView instanceof MenuItemActionBar) {
|
||||
((MenuItemActionBar) actionView).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
handleMenuItemClick(menuItem);
|
||||
}
|
||||
});
|
||||
} else if (actionView instanceof MenuItemActionView) {
|
||||
((MenuItemActionView) actionView).setMenuItemClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
handleMenuItemClick(menuItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -217,10 +252,17 @@ public class GeckoMenu extends ListView
|
||||
return subMenu;
|
||||
}
|
||||
|
||||
private void removeActionBarView() {
|
||||
private void removePrimaryActionBarView() {
|
||||
// Reset the adapter before removing the header view from a list.
|
||||
setAdapter(null);
|
||||
removeHeaderView((DefaultActionItemBar) mActionItemBarPresenter);
|
||||
removeHeaderView((DefaultActionItemBar) mPrimaryActionItemBar);
|
||||
setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
private void removeSecondaryActionBarView() {
|
||||
// Reset the adapter before removing the header view from a list.
|
||||
setAdapter(null);
|
||||
removeHeaderView((DefaultActionItemBar) mSecondaryActionItemBar);
|
||||
setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
@ -248,18 +290,27 @@ public class GeckoMenu extends ListView
|
||||
* remove the old ones. This also ensures that any text associated with
|
||||
* these is switched to the correct locale.
|
||||
*/
|
||||
if (mActionItemBarPresenter != null) {
|
||||
for (View item : mActionItems.values()) {
|
||||
mActionItemBarPresenter.removeActionItem(item);
|
||||
if (mPrimaryActionItemBar != null) {
|
||||
for (View item : mPrimaryActionItems.values()) {
|
||||
mPrimaryActionItemBar.removeActionItem(item);
|
||||
}
|
||||
}
|
||||
mActionItems.clear();
|
||||
mPrimaryActionItems.clear();
|
||||
|
||||
if (mSecondaryActionItemBar != null) {
|
||||
for (View item : mSecondaryActionItems.values()) {
|
||||
mSecondaryActionItemBar.removeActionItem(item);
|
||||
}
|
||||
}
|
||||
mSecondaryActionItems.clear();
|
||||
|
||||
// Remove the view, too -- the first addActionItem will re-add it,
|
||||
// and this is simpler than changing that logic.
|
||||
if (mActionItemBarPresenter instanceof DefaultActionItemBar) {
|
||||
removeActionBarView();
|
||||
if (mPrimaryActionItemBar instanceof DefaultActionItemBar) {
|
||||
removePrimaryActionBarView();
|
||||
}
|
||||
|
||||
removeSecondaryActionBarView();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -301,7 +352,9 @@ public class GeckoMenu extends ListView
|
||||
@Override
|
||||
public boolean hasVisibleItems() {
|
||||
for (GeckoMenuItem menuItem : mItems) {
|
||||
if (menuItem.isVisible() && !mActionItems.containsKey(menuItem))
|
||||
if (menuItem.isVisible() &&
|
||||
!mPrimaryActionItems.containsKey(menuItem) &&
|
||||
!mSecondaryActionItems.containsKey(menuItem))
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -345,16 +398,30 @@ public class GeckoMenu extends ListView
|
||||
}
|
||||
|
||||
// Remove it from own menu.
|
||||
if (mActionItems.containsKey(item)) {
|
||||
if (mActionItemBarPresenter != null)
|
||||
mActionItemBarPresenter.removeActionItem(mActionItems.get(item));
|
||||
if (mPrimaryActionItems.containsKey(item)) {
|
||||
if (mPrimaryActionItemBar != null)
|
||||
mPrimaryActionItemBar.removeActionItem(mPrimaryActionItems.get(item));
|
||||
|
||||
mActionItems.remove(item);
|
||||
mPrimaryActionItems.remove(item);
|
||||
mItems.remove(item);
|
||||
|
||||
if (mActionItems.size() == 0 &&
|
||||
mActionItemBarPresenter instanceof DefaultActionItemBar) {
|
||||
removeActionBarView();
|
||||
if (mPrimaryActionItems.size() == 0 &&
|
||||
mPrimaryActionItemBar instanceof DefaultActionItemBar) {
|
||||
removePrimaryActionBarView();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSecondaryActionItems.containsKey(item)) {
|
||||
if (mSecondaryActionItemBar != null)
|
||||
mSecondaryActionItemBar.removeActionItem(mSecondaryActionItems.get(item));
|
||||
|
||||
mSecondaryActionItems.remove(item);
|
||||
mItems.remove(item);
|
||||
|
||||
if (mSecondaryActionItems.size() == 0) {
|
||||
removeSecondaryActionBarView();
|
||||
}
|
||||
|
||||
return;
|
||||
@ -387,14 +454,14 @@ public class GeckoMenu extends ListView
|
||||
|
||||
@Override
|
||||
public boolean hasActionItemBar() {
|
||||
return (mActionItemBarPresenter != null);
|
||||
return (mPrimaryActionItemBar != null) && (mSecondaryActionItemBar != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowAsActionChanged(GeckoMenuItem item, boolean isActionItem) {
|
||||
public void onShowAsActionChanged(GeckoMenuItem item) {
|
||||
removeItem(item.getItemId());
|
||||
|
||||
if (isActionItem && addActionItem(item)) {
|
||||
if (item.isActionItem() && addActionItem(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -403,23 +470,33 @@ public class GeckoMenu extends ListView
|
||||
|
||||
public void onItemChanged(GeckoMenuItem item) {
|
||||
if (item.isActionItem()) {
|
||||
final MenuItemActionBar actionView = (MenuItemActionBar) mActionItems.get(item);
|
||||
if (actionView != null) {
|
||||
// The update could be coming from the background thread.
|
||||
// Post a runnable on the UI thread of the view for it to update.
|
||||
final GeckoMenuItem menuItem = item;
|
||||
actionView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (menuItem.isVisible()) {
|
||||
actionView.setVisibility(View.VISIBLE);
|
||||
actionView.initialize(menuItem);
|
||||
} else {
|
||||
actionView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
final View actionView;
|
||||
if (item.getActionEnum() == GeckoMenuItem.SHOW_AS_ACTION_ALWAYS) {
|
||||
actionView = mPrimaryActionItems.get(item);
|
||||
} else {
|
||||
actionView = mSecondaryActionItems.get(item);
|
||||
}
|
||||
|
||||
if (actionView != null) {
|
||||
// The update could be coming from the background thread.
|
||||
// Post a runnable on the UI thread of the view for it to update.
|
||||
final GeckoMenuItem menuItem = item;
|
||||
actionView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (menuItem.isVisible()) {
|
||||
actionView.setVisibility(View.VISIBLE);
|
||||
if (actionView instanceof MenuItemActionBar) {
|
||||
((MenuItemActionBar) actionView).initialize(menuItem);
|
||||
} else {
|
||||
((MenuItemActionView) actionView).initialize(menuItem);
|
||||
}
|
||||
} else {
|
||||
actionView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
@ -491,7 +568,7 @@ public class GeckoMenu extends ListView
|
||||
}
|
||||
|
||||
public void setActionItemBarPresenter(ActionItemBarPresenter presenter) {
|
||||
mActionItemBarPresenter = presenter;
|
||||
mPrimaryActionItemBar = presenter;
|
||||
}
|
||||
|
||||
// Action Items are added to the header view by default.
|
||||
@ -499,6 +576,7 @@ public class GeckoMenu extends ListView
|
||||
public static class DefaultActionItemBar extends LinearLayout
|
||||
implements ActionItemBarPresenter {
|
||||
private final int mRowHeight;
|
||||
private float mWeightSum;
|
||||
|
||||
public DefaultActionItemBar(Context context) {
|
||||
this(context, null);
|
||||
@ -508,7 +586,6 @@ public class GeckoMenu extends ListView
|
||||
super(context, attrs);
|
||||
|
||||
mRowHeight = getResources().getDimensionPixelSize(R.dimen.menu_item_row_height);
|
||||
setWeightSum(3.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -523,15 +600,27 @@ public class GeckoMenu extends ListView
|
||||
params = new LinearLayout.LayoutParams(0, mRowHeight);
|
||||
}
|
||||
|
||||
params.weight = 1.0f;
|
||||
if (actionItem instanceof MenuItemActionView) {
|
||||
params.weight = ((MenuItemActionView) actionItem).getChildCount();
|
||||
} else {
|
||||
params.weight = 1.0f;
|
||||
}
|
||||
|
||||
mWeightSum += params.weight;
|
||||
|
||||
actionItem.setLayoutParams(params);
|
||||
addView(actionItem);
|
||||
setWeightSum(mWeightSum);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeActionItem(View actionItem) {
|
||||
removeView(actionItem);
|
||||
if (indexOfChild(actionItem) != -1) {
|
||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) actionItem.getLayoutParams();
|
||||
mWeightSum -= params.weight;
|
||||
removeView(actionItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
package org.mozilla.gecko.menu;
|
||||
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.widget.GeckoActionProvider;
|
||||
|
||||
import android.content.Intent;
|
||||
@ -18,6 +19,10 @@ import android.view.View;
|
||||
public class GeckoMenuItem implements MenuItem {
|
||||
private static final String LOGTAG = "GeckoMenuItem";
|
||||
|
||||
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;
|
||||
|
||||
// A View that can show a MenuItem should be able to initialize from
|
||||
// the properties of the MenuItem.
|
||||
public static interface Layout {
|
||||
@ -26,13 +31,13 @@ public class GeckoMenuItem implements MenuItem {
|
||||
|
||||
public static interface OnShowAsActionChangedListener {
|
||||
public boolean hasActionItemBar();
|
||||
public void onShowAsActionChanged(GeckoMenuItem item, boolean isActionItem);
|
||||
public void onShowAsActionChanged(GeckoMenuItem item);
|
||||
}
|
||||
|
||||
private int mId;
|
||||
private int mOrder;
|
||||
private View mActionView;
|
||||
private boolean mActionItem = false;
|
||||
private int mActionEnum;
|
||||
private CharSequence mTitle;
|
||||
private CharSequence mTitleCondensed;
|
||||
private boolean mCheckable = false;
|
||||
@ -79,6 +84,10 @@ public class GeckoMenuItem implements MenuItem {
|
||||
return (mActionProvider != null);
|
||||
}
|
||||
|
||||
public int getActionEnum() {
|
||||
return mActionEnum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionProvider getActionProvider() {
|
||||
return mActionProvider;
|
||||
@ -164,7 +173,7 @@ public class GeckoMenuItem implements MenuItem {
|
||||
}
|
||||
|
||||
public boolean isActionItem() {
|
||||
return mActionItem;
|
||||
return (mActionEnum > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -201,10 +210,14 @@ public class GeckoMenuItem implements MenuItem {
|
||||
@Override
|
||||
public void onTargetSelected() {
|
||||
mMenu.close();
|
||||
|
||||
// Refresh the menu item to show the high frequency apps.
|
||||
mShowAsActionChangedListener.onShowAsActionChanged(GeckoMenuItem.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
mShowAsActionChangedListener.onShowAsActionChanged(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -293,27 +306,34 @@ public class GeckoMenuItem implements MenuItem {
|
||||
if (mShowAsActionChangedListener == null)
|
||||
return;
|
||||
|
||||
if (mActionItem == (actionEnum > 0))
|
||||
if (mActionEnum == actionEnum)
|
||||
return;
|
||||
|
||||
if (actionEnum > 0) {
|
||||
if (!mShowAsActionChangedListener.hasActionItemBar())
|
||||
return;
|
||||
|
||||
// Change the type to just an icon
|
||||
MenuItemActionBar actionView;
|
||||
if (style != 0) {
|
||||
actionView = new MenuItemActionBar(mMenu.getContext(), null, style);
|
||||
} else {
|
||||
actionView = new MenuItemActionBar(mMenu.getContext());
|
||||
}
|
||||
actionView.initialize(this);
|
||||
mActionView = actionView;
|
||||
if (!hasActionProvider()) {
|
||||
// Change the type to just an icon
|
||||
MenuItemActionBar actionView;
|
||||
if (style != 0) {
|
||||
actionView = new MenuItemActionBar(mMenu.getContext(), null, style);
|
||||
} else {
|
||||
if (actionEnum == SHOW_AS_ACTION_ALWAYS) {
|
||||
actionView = new MenuItemActionBar(mMenu.getContext());
|
||||
} else {
|
||||
actionView = new MenuItemActionBar(mMenu.getContext(), null, R.attr.menuItemSecondaryActionBarStyle);
|
||||
}
|
||||
}
|
||||
|
||||
mActionItem = (actionEnum > 0);
|
||||
actionView.initialize(this);
|
||||
mActionView = actionView;
|
||||
}
|
||||
|
||||
mActionEnum = actionEnum;
|
||||
}
|
||||
|
||||
mShowAsActionChangedListener.onShowAsActionChanged(this, mActionItem);
|
||||
mShowAsActionChangedListener.onShowAsActionChanged(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +39,7 @@ public class MenuItemActionBar extends ImageButton
|
||||
setId(item.getItemId());
|
||||
}
|
||||
|
||||
private void setIcon(Drawable icon) {
|
||||
void setIcon(Drawable icon) {
|
||||
if (icon != null) {
|
||||
setImageDrawable(icon);
|
||||
setVisibility(VISIBLE);
|
||||
@ -48,7 +48,7 @@ public class MenuItemActionBar extends ImageButton
|
||||
}
|
||||
}
|
||||
|
||||
private void setIcon(int icon) {
|
||||
void setIcon(int icon) {
|
||||
if (icon != 0) {
|
||||
setImageResource(icon);
|
||||
setVisibility(VISIBLE);
|
||||
@ -57,7 +57,7 @@ public class MenuItemActionBar extends ImageButton
|
||||
}
|
||||
}
|
||||
|
||||
private void setTitle(CharSequence title) {
|
||||
void setTitle(CharSequence title) {
|
||||
// set accessibility contentDescription here
|
||||
setContentDescription(title);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class MenuItemActionView extends LinearLayout
|
||||
private static final String LOGTAG = "GeckoMenuItemActionView";
|
||||
|
||||
private MenuItemDefault mMenuItem;
|
||||
private ImageButton mMenuButton;
|
||||
private MenuItemActionBar mMenuButton;
|
||||
private List<ImageButton> mActionButtons;
|
||||
private View.OnClickListener mActionButtonListener;
|
||||
|
||||
@ -41,18 +41,28 @@ public class MenuItemActionView extends LinearLayout
|
||||
public MenuItemActionView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
Resources res = context.getResources();
|
||||
int width = res.getDimensionPixelSize(R.dimen.menu_item_row_width);
|
||||
int height = res.getDimensionPixelSize(R.dimen.menu_item_row_height);
|
||||
setMinimumWidth(width);
|
||||
setMinimumHeight(height);
|
||||
|
||||
LayoutInflater.from(context).inflate(R.layout.menu_item_action_view, this);
|
||||
mMenuItem = (MenuItemDefault) findViewById(R.id.menu_item);
|
||||
mMenuButton = (ImageButton) findViewById(R.id.menu_item_button);
|
||||
mMenuButton = (MenuItemActionBar) findViewById(R.id.menu_item_button);
|
||||
mActionButtons = new ArrayList<ImageButton>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
View parent = (View) getParent();
|
||||
if ((right - left) < parent.getMeasuredWidth() || mActionButtons.size() != 0) {
|
||||
// Use the icon.
|
||||
mMenuItem.setVisibility(View.GONE);
|
||||
mMenuButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
// Use the button.
|
||||
mMenuItem.setVisibility(View.VISIBLE);
|
||||
mMenuButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(GeckoMenuItem item) {
|
||||
if (item == null)
|
||||
@ -65,16 +75,17 @@ public class MenuItemActionView extends LinearLayout
|
||||
|
||||
private void setIcon(Drawable icon) {
|
||||
mMenuItem.setIcon(icon);
|
||||
mMenuButton.setImageDrawable(icon);
|
||||
mMenuButton.setIcon(icon);
|
||||
}
|
||||
|
||||
private void setIcon(int icon) {
|
||||
mMenuItem.setIcon(icon);
|
||||
mMenuButton.setImageResource(icon);
|
||||
mMenuButton.setIcon(icon);
|
||||
}
|
||||
|
||||
private void setTitle(CharSequence title) {
|
||||
mMenuItem.setTitle(title);
|
||||
mMenuButton.setTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,7 +93,6 @@ public class MenuItemActionView extends LinearLayout
|
||||
super.setEnabled(enabled);
|
||||
mMenuItem.setEnabled(enabled);
|
||||
mMenuButton.setEnabled(enabled);
|
||||
mMenuButton.setAlpha(enabled ? 255 : 99);
|
||||
|
||||
for (ImageButton button : mActionButtons) {
|
||||
button.setEnabled(enabled);
|
||||
@ -107,13 +117,8 @@ public class MenuItemActionView extends LinearLayout
|
||||
// If this is the first icon, retain the text.
|
||||
// If not, make the menu item an icon.
|
||||
final int count = mActionButtons.size();
|
||||
if (count == 0) {
|
||||
mMenuItem.setVisibility(View.VISIBLE);
|
||||
mMenuButton.setVisibility(View.GONE);
|
||||
} else {
|
||||
mMenuItem.setVisibility(View.GONE);
|
||||
mMenuButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mMenuItem.setVisibility(View.GONE);
|
||||
mMenuButton.setVisibility(View.VISIBLE);
|
||||
|
||||
if (drawable != null) {
|
||||
ImageButton button = new ImageButton(getContext(), null, R.attr.menuItemShareActionButtonStyle);
|
||||
@ -126,8 +131,9 @@ public class MenuItemActionView extends LinearLayout
|
||||
params.weight = 1.0f;
|
||||
button.setLayoutParams(params);
|
||||
|
||||
// Fill in the action-buttons to the left of the actual menu button.
|
||||
mActionButtons.add(button);
|
||||
addView(button);
|
||||
addView(button, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,23 +5,29 @@
|
||||
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<org.mozilla.gecko.menu.MenuItemDefault
|
||||
android:id="@+id/menu_item"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="2.0"
|
||||
android:background="@drawable/action_bar_button"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
<!-- Application icons will be added dynamically -->
|
||||
|
||||
<ImageButton android:id="@+id/menu_item_button"
|
||||
android:layout_width="0dip"
|
||||
<FrameLayout android:layout_width="0dip"
|
||||
android:layout_height="@dimen/menu_item_row_height"
|
||||
android:layout_weight="1.0"
|
||||
android:padding="8dip"
|
||||
android:scaleType="centerInside"
|
||||
android:background="@drawable/action_bar_button"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:visibility="gone"/>
|
||||
android:layout_weight="1.0">
|
||||
|
||||
<org.mozilla.gecko.menu.MenuItemDefault
|
||||
android:id="@+id/menu_item"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="@drawable/action_bar_button"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
<org.mozilla.gecko.menu.MenuItemActionBar
|
||||
style="@style/Widget.MenuItemSecondaryActionBar"
|
||||
android:id="@+id/menu_item_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="@drawable/action_bar_button"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</merge>
|
||||
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- 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/. -->
|
||||
|
||||
<!--
|
||||
Note: This layout is intended to be used only above 11+.
|
||||
android:showDividers are available only 11+
|
||||
-->
|
||||
<view xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
class="org.mozilla.gecko.menu.GeckoMenu$DefaultActionItemBar"
|
||||
android:layout_width="@dimen/menu_item_row_width"
|
||||
android:layout_height="@dimen/browser_toolbar_height"
|
||||
android:orientation="horizontal"
|
||||
android:divider="@drawable/divider_vertical"
|
||||
android:showDividers="middle"
|
||||
android:dividerPadding="0dip"/>
|
@ -20,13 +20,15 @@
|
||||
android:title="@string/forward"
|
||||
android:visible="false"/>
|
||||
|
||||
<item android:id="@+id/share"
|
||||
android:icon="@drawable/ic_menu_share"
|
||||
android:title="@string/share" />
|
||||
|
||||
<item android:id="@+id/bookmark"
|
||||
android:icon="@drawable/ic_menu_bookmark_add"
|
||||
android:title="@string/bookmark"/>
|
||||
android:title="@string/bookmark"
|
||||
android:showAsAction="ifRoom"/>
|
||||
|
||||
<item android:id="@+id/share"
|
||||
android:icon="@drawable/ic_menu_share"
|
||||
android:title="@string/share"
|
||||
android:showAsAction="ifRoom"/>
|
||||
|
||||
<item android:id="@+id/new_tab"
|
||||
android:icon="@drawable/ic_menu_new_tab"
|
||||
|
@ -20,13 +20,15 @@
|
||||
android:title="@string/reload"
|
||||
android:showAsAction="always"/>
|
||||
|
||||
<item android:id="@+id/share"
|
||||
android:icon="@drawable/ic_menu_share"
|
||||
android:title="@string/share" />
|
||||
|
||||
<item android:id="@+id/bookmark"
|
||||
android:icon="@drawable/ic_menu_bookmark_add"
|
||||
android:title="@string/bookmark"/>
|
||||
android:title="@string/bookmark"
|
||||
android:showAsAction="ifRoom"/>
|
||||
|
||||
<item android:id="@+id/share"
|
||||
android:icon="@drawable/ic_menu_share"
|
||||
android:title="@string/share"
|
||||
android:showAsAction="ifRoom"/>
|
||||
|
||||
<item android:id="@+id/new_tab"
|
||||
android:icon="@drawable/ic_menu_new_tab"
|
||||
|
@ -27,7 +27,8 @@
|
||||
|
||||
<item android:id="@+id/share"
|
||||
android:icon="@drawable/ic_menu_share"
|
||||
android:title="@string/share" />
|
||||
android:title="@string/share"
|
||||
android:showAsAction="ifRoom"/>
|
||||
|
||||
<item android:id="@+id/new_tab"
|
||||
android:icon="@drawable/ic_menu_new_tab"
|
||||
|
@ -42,7 +42,8 @@
|
||||
<item name="menuItemActionBarStyle">@style/Widget.MenuItemActionBar</item>
|
||||
<item name="menuItemActionViewStyle">@style/Widget.MenuItemActionView</item>
|
||||
<item name="menuItemDefaultStyle">@style/Widget.MenuItemDefault</item>
|
||||
<item name="menuItemShareActionButtonStyle">@style/Widget.MenuItemShareActionButton</item>
|
||||
<item name="menuItemSecondaryActionBarStyle">@style/Widget.MenuItemSecondaryActionBar</item>
|
||||
<item name="menuItemShareActionButtonStyle">@style/Widget.MenuItemSecondaryActionBar</item>
|
||||
<item name="bookmarksListViewStyle">@style/Widget.BookmarksListView</item>
|
||||
<item name="topSitesGridItemViewStyle">@style/Widget.TopSitesGridItemView</item>
|
||||
<item name="topSitesGridViewStyle">@style/Widget.TopSitesGridView</item>
|
||||
|
@ -23,6 +23,9 @@
|
||||
<!-- Style for MenuItemDefault -->
|
||||
<attr name="menuItemDefaultStyle" format="reference"/>
|
||||
|
||||
<!-- Style for MenuItemActionBar when shown in SecondaryActionBar -->
|
||||
<attr name="menuItemSecondaryActionBarStyle" format="reference"/>
|
||||
|
||||
<!-- Style for MenuItemActionView's ShareActionButton -->
|
||||
<attr name="menuItemShareActionButtonStyle" format="reference"/>
|
||||
|
||||
|
@ -84,19 +84,19 @@
|
||||
<item name="android:scaleType">fitCenter</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.MenuItemActionView">
|
||||
<item name="android:divider">@drawable/divider_vertical</item>
|
||||
<item name="android:showDividers">middle</item>
|
||||
<item name="android:dividerPadding">12dip</item>
|
||||
<item name="android:gravity">left</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.MenuItemShareActionButton">
|
||||
<style name="Widget.MenuItemSecondaryActionBar">
|
||||
<item name="android:padding">8dip</item>
|
||||
<item name="android:background">@drawable/action_bar_button</item>
|
||||
<item name="android:scaleType">centerInside</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.MenuItemActionView">
|
||||
<item name="android:divider">@drawable/divider_vertical</item>
|
||||
<item name="android:showDividers">middle</item>
|
||||
<item name="android:dividerPadding">0dip</item>
|
||||
<item name="android:gravity">left</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.MenuItemDefault">
|
||||
<item name="android:paddingLeft">10dip</item>
|
||||
<item name="android:paddingRight">10dip</item>
|
||||
|
@ -59,6 +59,14 @@ public class GeckoActionProvider extends ActionProvider {
|
||||
historySize = 2;
|
||||
}
|
||||
|
||||
// Historical data is dependent on past selection of activities.
|
||||
// Activity count is determined by the number of activities that can handle
|
||||
// the particular intent. When no intent is set, the activity count is 0,
|
||||
// while the history count can be a valid number.
|
||||
if (historySize > dataModel.getActivityCount()) {
|
||||
return view;
|
||||
}
|
||||
|
||||
for (int i = 0; i < historySize; i++) {
|
||||
view.addActionButton(dataModel.getActivity(i).loadIcon(packageManager));
|
||||
}
|
||||
@ -105,6 +113,11 @@ public class GeckoActionProvider extends ActionProvider {
|
||||
public void setIntent(Intent intent) {
|
||||
ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName);
|
||||
dataModel.setIntent(intent);
|
||||
|
||||
// Inform the target listener to refresh it's UI, if needed.
|
||||
if (mOnTargetListener != null) {
|
||||
mOnTargetListener.onTargetSelected();
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnTargetSelectedListener(OnTargetSelectedListener listener) {
|
||||
@ -117,15 +130,16 @@ public class GeckoActionProvider extends ActionProvider {
|
||||
private class Callbacks implements OnMenuItemClickListener,
|
||||
OnClickListener {
|
||||
private void chooseActivity(int index) {
|
||||
if (mOnTargetListener != null)
|
||||
mOnTargetListener.onTargetSelected();
|
||||
|
||||
ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName);
|
||||
Intent launchIntent = dataModel.chooseActivity(index);
|
||||
if (launchIntent != null) {
|
||||
launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
mContext.startActivity(launchIntent);
|
||||
}
|
||||
|
||||
if (mOnTargetListener != null) {
|
||||
mOnTargetListener.onTargetSelected();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user