Bug 712526: Restrict tabs menu to occupy only 2/3 of the screen. [r=mfinkle] a=blassey
authorSriram Ramasubramanian <sriram@mozilla.com>
Fri, 27 Jan 2012 12:18:02 -0800
changeset 85181 f50df17e470ee67ddbed04192dbb519c6e4cfb35
parent 85180 b1070f76bf3c8731a334e04d1201bcb57c8dd78b
child 85182 49da94a53d6f834bf7d1845c94b1d6d27a009622
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, blassey
bugs712526
milestone11.0a2
Bug 712526: Restrict tabs menu to occupy only 2/3 of the screen. [r=mfinkle] a=blassey
mobile/android/base/TabsTray.java
mobile/android/base/resources/layout/tabs_tray.xml
--- a/mobile/android/base/TabsTray.java
+++ b/mobile/android/base/TabsTray.java
@@ -39,31 +39,36 @@ package org.mozilla.gecko;
 
 import java.util.ArrayList;
 
 import android.app.Activity;
 import android.content.Context;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.Build;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
 import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.ListView;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
 
 public class TabsTray extends Activity implements GeckoApp.OnTabsChangedListener {
 
-    private ListView mList;
+    private static int sPreferredHeight;
+    private static int sMaxHeight;
+    private static int sListItemHeight;
+    private static ListView mList;
     private TabsAdapter mTabsAdapter;
     private boolean mWaitingForClose;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         setContentView(R.layout.tabs_tray);
@@ -86,16 +91,22 @@ public class TabsTray extends Activity i
         
         LinearLayout container = (LinearLayout) findViewById(R.id.container);
         container.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View v) {
                 finishActivity();
             }
         });
 
+        DisplayMetrics metrics = new DisplayMetrics();
+        getWindowManager().getDefaultDisplay().getMetrics(metrics);
+        sPreferredHeight = (int) (0.67 * metrics.heightPixels);
+        sListItemHeight = (int) (100 * metrics.density); 
+        sMaxHeight = (int) (sPreferredHeight + (0.33 * sListItemHeight));
+
         GeckoApp.registerOnTabsChangedListener(this);
         Tabs.getInstance().refreshThumbnails();
         onTabsChanged(null);
     }
 
     @Override
     public void onDestroy() {
         super.onDestroy();
@@ -138,16 +149,38 @@ public class TabsTray extends Activity i
     }
 
     void finishActivity() {
         finish();
         overridePendingTransition(0, R.anim.shrink_fade_out);
         GeckoAppShell.sendEventToGecko(new GeckoEvent("Tab:Screenshot:Cancel",""));
     }
 
+    // Tabs List Container holds the ListView and the New Tab button
+    public static class TabsListContainer extends LinearLayout {
+        public TabsListContainer(Context context, AttributeSet attrs) {
+            super(context, attrs);
+        }
+
+        @Override
+        protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
+            super.onSizeChanged(width, height, oldWidth, oldHeight);
+
+            if ((height > sPreferredHeight) && (height != sMaxHeight)) {
+                setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
+                                                              sPreferredHeight));
+
+                // If the list ends perfectly on an item, increase the height of the container 
+                if (mList.getHeight() % sListItemHeight == 0)
+                    setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
+                                                                  sMaxHeight));
+            }
+        }
+    }
+
     // Adapter to bind tabs into a list 
     private class TabsAdapter extends BaseAdapter {
         public TabsAdapter(Context context, ArrayList<Tab> tabs) {
             mContext = context;
             mInflater = LayoutInflater.from(mContext);
             mTabs = new ArrayList<Tab>();
 
             if (tabs == null)
--- a/mobile/android/base/resources/layout/tabs_tray.xml
+++ b/mobile/android/base/resources/layout/tabs_tray.xml
@@ -1,19 +1,20 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:id="@+id/container"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:orientation="vertical">
 
-     <LinearLayout android:layout_width="match_parent"
-                   android:layout_height="wrap_content"
-                   android:orientation="vertical"
-                   android:background="@drawable/tabs_tray_bg_repeat">
+     <view class="org.mozilla.gecko.TabsTray$TabsListContainer"
+           android:layout_width="match_parent"
+           android:layout_height="wrap_content"
+           android:orientation="vertical"
+           android:background="@drawable/tabs_tray_bg_repeat">
 
          <ListView android:id="@+id/list"
                    style="@style/TabsList"
                    android:divider="@drawable/tabs_tray_list_divider"/>
 
          <LinearLayout android:layout_width="match_parent"
                        android:layout_height="2dp"
                        android:background="@drawable/tabs_tray_list_divider"/>
@@ -27,11 +28,11 @@
 
              <ImageView android:layout_width="20dip"
                         android:layout_height="20dip"
                         android:layout_marginRight="20dip"
                         android:src="@drawable/tab_new"/>
 
          </LinearLayout>
 
-     </LinearLayout>
+     </view>
 
 </LinearLayout>