Commit 2b66232b authored by dtrainor@chromium.org's avatar dtrainor@chromium.org

Fix OEM menu issue

- Some OEMs don't let us change the background, so the padding is incorrect.
- Also including sizing the menu too large causes clipping.

BUG=398837

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

Cr-Commit-Position: refs/heads/master@{#291193}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291193 0039d316-1c4b-4281-b951-d872f2087c98
parent cffd7f90
...@@ -9,6 +9,7 @@ import android.animation.AnimatorSet; ...@@ -9,6 +9,7 @@ import android.animation.AnimatorSet;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
...@@ -106,6 +107,11 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -106,6 +107,11 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
} }
}); });
// Some OEMs don't actually let us change the background... but they still return the
// padding of the new background, which breaks the menu height. If we still have a
// drawable here even though our style says @null we should use this padding instead...
Drawable originalBgDrawable = mPopup.getBackground();
// 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.
if (isByHardwareButton) { if (isByHardwareButton) {
...@@ -140,6 +146,14 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -140,6 +146,14 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
} }
} }
Rect sizingPadding = new Rect(bgPadding);
if (isByHardwareButton && originalBgDrawable != null) {
Rect originalPadding = new Rect();
originalBgDrawable.getPadding(originalPadding);
sizingPadding.top = originalPadding.top;
sizingPadding.bottom = originalPadding.bottom;
}
boolean showMenuButton = !mIsByHardwareButton; boolean showMenuButton = !mIsByHardwareButton;
if (!SHOW_SW_MENU_BUTTON) showMenuButton = false; 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
...@@ -148,8 +162,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -148,8 +162,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
this, menuItems, LayoutInflater.from(context), showMenuButton); this, menuItems, LayoutInflater.from(context), showMenuButton);
mPopup.setAdapter(mAdapter); mPopup.setAdapter(mAdapter);
setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight); setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight, sizingPadding);
setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame); setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame, sizingPadding);
mPopup.setOnItemClickListener(this); mPopup.setOnItemClickListener(this);
mPopup.show(); mPopup.show();
mPopup.getListView().setItemsCanFocus(true); mPopup.getListView().setItemsCanFocus(true);
...@@ -175,9 +189,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -175,9 +189,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
} }
} }
private void setPopupOffset(ListPopupWindow popup, int screenRotation, Rect appRect) { private void setPopupOffset(
Rect paddingRect = new Rect(); ListPopupWindow popup, int screenRotation, Rect appRect, Rect padding) {
popup.getBackground().getPadding(paddingRect);
int[] anchorLocation = new int[2]; int[] anchorLocation = new int[2];
popup.getAnchorView().getLocationInWindow(anchorLocation); popup.getAnchorView().getLocationInWindow(anchorLocation);
int anchorHeight = popup.getAnchorView().getHeight(); int anchorHeight = popup.getAnchorView().getHeight();
...@@ -201,9 +214,9 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -201,9 +214,9 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
break; break;
} }
popup.setHorizontalOffset(horizontalOffset); popup.setHorizontalOffset(horizontalOffset);
// The menu is displayed above the anchored view, so shift the menu up by the top // The menu is displayed above the anchored view, so shift the menu up by the bottom
// padding of the background. // padding of the background.
popup.setVerticalOffset(-paddingRect.bottom); popup.setVerticalOffset(-padding.bottom);
} else { } else {
// The menu is displayed over and below the anchored view, so shift the menu up by the // The menu is displayed over and below the anchored view, so shift the menu up by the
// height of the anchor view. // height of the anchor view.
...@@ -274,7 +287,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -274,7 +287,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
return mPopup; return mPopup;
} }
private void setMenuHeight(int numMenuItems, Rect appDimensions, int screenHeight) { private void setMenuHeight(
int numMenuItems, Rect appDimensions, int screenHeight, Rect padding) {
assert mPopup.getAnchorView() != null; assert mPopup.getAnchorView() != null;
View anchorView = mPopup.getAnchorView(); View anchorView = mPopup.getAnchorView();
int[] anchorViewLocation = new int[2]; int[] anchorViewLocation = new int[2];
...@@ -289,9 +303,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -289,9 +303,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
int availableScreenSpace = Math.max(anchorViewLocation[1], int availableScreenSpace = Math.max(anchorViewLocation[1],
appDimensions.height() - anchorViewLocation[1] - anchorViewImpactHeight); appDimensions.height() - anchorViewLocation[1] - anchorViewImpactHeight);
Rect padding = new Rect(); availableScreenSpace -= padding.bottom;
mPopup.getBackground().getPadding(padding); if (mIsByHardwareButton) availableScreenSpace -= padding.top;
availableScreenSpace -= mIsByHardwareButton ? padding.top : padding.bottom;
int numCanFit = availableScreenSpace / (mItemRowHeight + mItemDividerHeight); int numCanFit = availableScreenSpace / (mItemRowHeight + mItemDividerHeight);
......
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