* button)
* @param screenRotation Current device screen rotation.
* @param visibleDisplayFrame The display area rect in which AppMenu is supposed to fit in.
+ * @param screenHeight Current device screen height.
*/
void show(Context context, View anchorView, boolean isByHardwareButton, int screenRotation,
- Rect visibleDisplayFrame) {
+ Rect visibleDisplayFrame, int screenHeight) {
mPopup = new ListPopupWindow(context, null, android.R.attr.popupMenuStyle);
mPopup.setModal(true);
mPopup.setAnchorView(anchorView);
this, menuItems, LayoutInflater.from(context), showMenuButton);
mPopup.setAdapter(mAdapter);
- setMenuHeight(menuItems.size(), visibleDisplayFrame);
+ setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight);
setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame);
mPopup.setOnItemClickListener(this);
mPopup.show();
return mPopup;
}
- private void setMenuHeight(int numMenuItems, Rect appDimensions) {
+ private void setMenuHeight(int numMenuItems, Rect appDimensions, int screenHeight) {
assert mPopup.getAnchorView() != null;
View anchorView = mPopup.getAnchorView();
int[] anchorViewLocation = new int[2];
anchorViewLocation[1] -= appDimensions.top;
int anchorViewImpactHeight = mIsByHardwareButton ? anchorView.getHeight() : 0;
+ // Set appDimensions.height() for abnormal anchorViewLocation.
+ if (anchorViewLocation[1] > screenHeight) {
+ anchorViewLocation[1] = appDimensions.height();
+ }
int availableScreenSpace = Math.max(anchorViewLocation[1],
appDimensions.height() - anchorViewLocation[1] - anchorViewImpactHeight);