Bug 1056169 - Factor out TabRow and rename it to TabsLayoutItemView (r=lucasr)
authorMartyn Haigh <martyn.haigh@gmail.com>
Wed, 27 Aug 2014 17:11:56 +0100
changeset 227935 85c42119a5615ed54e4fc2c16e64269a1e643503
parent 227934 ce1c303ee66ab427dbee34bf68ec7fb511586734
child 227936 808da2456a3d466ba6eb581c45ff656abf69ce4a
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs1056169
milestone34.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 1056169 - Factor out TabRow and rename it to TabsLayoutItemView (r=lucasr)
mobile/android/base/moz.build
mobile/android/base/tabs/TabsLayoutItemView.java
mobile/android/base/tabs/TabsListLayout.java
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -387,16 +387,17 @@ gbjar.sources += [
     'Tabs.java',
     'tabs/PrivateTabsPanel.java',
     'tabs/RemoteTabsContainerPanel.java',
     'tabs/RemoteTabsList.java',
     'tabs/RemoteTabsPanel.java',
     'tabs/RemoteTabsSetupPanel.java',
     'tabs/RemoteTabsVerificationPanel.java',
     'tabs/TabCurve.java',
+    'tabs/TabsLayoutItemView.java',
     'tabs/TabsListLayout.java',
     'tabs/TabsPanel.java',
     'TabsAccessor.java',
     'Telemetry.java',
     'TelemetryContract.java',
     'TextSelection.java',
     'TextSelectionHandle.java',
     'ThumbnailHelper.java',
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tabs/TabsLayoutItemView.java
@@ -0,0 +1,31 @@
+/* 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.tabs;
+
+import org.mozilla.gecko.R;
+import org.mozilla.gecko.widget.TabThumbnailWrapper;
+
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+public class TabsLayoutItemView {
+    int id;
+    TextView title;
+    ImageView thumbnail;
+    ImageButton close;
+    ViewGroup info;
+    TabThumbnailWrapper thumbnailWrapper;
+
+    public TabsLayoutItemView(View view) {
+        info = (ViewGroup) view;
+        title = (TextView) view.findViewById(R.id.title);
+        thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
+        close = (ImageButton) view.findViewById(R.id.close);
+        thumbnailWrapper = (TabThumbnailWrapper) view.findViewById(R.id.wrapper);
+    }
+}
\ No newline at end of file
--- a/mobile/android/base/tabs/TabsListLayout.java
+++ b/mobile/android/base/tabs/TabsListLayout.java
@@ -15,36 +15,32 @@ import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.tabs.TabsPanel.TabsLayout;
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.PropertyAnimator.Property;
 import org.mozilla.gecko.animation.ViewHelper;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.widget.TwoWayView;
-import org.mozilla.gecko.widget.TabThumbnailWrapper;
 
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.VelocityTracker;
 import android.view.View;
 import android.view.ViewConfiguration;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
 import android.widget.Button;
-import android.widget.ImageButton;
-import android.widget.ImageView;
-import android.widget.TextView;
 
-class TabsListLayout extends TwoWayView 
+class TabsListLayout extends TwoWayView
                      implements TabsLayout {
     private static final String LOGTAG = "Gecko" + TabsListLayout.class.getSimpleName();
 
     private Context mContext;
     private TabsPanel mTabsPanel;
 
     final private boolean mIsPrivate;
 
@@ -81,19 +77,19 @@ class TabsListLayout extends TwoWayView
 
         mSwipeListener = new TabSwipeGestureListener();
         setOnTouchListener(mSwipeListener);
         setOnScrollListener(mSwipeListener.makeScrollListener());
 
         setRecyclerListener(new RecyclerListener() {
             @Override
             public void onMovedToScrapHeap(View view) {
-                TabRow row = (TabRow) view.getTag();
-                row.thumbnail.setImageDrawable(null);
-                row.close.setVisibility(View.VISIBLE);
+                TabsLayoutItemView item = (TabsLayoutItemView) view.getTag();
+                item.thumbnail.setImageDrawable(null);
+                item.close.setVisibility(View.VISIBLE);
             }
         });
     }
 
     @Override
     public void setTabsPanel(TabsPanel panel) {
         mTabsPanel = panel;
     }
@@ -118,49 +114,33 @@ class TabsListLayout extends TwoWayView
     public boolean shouldExpand() {
         return isVertical();
     }
 
     private void autoHidePanel() {
         mTabsPanel.autoHidePanel();
     }
 
-    // ViewHolder for a row in the list
-    private class TabRow {
-        int id;
-        TextView title;
-        ImageView thumbnail;
-        ImageButton close;
-        ViewGroup info;
-        TabThumbnailWrapper thumbnailWrapper;
 
-        public TabRow(View view) {
-            info = (ViewGroup) view;
-            title = (TextView) view.findViewById(R.id.title);
-            thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
-            close = (ImageButton) view.findViewById(R.id.close);
-            thumbnailWrapper = (TabThumbnailWrapper) view.findViewById(R.id.wrapper);
-        }
-    }
 
     // Adapter to bind tabs into a list
     private class TabsAdapter extends BaseAdapter implements Tabs.OnTabsChangedListener {
         private Context mContext;
         private ArrayList<Tab> mTabs;
         private LayoutInflater mInflater;
         private Button.OnClickListener mOnCloseClickListener;
 
         public TabsAdapter(Context context) {
             mContext = context;
             mInflater = LayoutInflater.from(mContext);
 
             mOnCloseClickListener = new Button.OnClickListener() {
                 @Override
                 public void onClick(View v) {
-                    TabRow tab = (TabRow) v.getTag();
+                    TabsLayoutItemView tab = (TabsLayoutItemView) v.getTag();
                     final int pos = (isVertical() ? tab.info.getWidth() : 0 - tab.info.getHeight());
                     animateClose(tab.info, pos);
                 }
             };
         }
 
         @Override
         public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
@@ -181,18 +161,18 @@ class TabsListLayout extends TwoWayView
                     // We just need to update the style for the unselected tab...
                 case THUMBNAIL:
                 case TITLE:
                 case RECORDING_CHANGE:
                     View view = TabsListLayout.this.getChildAt(getPositionForTab(tab) - TabsListLayout.this.getFirstVisiblePosition());
                     if (view == null)
                         return;
 
-                    TabRow row = (TabRow) view.getTag();
-                    assignValues(row, tab);
+                    TabsLayoutItemView item = (TabsLayoutItemView) view.getTag();
+                    assignValues(item, tab);
                     break;
             }
         }
 
         private void refreshTabsData() {
             // Store a different copy of the tabs, so that we don't have to worry about
             // accidentally updating it on the wrong thread.
             mTabs = new ArrayList<Tab>();
@@ -260,33 +240,33 @@ class TabsListLayout extends TwoWayView
                 mTabs.remove(tab);
                 notifyDataSetChanged(); // Be sure to call this whenever mTabs changes.
 
                 int selected = getPositionForTab(Tabs.getInstance().getSelectedTab());
                 updateSelectedStyle(selected);
             }
         }
 
-        private void assignValues(TabRow row, Tab tab) {
-            if (row == null || tab == null)
+        private void assignValues(TabsLayoutItemView item, Tab tab) {
+            if (item == null || tab == null)
                 return;
 
-            row.id = tab.getId();
+            item.id = tab.getId();
 
             Drawable thumbnailImage = tab.getThumbnail();
             if (thumbnailImage != null) {
-                row.thumbnail.setImageDrawable(thumbnailImage);
+                item.thumbnail.setImageDrawable(thumbnailImage);
             } else {
-                row.thumbnail.setImageResource(R.drawable.tab_thumbnail_default);
+                item.thumbnail.setImageResource(R.drawable.tab_thumbnail_default);
             }
-            if (row.thumbnailWrapper != null) {
-                row.thumbnailWrapper.setRecording(tab.isRecording());
+            if (item.thumbnailWrapper != null) {
+                item.thumbnailWrapper.setRecording(tab.isRecording());
             }
-            row.title.setText(tab.getDisplayTitle());
-            row.close.setTag(row);
+            item.title.setText(tab.getDisplayTitle());
+            item.close.setTag(item);
         }
 
         private void resetTransforms(View view) {
             ViewHelper.setAlpha(view, 1);
 
             if (isVertical()) {
                 ViewHelper.setTranslationX(view, 0);
             } else {
@@ -300,32 +280,32 @@ class TabsListLayout extends TwoWayView
                 } else {
                     ViewHelper.setWidth(view, mOriginalSize);
                 }
             }
         }
 
         @Override
         public View getView(int position, View convertView, ViewGroup parent) {
-            TabRow row;
+            TabsLayoutItemView item;
 
             if (convertView == null) {
                 convertView = mInflater.inflate(R.layout.tabs_row, null);
-                row = new TabRow(convertView);
-                row.close.setOnClickListener(mOnCloseClickListener);
-                convertView.setTag(row);
+                item = new TabsLayoutItemView(convertView);
+                item.close.setOnClickListener(mOnCloseClickListener);
+                convertView.setTag(item);
             } else {
-                row = (TabRow) convertView.getTag();
+                item = (TabsLayoutItemView) convertView.getTag();
                 // If we're recycling this view, there's a chance it was transformed during
                 // the close animation. Remove any of those properties.
                 resetTransforms(convertView);
             }
 
             Tab tab = mTabs.get(position);
-            assignValues(row, tab);
+            assignValues(item, tab);
 
             return convertView;
         }
     }
 
     private boolean isVertical() {
         return (getOrientation().compareTo(TwoWayView.Orientation.VERTICAL) == 0);
     }
@@ -438,17 +418,17 @@ class TabsListLayout extends TwoWayView
         PropertyAnimator animator = new PropertyAnimator(ANIMATION_DURATION);
 
         final boolean isVertical = isVertical();
         if (isVertical)
             animator.attach(view, Property.HEIGHT, 1);
         else
             animator.attach(view, Property.WIDTH, 1);
 
-        TabRow tab = (TabRow)view.getTag();
+        TabsLayoutItemView tab = (TabsLayoutItemView)view.getTag();
         final int tabId = tab.id;
 
         // Caching this assumes that all rows are the same height
         if (mOriginalSize == 0) {
             mOriginalSize = (isVertical ? view.getHeight() : view.getWidth());
         }
 
         animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@@ -475,17 +455,17 @@ class TabsListLayout extends TwoWayView
             animator.attach(view, Property.TRANSLATION_Y, 0);
 
 
         animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
             @Override
             public void onPropertyAnimationStart() { }
             @Override
             public void onPropertyAnimationEnd() {
-                TabRow tab = (TabRow) view.getTag();
+                TabsLayoutItemView tab = (TabsLayoutItemView) view.getTag();
                 tab.close.setVisibility(View.VISIBLE);
             }
         });
 
         animator.start();
     }
 
     private class TabSwipeGestureListener implements View.OnTouchListener {
@@ -573,17 +553,17 @@ class TabsListLayout extends TwoWayView
                 case MotionEvent.ACTION_UP: {
                     if (mSwipeView == null)
                         break;
 
                     cancelCheckForTap();
                     mSwipeView.setPressed(false);
 
                     if (!mSwiping) {
-                        TabRow tab = (TabRow) mSwipeView.getTag();
+                        TabsLayoutItemView tab = (TabsLayoutItemView) mSwipeView.getTag();
                         Tabs.getInstance().selectTab(tab.id);
                         autoHidePanel();
 
                         mVelocityTracker.recycle();
                         mVelocityTracker = null;
                         break;
                     }
 
@@ -661,17 +641,17 @@ class TabsListLayout extends TwoWayView
                     // set pressed state on the swiped view.
                     if (isScrollingX || isScrollingY)
                         cancelCheckForTap();
 
                     if (isSwipingToClose) {
                         mSwiping = true;
                         TabsListLayout.this.requestDisallowInterceptTouchEvent(true);
 
-                        TabRow tab = (TabRow) mSwipeView.getTag();
+                        TabsLayoutItemView tab = (TabsLayoutItemView) mSwipeView.getTag();
                         tab.close.setVisibility(View.INVISIBLE);
 
                         // Stops listview from highlighting the touched item
                         // in the list when swiping.
                         MotionEvent cancelEvent = MotionEvent.obtain(e);
                         cancelEvent.setAction(MotionEvent.ACTION_CANCEL |
                                 (e.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
                         TabsListLayout.this.onTouchEvent(cancelEvent);