Bug 792429 - Add more vertical space for the tabs tray on phones (r=sriram)

This commit is contained in:
Lucas Rocha 2012-10-13 00:23:20 +01:00
parent 2225a542bf
commit df9b72464a

View File

@ -9,6 +9,7 @@ import org.mozilla.gecko.sync.setup.SyncAccounts;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Rect;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -97,6 +98,23 @@ public class TabsPanel extends LinearLayout {
}); });
} }
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 // Tabs List Container holds the ListView
public static class TabsListContainer extends LinearLayout { public static class TabsListContainer extends LinearLayout {
private Context mContext; private Context mContext;
@ -109,7 +127,7 @@ public class TabsPanel extends LinearLayout {
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (!GeckoApp.mAppContext.hasTabsSideBar()) { 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); super.onMeasure(widthMeasureSpec, heightSpec);
} else { } else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@ -166,13 +184,8 @@ public class TabsPanel extends LinearLayout {
if (showAnimation) if (showAnimation)
dispatchLayoutChange(getWidth(), getHeight()); dispatchLayoutChange(getWidth(), getHeight());
} else { } else {
int actionBarHeight = (int) (mContext.getResources().getDimension(R.dimen.browser_toolbar_height)); int actionBarHeight = mContext.getResources().getDimensionPixelSize(R.dimen.browser_toolbar_height);
int height = actionBarHeight + getTabContainerHeight(mListContainer);
// 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;
dispatchLayoutChange(getWidth(), height); dispatchLayoutChange(getWidth(), height);
} }