Bug 817706: Tab-style switcher in tabs-tray for phones. [r=mfinkle]

--HG--
rename : mobile/android/base/resources/layout/tabs_panel.xml => mobile/android/base/resources/layout/tabs_panel.xml.in
This commit is contained in:
Sriram Ramasubramanian 2012-12-18 17:04:39 -08:00
parent 8aec8c2df1
commit c2a7bc048d
17 changed files with 216 additions and 173 deletions

View File

@ -499,8 +499,12 @@ abstract public class BrowserApp extends GeckoApp
showAwesomebar(AwesomeBar.Target.NEW_TAB);
}
public void showLocalTabs() {
showTabs(TabsPanel.Panel.LOCAL_TABS);
public void showNormalTabs() {
showTabs(TabsPanel.Panel.NORMAL_TABS);
}
public void showPrivateTabs() {
showTabs(TabsPanel.Panel.PRIVATE_TABS);
}
public void showRemoteTabs() {

View File

@ -690,7 +690,14 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
InputMethodManager imm =
(InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mTabs.getWindowToken(), 0);
mActivity.showLocalTabs();
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab != null) {
if (!tab.isPrivate())
mActivity.showNormalTabs();
else
mActivity.showPrivateTabs();
}
}
}

View File

@ -804,7 +804,9 @@ abstract public class GeckoApp
void addTab() { }
public void showLocalTabs() { }
public void showNormalTabs() { }
public void showPrivateTabs() { }
public void showRemoteTabs() { }

View File

