Bug 920791 - Hide banner when URL bar is focused. r=lucasr
authorJoshua Dover <jdover@mozilla.com>
Thu, 30 Jan 2014 10:45:31 -0800
changeset 182364 a4b73c79ac449d4a49404ff9fe4a3d9de8017507
parent 182363 b7d50811ea818054fedff80761d9593081db9b9b
child 182365 fb9b26afff458a0f606546998acca71a0036596f
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs920791
milestone29.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 920791 - Hide banner when URL bar is focused. r=lucasr
mobile/android/base/BrowserApp.java
mobile/android/base/home/HomeBanner.java
mobile/android/base/home/HomePager.java
mobile/android/base/toolbar/BrowserToolbar.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -515,16 +515,25 @@ abstract public class BrowserApp extends
                 hideBrowserSearch();
                 hideHomePager();
 
                 // Re-enable doorhanger notifications. They may trigger on the selected tab above.
                 mDoorHangerPopup.enable();
             }
         });
 
+        mBrowserToolbar.setOnFocusChangeListener(new View.OnFocusChangeListener() {
+            @Override
+            public void onFocusChange(View v, boolean hasFocus) {
+                if (isHomePagerVisible()) {
+                    mHomePager.onToolbarFocusChange(hasFocus);
+                }
+            }
+        });
+
         // Intercept key events for gamepad shortcuts
         mBrowserToolbar.setOnKeyListener(this);
 
         if (mTabsPanel != null) {
             mTabsPanel.setTabsLayoutChangeListener(this);
             updateSideBarState();
         }
 
--- a/mobile/android/base/home/HomeBanner.java
+++ b/mobile/android/base/home/HomeBanner.java
@@ -92,23 +92,23 @@ public class HomeBanner extends LinearLa
         GeckoAppShell.getEventDispatcher().registerEventListener("HomeBanner:Data", this);
     }
 
     @Override
     public void onDetachedFromWindow() {
         GeckoAppShell.getEventDispatcher().unregisterEventListener("HomeBanner:Data", this);
     }
 
-    public void showBanner() {
+    public void show() {
         if (!mDismissed) {
             GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("HomeBanner:Get", null));
         }
     }
 
-    public void hideBanner() {
+    public void hide() {
         animateDown();
     }
 
     public void setScrollingPages(boolean scrollingPages) {
         mScrollingPages = scrollingPages;
     }
 
     @Override
--- a/mobile/android/base/home/HomePager.java
+++ b/mobile/android/base/home/HomePager.java
@@ -283,19 +283,19 @@ public class HomePager extends ViewPager
     public void setCurrentItem(int item, boolean smoothScroll) {
         super.setCurrentItem(item, smoothScroll);
 
         if (mDecor != null) {
             mDecor.onPageSelected(item);
         }
         if (mHomeBanner != null) {
             if (item == mDefaultPanelIndex) {
-                mHomeBanner.showBanner();
+                mHomeBanner.show();
             } else {
-                mHomeBanner.hideBanner();
+                mHomeBanner.hide();
             }
         }
     }
 
     @Override
     public boolean onInterceptTouchEvent(MotionEvent event) {
         if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
             // Drop the soft keyboard by stealing focus from the URL bar.
@@ -310,16 +310,24 @@ public class HomePager extends ViewPager
         // Get touches to pages, pass to banner, and forward to pages.
         if (mHomeBanner != null) {
             mHomeBanner.handleHomeTouch(event);
         }
 
         return super.dispatchTouchEvent(event);
     }
 
+    public void onToolbarFocusChange(boolean hasFocus) {
+        if (hasFocus) {
+            mHomeBanner.hide();
+        } else if (mDefaultPanelIndex == getCurrentItem() || getAdapter().getCount() == 0) {
+            mHomeBanner.show();
+        }
+    }
+
     private void updateUiFromPanelConfigs(List<PanelConfig> panelConfigs) {
         // We only care about the adapter if HomePager is currently
         // loaded, which means it's visible in the activity.
         if (!mLoaded) {
             return;
         }
 
         if (mDecor != null) {
@@ -391,19 +399,19 @@ public class HomePager extends ViewPager
         @Override
         public void onPageSelected(int position) {
             if (mDecor != null) {
                 mDecor.onPageSelected(position);
             }
 
             if (mHomeBanner != null) {
                 if (position == mDefaultPanelIndex) {
-                    mHomeBanner.showBanner();
+                    mHomeBanner.show();
                 } else {
-                    mHomeBanner.hideBanner();
+                    mHomeBanner.hide();
                 }
             }
         }
 
         @Override
         public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
             if (mDecor != null) {
                 mDecor.onPageScrolled(position, positionOffset, positionOffsetPixels);
--- a/mobile/android/base/toolbar/BrowserToolbar.java
+++ b/mobile/android/base/toolbar/BrowserToolbar.java
@@ -137,16 +137,17 @@ public class BrowserToolbar extends Geck
     private List<View> mFocusOrder;
 
     private OnActivateListener mActivateListener;
     private OnCommitListener mCommitListener;
     private OnDismissListener mDismissListener;
     private OnFilterListener mFilterListener;
     private OnStartEditingListener mStartEditingListener;
     private OnStopEditingListener mStopEditingListener;
+    private OnFocusChangeListener mFocusChangeListener;
 
     final private BrowserApp mActivity;
     private boolean mHasSoftMenuButton;
 
     private UIMode mUIMode;
     private boolean mAnimatingEntry;
 
     private int mUrlBarViewOffset;
@@ -310,16 +311,19 @@ public class BrowserToolbar extends Geck
                 setContentDescription(contentDescription);
             }
         });
 
         mUrlEditLayout.setOnFocusChangeListener(new View.OnFocusChangeListener() {
             @Override
             public void onFocusChange(View v, boolean hasFocus) {
                 setSelected(hasFocus);
+                if (mFocusChangeListener != null) {
+                    mFocusChangeListener.onFocusChange(v, hasFocus);
+                }
             }
         });
 
         mTabs.setOnClickListener(new Button.OnClickListener() {
             @Override
             public void onClick(View v) {
                 toggleTabs();
             }
@@ -788,16 +792,20 @@ public class BrowserToolbar extends Geck
     public void setOnStartEditingListener(OnStartEditingListener listener) {
         mStartEditingListener = listener;
     }
 
     public void setOnStopEditingListener(OnStopEditingListener listener) {
         mStopEditingListener = listener;
     }
 
+    public void setOnFocusChangeListener(OnFocusChangeListener listener) {
+        mFocusChangeListener = listener;
+    }
+
     private void showUrlEditLayout() {
         setUrlEditLayoutVisibility(true, null);
     }
 
     private void showUrlEditLayout(PropertyAnimator animator) {
         setUrlEditLayoutVisibility(true, animator);
     }