Bug 1245831 - The action bar animation is overlapping with the three dot menu. r=sebastian
authorMark Capella <markcapella@twcny.rr.com>
Thu, 21 Apr 2016 13:11:46 +0200
changeset 331969 5344f269671b9cb2cebccfcb0cc6667053c77279
parent 331968 a850056f05279162055f782757d4577df9ca8b85
child 331970 c788233efce1cc3cfecb47e342d254ae6070f095
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1245831
milestone48.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 1245831 - The action bar animation is overlapping with the three dot menu. r=sebastian MozReview-Commit-ID: J0QXMhfZWt7
mobile/android/base/java/org/mozilla/gecko/ActionBarTextSelection.java
mobile/android/base/java/org/mozilla/gecko/ActionModeCompat.java
mobile/android/base/java/org/mozilla/gecko/ActionModeCompatView.java
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/widget/GeckoPopupMenu.java
--- a/mobile/android/base/java/org/mozilla/gecko/ActionBarTextSelection.java
+++ b/mobile/android/base/java/org/mozilla/gecko/ActionBarTextSelection.java
@@ -5,16 +5,17 @@
 package org.mozilla.gecko;
 
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.gfx.BitmapUtils.BitmapLoader;
 import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
 import org.mozilla.gecko.gfx.Layer;
 import org.mozilla.gecko.gfx.LayerView;
 import org.mozilla.gecko.gfx.LayerView.DrawListener;
+import org.mozilla.gecko.menu.GeckoMenu;
 import org.mozilla.gecko.menu.GeckoMenuItem;
 import org.mozilla.gecko.text.TextSelection;
 import org.mozilla.gecko.util.FloatUtils;
 import org.mozilla.gecko.util.GeckoEventListener;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.ActionModeCompat.Callback;
 import org.mozilla.gecko.AppConstants.Versions;
 
