From 003cb9e92015a5b9c1fa08a7cc8eac2be037a219 Mon Sep 17 00:00:00 2001 From: tedchoc Date: Fri, 3 Oct 2014 15:55:10 -0700 Subject: [PATCH] Fix the menu alignment for the three button menu. Also, fixes a crash for an index out of bounds check. Also also, adds two button layout for when two icons are shown in the top row. BUG=416552 Review URL: https://codereview.chromium.org/608283004 Cr-Commit-Position: refs/heads/master@{#298110} --- .../java/res/layout/two_button_menu_item.xml | 29 +++++++++++++ .../chrome/browser/appmenu/AppMenuAdapter.java | 47 ++++++++++++++++++++-- 2 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 chrome/android/java/res/layout/two_button_menu_item.xml diff --git a/chrome/android/java/res/layout/two_button_menu_item.xml b/chrome/android/java/res/layout/two_button_menu_item.xml new file mode 100644 index 000000000000..aaa2413ba704 --- /dev/null +++ b/chrome/android/java/res/layout/two_button_menu_item.xml @@ -0,0 +1,29 @@ + + + + + + + + + \ No newline at end of file diff --git a/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuAdapter.java index 2b60292ce451..c59f095ef9db 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuAdapter.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuAdapter.java @@ -18,6 +18,7 @@ import android.widget.BaseAdapter; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ImageView.ScaleType; +import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; @@ -44,18 +45,22 @@ class AppMenuAdapter extends BaseAdapter { */ private static final int TITLE_BUTTON_MENU_ITEM = 1; /** + * Menu item that has two buttons. Every one of these buttons is displayed as an icon. + */ + private static final int TWO_BUTTON_MENU_ITEM = 2; + /** * Menu item that has three buttons. Every one of these buttons is displayed as an icon. */ - private static final int THREE_BUTTON_MENU_ITEM = 2; + private static final int THREE_BUTTON_MENU_ITEM = 3; /** * Menu item that has four buttons. Every one of these buttons is displayed as an icon. */ - private static final int FOUR_BUTTON_MENU_ITEM = 3; + private static final int FOUR_BUTTON_MENU_ITEM = 4; /** * Menu item that has two buttons, the first one is a title and the second is a menu icon. * This is similar to {@link #TITLE_BUTTON_MENU_ITEM} but has some slight layout differences. */ - private static final int MENU_BUTTON_MENU_ITEM = 4; + private static final int MENU_BUTTON_MENU_ITEM = 5; /** MenuItem Animation Constants */ private static final int ENTER_ITEM_DURATION_MS = 350; @@ -107,6 +112,11 @@ class AppMenuAdapter extends BaseAdapter { } else if (viewCount == 3) { return THREE_BUTTON_MENU_ITEM; } else if (viewCount == 2) { + if (position == 0 + && ((!mShowMenuButton && item.getSubMenu().getItem(0).getIcon() != null) + || (hasMenuButton && item.getIcon() != null))) { + return TWO_BUTTON_MENU_ITEM; + } return hasMenuButton ? MENU_BUTTON_MENU_ITEM : TITLE_BUTTON_MENU_ITEM; } return STANDARD_MENU_ITEM; @@ -164,6 +174,30 @@ class AppMenuAdapter extends BaseAdapter { convertView.setEnabled(isEnabled); break; } + case TWO_BUTTON_MENU_ITEM: { + TwoButtonMenuItemViewHolder holder = null; + if (convertView == null) { + holder = new TwoButtonMenuItemViewHolder(); + convertView = mInflater.inflate(R.layout.two_button_menu_item, parent, false); + holder.buttons[0] = (ImageButton) convertView.findViewById(R.id.button_one); + holder.buttons[1] = (ImageButton) convertView.findViewById(R.id.button_two); + convertView.setTag(holder); + convertView.setTag(R.id.menu_item_enter_anim_id, + buildIconItemEnterAnimator(holder.buttons, hasMenuButton)); + } else { + holder = (TwoButtonMenuItemViewHolder) convertView.getTag(); + } + setupImageButton(holder.buttons[0], item.getSubMenu().getItem(0)); + if (hasMenuButton) { + setupMenuButton(holder.buttons[1]); + } else { + setupImageButton(holder.buttons[1], item.getSubMenu().getItem(1)); + } + + convertView.setFocusable(false); + convertView.setEnabled(false); + break; + } case THREE_BUTTON_MENU_ITEM: { ThreeButtonMenuItemViewHolder holder = null; if (convertView == null) { @@ -181,7 +215,7 @@ class AppMenuAdapter extends BaseAdapter { setupImageButton(holder.buttons[0], item.getSubMenu().getItem(0)); setupImageButton(holder.buttons[1], item.getSubMenu().getItem(1)); if (hasMenuButton) { - setupMenuButton(holder.buttons[3]); + setupMenuButton(holder.buttons[2]); } else { setupImageButton(holder.buttons[2], item.getSubMenu().getItem(2)); } @@ -298,6 +332,7 @@ class AppMenuAdapter extends BaseAdapter { ApiCompatibilityUtils.setPaddingRelative( button, (int) (MENU_BUTTON_START_PADDING_DP * mDpToPx), 0, 0, 0); button.getLayoutParams().width = (int) (MENU_BUTTON_WIDTH_DP * mDpToPx); + ((LinearLayout.LayoutParams) button.getLayoutParams()).weight = 0; button.setScaleType(ScaleType.CENTER); } @@ -381,6 +416,10 @@ class AppMenuAdapter extends BaseAdapter { public AppMenuItemIcon image; } + static class TwoButtonMenuItemViewHolder { + public ImageButton[] buttons = new ImageButton[2]; + } + static class ThreeButtonMenuItemViewHolder { public ImageButton[] buttons = new ImageButton[3]; } -- 2.11.4.GIT