From 31da143375628feaf325d849170e4b1c9d0f1dff Mon Sep 17 00:00:00 2001 From: Sriram Ramasubramanian Date: Fri, 18 Jan 2013 11:41:44 -0800 Subject: [PATCH] Bug 832433: Use Android spinners on tabs UI for phones. [r=mfinkle] --HG-- extra : rebase_source : 614269ba99d278771a293c45252ace306bdaa8d9 --- mobile/android/base/GeckoPopupMenu.java | 9 ++++ mobile/android/base/Makefile.in | 8 ++- mobile/android/base/MenuPopup.java | 18 +++++++ mobile/android/base/TabsPanel.java | 43 ++++++++++++++++ .../layout-v11/tabs_panel_header.xml | 51 +++++++++++++++++++ .../layout-xlarge-v11/tabs_panel_header.xml | 5 ++ .../resources/layout/tabs_panel_header.xml | 22 ++++++-- .../resources/menu/tabs_switcher_menu.xml | 17 +++++++ 8 files changed, 168 insertions(+), 5 deletions(-) create mode 100644 mobile/android/base/resources/layout-v11/tabs_panel_header.xml create mode 100644 mobile/android/base/resources/menu/tabs_switcher_menu.xml diff --git a/mobile/android/base/GeckoPopupMenu.java b/mobile/android/base/GeckoPopupMenu.java index 2f3f45c9213c..143684a10654 100644 --- a/mobile/android/base/GeckoPopupMenu.java +++ b/mobile/android/base/GeckoPopupMenu.java @@ -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) diff --git a/mobile/android/base/Makefile.in b/mobile/android/base/Makefile.in index 3483786dd676..2c2ceca238bf 100644 --- a/mobile/android/base/Makefile.in +++ b/mobile/android/base/Makefile.in @@ -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 \ diff --git a/mobile/android/base/MenuPopup.java b/mobile/android/base/MenuPopup.java index 0b1a3bff72f4..b71f6f16aabc 100644 --- a/mobile/android/base/MenuPopup.java +++ b/mobile/android/base/MenuPopup.java @@ -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); diff --git a/mobile/android/base/TabsPanel.java b/mobile/android/base/TabsPanel.java index 5358cc8dc7a6..d6ef9b16ca1c 100644 --- a/mobile/android/base/TabsPanel.java +++ b/mobile/android/base/TabsPanel.java @@ -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(); diff --git a/mobile/android/base/resources/layout-v11/tabs_panel_header.xml b/mobile/android/base/resources/layout-v11/tabs_panel_header.xml new file mode 100644 index 000000000000..cb0ee7ea5b98 --- /dev/null +++ b/mobile/android/base/resources/layout-v11/tabs_panel_header.xml @@ -0,0 +1,51 @@ + + + + + + + +