Bug 1139553 - Black overlay for doorhanger background. r=ally,a=RyanVM
authorChenxia Liu <liuche@mozilla.com>
Wed, 27 May 2015 10:46:44 -0700
changeset 248052 f7e900c02fddcb6270d265bac45ec2f04723d834
parent 248051 0935b76b6ec725b26d5195d74b6b7d9bdc175d6a
child 248053 f3760acfed2ac7f66c0170948e5c91561bfda44a
push id60888
push userkwierso@gmail.com
push dateThu, 11 Jun 2015 01:38:38 +0000
treeherdermozilla-inbound@39e638ed06bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersally, RyanVM
bugs1139553
milestone41.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 1139553 - Black overlay for doorhanger background. r=ally,a=RyanVM
mobile/android/base/BrowserApp.java
mobile/android/base/resources/layout/firstrun_pane.xml
mobile/android/base/resources/layout/gecko_app.xml
mobile/android/base/resources/values/colors.xml
mobile/android/base/toolbar/ToolbarDisplayLayout.java
mobile/android/base/widget/AnchoredPopup.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -1,15 +1,18 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * 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 com.nineoldandroids.animation.Animator;
+import com.nineoldandroids.animation.AnimatorListenerAdapter;
+import com.nineoldandroids.animation.ObjectAnimator;
 import org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.DynamicToolbar.PinReason;
 import org.mozilla.gecko.DynamicToolbar.VisibilityTransition;
 import org.mozilla.gecko.GeckoProfileDirectories.NoMozillaDirectoryException;
 import org.mozilla.gecko.Tabs.TabEvents;
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.TransitionsTracker;
 import org.mozilla.gecko.animation.ViewHelper;
@@ -149,17 +152,17 @@ public class BrowserApp extends GeckoApp
                         implements TabsPanel.TabsLayoutChangeListener,
                                    PropertyAnimator.PropertyAnimationListener,
                                    View.OnKeyListener,
                                    LayerView.OnMetricsChangedListener,
                                    BrowserSearch.OnSearchListener,
                                    BrowserSearch.OnEditSuggestionListener,
                                    OnUrlOpenListener,
                                    OnUrlOpenInBackgroundListener,
