Bug 1176250 - Current tab sometimes not visible in Tabs Tray on tablet (r=s.kaspari)
authorMartyn Haigh <mhaigh@mozilla.org>
Fri, 26 Jun 2015 14:02:24 -0700
changeset 250665 7341164aa82a601eed1b0338a27c25c2315dffbf
parent 250664 87f6240419e4e022e02dc77a7d36a7b9ac24e891
child 250666 1f967726f39a964c765f1d1cfb25026971cbf908
push id28967
push userkwierso@gmail.com
push dateTue, 30 Jun 2015 23:31:58 +0000
treeherdermozilla-central@fafe4a3be0ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerss.kaspari
bugs1176250
milestone42.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 1176250 - Current tab sometimes not visible in Tabs Tray on tablet (r=s.kaspari)
mobile/android/base/tabs/TabsGridLayout.java
--- a/mobile/android/base/tabs/TabsGridLayout.java
+++ b/mobile/android/base/tabs/TabsGridLayout.java
@@ -46,27 +46,27 @@ import java.util.List;
  * Expected to replace TabsListLayout once complete.
  */
 
 class TabsGridLayout extends GridView
                      implements TabsLayout,
                                 Tabs.OnTabsChangedListener {
     private static final String LOGTAG = "Gecko" + TabsGridLayout.class.getSimpleName();
 
+    public static final int ANIM_DELAY_MULTIPLE_MS = 20;
     private static final int ANIM_TIME_MS = 200;
-    public static final int ANIM_DELAY_MULTIPLE_MS = 20;
     private static final DecelerateInterpolator ANIM_INTERPOLATOR = new DecelerateInterpolator();
 
     private final Context mContext;
-    private TabsPanel mTabsPanel;
     private final SparseArray<PointF> mTabLocations = new SparseArray<PointF>();
     private final boolean mIsPrivate;
     private final TabsLayoutAdapter mTabsAdapter;
-
     private final int mColumnWidth;
+    private TabsPanel mTabsPanel;
+    private int lastSelectedTabId;
 
     public TabsGridLayout(Context context, AttributeSet attrs) {
         super(context, attrs, R.attr.tabGridLayoutViewStyle);
         mContext = context;
 
         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabsLayout);
         mIsPrivate = (a.getInt(R.styleable.TabsLayout_tabs, 0x0) == 1);
         a.recycle();
@@ -107,50 +107,16 @@ class TabsGridLayout extends GridView
             }
         });
 
         TabSwipeGestureListener mSwipeListener = new TabSwipeGestureListener();
         setOnTouchListener(mSwipeListener);
         setOnScrollListener(mSwipeListener.makeScrollListener());
     }
 
-    private class TabsGridLayoutAdapter extends TabsLayoutAdapter {
-
-        final private Button.OnClickListener mCloseClickListener;
-
-        public TabsGridLayoutAdapter(Context context) {
-            super(context, R.layout.new_tablet_tabs_item_cell);
-
-            mCloseClickListener = new Button.OnClickListener() {
-                @Override
-                public void onClick(View v) {
-                    closeTab(v);
-                }
-            };
-        }
-
-        @Override
-        TabsLayoutItemView newView(int position, ViewGroup parent) {
-            final TabsLayoutItemView item = super.newView(position, parent);
-
-            item.setCloseOnClickListener(mCloseClickListener);
-
-            return item;
-        }
-
-        @Override
-        public void bindView(TabsLayoutItemView view, Tab tab) {
-            super.bindView(view, tab);
-
-            // If we're recycling this view, there's a chance it was transformed during
-            // the close animation. Remove any of those properties.
-            resetTransforms(view);
-        }
-    }
-
     private void populateTabLocations(final Tab removedTab) {
         mTabLocations.clear();
 
         final int firstPosition = getFirstVisiblePosition();
         final int lastPosition = getLastVisiblePosition();
         final int numberOfColumns = getNumColumns();
         final int childCount = getChildCount();
         final int removedPosition = mTabsAdapter.getPositionForTab(removedTab);
@@ -194,20 +160,26 @@ class TabsGridLayout extends GridView
     }
 
     @Override
     public void show() {
         setVisibility(View.VISIBLE);
         Tabs.getInstance().refreshThumbnails();
         Tabs.registerOnTabsChangedListener(this);
         refreshTabsData();
+
+        Tab currentlySelectedTab = Tabs.getInstance().getSelectedTab();
+        if (lastSelectedTabId != currentlySelectedTab.getId()) {
+            smoothScrollToPosition(mTabsAdapter.getPositionForTab(currentlySelectedTab));
+        }
     }
 
     @Override
     public void hide() {
+        lastSelectedTabId = Tabs.getInstance().getSelectedTab().getId();
         setVisibility(View.GONE);
         Tabs.unregisterOnTabsChangedListener(this);
         GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Screenshot:Cancel", ""));
         mTabsAdapter.clear();
     }
 
     @Override
     public boolean shouldExpand() {
@@ -434,16 +406,49 @@ class TabsGridLayout extends GridView
                 TabsLayoutItemView tab = (TabsLayoutItemView) view;
                 tab.setCloseVisible(true);
             }
         });
 
         animator.start();
     }
 
+    private class TabsGridLayoutAdapter extends TabsLayoutAdapter {
+
+        final private Button.OnClickListener mCloseClickListener;
+
+        public TabsGridLayoutAdapter(Context context) {
+            super(context, R.layout.new_tablet_tabs_item_cell);
+
+            mCloseClickListener = new Button.OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    closeTab(v);
+                }
+            };
+        }
+
+        @Override
+        TabsLayoutItemView newView(int position, ViewGroup parent) {
+            final TabsLayoutItemView item = super.newView(position, parent);
+
+            item.setCloseOnClickListener(mCloseClickListener);
+
+            return item;
+        }
+
+        @Override
+        public void bindView(TabsLayoutItemView view, Tab tab) {
+            super.bindView(view, tab);
+
+            // If we're recycling this view, there's a chance it was transformed during
+            // the close animation. Remove any of those properties.
+            resetTransforms(view);
+        }
+    }
 
     private class TabSwipeGestureListener implements View.OnTouchListener {
         // same value the stock browser uses for after drag animation velocity in pixels/sec
         // http://androidxref.com/4.0.4/xref/packages/apps/Browser/src/com/android/browser/NavTabScroller.java#61
         private static final float MIN_VELOCITY = 750;
 
         private final int mSwipeThreshold;
         private final int mMinFlingVelocity;
@@ -548,17 +553,17 @@ class TabsGridLayout extends GridView
                     float deltaX = ViewHelper.getTranslationX(mSwipeView);
 
                     if (Math.abs(deltaX) > mTabWidth / 2) {
                         dismiss = true;
                     } else if (mMinFlingVelocity <= velocityX && velocityX <= mMaxFlingVelocity) {
                         dismiss = mSwiping && (deltaX * mVelocityTracker.getYVelocity() > 0);
                     }
                     if (dismiss) {
-                       closeTab(mSwipeView.findViewById(R.id.close));
+                        closeTab(mSwipeView.findViewById(R.id.close));
                     } else {
                         animateCancel(mSwipeView);
                     }
                     mVelocityTracker.recycle();
                     mVelocityTracker = null;
                     mSwipeView = null;
 
                     mSwipeStartX = 0;