From f8fd73999e308fa27512aed03d2afba7092c920c Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Sat, 24 Nov 2018 20:33:09 +0100 Subject: [PATCH] improve size calculation --- .../android/vanilla/ui/FancyMenu.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/ui/FancyMenu.java b/app/src/main/java/ch/blinkenlights/android/vanilla/ui/FancyMenu.java index 47eb290e..bef7be59 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/ui/FancyMenu.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/ui/FancyMenu.java @@ -193,10 +193,17 @@ public class FancyMenu { * @param the estimated height * @return the height to use instead of the input */ - private int getMenuHeight(int suggested) { + private int getMenuHeight(View parent, int suggested) { DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); - int maxHeight = (int)((float)metrics.heightPixels * 0.35); - return (suggested > maxHeight ? maxHeight : ListPopupWindow.WRAP_CONTENT); + int pos[] = new int[2]; + // Don't calculate a size which is less than 20% of the screen space + // (unless the menu is smaller than that) + int min = metrics.heightPixels / 5; + + parent.getLocationInWindow(pos); + int available = metrics.heightPixels - pos[1] - parent.getHeight(); + available = Math.max(available, min); + return Math.min(available, suggested); } /** @@ -222,7 +229,7 @@ public class FancyMenu { int result[] = new int[2]; measureAdapter(adapter, result); - pw.setHeight(getMenuHeight(result[0])); + pw.setHeight(getMenuHeight(parent, result[0])); pw.setWidth(result[1]); pw.setAdapter(adapter);