Bug 1275880 - Correct action mode styling. r=liuche
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 27 May 2016 12:49:55 -0700
changeset 340668 7f6135916882e9dff30c5549e278f49f2fca2c17
parent 340667 cb494ac32123f3498ef62b5e312dc4970f15cbc1
child 340669 62994b8424002efc18e8ba6b58471e051b42e930
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1275880
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1275880 - Correct action mode styling. r=liuche MozReview-Commit-ID: H7up9G5vlcg
mobile/android/base/java/org/mozilla/gecko/ActionModeCompatView.java
mobile/android/base/resources/layout/gecko_app.xml
mobile/android/base/resources/values/colors.xml
mobile/android/base/resources/values/dimens.xml
mobile/android/base/resources/values/styles.xml
--- a/mobile/android/base/java/org/mozilla/gecko/ActionModeCompatView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/ActionModeCompatView.java
@@ -1,14 +1,17 @@
 /* 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;
 
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Paint;
 import org.mozilla.gecko.animation.AnimationUtils;
 import org.mozilla.gecko.menu.GeckoMenu;
 import org.mozilla.gecko.widget.GeckoPopupMenu;
 
 import android.content.Context;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.Menu;
@@ -31,47 +34,54 @@ class ActionModeCompatView extends Linea
     private ViewGroup mActionButtonBar;
     private GeckoPopupMenu mPopupMenu;
 
     // Maximum number of items to show as actions
     private static final int MAX_ACTION_ITEMS = 4;
 
     private int mActionButtonsWidth;
 
-    public ActionModeCompatView(Context context) {
-        super(context);
-        init(context);
-    }
+    private Paint mBottomDividerPaint;
+    private int mBottomDividerOffset;
 
     public ActionModeCompatView(Context context, AttributeSet attrs) {
         super(context, attrs);
-        init(context);
+        init(context, attrs, 0);
     }
 
     public ActionModeCompatView(Context context, AttributeSet attrs, int style) {
         super(context, attrs, style);
-        init(context);
+        init(context, attrs, style);
     }
 
-    public void init(Context context) {
+    public void init(final Context context, final AttributeSet attrs, final int defStyle) {
         LayoutInflater.from(context).inflate(R.layout.actionbar, this);
 
         mTitleView = (Button) findViewById(R.id.actionmode_title);
         mMenuButton = (ImageButton) findViewById(R.id.actionbar_menu);
         mActionButtonBar = (ViewGroup) findViewById(R.id.actionbar_buttons);
 
         mPopupMenu = new GeckoPopupMenu(getContext(), mMenuButton);
         mPopupMenu.getMenu().setActionItemBarPresenter(this);
 
         mMenuButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 openMenu();
             }
         });
+
+        // The built-in action bar uses colorAccent for the divider so we duplicate that here.
+        final TypedArray arr = context.obtainStyledAttributes(attrs, new int[] { R.attr.colorAccent }, defStyle, 0);
+        final int bottomDividerColor = arr.getColor(0, 0);
+        arr.recycle();
+
+        mBottomDividerPaint = new Paint();
+        mBottomDividerPaint.setColor(bottomDividerColor);
+        mBottomDividerOffset = getResources().getDimensionPixelSize(R.dimen.action_bar_divider_height);
     }
 
     public void initForMode(final ActionModeCompat mode) {
         mTitleView.setOnClickListener(mode);
         mPopupMenu.setOnMenuItemClickListener(mode);
         mPopupMenu.setOnMenuItemLongClickListener(mode);
     }
 
@@ -173,9 +183,20 @@ class ActionModeCompatView extends Linea
         mTitleView.startAnimation(t);
         mActionButtonBar.startAnimation(s);
 
         if ((mMenuButton.getVisibility() == View.VISIBLE) &&
             (mPopupMenu.getMenu().size() > 0)) {
             mMenuButton.startAnimation(s);
         }
     }
+
+    @Override
+    protected void onDraw(Canvas canvas) {
+        super.onDraw(canvas);
+
+        // Draw the divider at the bottom of the screen. We could do this with a layer-list
+        // but then we'd have overdraw (http://stackoverflow.com/a/13509472).
+        final int bottom = getHeight();
+        final int top = bottom - mBottomDividerOffset;
+        canvas.drawRect(0, top, getWidth(), bottom, mBottomDividerPaint);
+    }
 }
--- a/mobile/android/base/resources/layout/gecko_app.xml
+++ b/mobile/android/base/resources/layout/gecko_app.xml
@@ -141,17 +141,17 @@
                     android:layout_height="match_parent"
                     android:clickable="true"
                     android:focusable="true"
                     android:background="@drawable/url_bar_bg"/>
 
                 <org.mozilla.gecko.ActionModeCompatView android:id="@+id/actionbar"
                                                         android:layout_height="match_parent"
                                                         android:layout_width="match_parent"
-                                                        style="@style/GeckoActionBar"/>
+                                                        style="@style/GeckoActionBar.ActionMode"/>
 
             </ViewFlipper>
 
         </LinearLayout>
 
         <org.mozilla.gecko.toolbar.ToolbarProgressView android:id="@+id/progress"
                                                        android:layout_width="match_parent"
                                                        android:layout_height="14dp"
--- a/mobile/android/base/resources/values/colors.xml
+++ b/mobile/android/base/resources/values/colors.xml
@@ -133,9 +133,11 @@
   <color name="canvas_delegate_paint">#FFFF0000</color>
 
   <!-- Top sites thumbnail colors -->
   <color name="top_site_default">#FFECF0F3</color>
   <color name="top_site_border">#FFCFD9E1</color>
 
   <color name="private_active_text">#FFFFFF</color>
 
+  <color name="action_bar_bg_color">@color/toolbar_grey</color>
+
 </resources>
--- a/mobile/android/base/resources/values/dimens.xml
+++ b/mobile/android/base/resources/values/dimens.xml
@@ -202,15 +202,19 @@
     <dimen name="find_in_page_text_margin_left">5dip</dimen>
     <dimen name="find_in_page_text_margin_right">12dip</dimen>
     <dimen name="find_in_page_text_padding_left">10dip</dimen>
     <dimen name="find_in_page_text_padding_right">10dip</dimen>
     <dimen name="find_in_page_status_margin_right">10dip</dimen>
     <dimen name="find_in_page_control_margin_top">2dip</dimen>
     <dimen name="progress_bar_scroll_offset">1.5dp</dimen>
 
+    <!-- Matches the built-in divider height. fwiw, in the framework
+         I suspect this is a drawable rather than a dimen.  -->
+    <dimen name="action_bar_divider_height">2dp</dimen>
+
     <!-- http://blog.danlew.net/2015/01/06/handling-android-resources-with-non-standard-formats/ -->
     <item name="match_parent" type="dimen">-1</item>
     <item name="wrap_content" type="dimen">-2</item>
 
     <item name="tab_strip_content_start" type="dimen">12dp</item>
     <item name="firstrun_tab_strip_content_start" type="dimen">15dp</item>
 </resources>
--- a/mobile/android/base/resources/values/styles.xml
+++ b/mobile/android/base/resources/values/styles.xml
@@ -657,21 +657,27 @@
         <item name="android:textAppearance">?android:textAppearanceSmall</item>
     </style>
 
     <style name="ToastButton" parent="ToastButtonBase">
         <item name="android:textAppearance">?android:textAppearanceSmall</item>
         <item name="android:textStyle">bold</item>
     </style>
 
+    <!-- Ideally, we use the same style for the action bar & action mode, but unfortunately
+         some attrs that share a purpose have different names so instead we inherit. -->
     <style name="GeckoActionBar" parent="ThemeOverlay.AppCompat.ActionBar">
-        <item name="android:colorBackground">@color/toolbar_grey</item>
+        <item name="android:colorBackground">@color/action_bar_bg_color</item>
         <item name="colorAccent">@color/fennec_ui_orange</item>
         <item name="colorControlNormal">@color/toolbar_icon_grey</item>
     </style>
+    <style name="GeckoActionBar.ActionMode">
+        <item name="android:background">@color/action_bar_bg_color</item>
+        <!-- Note: the bottom divider is drawn in code. -->
+    </style>
 
     <style name="PreferencesActionBar" parent="Widget.AppCompat.ActionBar.Solid">
         <item name="displayOptions">showHome|homeAsUp|showTitle</item>
     </style>
 
     <style name="GeckoActionBar.Title">
         <item name="android:gravity">center_vertical</item>
         <item name="android:minWidth">0dp</item>