Commit 7ca8e721 authored by dtrainor@chromium.org's avatar dtrainor@chromium.org

Add menu button to menu

To prepare for menus overlapping anchors, add the dismiss menu button to the menu.

BUG=375379
NOTRY=true

Review URL: https://codereview.chromium.org/381133003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284496 0039d316-1c4b-4281-b951-d872f2087c98
parent d823551f
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/btn_menu_disabled" />
<item android:state_pressed="true" android:drawable="@drawable/btn_menu_pressed" />
<item android:state_selected="true" android:drawable="@drawable/btn_menu_pressed" />
<item android:state_focused="true" android:drawable="@drawable/btn_menu_pressed" />
<item android:drawable="@drawable/btn_menu_normal" />
</selector>
\ No newline at end of file
...@@ -12,35 +12,35 @@ ...@@ -12,35 +12,35 @@
<ImageButton <ImageButton
android:id="@+id/button_one" android:id="@+id/button_one"
android:layout_width="56dp" android:layout_width="59dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingEnd="8dp" android:paddingEnd="11dp"
android:background="?android:attr/listChoiceBackgroundIndicator" android:background="?android:attr/listChoiceBackgroundIndicator"
android:scaleType="center" /> android:scaleType="center" />
<ImageButton <ImageButton
android:id="@+id/button_two" android:id="@+id/button_two"
android:layout_width="64dp" android:layout_width="70dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingStart="8dp" android:paddingStart="11dp"
android:paddingEnd="8dp" android:paddingEnd="11dp"
android:background="?android:attr/listChoiceBackgroundIndicator" android:background="?android:attr/listChoiceBackgroundIndicator"
android:scaleType="center" /> android:scaleType="center" />
<ImageButton <ImageButton
android:id="@+id/button_three" android:id="@+id/button_three"
android:layout_width="64dp" android:layout_width="70dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingStart="8dp" android:paddingStart="11dp"
android:paddingEnd="8dp" android:paddingEnd="11dp"
android:background="?android:attr/listChoiceBackgroundIndicator" android:background="?android:attr/listChoiceBackgroundIndicator"
android:scaleType="center" /> android:scaleType="center" />
<ImageButton <ImageButton
android:id="@+id/button_four" android:id="@+id/button_four"
android:layout_width="56dp" android:layout_width="59dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingStart="8dp" android:paddingStart="11dp"
android:background="?android:attr/listChoiceBackgroundIndicator" android:background="?android:attr/listChoiceBackgroundIndicator"
android:scaleType="center" /> android:scaleType="center" />
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<dimen name="swipe_commit_distance">120dp</dimen> <dimen name="swipe_commit_distance">120dp</dimen>
<!-- Custom Menu dimensions --> <!-- Custom Menu dimensions -->
<dimen name="menu_width">260dp</dimen> <dimen name="menu_width">258dp</dimen>
<dimen name="menu_vertical_offset">0dp</dimen> <dimen name="menu_vertical_offset">0dp</dimen>
<!-- The amount to fade the edges of the menu to indicate more content is available <!-- The amount to fade the edges of the menu to indicate more content is available
via scrolling. --> via scrolling. -->
......
...@@ -34,6 +34,9 @@ import java.util.List; ...@@ -34,6 +34,9 @@ import java.util.List;
* - Disabled items are grayed out. * - Disabled items are grayed out.
*/ */
public class AppMenu implements OnItemClickListener, OnKeyListener { public class AppMenu implements OnItemClickListener, OnKeyListener {
/** Whether or not to show the software menu button in the menu. */
private static final boolean SHOW_SW_MENU_BUTTON = false;
private static final float LAST_ITEM_SHOW_FRACTION = 0.5f; private static final float LAST_ITEM_SHOW_FRACTION = 0.5f;
private final Menu mMenu; private final Menu mMenu;
...@@ -97,12 +100,19 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -97,12 +100,19 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
mHandler.onMenuVisibilityChanged(false); mHandler.onMenuVisibilityChanged(false);
} }
}); });
mPopup.setWidth(context.getResources().getDimensionPixelSize(R.dimen.menu_width));
// Need to explicitly set the background here. Relying on it being set in the style caused // Need to explicitly set the background here. Relying on it being set in the style caused
// an incorrectly drawn background. // an incorrectly drawn background.
mPopup.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.menu_bg)); mPopup.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.menu_bg));
Rect bgPadding = new Rect();
mPopup.getBackground().getPadding(bgPadding);
int popupWidth = context.getResources().getDimensionPixelSize(R.dimen.menu_width) +
bgPadding.left + bgPadding.right;
mPopup.setWidth(popupWidth);
mCurrentScreenRotation = screenRotation; mCurrentScreenRotation = screenRotation;
mIsByHardwareButton = isByHardwareButton; mIsByHardwareButton = isByHardwareButton;
...@@ -116,9 +126,12 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -116,9 +126,12 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
} }
} }
boolean showMenuButton = !mIsByHardwareButton;
if (!SHOW_SW_MENU_BUTTON) showMenuButton = false;
// A List adapter for visible items in the Menu. The first row is added as a header to the // A List adapter for visible items in the Menu. The first row is added as a header to the
// list view. // list view.
mAdapter = new AppMenuAdapter(this, menuItems, LayoutInflater.from(context)); mAdapter = new AppMenuAdapter(
this, menuItems, LayoutInflater.from(context), showMenuButton);
mPopup.setAdapter(mAdapter); mPopup.setAdapter(mAdapter);
setMenuHeight(menuItems.size(), visibleDisplayFrame); setMenuHeight(menuItems.size(), visibleDisplayFrame);
...@@ -264,4 +277,4 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -264,4 +277,4 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
} }
} }
} }
\ No newline at end of file
...@@ -47,12 +47,15 @@ class AppMenuAdapter extends BaseAdapter { ...@@ -47,12 +47,15 @@ class AppMenuAdapter extends BaseAdapter {
private final LayoutInflater mInflater; private final LayoutInflater mInflater;
private final List<MenuItem> mMenuItems; private final List<MenuItem> mMenuItems;
private final int mNumMenuItems; private final int mNumMenuItems;
private final boolean mShowMenuButton;
public AppMenuAdapter(AppMenu appMenu, List<MenuItem> menuItems, LayoutInflater inflater) { public AppMenuAdapter(AppMenu appMenu, List<MenuItem> menuItems, LayoutInflater inflater,
boolean showMenuButton) {
mAppMenu = appMenu; mAppMenu = appMenu;
mMenuItems = menuItems; mMenuItems = menuItems;
mInflater = inflater; mInflater = inflater;
mNumMenuItems = menuItems.size(); mNumMenuItems = menuItems.size();
mShowMenuButton = showMenuButton;
} }
@Override @Override
...@@ -67,14 +70,16 @@ class AppMenuAdapter extends BaseAdapter { ...@@ -67,14 +70,16 @@ class AppMenuAdapter extends BaseAdapter {
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
if (getItem(position).hasSubMenu()) { MenuItem item = getItem(position);
if (getItem(position).getSubMenu().size() == 4) { int viewCount = item.hasSubMenu() ? item.getSubMenu().size() : 1;
return FOUR_BUTTON_MENU_ITEM; if (mShowMenuButton && position == 0) viewCount++;
} else if (getItem(position).getSubMenu().size() == 3) {
return THREE_BUTTON_MENU_ITEM; if (viewCount == 4) {
} else if (getItem(position).getSubMenu().size() == 2) { return FOUR_BUTTON_MENU_ITEM;
return TITLE_BUTTON_MENU_ITEM; } else if (viewCount == 3) {
} return THREE_BUTTON_MENU_ITEM;
} else if (viewCount == 2) {
return TITLE_BUTTON_MENU_ITEM;
} }
return STANDARD_MENU_ITEM; return STANDARD_MENU_ITEM;
} }
...@@ -142,7 +147,12 @@ class AppMenuAdapter extends BaseAdapter { ...@@ -142,7 +147,12 @@ class AppMenuAdapter extends BaseAdapter {
} }
setupImageButton(holder.buttonOne, item.getSubMenu().getItem(0)); setupImageButton(holder.buttonOne, item.getSubMenu().getItem(0));
setupImageButton(holder.buttonTwo, item.getSubMenu().getItem(1)); setupImageButton(holder.buttonTwo, item.getSubMenu().getItem(1));
setupImageButton(holder.buttonThree, item.getSubMenu().getItem(2));
if (mShowMenuButton && position == 0) {
setupMenuButton(holder.buttonThree);
} else {
setupImageButton(holder.buttonThree, item.getSubMenu().getItem(2));
}
convertView.setFocusable(false); convertView.setFocusable(false);
convertView.setEnabled(false); convertView.setEnabled(false);
break; break;
...@@ -163,7 +173,12 @@ class AppMenuAdapter extends BaseAdapter { ...@@ -163,7 +173,12 @@ class AppMenuAdapter extends BaseAdapter {
setupImageButton(holder.buttonOne, item.getSubMenu().getItem(0)); setupImageButton(holder.buttonOne, item.getSubMenu().getItem(0));
setupImageButton(holder.buttonTwo, item.getSubMenu().getItem(1)); setupImageButton(holder.buttonTwo, item.getSubMenu().getItem(1));
setupImageButton(holder.buttonThree, item.getSubMenu().getItem(2)); setupImageButton(holder.buttonThree, item.getSubMenu().getItem(2));
setupImageButton(holder.buttonFour, item.getSubMenu().getItem(3));
if (mShowMenuButton && position == 0) {
setupMenuButton(holder.buttonFour);
} else {
setupImageButton(holder.buttonFour, item.getSubMenu().getItem(3));
}
convertView.setFocusable(false); convertView.setFocusable(false);
convertView.setEnabled(false); convertView.setEnabled(false);
break; break;
...@@ -179,7 +194,7 @@ class AppMenuAdapter extends BaseAdapter { ...@@ -179,7 +194,7 @@ class AppMenuAdapter extends BaseAdapter {
} else { } else {
holder = (TitleButtonMenuItemViewHolder) convertView.getTag(); holder = (TitleButtonMenuItemViewHolder) convertView.getTag();
} }
final MenuItem titleItem = item.getSubMenu().getItem(0); final MenuItem titleItem = item.hasSubMenu() ? item.getSubMenu().getItem(0) : item;
holder.title.setText(titleItem.getTitle()); holder.title.setText(titleItem.getTitle());
holder.title.setEnabled(titleItem.isEnabled()); holder.title.setEnabled(titleItem.isEnabled());
holder.title.setFocusable(titleItem.isEnabled()); holder.title.setFocusable(titleItem.isEnabled());
...@@ -189,7 +204,11 @@ class AppMenuAdapter extends BaseAdapter { ...@@ -189,7 +204,11 @@ class AppMenuAdapter extends BaseAdapter {
mAppMenu.onItemClick(titleItem); mAppMenu.onItemClick(titleItem);
} }
}); });
if (item.getSubMenu().getItem(1).getIcon() != null) {
if (mShowMenuButton && position == 0) {
holder.button.setVisibility(View.VISIBLE);
setupMenuButton(holder.button);
} else if (item.getSubMenu().getItem(1).getIcon() != null) {
holder.button.setVisibility(View.VISIBLE); holder.button.setVisibility(View.VISIBLE);
setupImageButton(holder.button, item.getSubMenu().getItem(1)); setupImageButton(holder.button, item.getSubMenu().getItem(1));
} else { } else {
...@@ -222,6 +241,19 @@ class AppMenuAdapter extends BaseAdapter { ...@@ -222,6 +241,19 @@ class AppMenuAdapter extends BaseAdapter {
}); });
} }
private void setupMenuButton(ImageButton button) {
button.setImageResource(R.drawable.btn_menu_pressed);
button.setContentDescription(button.getResources().getString(R.string.menu_dismiss_btn));
button.setEnabled(true);
button.setFocusable(true);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mAppMenu.dismiss();
}
});
}
static class StandardMenuItemViewHolder { static class StandardMenuItemViewHolder {
public TextView text; public TextView text;
public AppMenuItemIcon image; public AppMenuItemIcon image;
......
...@@ -238,6 +238,9 @@ You are signing in with a managed account and giving its administrator control o ...@@ -238,6 +238,9 @@ You are signing in with a managed account and giving its administrator control o
<message name="IDS_TRANSLATE_NEVER_TRANSLATE_LANGUAGE" meaning="Android" desc="Text to display on the never translate language button. [CHAR-LIMIT=64]"> <message name="IDS_TRANSLATE_NEVER_TRANSLATE_LANGUAGE" meaning="Android" desc="Text to display on the never translate language button. [CHAR-LIMIT=64]">
Never translate <ph name="LANGUAGE">%1$s<ex>French</ex></ph> Never translate <ph name="LANGUAGE">%1$s<ex>French</ex></ph>
</message> </message>
<message name="IDS_MENU_DISMISS_BTN" desc="Content description for the settings menu button when the menu is open.">
Dismiss the menu
</message>
<message name="IDS_MENU_PRINT" desc="Menu item for printing the current page. [CHAR-LIMIT=27]"> <message name="IDS_MENU_PRINT" desc="Menu item for printing the current page. [CHAR-LIMIT=27]">
Print… Print…
</message> </message>
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<ImageButton android:id="@+id/menu_button" <ImageButton android:id="@+id/menu_button"
android:layout_width="38dp" android:layout_width="38dp"
android:layout_height="38dp" android:layout_height="38dp"
android:src="@drawable/menu_dots" android:src="@drawable/btn_menu"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:scaleType="center" /> android:scaleType="center" />
</org.chromium.chrome.shell.ChromeShellToolbar> </org.chromium.chrome.shell.ChromeShellToolbar>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment