Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1216)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java

Issue 531263002: Fix OEM menu issue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2125
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java b/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java
index b3d1cfe44567eaf3fb9303e27e480dbbf149d943..3f3ac689cda0846324cf548e23c7011a2667e960 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java
@@ -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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698