Bug 1132747 - Set the padding for share in the context menu on Lollipop. r=mhaigh a=sylvestre
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 27 Mar 2015 17:59:06 -0700
changeset 258363 cbe44fd0d2fc
parent 258362 5b70a93a7f10
child 258364 a1c4c4d43776
push id4653
push usermichael.l.comella@gmail.com
push date2015-04-08 16:51 +0000
treeherdermozilla-beta@cbe44fd0d2fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhaigh, sylvestre
bugs1132747
milestone38.0
Bug 1132747 - Set the padding for share in the context menu on Lollipop. r=mhaigh a=sylvestre
mobile/android/base/menu/GeckoMenuItem.java
mobile/android/base/menu/MenuItemActionView.java
mobile/android/base/prompts/PromptListAdapter.java
mobile/android/base/resources/values-v21/dimens.xml
mobile/android/base/resources/values/dimens.xml
mobile/android/base/widget/GeckoActionProvider.java
--- a/mobile/android/base/menu/GeckoMenuItem.java
+++ b/mobile/android/base/menu/GeckoMenuItem.java
@@ -136,19 +136,21 @@ public class GeckoMenuItem implements Me
     public ActionProvider getActionProvider() {
         return null;
     }
 
     @Override
     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);
             }
         }
 
         return mActionView;
     }
 
     @Override
     public char getAlphabeticShortcut() {
--- a/mobile/android/base/menu/MenuItemActionView.java
+++ b/mobile/android/base/menu/MenuItemActionView.java
@@ -155,9 +155,23 @@ public class MenuItemActionView extends 
     }
 
     @Override
     public void onClick(View view) {
         for (View.OnClickListener listener : mActionButtonListeners) {
             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());
+    }
 }
--- a/mobile/android/base/prompts/PromptListAdapter.java
+++ b/mobile/android/base/prompts/PromptListAdapter.java
@@ -174,17 +174,18 @@ public class PromptListAdapter extends A
         }
         return -1;
     }
 
     private View getActionView(PromptListItem item, final ListView list, final int position) {
         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
             public void onClick(View v) {
                 ListView.OnItemClickListener listener = list.getOnItemClickListener();
                 if (listener != null) {
                     listener.onItemClick(list, view, position, position);
                 }
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/values-v21/dimens.xml
@@ -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>
--- a/mobile/android/base/resources/values/dimens.xml
+++ b/mobile/android/base/resources/values/dimens.xml
@@ -93,16 +93,18 @@
 
     <!-- Padding at the top of the site identity popup, when no identity data is available. -->
     <dimen name="identity_padding_top">5dp</dimen>
 
     <dimen name="doorhanger_input_width">250dp</dimen>
     <dimen name="doorhanger_spinner_textsize">9sp</dimen>
     <dimen name="doorhanger_padding">15dp</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>
     <dimen name="menu_item_state_icon">18dp</dimen>
     <!-- This is chosen to match Android's listPreferredItemHeight.
          TODO: We should inherit these from the system.
          http://androidxref.com/4.2.2_r1/xref/frameworks/base/core/res/res/values/themes.xml#123 -->
     <dimen name="menu_item_row_height">64dip</dimen>
--- a/mobile/android/base/widget/GeckoActionProvider.java
+++ b/mobile/android/base/widget/GeckoActionProvider.java
@@ -85,28 +85,41 @@ public class GeckoActionProvider {
 
     public GeckoActionProvider(Context context) {
         mContext = 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);
 
         final PackageManager packageManager = mContext.getPackageManager();
         int historySize = dataModel.getDistinctActivityCountInHistory();
         if (historySize > maxHistorySize) {
             historySize = maxHistorySize;
         }
@@ -246,9 +259,15 @@ public class GeckoActionProvider {
         public void onClick(View view) {
             Integer index = (Integer) view.getTag();
             chooseActivity(index);
 
             // Context: Sharing via chrome mainmenu and content contextmenu quickshare (no explicit session is active)
             Telemetry.sendUIEvent(TelemetryContract.Event.SHARE, TelemetryContract.Method.BUTTON);
         }
     }
+
+    public enum ActionViewType {
+        DEFAULT,
+        QUICK_SHARE_ICON,
+        CONTEXT_MENU,
+    }
 }