Bug 703656: Optimize tab adapter in TabsTray [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Tue, 22 Nov 2011 12:32:45 -0800
changeset 83681 58df20db1f3821fcd055a1dca43dea2bea33e97a
parent 83680 4e6b25935185d16f9ae1a473c35214bd105880b0
child 83682 e3ec5c72d46726a450f4efea34347a12249166c5
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs703656
milestone11.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 703656: Optimize tab adapter in TabsTray [r=mfinkle]
mobile/android/base/TabsTray.java
--- a/mobile/android/base/TabsTray.java
+++ b/mobile/android/base/TabsTray.java
@@ -146,27 +146,61 @@ public class TabsTray extends Activity i
 
     void finishActivity() {
         finish();
         overridePendingTransition(0, R.anim.shrink_fade_out);
     }
 
     // Adapter to bind tabs into a list 
     private class TabsAdapter extends BaseAdapter {
-	public TabsAdapter(Context context, ArrayList<Tab> tabs) {
+        public TabsAdapter(Context context, ArrayList<Tab> tabs) {
             mContext = context;
             mInflater = LayoutInflater.from(mContext);
             mTabs = new ArrayList<Tab>();
 
             if (tabs == null)
                 return;
 
             for (int i = 0; i < tabs.size(); i++) {
                 mTabs.add(tabs.get(i));
             }
+            
+            mOnInfoClickListener = new View.OnClickListener() {
+                public void onClick(View v) {
+                    GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Select", v.getTag().toString()));
+                    finishActivity();
+                }
+            };
+
+            mOnCloseClickListener = new Button.OnClickListener() {
+                public void onClick(View v) {
+                    if (mWaitingForClose)
+                        return;
+                
+                    mWaitingForClose = true;
+                
+                    int tabId = Integer.parseInt(v.getTag().toString());
+                    Tabs tabs = Tabs.getInstance();
+                    Tab tab = tabs.getTab(tabId);
+                
+                    if (tabs.isSelectedTab(tab)) {
+                        int index = tabs.getIndexOf(tab);
+                        if (index >= 1)
+                            index--;
+                        else
+                            index = 1;
+                        int id = tabs.getTabAt(index).getId();
+                        GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Select", String.valueOf(id)));
+                        GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Close", v.getTag().toString()));
+                    } else {
+                        GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Close", v.getTag().toString()));
+                        GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Select", String.valueOf(tabs.getSelectedTabId())));
+                    }
+                }
+            };
         }
 
         @Override    
         public int getCount() {
             return mTabs.size();
         }
     
         @Override    
@@ -202,61 +236,30 @@ public class TabsTray extends Activity i
             title.setText(tab.getDisplayTitle());
 
             if (Tabs.getInstance().isSelectedTab(tab))
                 title.setTypeface(title.getTypeface(), Typeface.BOLD);
         }
 
         @Override    
         public View getView(int position, View convertView, ViewGroup parent) {
+            convertView = mInflater.inflate(R.layout.tabs_row, null);
 
-            convertView = mInflater.inflate(R.layout.tabs_row, null);
-            
             Tab tab = mTabs.get(position);
 
             RelativeLayout info = (RelativeLayout) convertView.findViewById(R.id.info);
-            info.setTag("" + tab.getId());
-            info.setOnClickListener(new View.OnClickListener() {
-                public void onClick(View v) {
-                    GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Select", "" + v.getTag()));
-                    finishActivity();
-                }
-            });
+            info.setTag(String.valueOf(tab.getId()));
+            info.setOnClickListener(mOnInfoClickListener);
 
             assignValues(convertView, tab);
             
             ImageButton close = (ImageButton) convertView.findViewById(R.id.close);
             if (mTabs.size() > 1) {
-                close.setTag("" + tab.getId());
-                close.setOnClickListener(new Button.OnClickListener() {
-                    public void onClick(View v) {
-                        if (mWaitingForClose)
-                            return;
-
-                        mWaitingForClose = true;
-
-                        int tabId = Integer.parseInt("" + v.getTag());
-                        Tabs tabs = Tabs.getInstance();
-                        Tab tab = tabs.getTab(tabId);
-
-                        if (tabs.isSelectedTab(tab)) {
-                            int index = tabs.getIndexOf(tab);
-                            if (index >= 1)
-                                index--;
-                            else
-                                index = 1;
-                            int id = tabs.getTabAt(index).getId();
-                            GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Select", String.valueOf(id)));
-                            GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Close", v.getTag().toString()));
-                        } else {
-                            GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Close", v.getTag().toString()));
-                            GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Select", String.valueOf(tabs.getSelectedTabId())));
-                        }
-                    }
-                });
+                close.setTag(String.valueOf(tab.getId()));
+                close.setOnClickListener(mOnCloseClickListener);
             } else {
                 close.setVisibility(View.GONE);
             }
 
             return convertView;
         }
 
         @Override
@@ -265,10 +268,12 @@ public class TabsTray extends Activity i
 
         @Override
         public void notifyDataSetInvalidated() {
         }
     
         private Context mContext;
         private ArrayList<Tab> mTabs;
         private LayoutInflater mInflater;
+        private View.OnClickListener mOnInfoClickListener;
+        private Button.OnClickListener mOnCloseClickListener;
     }
 }