@ -78,12 +78,16 @@ public final class GeckoViewsFactory implements LayoutInflater.Factory {
return new FindInPageBar(context, attrs);
else if (TextUtils.equals(viewName, "MenuButton"))
return new MenuButton(context, attrs);
else if (TextUtils.equals(viewName, "RemoteTabs"))
return new RemoteTabs(context, attrs);
else if (TextUtils.equals(viewName, "TabsButton"))
return new TabsButton(context, attrs);
else if (TextUtils.equals(viewName, "TabsPanel"))
return new TabsPanel(context, attrs);
else if (TextUtils.equals(viewName, "TabsPanelButton"))
return new TabsPanelButton(context, attrs);
else if (TextUtils.equals(viewName, "TabsTray"))
return new TabsTray(context, attrs);
else if (TextUtils.equals(viewName, "TextSelectionHandle"))
return new TextSelectionHandle(context, attrs);
else if (TextUtils.equals(viewName, "gfx.LayerView"))

View File

@ -249,6 +249,7 @@ FENNEC_PP_XML_FILES = \
res/layout-large-v11/browser_toolbar_menu.xml \
res/layout-xlarge-v11/browser_toolbar_menu.xml \
res/layout/gecko_app.xml \
res/layout/tabs_panel.xml \
res/layout/text_selection_handles.xml \
res/layout-xlarge-land-v11/abouthome_content.xml \
res/layout-xlarge-v11/awesomebar_search.xml \
@ -405,7 +406,7 @@ RES_LAYOUT = \
res/layout/remote_tabs_child.xml \
res/layout/remote_tabs_group.xml \
res/layout/tabs_counter.xml \
res/layout/tabs_panel.xml \
res/layout/tabs_panel_indicator.xml \
res/layout/tabs_panel_toolbar_menu.xml \
res/layout/tabs_row.xml \
res/layout/tabs_tray.xml \
@ -1063,6 +1064,7 @@ MOZ_ANDROID_DRAWABLES += \
mobile/android/base/resources/drawable/tab_new_button.xml \
mobile/android/base/resources/drawable/tabs_button.xml \
mobile/android/base/resources/drawable/tabs_level.xml \
mobile/android/base/resources/drawable/tabs_panel_indicator.xml \
mobile/android/base/resources/drawable/tabs_tray_bg_repeat.xml \
mobile/android/base/resources/drawable/tabs_tray_selected_bg_repeat.xml \
mobile/android/base/resources/drawable/tabs_tray_active_selector.xml \

View File

@ -21,18 +21,23 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;
import android.widget.TextView;
public class TabsPanel extends LinearLayout
public class TabsPanel extends TabHost
implements GeckoPopupMenu.OnMenuItemClickListener,
LightweightTheme.OnChangeListener {
private static final String LOGTAG = "GeckoTabsPanel";
public static enum Panel {
LOCAL_TABS,
NORMAL_TABS,
PRIVATE_TABS,
REMOTE_TABS
}
@ -51,17 +56,16 @@ public class TabsPanel extends LinearLayout
private GeckoApp mActivity;
private PanelView mPanel;
private TabsPanelToolbar mToolbar;
private TabsListContainer mListContainer;
private TabsLayoutChangeListener mLayoutChangeListener;
private static ImageButton mMenuButton;
private static ImageButton mAddTab;
private static ImageButton mRemoteTabs;
private TextView mTitle;
private TabWidget mTabWidget;
private Panel mCurrentPanel;
private boolean mIsSideBar;
private boolean mVisible;
private boolean mInflated;
private GeckoPopupMenu mPopupMenu;
private Menu mMenu;
@ -74,29 +78,83 @@ public class TabsPanel extends LinearLayout
mContext = context;
mActivity = (GeckoApp) context;
setOrientation(LinearLayout.VERTICAL);
LayoutInflater.from(context).inflate(R.layout.tabs_panel, this);
mCurrentPanel = Panel.LOCAL_TABS;
mCurrentPanel = Panel.NORMAL_TABS;
mVisible = false;
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabsPanel);
mIsSideBar = a.getBoolean(R.styleable.TabsPanel_sidebar, false);
a.recycle();
mToolbar = (TabsPanelToolbar) findViewById(R.id.toolbar);
mListContainer = (TabsListContainer) findViewById(R.id.list_container);
mPopupMenu = new GeckoPopupMenu(context);
mPopupMenu.inflate(R.menu.tabs_menu);
mPopupMenu.setOnMenuItemClickListener(this);
mMenu = mPopupMenu.getMenu();
LayoutInflater.from(context).inflate(R.layout.tabs_panel, this);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
// HACK: Without this, the onFinishInflate is called twice
// This issue is due to a bug when Android inflates a layout with a
// parent. Fixed in Honeycomb
if (mInflated)
return;
mInflated = true;
initialize();
}
private void initialize() {
// This should be called before adding any tabs
// to the TabHost.
setup();
initToolbar();
addTab(R.string.tabs_normal, R.id.normal_tabs);
addTab(R.string.tabs_private, R.id.private_tabs);
addTab(R.string.tabs_synced, R.id.synced_tabs);
}
private void addTab(int resId, int contentId) {
String title = mContext.getString(resId);
TabSpec spec = newTabSpec(title);
GeckoTextView indicatorView = (GeckoTextView) LayoutInflater.from(mContext).inflate(R.layout.tabs_panel_indicator, null);
indicatorView.setText(title);
spec.setIndicator(indicatorView);
spec.setContent(contentId);
final int index = mTabWidget.getTabCount();
PanelView panel = (PanelView) findViewById(contentId);
panel.setTabsPanel(this);
panel.show();
addTab(spec);
indicatorView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Panel panel = Panel.NORMAL_TABS;
if (index == 1)
panel = Panel.PRIVATE_TABS;
else if (index == 2)
panel = Panel.REMOTE_TABS;
TabsPanel.this.show(panel);
}
});
}
void initToolbar() {
mTitle = (TextView) mToolbar.findViewById(R.id.title);
mToolbar = (TabsPanelToolbar) findViewById(R.id.toolbar);
mTabWidget = (TabWidget) findViewById(android.R.id.tabs);
mTabWidget.setDividerDrawable(null);
mTabWidget.setStripEnabled(false);
mAddTab = (ImageButton) mToolbar.findViewById(R.id.add_tab);
mAddTab.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
@ -105,16 +163,6 @@ public class TabsPanel extends LinearLayout
}
});
mRemoteTabs = (ImageButton) mToolbar.findViewById(R.id.remote_tabs);
mRemoteTabs.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
if (mRemoteTabs.getDrawable().getLevel() == REMOTE_TABS_SHOWN)
mActivity.showLocalTabs();
else
mActivity.showRemoteTabs();
}
});
mMenuButton = (ImageButton) mToolbar.findViewById(R.id.menu);
mMenuButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
@ -240,7 +288,7 @@ public class TabsPanel extends LinearLayout
}
// Tabs List Container holds the ListView
public static class TabsListContainer extends LinearLayout {
public static class TabsListContainer extends FrameLayout {
private Context mContext;
public TabsListContainer(Context context, AttributeSet attrs) {
@ -272,6 +320,8 @@ public class TabsPanel extends LinearLayout
(int) context.getResources().getDimension(R.dimen.browser_toolbar_height)));
LayoutInflater.from(context).inflate(R.layout.tabs_panel_toolbar_menu, this);
TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
tabWidget.setStripEnabled(false);
}
@Override
@ -310,56 +360,28 @@ public class TabsPanel extends LinearLayout
public void show(Panel panel) {
if (mPanel != null) {
// Remove the old panel.
// Hide the old panel.
mPanel.hide();
mListContainer.removeAllViews();
}
final boolean showAnimation = !mVisible;
mVisible = true;
mCurrentPanel = panel;
if (panel == Panel.LOCAL_TABS) {
mPanel = new TabsTray(mContext, null);
mTitle.setText("");
mRemoteTabs.setImageLevel(REMOTE_TABS_HIDDEN);
} else {
mPanel = new RemoteTabs(mContext, null);
mTitle.setText(R.string.remote_tabs);
mRemoteTabs.setVisibility(View.VISIBLE);
mRemoteTabs.setImageLevel(REMOTE_TABS_SHOWN);
}
int index = panel.ordinal();
setCurrentTab(index);
mPanel.setTabsPanel(this);
mPanel = (PanelView) getTabContentView().getChildAt(index);
mPanel.show();
mListContainer.addView(mPanel.getLayout());
if (isSideBar()) {
if (showAnimation)
dispatchLayoutChange(getWidth(), getHeight());
} else {
int actionBarHeight = mContext.getResources().getDimensionPixelSize(R.dimen.browser_toolbar_height);
int height = actionBarHeight + getTabContainerHeight(mListContainer);
int height = actionBarHeight + getTabContainerHeight(getTabContentView());
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) {
if (!result.booleanValue()) {
return;
}
TabsAccessor.areClientsAvailable(context, new TabsAccessor.OnClientsAvailableListener() {
@Override
public void areAvailable(boolean available) {
final int visibility = available ? View.VISIBLE : View.GONE;
mRemoteTabs.setVisibility(visibility);
}
});
}
}.execute(context);
}
public void hide() {
@ -371,14 +393,11 @@ public class TabsPanel extends LinearLayout
}
public void refresh() {
mListContainer.forceLayout();
clearAllTabs();
removeAllViews();
int index = indexOfChild(mToolbar);
removeViewAt(index);
mToolbar = new TabsPanelToolbar(mContext, null);
addView(mToolbar, index);
initToolbar();
LayoutInflater.from(mContext).inflate(R.layout.tabs_panel, this);
initialize();
if (mVisible)
show(mCurrentPanel);

View File

@ -139,6 +139,9 @@ size. -->
<!ENTITY new_private_tab "New Private Tab">
<!ENTITY synced_tabs "Synced Tabs">
<!ENTITY close_all_tabs "Close All Tabs">
<!ENTITY tabs_normal "Tabs">
<!ENTITY tabs_private "Private">
<!ENTITY tabs_synced "Synced">
<!ENTITY wallpaper_success "Wallpaper updated">
<!ENTITY wallpaper_progress "Setting wallpaper">
<!ENTITY wallpaper_fail "Unable to set wallpaper">

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false" android:drawable="@android:color/transparent"/>
<item android:state_selected="true" android:drawable="@drawable/highlight"/>
</selector>

View File

@ -24,24 +24,11 @@
android:layout_height="fill_parent"
android:layout_marginRight="15dip">
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1.0"
style="@style/TabRowTextAppearance"
android:gravity="center_vertical"
android:padding="10dip"
android:textSize="13sp"/>
<TabWidget android:id="@android:id/tabs"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
<ImageButton android:id="@+id/remote_tabs"
android:layout_width="@dimen/browser_toolbar_height"
android:layout_height="@dimen/browser_toolbar_height"
android:gravity="center_vertical"
android:padding="10dip"
android:src="@drawable/remote_tabs_level"
android:contentDescription="@string/remote_tabs"
android:background="@drawable/action_bar_button"
android:visibility="gone"/>
<org.mozilla.gecko.TabsPanelButton android:id="@+id/add_tab"
android:layout_width="63dip"

View File

@ -24,24 +24,10 @@
android:layout_height="fill_parent"
android:layout_marginRight="28dip">
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1.0"
style="@style/TabRowTextAppearance"
android:gravity="center_vertical"
android:padding="10dip"
android:textSize="16sp"/>
<ImageButton android:id="@+id/remote_tabs"
android:layout_width="@dimen/browser_toolbar_height"
android:layout_height="@dimen/browser_toolbar_height"
android:gravity="center_vertical"
android:padding="12dip"
android:src="@drawable/remote_tabs_level"
android:contentDescription="@string/remote_tabs"
android:background="@drawable/action_bar_button"
android:visibility="gone"/>
<TabWidget android:id="@android:id/tabs"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
<org.mozilla.gecko.TabsPanelButton android:id="@+id/add_tab"
android:layout_width="85dip"

View File

@ -8,6 +8,11 @@
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
<ImageButton android:id="@+id/add_tab"
android:layout_width="@dimen/browser_toolbar_height"
android:layout_height="@dimen/browser_toolbar_height"
@ -19,23 +24,6 @@
android:contentDescription="@string/new_tab"
android:background="@drawable/action_bar_button"/>
<ImageButton android:id="@+id/remote_tabs"
android:layout_width="@dimen/browser_toolbar_height"
android:layout_height="@dimen/browser_toolbar_height"
android:paddingTop="15dip"
android:paddingBottom="15dip"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:src="@drawable/remote_tabs_level"
android:contentDescription="@string/remote_tabs"
android:background="@drawable/action_bar_button"
android:visibility="gone"/>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<ImageButton android:id="@+id/menu"
android:layout_width="@dimen/browser_toolbar_height"
android:layout_height="@dimen/browser_toolbar_height"

View File

@ -9,11 +9,11 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.mozilla.gecko.TabsPanel android:id="@+id/tabs_panel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tabs_tray_bg_repeat"
gecko:sidebar="false"/>
<org.mozilla.gecko.TabsPanel android:id="@+id/tabs_panel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tabs_tray_bg_repeat"
gecko:sidebar="false"/>
<view class="org.mozilla.gecko.GeckoApp$MainLayout"
android:id="@+id/main_layout"

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<view class="org.mozilla.gecko.TabsPanel$TabsPanelToolbar"
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="@dimen/browser_toolbar_height"/>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<view class="org.mozilla.gecko.TabsPanel$TabsListContainer"
android:id="@+id/list_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"/>
<View android:layout_width="fill_parent"
android:layout_height="3dp"
android:layout_alignParentTop="true"
android:background="@drawable/tabs_shadow"/>
</RelativeLayout>
</merge>

View File

@ -0,0 +1,53 @@
#filter substitution
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res/@ANDROID_PACKAGE_NAME@">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<view class="org.mozilla.gecko.TabsPanel$TabsPanelToolbar"
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="@dimen/browser_toolbar_height"/>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0">
<view class="org.mozilla.gecko.TabsPanel$TabsListContainer"
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<org.mozilla.gecko.TabsTray android:id="@+id/normal_tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
gecko:tabs="tabs_normal"/>
<org.mozilla.gecko.TabsTray android:id="@+id/private_tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
gecko:tabs="tabs_private"/>
<org.mozilla.gecko.RemoteTabs android:id="@+id/synced_tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</view>
<View android:layout_width="fill_parent"
android:layout_height="3dp"
android:layout_alignParentTop="true"
android:background="@drawable/tabs_shadow"/>
</RelativeLayout>
</LinearLayout>
</merge>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<Gecko.TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:gravity="center"
android:background="@drawable/tabs_panel_indicator"
android:padding="10dp"
android:singleLine="true"
android:ellipsize="marquee"
android:textSize="13sp"
android:textColor="#FFE5F2FF"/>

View File

@ -24,24 +24,10 @@
android:layout_height="fill_parent"
android:layout_marginRight="22dip">
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1.0"
style="@style/TabRowTextAppearance"
android:gravity="center_vertical"
android:padding="10dip"
android:textSize="16sp"/>
<ImageButton android:id="@+id/remote_tabs"
android:layout_width="@dimen/browser_toolbar_height"
android:layout_height="@dimen/browser_toolbar_height"
android:gravity="center_vertical"
android:padding="12dip"
android:src="@drawable/remote_tabs_level"
android:contentDescription="@string/remote_tabs"
android:background="@drawable/action_bar_button"
android:visibility="gone"/>
<TabWidget android:id="@android:id/tabs"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
<org.mozilla.gecko.TabsPanelButton android:id="@+id/add_tab"
android:layout_width="75dip"

View File

@ -142,6 +142,9 @@
<string name="new_private_tab">&new_private_tab;</string>
<string name="synced_tabs">&synced_tabs;</string>
<string name="close_all_tabs">&close_all_tabs;</string>
<string name="tabs_normal">&tabs_normal;</string>
<string name="tabs_private">&tabs_private;</string>
<string name="tabs_synced">&tabs_synced;</string>
<!-- This string only appears in developer builds, which
is why it is not localizable. -->
<string name="toggle_profiling">Toggle Profiling</string>