2012-06-08 04:47:22 +00:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2013-05-07 17:04:11 +00:00
|
|
|
import org.mozilla.gecko.animation.PropertyAnimator;
|
|
|
|
import org.mozilla.gecko.animation.ViewHelper;
|
2013-01-29 22:43:34 +00:00
|
|
|
import org.mozilla.gecko.widget.IconTabWidget;
|
|
|
|
|
2012-06-08 04:47:22 +00:00
|
|
|
import android.content.Context;
|
2013-03-01 00:29:20 +00:00
|
|
|
import android.content.res.Resources;
|
2012-10-12 23:23:20 +00:00
|
|
|
import android.graphics.Rect;
|
2013-04-26 13:12:08 +00:00
|
|
|
import android.os.Build;
|
2012-06-08 04:47:22 +00:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.Button;
|
2012-12-19 01:04:39 +00:00
|
|
|
import android.widget.FrameLayout;
|
2012-06-08 04:47:22 +00:00
|
|
|
import android.widget.ImageButton;
|
2012-06-19 21:10:21 +00:00
|
|
|
import android.widget.LinearLayout;
|
2013-01-29 23:57:52 +00:00
|
|
|
import android.widget.RelativeLayout;
|
2012-06-08 04:47:22 +00:00
|
|
|
|
2013-01-18 19:58:45 +00:00
|
|
|
public class TabsPanel extends LinearLayout
|
2013-02-21 22:21:57 +00:00
|
|
|
implements LightweightTheme.OnChangeListener,
|
2013-01-29 22:43:34 +00:00
|
|
|
IconTabWidget.OnTabChangedListener {
|
2012-06-08 04:47:22 +00:00
|
|
|
private static final String LOGTAG = "GeckoTabsPanel";
|
|
|
|
|
|
|
|
public static enum Panel {
|
2012-12-19 01:04:39 +00:00
|
|
|
NORMAL_TABS,
|
|
|
|
PRIVATE_TABS,
|
2012-06-08 04:47:22 +00:00
|
|
|
REMOTE_TABS
|
|
|
|
}
|
|
|
|
|
2012-07-18 00:54:54 +00:00
|
|
|
public static interface PanelView {
|
2012-06-08 04:47:22 +00:00
|
|
|
public ViewGroup getLayout();
|
2012-07-28 06:31:40 +00:00
|
|
|
public void setTabsPanel(TabsPanel panel);
|
2012-06-08 04:47:22 +00:00
|
|
|
public void show();
|
|
|
|
public void hide();
|
2013-02-22 07:22:37 +00:00
|
|
|
public boolean shouldExpand();
|
2012-06-08 04:47:22 +00:00
|
|
|
}
|
|
|
|
|
2012-07-18 00:54:54 +00:00
|
|
|
public static interface TabsLayoutChangeListener {
|
2012-06-08 04:48:29 +00:00
|
|
|
public void onTabsLayoutChange(int width, int height);
|
|
|
|
}
|
|
|
|
|
2012-06-08 04:47:22 +00:00
|
|
|
private Context mContext;
|
2012-07-28 06:31:40 +00:00
|
|
|
private GeckoApp mActivity;
|
2013-04-26 13:12:08 +00:00
|
|
|
private RelativeLayout mHeader;
|
2013-02-22 07:22:37 +00:00
|
|
|
private TabsListContainer mTabsContainer;
|
2012-06-08 04:47:22 +00:00
|
|
|
private PanelView mPanel;
|
2013-01-18 19:58:45 +00:00
|
|
|
private PanelView mPanelNormal;
|
|
|
|
private PanelView mPanelPrivate;
|
|
|
|
private PanelView mPanelRemote;
|
2013-01-29 23:57:52 +00:00
|
|
|
private RelativeLayout mFooter;
|
2012-06-08 04:48:29 +00:00
|
|
|
private TabsLayoutChangeListener mLayoutChangeListener;
|
2012-06-08 04:47:22 +00:00
|
|
|
|
2013-01-29 22:43:34 +00:00
|
|
|
private IconTabWidget mTabWidget;
|
2012-12-04 21:15:50 +00:00
|
|
|
private static ImageButton mAddTab;
|
2012-06-08 04:47:22 +00:00
|
|
|
|
|
|
|
private Panel mCurrentPanel;
|
2012-07-23 20:08:48 +00:00
|
|
|
private boolean mIsSideBar;
|
2012-06-08 04:47:22 +00:00
|
|
|
private boolean mVisible;
|
2013-01-18 19:41:44 +00:00
|
|
|
|
2012-06-08 04:47:22 +00:00
|
|
|
public TabsPanel(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
mContext = context;
|
2012-07-28 06:31:40 +00:00
|
|
|
mActivity = (GeckoApp) context;
|
2012-06-08 04:47:22 +00:00
|
|
|
|
2013-01-18 19:58:45 +00:00
|
|
|
setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
|
|
|
|
LinearLayout.LayoutParams.FILL_PARENT));
|
|
|
|
setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
2012-12-19 01:04:39 +00:00
|
|
|
mCurrentPanel = Panel.NORMAL_TABS;
|
2012-06-08 04:47:22 +00:00
|
|
|
mVisible = false;
|
|
|
|
|
2013-02-22 07:22:37 +00:00
|
|
|
mIsSideBar = false;
|
2012-07-23 20:08:48 +00:00
|
|
|
|
2012-12-19 01:04:39 +00:00
|
|
|
LayoutInflater.from(context).inflate(R.layout.tabs_panel, this);
|
|
|
|
initialize();
|
|
|
|
}
|
|
|
|
|
2013-01-29 22:43:34 +00:00
|
|
|
private void initialize() {
|
2013-04-26 13:12:08 +00:00
|
|
|
mHeader = (RelativeLayout) findViewById(R.id.tabs_panel_header);
|
2013-02-22 07:22:37 +00:00
|
|
|
mTabsContainer = (TabsListContainer) findViewById(R.id.tabs_container);
|
|
|
|
|
2013-01-18 19:58:45 +00:00
|
|
|
mPanelNormal = (TabsTray) findViewById(R.id.normal_tabs);
|
|
|
|
mPanelNormal.setTabsPanel(this);
|
2012-12-19 01:04:39 +00:00
|
|
|
|
2013-01-18 19:58:45 +00:00
|
|
|
mPanelPrivate = (TabsTray) findViewById(R.id.private_tabs);
|
|
|
|
mPanelPrivate.setTabsPanel(this);
|
2012-12-19 01:04:39 +00:00
|
|
|
|
2013-01-18 19:58:45 +00:00
|
|
|
mPanelRemote = (RemoteTabs) findViewById(R.id.synced_tabs);
|
|
|
|
mPanelRemote.setTabsPanel(this);
|
2012-12-19 01:04:39 +00:00
|
|
|
|
2013-01-29 23:57:52 +00:00
|
|
|
mFooter = (RelativeLayout) findViewById(R.id.tabs_panel_footer);
|
2012-12-19 01:04:39 +00:00
|
|
|
|
2013-01-16 19:26:48 +00:00
|
|
|
mAddTab = (ImageButton) findViewById(R.id.add_tab);
|
2012-12-04 21:15:50 +00:00
|
|
|
mAddTab.setOnClickListener(new Button.OnClickListener() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-06-08 04:47:22 +00:00
|
|
|
public void onClick(View v) {
|
2013-01-02 21:43:01 +00:00
|
|
|
TabsPanel.this.addTab();
|
2012-06-08 04:47:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-17 23:09:02 +00:00
|
|
|
Button button;
|
2013-03-01 00:29:20 +00:00
|
|
|
Resources resources = getContext().getResources();
|
|
|
|
|
2013-01-29 22:43:34 +00:00
|
|
|
mTabWidget = (IconTabWidget) findViewById(R.id.tab_widget);
|
2013-03-01 00:29:20 +00:00
|
|
|
|
2013-04-17 23:09:02 +00:00
|
|
|
button = mTabWidget.addTab(R.drawable.tabs_normal, R.string.tabs_normal);
|
|
|
|
button = mTabWidget.addTab(R.drawable.tabs_private, R.string.tabs_private);
|
|
|
|
button = mTabWidget.addTab(R.drawable.tabs_synced, R.string.tabs_synced);
|
2013-03-01 00:29:20 +00:00
|
|
|
|
2013-01-29 22:43:34 +00:00
|
|
|
mTabWidget.setTabSelectionListener(this);
|
2012-06-13 05:29:23 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 21:43:01 +00:00
|
|
|
public void addTab() {
|
|
|
|
if (mCurrentPanel == Panel.NORMAL_TABS)
|
|
|
|
mActivity.addTab();
|
|
|
|
else
|
|
|
|
mActivity.addPrivateTab();
|
|
|
|
|
|
|
|
mActivity.autoHideTabs();
|
|
|
|
}
|
|
|
|
|
2013-01-16 19:11:03 +00:00
|
|
|
@Override
|
2013-01-29 22:43:34 +00:00
|
|
|
public void onTabChanged(int index) {
|
|
|
|
if (index == 0)
|
2013-02-22 07:23:16 +00:00
|
|
|
show(Panel.NORMAL_TABS, false);
|
2013-01-29 22:43:34 +00:00
|
|
|
else if (index == 1)
|
2013-02-22 07:23:16 +00:00
|
|
|
show(Panel.PRIVATE_TABS, false);
|
2013-01-29 22:43:34 +00:00
|
|
|
else
|
2013-02-22 07:23:16 +00:00
|
|
|
show(Panel.REMOTE_TABS, false);
|
2012-12-19 00:45:55 +00:00
|
|
|
}
|
|
|
|
|
2013-02-22 07:22:37 +00:00
|
|
|
private static int getTabContainerHeight(TabsListContainer listContainer) {
|
2013-03-18 21:46:54 +00:00
|
|
|
Resources resources = listContainer.getContext().getResources();
|
2013-02-22 07:22:37 +00:00
|
|
|
|
|
|
|
PanelView panelView = listContainer.getCurrentPanelView();
|
|
|
|
if (panelView != null && !panelView.shouldExpand()) {
|
2013-03-18 21:46:54 +00:00
|
|
|
return resources.getDimensionPixelSize(R.dimen.tabs_tray_horizontal_height);
|
2013-02-22 07:22:37 +00:00
|
|
|
}
|
2012-10-12 23:23:20 +00:00
|
|
|
|
2013-03-18 21:46:54 +00:00
|
|
|
int actionBarHeight = resources.getDimensionPixelSize(R.dimen.browser_toolbar_height);
|
|
|
|
int screenHeight = resources.getDisplayMetrics().heightPixels;
|
2012-10-12 23:23:20 +00:00
|
|
|
|
|
|
|
Rect windowRect = new Rect();
|
2013-02-22 07:22:37 +00:00
|
|
|
listContainer.getWindowVisibleDisplayFrame(windowRect);
|
2012-10-12 23:23:20 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-11-01 05:14:16 +00:00
|
|
|
@Override
|
|
|
|
public void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
mActivity.getLightweightTheme().addListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
mActivity.getLightweightTheme().removeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLightweightThemeChanged() {
|
2013-03-14 22:26:25 +00:00
|
|
|
int background = mActivity.getResources().getColor(R.color.background_tabs);
|
2013-02-13 16:50:57 +00:00
|
|
|
LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getColorDrawable(this, background, true);
|
2012-11-01 05:14:16 +00:00
|
|
|
if (drawable == null)
|
|
|
|
return;
|
|
|
|
|
2012-12-13 21:13:36 +00:00
|
|
|
drawable.setAlpha(34, 0);
|
|
|
|
setBackgroundDrawable(drawable);
|
2012-11-01 05:14:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLightweightThemeReset() {
|
2013-03-14 22:26:25 +00:00
|
|
|
setBackgroundColor(getContext().getResources().getColor(R.color.background_tabs));
|
2012-11-01 05:14:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
onLightweightThemeChanged();
|
|
|
|
}
|
|
|
|
|
2012-06-13 05:29:23 +00:00
|
|
|
// Tabs List Container holds the ListView
|
2012-12-19 01:04:39 +00:00
|
|
|
public static class TabsListContainer extends FrameLayout {
|
2012-07-28 06:31:40 +00:00
|
|
|
private Context mContext;
|
|
|
|
|
2012-06-13 05:29:23 +00:00
|
|
|
public TabsListContainer(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
2012-07-28 06:31:40 +00:00
|
|
|
mContext = context;
|
2012-06-13 05:29:23 +00:00
|
|
|
}
|
|
|
|
|
2013-02-22 07:22:37 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-06-13 05:29:23 +00:00
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2013-05-24 16:21:01 +00:00
|
|
|
if (!GeckoAppShell.getGeckoInterface().hasTabsSideBar()) {
|
2013-01-18 19:58:45 +00:00
|
|
|
int heightSpec = MeasureSpec.makeMeasureSpec(getTabContainerHeight(TabsListContainer.this), MeasureSpec.EXACTLY);
|
2012-06-13 05:29:23 +00:00
|
|
|
super.onMeasure(widthMeasureSpec, heightSpec);
|
|
|
|
} else {
|
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
}
|
|
|
|
}
|
2012-06-08 04:47:22 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 21:10:21 +00:00
|
|
|
// Tabs Panel Toolbar contains the Buttons
|
2012-12-19 20:27:42 +00:00
|
|
|
public static class TabsPanelToolbar extends LinearLayout
|
2012-11-01 05:12:02 +00:00
|
|
|
implements LightweightTheme.OnChangeListener {
|
|
|
|
private BrowserApp mActivity;
|
|
|
|
|
2012-06-19 21:10:21 +00:00
|
|
|
public TabsPanelToolbar(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
2012-12-04 21:13:24 +00:00
|
|
|
mActivity = (BrowserApp) context;
|
2012-06-19 21:10:21 +00:00
|
|
|
|
|
|
|
setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
|
|
|
|
(int) context.getResources().getDimension(R.dimen.browser_toolbar_height)));
|
|
|
|
|
2012-12-19 20:27:42 +00:00
|
|
|
setOrientation(LinearLayout.HORIZONTAL);
|
2012-11-01 05:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
mActivity.getLightweightTheme().addListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
mActivity.getLightweightTheme().removeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLightweightThemeChanged() {
|
2013-03-14 22:26:25 +00:00
|
|
|
int background = mActivity.getResources().getColor(R.color.background_tabs);
|
2013-02-13 16:50:57 +00:00
|
|
|
LightweightThemeDrawable drawable = mActivity.getLightweightTheme().getColorDrawable(this, background);
|
2012-11-01 05:12:02 +00:00
|
|
|
if (drawable == null)
|
|
|
|
return;
|
|
|
|
|
2012-12-13 21:13:36 +00:00
|
|
|
drawable.setAlpha(34, 34);
|
|
|
|
setBackgroundDrawable(drawable);
|
2012-11-01 05:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLightweightThemeReset() {
|
2013-03-14 22:26:25 +00:00
|
|
|
setBackgroundColor(getContext().getResources().getColor(R.color.background_tabs));
|
2012-11-01 05:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
onLightweightThemeChanged();
|
2012-06-19 21:10:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 04:47:22 +00:00
|
|
|
public void show(Panel panel) {
|
2013-02-22 07:23:16 +00:00
|
|
|
show(panel, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void show(Panel panel, boolean shouldResize) {
|
2013-02-19 20:39:05 +00:00
|
|
|
if (!isShown())
|
|
|
|
setVisibility(View.VISIBLE);
|
|
|
|
|
2012-06-08 04:47:22 +00:00
|
|
|
if (mPanel != null) {
|
2012-12-19 01:04:39 +00:00
|
|
|
// Hide the old panel.
|
2012-06-08 04:47:22 +00:00
|
|
|
mPanel.hide();
|
|
|
|
}
|
|
|
|
|
2012-08-15 21:37:00 +00:00
|
|
|
final boolean showAnimation = !mVisible;
|
2012-06-08 04:47:22 +00:00
|
|
|
mVisible = true;
|
|
|
|
mCurrentPanel = panel;
|
|
|
|
|
2012-12-19 01:04:39 +00:00
|
|
|
int index = panel.ordinal();
|
2013-01-29 22:43:34 +00:00
|
|
|
mTabWidget.setCurrentTab(index);
|
2012-06-08 04:47:22 +00:00
|
|
|
|
2013-01-18 19:58:45 +00:00
|
|
|
if (index == 0) {
|
|
|
|
mPanel = mPanelNormal;
|
|
|
|
} else if (index == 1) {
|
|
|
|
mPanel = mPanelPrivate;
|
|
|
|
} else {
|
|
|
|
mPanel = mPanelRemote;
|
|
|
|
}
|
2013-01-18 19:41:44 +00:00
|
|
|
|
2012-06-08 04:47:22 +00:00
|
|
|
mPanel.show();
|
2012-06-08 04:48:29 +00:00
|
|
|
|
2013-01-10 20:22:43 +00:00
|
|
|
if (mCurrentPanel == Panel.REMOTE_TABS) {
|
2013-01-16 19:26:48 +00:00
|
|
|
if (mFooter != null)
|
|
|
|
mFooter.setVisibility(View.GONE);
|
|
|
|
|
2013-01-02 21:43:01 +00:00
|
|
|
mAddTab.setVisibility(View.INVISIBLE);
|
2013-01-10 20:22:43 +00:00
|
|
|
} else {
|
2013-01-16 19:26:48 +00:00
|
|
|
if (mFooter != null)
|
|
|
|
mFooter.setVisibility(View.VISIBLE);
|
|
|
|
|
2013-01-02 21:43:01 +00:00
|
|
|
mAddTab.setVisibility(View.VISIBLE);
|
2013-01-10 20:22:43 +00:00
|
|
|
mAddTab.setImageLevel(index);
|
|
|
|
}
|
2013-01-02 21:43:01 +00:00
|
|
|
|
2013-02-22 07:23:16 +00:00
|
|
|
if (shouldResize) {
|
|
|
|
if (isSideBar()) {
|
|
|
|
if (showAnimation)
|
|
|
|
dispatchLayoutChange(getWidth(), getHeight());
|
|
|
|
} else {
|
|
|
|
int actionBarHeight = mContext.getResources().getDimensionPixelSize(R.dimen.browser_toolbar_height);
|
|
|
|
int height = actionBarHeight + getTabContainerHeight(mTabsContainer);
|
|
|
|
dispatchLayoutChange(getWidth(), height);
|
|
|
|
}
|
2012-06-13 05:29:23 +00:00
|
|
|
}
|
2012-06-08 04:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void hide() {
|
2012-06-13 05:47:52 +00:00
|
|
|
if (mVisible) {
|
|
|
|
mVisible = false;
|
|
|
|
dispatchLayoutChange(0, 0);
|
|
|
|
}
|
2012-06-08 04:48:29 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 04:47:22 +00:00
|
|
|
public void refresh() {
|
2012-12-19 01:04:39 +00:00
|
|
|
removeAllViews();
|
2012-06-19 21:10:21 +00:00
|
|
|
|
2012-12-19 01:04:39 +00:00
|
|
|
LayoutInflater.from(mContext).inflate(R.layout.tabs_panel, this);
|
|
|
|
initialize();
|
2012-06-19 21:10:21 +00:00
|
|
|
|
|
|
|
if (mVisible)
|
2012-06-08 04:47:22 +00:00
|
|
|
show(mCurrentPanel);
|
|
|
|
}
|
|
|
|
|
2012-07-28 06:31:40 +00:00
|
|
|
public void autoHidePanel() {
|
|
|
|
mActivity.autoHideTabs();
|
|
|
|
}
|
|
|
|
|
2012-06-08 04:47:22 +00:00
|
|
|
@Override
|
|
|
|
public boolean isShown() {
|
|
|
|
return mVisible;
|
|
|
|
}
|
2012-06-08 04:48:29 +00:00
|
|
|
|
2012-07-23 20:08:48 +00:00
|
|
|
public boolean isSideBar() {
|
|
|
|
return mIsSideBar;
|
|
|
|
}
|
|
|
|
|
2013-02-22 07:22:37 +00:00
|
|
|
public void setIsSideBar(boolean isSideBar) {
|
|
|
|
mIsSideBar = isSideBar;
|
|
|
|
}
|
|
|
|
|
2013-01-29 18:58:09 +00:00
|
|
|
public Panel getCurrentPanel() {
|
|
|
|
return mCurrentPanel;
|
|
|
|
}
|
|
|
|
|
2013-04-26 13:12:08 +00:00
|
|
|
public void prepareTabsAnimation(PropertyAnimator animator) {
|
|
|
|
// Not worth doing this on pre-Honeycomb without proper
|
|
|
|
// hardware accelerated animations.
|
|
|
|
if (Build.VERSION.SDK_INT < 11) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Resources resources = getContext().getResources();
|
|
|
|
final int toolbarHeight = resources.getDimensionPixelSize(R.dimen.browser_toolbar_height);
|
2013-05-03 13:16:57 +00:00
|
|
|
final int tabsPanelWidth = getWidth();
|
2013-04-26 13:12:08 +00:00
|
|
|
|
|
|
|
if (mVisible) {
|
2013-05-03 13:16:57 +00:00
|
|
|
if (mIsSideBar) {
|
2013-05-07 17:04:10 +00:00
|
|
|
ViewHelper.setTranslationX(mHeader, -tabsPanelWidth);
|
2013-05-03 13:16:57 +00:00
|
|
|
} else {
|
2013-05-07 17:04:10 +00:00
|
|
|
ViewHelper.setTranslationY(mHeader, -toolbarHeight);
|
2013-05-03 13:16:57 +00:00
|
|
|
}
|
2013-04-26 13:12:08 +00:00
|
|
|
|
2013-05-03 13:16:57 +00:00
|
|
|
if (mIsSideBar) {
|
2013-05-07 17:04:10 +00:00
|
|
|
ViewHelper.setTranslationX(mTabsContainer, -tabsPanelWidth);
|
2013-05-03 13:16:57 +00:00
|
|
|
} else {
|
2013-05-07 17:04:10 +00:00
|
|
|
ViewHelper.setTranslationY(mTabsContainer, -toolbarHeight);
|
|
|
|
ViewHelper.setAlpha(mTabsContainer, 0);
|
2013-05-03 13:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The footer view is only present on the sidebar
|
|
|
|
if (mIsSideBar) {
|
2013-05-07 17:04:10 +00:00
|
|
|
ViewHelper.setTranslationX(mFooter, -tabsPanelWidth);
|
2013-05-03 13:16:57 +00:00
|
|
|
}
|
2013-04-26 13:12:08 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 13:16:57 +00:00
|
|
|
if (mIsSideBar) {
|
|
|
|
final int translationX = (mVisible ? 0 : -tabsPanelWidth);
|
|
|
|
|
|
|
|
animator.attach(mTabsContainer,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
translationX);
|
|
|
|
animator.attach(mHeader,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
translationX);
|
|
|
|
animator.attach(mFooter,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
translationX);
|
|
|
|
} else {
|
|
|
|
final int translationY = (mVisible ? 0 : -toolbarHeight);
|
|
|
|
|
|
|
|
animator.attach(mTabsContainer,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
mVisible ? 1.0f : 0.0f);
|
|
|
|
animator.attach(mTabsContainer,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_Y,
|
|
|
|
translationY);
|
|
|
|
animator.attach(mHeader,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_Y,
|
|
|
|
translationY);
|
|
|
|
}
|
2013-04-26 13:12:08 +00:00
|
|
|
|
|
|
|
mHeader.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
mTabsContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void finishTabsAnimation() {
|
|
|
|
if (Build.VERSION.SDK_INT < 11) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mHeader.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
mTabsContainer.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
}
|
|
|
|
|
2012-06-08 04:48:29 +00:00
|
|
|
public void setTabsLayoutChangeListener(TabsLayoutChangeListener listener) {
|
|
|
|
mLayoutChangeListener = listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void dispatchLayoutChange(int width, int height) {
|
|
|
|
if (mLayoutChangeListener != null)
|
|
|
|
mLayoutChangeListener.onTabsLayoutChange(width, height);
|
|
|
|
}
|
2012-06-08 04:47:22 +00:00
|
|
|
}
|