Bug 817721/817735/817732 - New TabsPanel sizing (r=mfinkle)

This commit is contained in:
Lucas Rocha 2013-02-22 07:22:37 +00:00
parent 3efc21535a
commit 06b5522e66
5 changed files with 47 additions and 5 deletions

View File

@ -4,6 +4,8 @@
package org.mozilla.gecko;
import org.mozilla.gecko.widget.TwoWayView;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
@ -66,6 +68,11 @@ public class RemoteTabs extends ExpandableListView
mTabsPanel.autoHidePanel();
}
@Override
public boolean shouldExpand() {
return true;
}
@Override
public boolean onGroupClick(ExpandableListView parent, View view, int position, long id) {
// By default, the group collapses/expands. Consume the event.

View File

@ -7,6 +7,8 @@ package org.mozilla.gecko;
import org.mozilla.gecko.widget.IconTabWidget;
import org.mozilla.gecko.widget.TwoWayView;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
@ -41,6 +43,7 @@ public class TabsPanel extends LinearLayout
public void setTabsPanel(TabsPanel panel);
public void show();
public void hide();
public boolean shouldExpand();
}
public static interface TabsLayoutChangeListener {
@ -49,6 +52,7 @@ public class TabsPanel extends LinearLayout
private Context mContext;
private GeckoApp mActivity;
private TabsListContainer mTabsContainer;
private PanelView mPanel;
private PanelView mPanelNormal;
private PanelView mPanelPrivate;
@ -93,6 +97,8 @@ public class TabsPanel extends LinearLayout
}
private void initialize() {
mTabsContainer = (TabsListContainer) findViewById(R.id.tabs_container);
mPanelNormal = (TabsTray) findViewById(R.id.normal_tabs);
mPanelNormal.setTabsPanel(this);
@ -174,16 +180,25 @@ public class TabsPanel extends LinearLayout
}
}
private static int getTabContainerHeight(View view) {
Context context = view.getContext();
private static int getTabContainerHeight(TabsListContainer listContainer) {
Context context = listContainer.getContext();
PanelView panelView = listContainer.getCurrentPanelView();
if (panelView != null && !panelView.shouldExpand()) {
final View v = (View) panelView;
final int sizeSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
v.measure(sizeSpec, sizeSpec);
return v.getMeasuredHeight();
}
int actionBarHeight = context.getResources().getDimensionPixelSize(R.dimen.browser_toolbar_height);
int screenHeight = context.getResources().getDisplayMetrics().heightPixels;
Rect windowRect = new Rect();
view.getWindowVisibleDisplayFrame(windowRect);
listContainer.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.
@ -234,6 +249,20 @@ public class TabsPanel extends LinearLayout
mContext = context;
}
public PanelView getCurrentPanelView() {
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (!(child instanceof PanelView))
continue;
if (child.getVisibility() == View.VISIBLE)
return (PanelView) child;
}
return null;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (!GeckoApp.mAppContext.hasTabsSideBar()) {
@ -341,7 +370,7 @@ public class TabsPanel extends LinearLayout
dispatchLayoutChange(getWidth(), getHeight());
} else {
int actionBarHeight = mContext.getResources().getDimensionPixelSize(R.dimen.browser_toolbar_height);
int height = actionBarHeight + getTabContainerHeight(this);
int height = actionBarHeight + getTabContainerHeight(mTabsContainer);
dispatchLayoutChange(getWidth(), height);
}
}

View File

@ -106,6 +106,11 @@ public class TabsTray extends TwoWayView
mTabsAdapter.clear();
}
@Override
public boolean shouldExpand() {
return isVertical();
}
private void autoHidePanel() {
mTabsPanel.autoHidePanel();
}

View File

@ -28,7 +28,7 @@
</RelativeLayout>
<view class="org.mozilla.gecko.TabsPanel$TabsListContainer"
android:id="@android:id/tabcontent"
android:id="@+id/tabs_container"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0">

View File

@ -28,6 +28,7 @@
</RelativeLayout>
<view class="org.mozilla.gecko.TabsPanel$TabsListContainer"
android:id="@+id/tabs_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content">