Bug 1133770 - Display the selected tab in the tab strip on device rotation. r=mhaigh, a=lizzard
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 18 Feb 2015 14:23:19 -0800
changeset 250077 eb261fd50770
parent 250076 b5f695706683
child 250078 e7319d343f20
push id4497
push userryanvm@gmail.com
push date2015-02-25 20:26 +0000
treeherdermozilla-beta@b23a690fa325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhaigh, lizzard
bugs1133770, 1134408
milestone37.0
Bug 1133770 - Display the selected tab in the tab strip on device rotation. r=mhaigh, a=lizzard This does not always work in the case that one of the last few tabs (to the right) are selected and the device is rotated from landscape to portrait. Filed bug 1134408 to track this.
mobile/android/base/BrowserApp.java
mobile/android/base/tabs/TabStrip.java
mobile/android/base/tabs/TabStripView.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -62,16 +62,17 @@ import org.mozilla.gecko.mozglue.Context
 import org.mozilla.gecko.preferences.ClearOnShutdownPref;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.prompts.Prompt;
 import org.mozilla.gecko.prompts.PromptListItem;
 import org.mozilla.gecko.sync.setup.SyncAccounts;
 import org.mozilla.gecko.tabs.TabHistoryController;
 import org.mozilla.gecko.tabs.TabHistoryFragment;
 import org.mozilla.gecko.tabs.TabHistoryPage;
+import org.mozilla.gecko.tabs.TabStrip;
 import org.mozilla.gecko.tabs.TabsPanel;
 import org.mozilla.gecko.tabs.TabHistoryController.OnShowTabHistory;
 import org.mozilla.gecko.tiles.TilesRecorder;
 import org.mozilla.gecko.toolbar.AutocompleteHandler;
 import org.mozilla.gecko.toolbar.BrowserToolbar;
 import org.mozilla.gecko.toolbar.BrowserToolbar.TabEditingState;
 import org.mozilla.gecko.toolbar.ToolbarProgressView;
 import org.mozilla.gecko.util.Clipboard;
@@ -173,16 +174,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 TabStrip mTabStrip;
     private ToolbarProgressView mProgressView;
     private HomePager mHomePager;
     private TabsPanel mTabsPanel;
     private ViewGroup mHomePagerContainer;
     protected Telemetry.Timer mAboutHomeStartupTimer;
     private ActionModeCompat mActionMode;
     private boolean mHideDynamicToolbarOnActionModeEnd;
     private TabHistoryController tabHistoryController;
@@ -544,17 +546,17 @@ public class BrowserApp extends GeckoApp
             mBrowserToolbar.setTitle(intent.getDataString());
 
             Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT);
         } else if (GuestSession.NOTIFICATION_INTENT.equals(action)) {
             GuestSession.handleIntent(this, intent);
         }
 
         if (NewTabletUI.isEnabled(this)) {
-            findViewById(R.id.new_tablet_tab_strip).setVisibility(View.VISIBLE);
+            mTabStrip = (TabStrip) (((ViewStub) findViewById(R.id.new_tablet_tab_strip)).inflate());
         }
 
         ((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideOnTouchListener());
         ((GeckoApp.MainLayout) mMainLayout).setMotionEventInterceptor(new MotionEventInterceptor() {
             @Override
             public boolean onInterceptMotionEvent(View view, MotionEvent event) {
                 // If we get a gamepad panning MotionEvent while the focus is not on the layerview,
                 // put the focus on the layerview and carry on
@@ -1342,16 +1344,20 @@ public class BrowserApp extends GeckoApp
     public void refreshChrome() {
         invalidateOptionsMenu();
 
         if (mTabsPanel != null) {
             updateSideBarState();
             mTabsPanel.refresh();
         }
 
+        if (mTabStrip != null) {
+            mTabStrip.refresh();
+        }
+
         mBrowserToolbar.refresh();
     }
 
     @Override
     public boolean hasTabsSideBar() {
         return (mTabsPanel != null && mTabsPanel.isSideBar());
     }
 
--- a/mobile/android/base/tabs/TabStrip.java
+++ b/mobile/android/base/tabs/TabStrip.java
@@ -123,16 +123,20 @@ public class TabStrip extends ThemedLine
                 case FAVICON:
                 case RECORDING_CHANGE:
                     tabStripView.updateTab(tab);
                     break;
             }
         }
     }
 
+    public void refresh() {
+        tabStripView.refresh();
+    }
+
     @Override
     public void onLightweightThemeChanged() {
         final Drawable drawable = getTheme().getDrawable(this);
         if (drawable == null) {
             return;
         }
 
         final StateListDrawable stateList = new StateListDrawable();
--- a/mobile/android/base/tabs/TabStripView.java
+++ b/mobile/android/base/tabs/TabStripView.java
@@ -97,17 +97,17 @@ public class TabStripView extends TwoWay
     }
 
     private void updateSelectedPosition(boolean ensureVisible) {
         final int selected = getPositionForSelectedTab();
         if (selected != -1) {
             updateSelectedStyle(selected);
 
             if (ensureVisible) {
-                ensurePositionIsVisible(selected);
+                ensurePositionIsVisible(selected, true);
             }
         }
     }
 
     private void animateRemoveTab(Tab removedTab) {
         final int removedPosition = adapter.getPositionForTab(removedTab);
 
         final View removedView = getViewForTab(removedTab);
@@ -234,20 +234,24 @@ public class TabStripView extends TwoWay
 
                 animatorSet.start();
 
                 return true;
             }
         });
     }
 
-    private void ensurePositionIsVisible(final int position) {
+    /**
+     * Ensures the tab at the given position is visible. If we are not restoring tabs and
+     * shouldAnimate == true, the tab will animate to be visible, if it is not already visible.
+     */
+    private void ensurePositionIsVisible(final int position, final boolean shouldAnimate) {
         // We just want to move the strip to the right position
         // when restoring tabs on startup.
-        if (isRestoringTabs) {
+        if (isRestoringTabs || !shouldAnimate) {
             setSelection(position);
             return;
         }
 
         getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
             @Override
             public boolean onPreDraw() {
                 getViewTreeObserver().removeOnPreDrawListener(this);
@@ -409,16 +413,23 @@ public class TabStripView extends TwoWay
 
     @Override
     public void draw(Canvas canvas) {
         super.draw(canvas);
         drawDividers(canvas);
         drawFadingEdge(canvas);
     }
 
+    public void refresh() {
+        final int selectedPosition = getPositionForSelectedTab();
+        if (selectedPosition != -1) {
+            ensurePositionIsVisible(selectedPosition, false);
+        }
+    }
+
     private class TabAnimatorListener implements AnimatorListener {
         private void setLayerType(int layerType) {
             final int childCount = getChildCount();
             for (int i = 0; i < childCount; i++) {
                 getChildAt(i).setLayerType(layerType, null);
             }
         }