@@ -244,16 +245,17 @@ class ActionBarTextSelection extends Lay
             return;
         }
 
         final Context context = anchorHandle.getContext();
         if (context instanceof ActionModeCompat.Presenter) {
             final ActionModeCompat.Presenter presenter = (ActionModeCompat.Presenter) context;
             mCallback = new TextSelectionActionModeCallback(items);
             presenter.startActionModeCompat(mCallback);
+            mCallback.animateIn();
         }
     }
 
     private void endActionMode() {
         Context context = anchorHandle.getContext();
         if (context instanceof ActionModeCompat.Presenter) {
             final ActionModeCompat.Presenter presenter = (ActionModeCompat.Presenter) context;
             presenter.endActionModeCompat();
@@ -316,18 +318,24 @@ class ActionBarTextSelection extends Lay
 
         public void updateItems(JSONArray items) {
             mItems = items;
             if (mActionMode != null) {
                 mActionMode.invalidate();
             }
         }
 
+        public void animateIn() {
+            if (mActionMode != null) {
+                mActionMode.animateIn();
+            }
+        }
+
         @Override
-        public boolean onPrepareActionMode(final ActionModeCompat mode, final Menu menu) {
+        public boolean onPrepareActionMode(final ActionModeCompat mode, final GeckoMenu menu) {
             // Android would normally expect us to only update the state of menu items here
             // To make the js-java interaction a bit simpler, we just wipe out the menu here and recreate all
             // the javascript menu items in onPrepare instead. This will be called any time invalidate() is called on the
             // action mode.
             menu.clear();
 
             int length = mItems.length();
             for (int i = 0; i < length; i++) {
@@ -349,17 +357,17 @@ class ActionBarTextSelection extends Lay
                 } catch (Exception ex) {
                     Log.i(LOGTAG, "Exception building menu", ex);
                 }
             }
             return true;
         }
 
         @Override
-        public boolean onCreateActionMode(ActionModeCompat mode, Menu menu) {
+        public boolean onCreateActionMode(ActionModeCompat mode, GeckoMenu unused) {
             mActionMode = mode;
             return true;
         }
 
         @Override
         public boolean onActionItemClicked(ActionModeCompat mode, MenuItem item) {
             try {
                 final JSONObject obj = mItems.getJSONObject(item.getItemId());
--- a/mobile/android/base/java/org/mozilla/gecko/ActionModeCompat.java
+++ b/mobile/android/base/java/org/mozilla/gecko/ActionModeCompat.java
@@ -1,16 +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 org.mozilla.gecko.menu.GeckoMenu;
+import org.mozilla.gecko.menu.GeckoMenuItem;
 import org.mozilla.gecko.widget.GeckoPopupMenu;
-import org.mozilla.gecko.menu.GeckoMenuItem;
 
 import android.view.Gravity;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 import android.widget.Toast;
 
 class ActionModeCompat implements GeckoPopupMenu.OnMenuItemClickListener,
@@ -21,21 +22,21 @@ class ActionModeCompat implements GeckoP
     private final Callback mCallback;
     private final ActionModeCompatView mView;
     private final Presenter mPresenter;
 
     /* A set of callbacks to be called during this ActionMode's lifecycle. These will control the
      * creation, interaction with, and destruction of menuitems for the view */
     public static interface Callback {
         /* Called when action mode is first created. Implementors should use this to inflate menu resources. */
-        public boolean onCreateActionMode(ActionModeCompat mode, Menu menu);
+        public boolean onCreateActionMode(ActionModeCompat mode, GeckoMenu menu);
 
         /* Called to refresh an action mode's action menu. Called whenever the mode is invalidated. Implementors
          * should use this to enable/disable/show/hide menu items. */
-        public boolean onPrepareActionMode(ActionModeCompat mode, Menu menu);
+        public boolean onPrepareActionMode(ActionModeCompat mode, GeckoMenu menu);
 
         /* Called to report a user click on an action button. */
         public boolean onActionItemClicked(ActionModeCompat mode, MenuItem item);
 
         /* Called when an action mode is about to be exited and destroyed. */
         public void onDestroyActionMode(ActionModeCompat mode);
     }
 
@@ -72,27 +73,31 @@ class ActionModeCompat implements GeckoP
     public void setTitle(CharSequence title) {
         mView.setTitle(title);
     }
 
     public void setTitle(int resId) {
         mView.setTitle(resId);
     }
 
-    public Menu getMenu() {
+    public GeckoMenu getMenu() {
         return mView.getMenu();
     }
 
     public void invalidate() {
         if (mCallback != null) {
             mCallback.onPrepareActionMode(this, mView.getMenu());
         }
         mView.invalidate();
     }
 
+    public void animateIn() {
+        mView.animateIn();
+    }
+
     /* GeckoPopupMenu.OnMenuItemClickListener */
     @Override
     public boolean onMenuItemClick(MenuItem item) {
         if (mCallback != null) {
             return mCallback.onActionItemClicked(this, item);
         }
         return false;
     }
--- a/mobile/android/base/java/org/mozilla/gecko/ActionModeCompatView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/ActionModeCompatView.java
@@ -54,17 +54,17 @@ class ActionModeCompatView extends Linea
     public void init(Context context) {
         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);
-        ((GeckoMenu) mPopupMenu.getMenu()).setActionItemBarPresenter(this);
+        mPopupMenu.getMenu().setActionItemBarPresenter(this);
 
         mMenuButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 openMenu();
             }
         });
     }
@@ -82,17 +82,17 @@ class ActionModeCompatView extends Linea
     public void setTitle(CharSequence title) {
         mTitleView.setText(title);
     }
 
     public void setTitle(int resId) {
         mTitleView.setText(resId);
     }
 
-    public Menu getMenu() {
+    public GeckoMenu getMenu() {
         return mPopupMenu.getMenu();
     }
 
     @Override
     public void invalidate() {
         // onFinishInflate may not have been called yet on some versions of Android
         if (mPopupMenu != null && mMenuButton != null) {
             mMenuButton.setVisibility(mPopupMenu.getMenu().hasVisibleItems() ? View.VISIBLE : View.GONE);
@@ -167,11 +167,15 @@ class ActionModeCompatView extends Linea
         t.setDuration(duration);
 
         ScaleAnimation s = new ScaleAnimation(1f, 1f, 0f, 1f,
                                               Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
         s.setDuration((long) (duration * 1.5f));
 
         mTitleView.startAnimation(t);
         mActionButtonBar.startAnimation(s);
-        mMenuButton.startAnimation(s);
+
+        if ((mMenuButton.getVisibility() == View.VISIBLE) &&
+            (mPopupMenu.getMenu().size() > 0)) {
+            mMenuButton.startAnimation(s);
+        }
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -3997,22 +3997,19 @@ public class BrowserApp extends GeckoApp
         // If actionMode is null, we're not currently showing one. Flip to the action mode view
         if (mActionMode == null) {
             mActionBarFlipper.showNext();
             DynamicToolbarAnimator toolbar = mLayerView.getDynamicToolbarAnimator();
 
             // If the toolbar is dynamic and not currently showing, just slide it in
             if (mDynamicToolbar.isEnabled() && toolbar.getToolbarTranslation() != 0) {
                 mDynamicToolbar.setTemporarilyVisible(true, VisibilityTransition.ANIMATE);
-            } else {
-                // Otherwise, we animate the actionbar itself
-                mActionBar.animateIn();
             }
-
             mDynamicToolbar.setPinned(true, PinReason.ACTION_MODE);
+
         } else {
             // Otherwise, we're already showing an action mode. Just finish it and show the new one
             mActionMode.finish();
         }
 
         mActionMode = new ActionModeCompat(BrowserApp.this, callback, mActionBar);
         if (callback.onCreateActionMode(mActionMode, mActionMode.getMenu())) {
             mActionMode.invalidate();
--- a/mobile/android/base/java/org/mozilla/gecko/widget/GeckoPopupMenu.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/GeckoPopupMenu.java
@@ -77,17 +77,17 @@ public class GeckoPopupMenu implements G
         setAnchor(anchor);
     }
 
     /**
      * Returns the menu that is current being shown.
      *
      * @return The menu being shown.
      */
-    public Menu getMenu() {
+    public GeckoMenu getMenu() {
         return mMenu;
     }
 
     /**
      * Returns the menu inflater that was used to create the menu.
      *
      * @return The menu inflater used.
      */