-                                   AnchoredPopup.OnShowListener,
+                                   AnchoredPopup.OnVisibilityChangeListener,
                                    ActionModeCompat.Presenter,
                                    LayoutInflater.Factory {
     private static final String LOGTAG = "GeckoBrowserApp";
 
     private static final boolean ZOOMED_VIEW_ENABLED = AppConstants.NIGHTLY_BUILD;
 
     private static final int TABS_ANIMATION_DURATION = 450;
 
@@ -179,16 +182,17 @@ public class BrowserApp extends GeckoApp
 
     private BrowserSearch mBrowserSearch;
     private View mBrowserSearchContainer;
 
     public ViewGroup mBrowserChrome;
     public ViewFlipper mActionBarFlipper;
     public ActionModeCompatView mActionBar;
     private BrowserToolbar mBrowserToolbar;
+    private View mDoorhangerOverlay;
     // We can't name the TabStrip class because it's not included on API 9.
     private Refreshable mTabStrip;
     private ToolbarProgressView mProgressView;
     private FirstrunPane mFirstrunPane;
     private HomePager mHomePager;
     private TabsPanel mTabsPanel;
     private ViewGroup mHomePagerContainer;
     private ActionModeCompat mActionMode;
@@ -909,16 +913,21 @@ public class BrowserApp extends GeckoApp
             return;
         }
 
         super.onBackPressed();
     }
 
     @Override
     public void onAttachedToWindow() {
+        // Gingerbread 2.3 doesn't handle starting alphas correctly, so disable doorhanger overlays for that, and perf.
+        if (!Versions.preHC){
+            mDoorhangerOverlay = findViewById(R.id.doorhanger_overlay);
+            mDoorhangerOverlay.setVisibility(View.VISIBLE);
+        }
         // We can't show the first run experience until Gecko has finished initialization (bug 1077583).
         checkFirstrun(this, new SafeIntent(getIntent()));
     }
 
     @Override
     protected void processTabQueue() {
         if (AppConstants.NIGHTLY_BUILD && AppConstants.MOZ_ANDROID_TAB_QUEUE && mInitialized) {
             ThreadUtils.postToBackgroundThread(new Runnable() {
@@ -1374,39 +1383,59 @@ public class BrowserApp extends GeckoApp
         super.onDestroy();
     }
 
     @Override
     protected void initializeChrome() {
         super.initializeChrome();
 
         mDoorHangerPopup.setAnchor(mBrowserToolbar.getDoorHangerAnchor());
-        mDoorHangerPopup.setOnShowListener(this);
+        mDoorHangerPopup.setOnVisibilityChangeListener(this);
 
         mDynamicToolbar.setLayerView(mLayerView);
         setDynamicToolbarEnabled(mDynamicToolbar.isEnabled());
 
         // Intercept key events for gamepad shortcuts
         mLayerView.setOnKeyListener(this);
 
         // Initialize the actionbar menu items on startup for both large and small tablets
         if (HardwareUtils.isTablet()) {
             onCreatePanelMenu(Window.FEATURE_OPTIONS_PANEL, null);
             invalidateOptionsMenu();
         }
     }
 
     @Override
     public void onDoorHangerShow() {
-        ThreadUtils.postToUiThread(new Runnable() {
-            @Override
-            public void run() {
-                mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
-            }
-        });
+        mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
+
+        if (Versions.preHC) {
+            return;
+        }
+
+        final Animator alphaAnimator = ObjectAnimator.ofFloat(mDoorhangerOverlay, "alpha", 1);
+        alphaAnimator.setDuration(250);
+        TransitionsTracker.track(alphaAnimator);
+
+        alphaAnimator.start();
+
+    }
+
+    @Override
+    public void onDoorHangerHide() {
+        if (Versions.preHC) {
+            return;
+        }
+
+        final Animator alphaAnimator = ObjectAnimator.ofFloat(mDoorhangerOverlay, "alpha", 0);
+        alphaAnimator.setDuration(200);
+
+        TransitionsTracker.track(alphaAnimator);
+
+        alphaAnimator.start();
     }
 
     private void handleClearHistory(final boolean clearSearchHistory) {
         final BrowserDB db = getProfile().getDB();
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
                 db.clearHistory(getContentResolver(), clearSearchHistory);
--- a/mobile/android/base/resources/layout/firstrun_pane.xml
+++ b/mobile/android/base/resources/layout/firstrun_pane.xml
@@ -3,17 +3,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/.  -->
 
 <org.mozilla.gecko.firstrun.FirstrunPane xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:gecko="http://schemas.android.com/apk/res-auto"
              android:layout_height="match_parent"
              android:layout_width="match_parent"
-             android:background="@color/firstrun_background">
+             android:background="@color/dark_transparent_overlay">
 
     <org.mozilla.gecko.firstrun.FirstrunPager
                     android:id="@+id/firstrun_pager"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
                     android:background="@color/firstrun_pager_background">
 
         <org.mozilla.gecko.home.HomePagerTabStrip android:id="@+id/firstrun_tab_strip"
--- a/mobile/android/base/resources/layout/gecko_app.xml
+++ b/mobile/android/base/resources/layout/gecko_app.xml
@@ -52,16 +52,24 @@
 
                 <ViewStub android:id="@+id/firstrun_pager_stub"
                           android:layout="@layout/firstrun_pane"
                           android:layout_width="match_parent"
                           android:layout_height="match_parent"/>
 
             </FrameLayout>
 
+            <LinearLayout android:id="@+id/doorhanger_overlay"
+                          android:layout_width="match_parent"
+                          android:layout_height="match_parent"
+                          android:background="@color/dark_transparent_overlay"
+                          android:visibility="gone"
+                          android:alpha="0"
+                          android:layerType="hardware"/>
+
         </RelativeLayout>
 
         <org.mozilla.gecko.FindInPageBar android:id="@+id/find_in_page"
                                          android:layout_width="match_parent"
                                          android:layout_height="wrap_content"
                                          android:layout_alignParentBottom="true"
                                          style="@style/FindBar"
                                          android:visibility="gone"/>
--- a/mobile/android/base/resources/values/colors.xml
+++ b/mobile/android/base/resources/values/colors.xml
@@ -52,18 +52,19 @@
   <color name="highlight_shaped_focused">#FF565B60</color>
 
   <!-- highlight on private nav button: 20% white over private_toolbar_grey -->
   <color name="highlight_nav_pb">#FF545654</color>
 
   <!-- highlight-focused on private nav button: 10% white over private_toolbar_grey -->
   <color name="highlight_nav_focused_pb">#FF3F423F</color>
 
+  <color name="dark_transparent_overlay">#99000000</color>
+
   <!-- Firstrun tour-->
-  <color name="firstrun_background">#99000000</color>
   <color name="firstrun_tabstrip">#1193CB</color>
   <color name="firstrun_pager_background">#16A3DF</color>
 
   <!-- Tab Queue -->
   <color name="tab_queue_dismiss_button_foreground">#16A3DF</color>
   <color name="tab_queue_dismiss_button_foreground_pressed">#1193CB</color>
   <color name="tab_queue_background">#16A3DF</color>
 
--- a/mobile/android/base/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/toolbar/ToolbarDisplayLayout.java
@@ -168,16 +168,17 @@ public class ToolbarDisplayLayout extend
             }
             mFaviconSize = Math.round(Favicons.browserToolbarFaviconSize);
         }
 
         mSiteSecurityVisible = (mSiteSecurity.getVisibility() == View.VISIBLE);
 
         mSiteIdentityPopup = new SiteIdentityPopup(mActivity);
         mSiteIdentityPopup.setAnchor(this);
+        mSiteIdentityPopup.setOnVisibilityChangeListener(mActivity);
 
         mStop = (ImageButton) findViewById(R.id.stop);
         mPageActionLayout = (PageActionLayout) findViewById(R.id.page_action_layout);
     }
 
     @Override
     public void onAttachedToWindow() {
         mIsAttached = true;
--- a/mobile/android/base/widget/AnchoredPopup.java
+++ b/mobile/android/base/widget/AnchoredPopup.java
@@ -18,22 +18,23 @@ import android.view.ViewGroup;
 import android.widget.LinearLayout;
 import android.widget.PopupWindow;
 import org.mozilla.gecko.util.HardwareUtils;
 
 /**
  * AnchoredPopup is the base class for doorhanger notifications, and is anchored to the urlbar.
  */
 public abstract class AnchoredPopup extends PopupWindow {
-    public interface OnShowListener {
+    public interface OnVisibilityChangeListener {
         public void onDoorHangerShow();
+        public void onDoorHangerHide();
     }
 
     private View mAnchor;
-    private OnShowListener mOnShowListener;
+    private OnVisibilityChangeListener onVisibilityChangeListener;
 
     protected LinearLayout mContent;
     protected boolean mInflated;
 
     protected final Context mContext;
 
     public AnchoredPopup(Context context) {
         super(context);
@@ -69,31 +70,31 @@ public abstract class AnchoredPopup exte
      * Sets the anchor for this popup.
      *
      * @param anchor Anchor view for positioning the arrow.
      */
     public void setAnchor(View anchor) {
         mAnchor = anchor;
     }
 
-    public void setOnShowListener(OnShowListener listener) {
-        mOnShowListener = listener;
+    public void setOnVisibilityChangeListener(OnVisibilityChangeListener listener) {
+        onVisibilityChangeListener = listener;
     }
 
     /**
      * Shows the popup with the arrow pointing to the center of the anchor view. If the anchor
      * isn't visible, the popup will just be shown at the top of the root view.
      */
     public void show() {
         if (!mInflated) {
             throw new IllegalStateException("ArrowPopup#init() must be called before ArrowPopup#show()");
         }
 
-        if (mOnShowListener != null) {
-            mOnShowListener.onDoorHangerShow();
+        if (onVisibilityChangeListener != null) {
+            onVisibilityChangeListener.onDoorHangerShow();
         }
 
         final int[] anchorLocation = new int[2];
         if (mAnchor != null) {
             mAnchor.getLocationInWindow(anchorLocation);
         }
 
         // The doorhanger should overlap the bottom of the urlbar.
@@ -126,9 +127,17 @@ public abstract class AnchoredPopup exte
         } else {
             // If the anchor is null or out of the window bounds, just show the popup at the top of the
             // root view.
             final View anchor = validAnchor ? mAnchor : decorView;
 
             showAtLocation(anchor, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, offsetY);
         }
     }
+
+    @Override
+    public void dismiss() {
+        super.dismiss();
+        if (onVisibilityChangeListener != null) {
+            onVisibilityChangeListener.onDoorHangerHide();
+        }
+    }
 }