Bug 832433: Use Android spinners on tabs UI for phones. [r=mfinkle]

--HG--
extra : rebase_source : 614269ba99d278771a293c45252ace306bdaa8d9
This commit is contained in:
Sriram Ramasubramanian 2013-01-18 11:41:44 -08:00
parent 3f1a61ae26
commit 31da143375
8 changed files with 168 additions and 5 deletions

View File

@ -130,6 +130,15 @@ public class GeckoPopupMenu implements GeckoMenu.Callback,
}
}
/**
* Show/hide the arrow pointing to the anchor.
*
* @param show Show/hide the arrow.
*/
public void showArrowToAnchor(boolean show) {
mMenuPopup.showArrowToAnchor(show);
}
@Override
public boolean onMenuItemSelected(MenuItem item) {
if (mClickListener != null)

View File

@ -420,6 +420,10 @@ RES_LAYOUT = \
res/layout/validation_message.xml \
$(NULL)
RES_LAYOUT_V11 = \
res/layout-v11/tabs_panel_header.xml \
$(NULL)
RES_LAYOUT_LARGE_V11 = \
res/layout-large-v11/doorhangerpopup.xml \
res/layout-large-v11/site_identity_popup.xml \
@ -1043,6 +1047,7 @@ RES_MENU = \
res/menu/awesomebar_contextmenu.xml \
res/menu/gecko_app_menu.xml \
res/menu/tabs_menu.xml \
res/menu/tabs_switcher_menu.xml \
res/menu/titlebar_contextmenu.xml \
res/menu/abouthome_topsites_contextmenu.xml \
res/menu-v11/tabs_menu.xml \
@ -1111,7 +1116,7 @@ MOZ_BRANDING_DRAWABLE_MDPI = $(shell if test -e $(topsrcdir)/$(MOZ_BRANDING_DIRE
MOZ_BRANDING_DRAWABLE_HDPI = $(shell if test -e $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/android-resources-hdpi.mn; then cat $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/android-resources-hdpi.mn | tr '\n' ' '; fi)
MOZ_BRANDING_DRAWABLE_XHDPI = $(shell if test -e $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/android-resources-xhdpi.mn; then cat $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/android-resources-xhdpi.mn | tr '\n' ' '; fi)
RESOURCES=$(RES_LAYOUT) $(RES_LAYOUT_LARGE_V11) $(RES_LAYOUT_XLARGE_V11) $(RES_VALUES) $(RES_VALUES_LAND) $(RES_VALUES_V11) $(RES_VALUES_LARGE_V11) $(RES_VALUES_XLARGE_V11) $(RES_VALUES_LAND_V14) $(RES_XML) $(RES_ANIM) $(RES_DRAWABLE_NODPI) $(RES_DRAWABLE_BASE) $(RES_DRAWABLE_LDPI) $(RES_DRAWABLE_HDPI) $(RES_DRAWABLE_XHDPI) $(RES_DRAWABLE_MDPI_V11) $(RES_DRAWABLE_HDPI_V11) $(RES_DRAWABLE_XHDPI_V11) $(RES_DRAWABLE_LAND_V14) $(RES_DRAWABLE_LAND_MDPI_V14) $(RES_DRAWABLE_LAND_HDPI_V14) $(RES_DRAWABLE_LAND_XHDPI_V14) $(RES_DRAWABLE_LARGE_MDPI_V11) $(RES_DRAWABLE_LARGE_HDPI_V11) $(RES_DRAWABLE_LARGE_XHDPI_V11) $(RES_DRAWABLE_XLARGE_MDPI_V11) $(RES_DRAWABLE_XLARGE_HDPI_V11) $(RES_DRAWABLE_XLARGE_XHDPI_V11) $(RES_COLOR) $(RES_MENU)
RESOURCES=$(RES_LAYOUT) $(RES_LAYOUT_V11) $(RES_LAYOUT_LARGE_V11) $(RES_LAYOUT_XLARGE_V11) $(RES_VALUES) $(RES_VALUES_LAND) $(RES_VALUES_V11) $(RES_VALUES_LARGE_V11) $(RES_VALUES_XLARGE_V11) $(RES_VALUES_LAND_V14) $(RES_XML) $(RES_ANIM) $(RES_DRAWABLE_NODPI) $(RES_DRAWABLE_BASE) $(RES_DRAWABLE_LDPI) $(RES_DRAWABLE_HDPI) $(RES_DRAWABLE_XHDPI) $(RES_DRAWABLE_MDPI_V11) $(RES_DRAWABLE_HDPI_V11) $(RES_DRAWABLE_XHDPI_V11) $(RES_DRAWABLE_LAND_V14) $(RES_DRAWABLE_LAND_MDPI_V14) $(RES_DRAWABLE_LAND_HDPI_V14) $(RES_DRAWABLE_LAND_XHDPI_V14) $(RES_DRAWABLE_LARGE_MDPI_V11) $(RES_DRAWABLE_LARGE_HDPI_V11) $(RES_DRAWABLE_LARGE_XHDPI_V11) $(RES_DRAWABLE_XLARGE_MDPI_V11) $(RES_DRAWABLE_XLARGE_HDPI_V11) $(RES_DRAWABLE_XLARGE_XHDPI_V11) $(RES_COLOR) $(RES_MENU)
RES_DIRS= \
res/layout \
@ -1119,6 +1124,7 @@ RES_DIRS= \
res/layout-large-v11 \
res/layout-xlarge-v11 \
res/layout-xlarge-land-v11 \
res/layout-v11 \
res/values \
res/values-v11 \
res/values-large-v11 \

View File

@ -30,6 +30,7 @@ public class MenuPopup extends PopupWindow {
private int mYOffset;
private int mArrowMargin;
private int mPopupWidth;
private boolean mShowArrow;
public MenuPopup(Context context) {
super(context);
@ -53,6 +54,7 @@ public class MenuPopup extends PopupWindow {
mArrowTop = (ImageView) layout.findViewById(R.id.menu_arrow_top);
mArrowBottom = (ImageView) layout.findViewById(R.id.menu_arrow_bottom);
mPanel = (RelativeLayout) layout.findViewById(R.id.menu_panel);
mShowArrow = true;
}
/**
@ -66,11 +68,27 @@ public class MenuPopup extends PopupWindow {
mPanel.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
/**
* Show/hide the arrow pointing to the anchor.
*
* @param show Show/hide the arrow.
*/
public void showArrowToAnchor(boolean show) {
mShowArrow = show;
}
/**
* A small little offset for the arrow to overlap the anchor.
*/
@Override
public void showAsDropDown(View anchor) {
if (!mShowArrow) {
mArrowTop.setVisibility(View.GONE);
mArrowBottom.setVisibility(View.GONE);
showAsDropDown(anchor, 0, -mYOffset);
return;
}
int[] anchorLocation = new int[2];
anchor.getLocationOnScreen(anchorLocation);

View File

@ -58,6 +58,7 @@ public class TabsPanel extends TabHost
private static ImageButton mMenuButton;
private static ImageButton mAddTab;
private TabWidget mTabWidget;
private Button mTabsMenuButton;
private Spinner mTabsSpinner;
private Panel mCurrentPanel;
@ -65,6 +66,9 @@ public class TabsPanel extends TabHost
private boolean mVisible;
private boolean mInflated;
private GeckoPopupMenu mTabsPopupMenu;
private Menu mTabsMenu;
private GeckoPopupMenu mPopupMenu;
private Menu mMenu;
@ -85,6 +89,12 @@ public class TabsPanel extends TabHost
mPopupMenu.setOnMenuItemClickListener(this);
mMenu = mPopupMenu.getMenu();
mTabsPopupMenu = new GeckoPopupMenu(context);
mTabsPopupMenu.inflate(R.menu.tabs_switcher_menu);
mTabsPopupMenu.setOnMenuItemClickListener(this);
mTabsPopupMenu.showArrowToAnchor(false);
mTabsMenu = mTabsPopupMenu.getMenu();
LayoutInflater.from(context).inflate(R.layout.tabs_panel, this);
}
@ -158,6 +168,14 @@ public class TabsPanel extends TabHost
mTabsSpinner = (Spinner) findViewById(R.id.tabs_menu);
mTabsSpinner.setOnItemSelectedListener(this);
mTabsMenuButton = (Button) findViewById(R.id.tabs_switcher_menu);
mTabsPopupMenu.setAnchor(mTabsMenuButton);
mTabsMenuButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
TabsPanel.this.openTabsSwitcherMenu();
}
});
mMenuButton = (ImageButton) findViewById(R.id.menu);
mMenuButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
@ -186,6 +204,10 @@ public class TabsPanel extends TabHost
mPopupMenu.show();
}
public void openTabsSwitcherMenu() {
mTabsPopupMenu.show();
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Panel panel = TabsPanel.Panel.NORMAL_TABS;
@ -205,6 +227,20 @@ public class TabsPanel extends TabHost
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.tabs_normal:
show(Panel.NORMAL_TABS);
return true;
case R.id.tabs_private:
mTabsMenuButton.setText(R.string.tabs_private);
show(Panel.PRIVATE_TABS);
return true;
case R.id.tabs_synced:
mTabsMenuButton.setText(R.string.tabs_synced);
show(Panel.REMOTE_TABS);
return true;
case R.id.close_all_tabs:
for (Tab tab : Tabs.getInstance().getTabsInOrder()) {
Tabs.getInstance().closeTab(tab);
@ -356,6 +392,13 @@ public class TabsPanel extends TabHost
setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
mTabsSpinner.setSelection(index);
if (index == 0)
mTabsMenuButton.setText(R.string.tabs_normal);
else if (index == 1)
mTabsMenuButton.setText(R.string.tabs_private);
else
mTabsMenuButton.setText(R.string.tabs_synced);
mPanel = (PanelView) getTabContentView().getChildAt(index);
mPanel.show();

View File

@ -0,0 +1,51 @@
<?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">
<TabWidget android:id="@android:id/tabs"
android:layout_width="0dip"
android:layout_height="0dip"
android:visibility="gone"/>
<Button android:id="@id/tabs_switcher_menu"
android:layout_width="0dip"
android:layout_height="0dip"
android:visibility="gone"/>
<Spinner android:id="@+id/tabs_menu"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:minWidth="200dp"
android:gravity="left"
android:background="@drawable/spinner"
android:popupBackground="@drawable/menu_popup_bg"
android:dropDownHorizontalOffset="0dip"
android:dropDownSelector="@drawable/action_bar_button"
android:entries="@array/tabs_panel_spinner"/>
<View android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
<ImageButton android:id="@+id/add_tab"
style="@style/AddressBar.ImageButton"
android:layout_width="@dimen/browser_toolbar_height"
android:layout_height="@dimen/browser_toolbar_height"
android:padding="@dimen/browser_toolbar_button_padding"
android:src="@drawable/tab_new_level"
android:contentDescription="@string/new_tab"
android:background="@drawable/action_bar_button"/>
<ImageButton android:id="@+id/menu"
style="@style/AddressBar.ImageButton"
android:layout_width="@dimen/browser_toolbar_height"
android:layout_height="@dimen/browser_toolbar_height"
android:padding="@dimen/browser_toolbar_button_padding"
android:src="@drawable/tabs_menu"
android:contentDescription="@string/menu"
android:background="@drawable/action_bar_button"/>
</merge>

View File

@ -10,6 +10,11 @@
android:layout_height="0dip"
android:visibility="gone"/>
<Button android:id="@id/tabs_switcher_menu"
android:layout_width="0dip"
android:layout_height="0dip"
android:visibility="gone"/>
<Spinner android:id="@+id/tabs_menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

View File

@ -7,16 +7,30 @@
<TabWidget android:id="@android:id/tabs"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:tabStripEnabled="false"
android:divider="@drawable/tab_indicator_divider"/>
android:layout_height="0dip"
android:visibility="gone"/>
<Spinner android:id="@+id/tabs_menu"
android:layout_width="0dip"
android:layout_height="0dip"
android:visibility="gone"/>
<Button android:id="@+id/tabs_switcher_menu"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:minWidth="200dp"
android:gravity="left|center_vertical"
android:textColor="#FFFFFFFF"
android:textSize="18sp"
android:text="@string/tabs_normal"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:background="@drawable/spinner"/>
<View android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
<ImageButton android:id="@+id/add_tab"
style="@style/AddressBar.ImageButton"
android:layout_width="@dimen/browser_toolbar_height"

View File

@ -0,0 +1,17 @@
<?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/. -->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/tabs_normal"
android:title="@string/tabs_normal"/>
<item android:id="@+id/tabs_private"
android:title="@string/tabs_private"/>
<item android:id="@+id/tabs_synced"
android:title="@string/tabs_synced"/>
</menu>