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;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
......@@ -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
// an incorrectly drawn background.
if (isByHardwareButton) {
......@@ -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;
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
......@@ -148,8 +162,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
this, menuItems, LayoutInflater.from(context), showMenuButton);
mPopup.setAdapter(mAdapter);
setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight);
setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame);
setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight, sizingPadding);
setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame, sizingPadding);
mPopup.setOnItemClickListener(this);
mPopup.show();
mPopup.getListView().setItemsCanFocus(true);
......@@ -175,9 +189,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
}
}
private void setPopupOffset(ListPopupWindow popup, int screenRotation, Rect appRect) {
Rect paddingRect = new Rect();
popup.getBackground().getPadding(paddingRect);
private void setPopupOffset(
ListPopupWindow popup, int screenRotation, Rect appRect, Rect padding) {
int[] anchorLocation = new int[2];
popup.getAnchorView().getLocationInWindow(anchorLocation);
int anchorHeight = popup.getAnchorView().getHeight();
......@@ -201,9 +214,9 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
break;
}
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.
popup.setVerticalOffset(-paddingRect.bottom);
popup.setVerticalOffset(-padding.bottom);
} else {
// The menu is displayed over and below the anchored view, so shift the menu up by the
// height of the anchor view.
......@@ -274,7 +287,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
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;
View anchorView = mPopup.getAnchorView();
int[] anchorViewLocation = new int[2];
......@@ -289,9 +303,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
int availableScreenSpace = Math.max(anchorViewLocation[1],
appDimensions.height() - anchorViewLocation[1] - anchorViewImpactHeight);
Rect padding = new Rect();
mPopup.getBackground().getPadding(padding);
availableScreenSpace -= mIsByHardwareButton ? padding.top : padding.bottom;
availableScreenSpace -= padding.bottom;
if (mIsByHardwareButton) availableScreenSpace -= padding.top;
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