Bug 817706: Enhance tabs-tray to show either normal or private tabs only. [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Tue, 18 Dec 2012 16:44:37 -0800
changeset 125824 93e12399bae42c6a3aa28637e2fe438755feb89a
parent 125823 f578e6d37c130d71a1aefa467f8c05b943ba4804
child 125825 296cc3ea6e9e4cec791933e481aef825760a6430
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs817706
milestone20.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 817706: Enhance tabs-tray to show either normal or private tabs only. [r=mfinkle]
mobile/android/base/TabsTray.java
mobile/android/base/resources/values/attrs.xml
--- a/mobile/android/base/TabsTray.java
+++ b/mobile/android/base/TabsTray.java
@@ -3,16 +3,17 @@
  * 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 org.mozilla.gecko.PropertyAnimator.Property;
 
 import android.content.Context;
+import android.content.res.TypedArray;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.VelocityTracker;
 import android.view.View;
@@ -58,17 +59,21 @@ public class TabsTray extends LinearLayo
         LayoutInflater.from(context).inflate(R.layout.tabs_tray, this);
 
         mCloseAnimationCount = 0;
         mPendingClosedTabs = new ArrayList<View>();
 
         mList = (ListView) findViewById(R.id.list);
         mList.setItemsCanFocus(true);
 
-        mTabsAdapter = new TabsAdapter(mContext);
+        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabsTray);
+        boolean isPrivate = (a.getInt(R.styleable.TabsTray_tabs, 0x0) == 1);
+        a.recycle();
+
+        mTabsAdapter = new TabsAdapter(mContext, isPrivate);
         mList.setAdapter(mTabsAdapter);
 
         mSwipeListener = new TabSwipeGestureListener(mList);
         mList.setOnTouchListener(mSwipeListener);
         mList.setOnScrollListener(mSwipeListener.makeScrollListener());
 
         mList.setRecyclerListener(new RecyclerListener() {
             @Override
@@ -121,23 +126,25 @@ public class TabsTray extends LinearLayo
             thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
             close = (ImageButton) view.findViewById(R.id.close);
         }
     }
 
     // Adapter to bind tabs into a list
     private class TabsAdapter extends BaseAdapter implements Tabs.OnTabsChangedListener {
         private Context mContext;
+        private boolean mIsPrivate;
         private ArrayList<Tab> mTabs;
         private LayoutInflater mInflater;
         private Button.OnClickListener mOnCloseClickListener;
 
-        public TabsAdapter(Context context) {
+        public TabsAdapter(Context context, boolean isPrivate) {
             mContext = context;
             mInflater = LayoutInflater.from(mContext);
+            mIsPrivate = isPrivate;
 
             mOnCloseClickListener = new Button.OnClickListener() {
                 public void onClick(View v) {
                     TabRow tab = (TabRow) v.getTag();
                     animateClose(tab.info, tab.info.getWidth());
                 }
             };
         }
@@ -172,17 +179,18 @@ public class TabsTray extends LinearLayo
 
         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>();
 
             Iterable<Tab> tabs = Tabs.getInstance().getTabsInOrder();
             for (Tab tab : tabs) {
-                mTabs.add(tab);
+                if (tab.isPrivate() == mIsPrivate)
+                    mTabs.add(tab);
             }
 
             notifyDataSetChanged(); // Be sure to call this whenever mTabs changes.
             updateSelectedPosition();
         }
 
         // Updates the selected position in the list so that it will be scrolled to the right place.
         private void updateSelectedPosition() {
@@ -213,18 +221,20 @@ public class TabsTray extends LinearLayo
         private int getPositionForTab(Tab tab) {
             if (mTabs == null || tab == null)
                 return -1;
 
             return mTabs.indexOf(tab);
         }
 
         private void removeTab(Tab tab) {
-            mTabs.remove(tab);
-            notifyDataSetChanged(); // Be sure to call this whenever mTabs changes.
+            if (tab.isPrivate() == mIsPrivate) {
+                mTabs.remove(tab);
+                notifyDataSetChanged(); // Be sure to call this whenever mTabs changes.
+            }
         }
 
         private void assignValues(TabRow row, Tab tab) {
             if (row == null || tab == null)
                 return;
 
             row.id = tab.getId();
 
--- a/mobile/android/base/resources/values/attrs.xml
+++ b/mobile/android/base/resources/values/attrs.xml
@@ -44,16 +44,23 @@
     <declare-styleable name="TabsButton">
         <attr name="cropped" format="boolean"/>
     </declare-styleable>
 
     <declare-styleable name="TabsPanel">
         <attr name="sidebar" format="boolean"/>
     </declare-styleable>
 
+    <declare-styleable name="TabsTray">
+        <attr name="tabs">
+            <flag name="tabs_normal" value="0x00" />
+            <flag name="tabs_private" value ="0x01" />
+        </attr>
+    </declare-styleable>
+
     <declare-styleable name="TextSelectionHandle">
         <attr name="handleType">
             <flag name="start" value="0x01" />
             <flag name="middle" value="0x02" />
             <flag name="end" value="0x03" />
         </attr>
     </declare-styleable>