Bug 792429 - Add more vertical space for the tabs tray on phones (r=sriram)
authorLucas Rocha <lucasr@mozilla.com>
Sat, 13 Oct 2012 00:23:20 +0100
changeset 110400 d16548ef9acccf64c85c32195f76a3a3aa11ecf2
parent 110399 4e3c9bd6bd60783bd927eb7214c99f7807c83750
child 110401 f271acb304c2b8eae1975f84ee0d8756d3e69292
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewerssriram
bugs792429
milestone19.0a1
Bug 792429 - Add more vertical space for the tabs tray on phones (r=sriram)
mobile/android/base/TabsPanel.java
--- a/mobile/android/base/TabsPanel.java
+++ b/mobile/android/base/TabsPanel.java
@@ -4,16 +4,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import org.mozilla.gecko.sync.setup.SyncAccounts;
 
 import android.content.Context;
 import android.content.res.TypedArray;
+import android.graphics.Rect;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.LinearLayout;
 import android.widget.RelativeLayout;
@@ -92,29 +93,46 @@ public class TabsPanel extends LinearLay
                 if (mRemoteTabs.getDrawable().getLevel() == REMOTE_TABS_SHOWN)
                     mActivity.showLocalTabs();
                 else
                     mActivity.showRemoteTabs();
             }
         });
     }
 
+    private static int getTabContainerHeight(View view) {
+        Context context = view.getContext();
+
+        int actionBarHeight = context.getResources().getDimensionPixelSize(R.dimen.browser_toolbar_height);
+        int screenHeight = context.getResources().getDisplayMetrics().heightPixels;
+
+        Rect windowRect = new Rect();
+        view.getWindowVisibleDisplayFrame(windowRect);
+        int windowHeight = windowRect.bottom - windowRect.top;
+
+        // The web content area should have at least 1.5x the height of the action bar.
+        // The tabs panel shouldn't take less than 50% of the screen height and can take
+        // up to 80% of the window height.
+        return (int) Math.max(screenHeight * 0.5f,
+                              Math.min(windowHeight - 2.5f * actionBarHeight, windowHeight * 0.8f) - actionBarHeight);
+    }
+
     // Tabs List Container holds the ListView
     public static class TabsListContainer extends LinearLayout {
         private Context mContext;
 
         public TabsListContainer(Context context, AttributeSet attrs) {
             super(context, attrs);
             mContext = context;
         }
 
         @Override
         protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
             if (!GeckoApp.mAppContext.hasTabsSideBar()) {
-                int heightSpec = MeasureSpec.makeMeasureSpec((int) (0.5 * mContext.getResources().getDisplayMetrics().heightPixels), MeasureSpec.EXACTLY);
+                int heightSpec = MeasureSpec.makeMeasureSpec(getTabContainerHeight(this), MeasureSpec.EXACTLY);
                 super.onMeasure(widthMeasureSpec, heightSpec);
             } else {
                 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
             }
         }
     }
 
     // Tabs Panel Toolbar contains the Buttons
@@ -161,23 +179,18 @@ public class TabsPanel extends LinearLay
         mPanel.setTabsPanel(this);
         mPanel.show();
         mListContainer.addView(mPanel.getLayout());
 
         if (isSideBar()) {
             if (showAnimation)
                 dispatchLayoutChange(getWidth(), getHeight());
         } else {
-            int actionBarHeight = (int) (mContext.getResources().getDimension(R.dimen.browser_toolbar_height));
-
-            // TabsListContainer takes time to resize on rotation.
-            // It's better to add 50% of the screen-size and dispatch it as height.
-            int listHeight = (int) (0.5 * mContext.getResources().getDisplayMetrics().heightPixels);
-
-            int height = actionBarHeight + listHeight; 
+            int actionBarHeight = mContext.getResources().getDimensionPixelSize(R.dimen.browser_toolbar_height);
+            int height = actionBarHeight + getTabContainerHeight(mListContainer);
             dispatchLayoutChange(getWidth(), height);
         }
 
         // If Sync is set up, query the database for remote clients.
         final Context context = mContext;
         new SyncAccounts.AccountsExistTask() {
             @Override
             protected void onPostExecute(Boolean result) {