Skip to content

Commit

Permalink
Bug 1132747 - Set the padding for share in the context menu on Lollip…
Browse files Browse the repository at this point in the history
…op. r=mhaigh

--HG--
extra : rebase_source : 73188995644bc759f7f0d35d6046f36fb0da4221
extra : source : 4458dea727edc5d5c84db0b27cb62fda29d148c9
  • Loading branch information
mcomella committed Mar 28, 2015
1 parent e10472f commit a3e57f7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 10 deletions.
6 changes: 4 additions & 2 deletions mobile/android/base/menu/GeckoMenuItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ public ActionProvider getActionProvider() {
public View getActionView() {
if (mActionProvider != null) {
if (getActionEnum() == MenuItem.SHOW_AS_ACTION_IF_ROOM) {
return mActionProvider.onCreateActionView(SECONDARY_ACTION_BAR_HISTORY_SIZE, false);
return mActionProvider.onCreateActionView(SECONDARY_ACTION_BAR_HISTORY_SIZE,
GeckoActionProvider.ActionViewType.DEFAULT);
} else {
return mActionProvider.onCreateActionView(QUICK_SHARE_ACTION_BAR_HISTORY_SIZE, true);
return mActionProvider.onCreateActionView(QUICK_SHARE_ACTION_BAR_HISTORY_SIZE,
GeckoActionProvider.ActionViewType.QUICK_SHARE_ICON);
}
}

Expand Down
14 changes: 14 additions & 0 deletions mobile/android/base/menu/MenuItemActionView.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,18 @@ public void onClick(View view) {
listener.onClick(view);
}
}

/**
* Update the styles if this view is being used in the context menus.
*
* Ideally, we just use different layout files and styles to set this, but
* MenuItemActionView is too integrated into GeckoActionProvider to provide
* an easy separation so instead I provide this hack. I'm sorry.
*/
public void initContextMenuStyles() {
final int defaultContextMenuPadding = getContext().getResources().getDimensionPixelOffset(
R.dimen.context_menu_item_horizontal_padding);
mMenuItem.setPadding(defaultContextMenuPadding, getPaddingTop(),
defaultContextMenuPadding, getPaddingBottom());
}
}
3 changes: 2 additions & 1 deletion mobile/android/base/prompts/PromptListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ private View getActionView(PromptListItem item, final ListView list, final int p
final GeckoActionProvider provider = GeckoActionProvider.getForType(item.getIntent().getType(), getContext());
provider.setIntent(item.getIntent());

final MenuItemActionView view = (MenuItemActionView) provider.onCreateActionView();
final MenuItemActionView view = (MenuItemActionView) provider.onCreateActionView(
GeckoActionProvider.ActionViewType.CONTEXT_MENU);
// If a quickshare button is clicked, we need to close the dialog.
view.addActionButtonClickListener(new View.OnClickListener() {
@Override
Expand Down
8 changes: 8 additions & 0 deletions mobile/android/base/resources/values-v21/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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/. -->

<resources>
<dimen name="context_menu_item_horizontal_padding">17dp</dimen>
</resources>
2 changes: 2 additions & 0 deletions mobile/android/base/resources/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
<dimen name="doorhanger_section_padding_large">30dp</dimen>
<dimen name="doorhanger_icon_size">60dp</dimen>

<dimen name="context_menu_item_horizontal_padding">10dp</dimen>

<dimen name="flow_layout_spacing">6dp</dimen>
<dimen name="menu_item_icon">21dp</dimen>
<dimen name="menu_item_textsize">16sp</dimen>
Expand Down
33 changes: 26 additions & 7 deletions mobile/android/base/widget/GeckoActionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,31 @@ public GeckoActionProvider(Context context) {
/**
* Creates the action view using the default history size.
*/
public View onCreateActionView() {
return onCreateActionView(MAX_HISTORY_SIZE_DEFAULT, false);
public View onCreateActionView(final ActionViewType viewType) {
return onCreateActionView(MAX_HISTORY_SIZE_DEFAULT, viewType);
}

public View onCreateActionView(final int maxHistorySize, final boolean isForQuickShareBar) {
public View onCreateActionView(final int maxHistorySize, final ActionViewType viewType) {
// Create the view and set its data model.
ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName);
final MenuItemActionView view;
if (isForQuickShareBar) {
view = new QuickShareBarActionView(mContext, null);
} else {
view = new MenuItemActionView(mContext, null);
switch (viewType) {
case DEFAULT:
view = new MenuItemActionView(mContext, null);
break;

case QUICK_SHARE_ICON:
view = new QuickShareBarActionView(mContext, null);
break;

case CONTEXT_MENU:
view = new MenuItemActionView(mContext, null);
view.initContextMenuStyles();
break;

default:
throw new IllegalArgumentException(
"Unknown " + ActionViewType.class.getSimpleName() + ": " + viewType);
}
view.addActionButtonClickListener(mCallbacks);

Expand Down Expand Up @@ -251,4 +264,10 @@ public void onClick(View view) {
Telemetry.sendUIEvent(TelemetryContract.Event.SHARE, TelemetryContract.Method.BUTTON);
}
}

public enum ActionViewType {
DEFAULT,
QUICK_SHARE_ICON,
CONTEXT_MENU,
}
}

0 comments on commit a3e57f7

Please sign in to comment.