From b429e172f17ae5e8c558c579578e5d37a45c7890 Mon Sep 17 00:00:00 2001 From: "Wesley.CW Wang" Date: Thu, 27 Sep 2018 20:41:31 +0800 Subject: [PATCH] Fix Power Menu vanish when display size is Large - Break the power button alignment when power menu height larger then screen height, remove power menu padding and set gravity to center vertical within the screen. Test: Manually, set display size or font size to large, larger or largest & check power menu should be center vertical/horizontal when power menu height larger then screen height. Bug: 110761858 Change-Id: Ice7f816a30fa0f565a9098b3d6d5989aca9a4e5b Merged-In: Ice7f816a30fa0f565a9098b3d6d5989aca9a4e5b --- .../android/systemui/HardwareUiLayout.java | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/HardwareUiLayout.java b/packages/SystemUI/src/com/android/systemui/HardwareUiLayout.java index 198a4e6cedb88..b1463a3c53ea1 100644 --- a/packages/SystemUI/src/com/android/systemui/HardwareUiLayout.java +++ b/packages/SystemUI/src/com/android/systemui/HardwareUiLayout.java @@ -143,9 +143,6 @@ public class HardwareUiLayout extends LinearLayout implements Tunable { mSeparatedView.setBackground(mSeparatedViewBackground); updateEdgeMargin(mEdgeBleed ? 0 : getEdgePadding()); mOldHeight = mList.getMeasuredHeight(); - mList.addOnLayoutChangeListener( - (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> - updatePosition()); updateRotation(); } else { return; @@ -155,6 +152,8 @@ public class HardwareUiLayout extends LinearLayout implements Tunable { if (newHeight != mOldHeight) { animateChild(mOldHeight, newHeight); } + + post(() -> updatePaddingAndGravityIfTooTall()); post(() -> updatePosition()); } @@ -241,7 +240,7 @@ public class HardwareUiLayout extends LinearLayout implements Tunable { separatedViewLayoutParams.gravity = rotateGravityRight(separatedViewLayoutParams.gravity); mSeparatedView.setLayoutParams(separatedViewLayoutParams); - setGravity(p.gravity); + setGravity(rotateGravityRight(getGravity())); } private void swapDimens(View v) { @@ -299,7 +298,7 @@ public class HardwareUiLayout extends LinearLayout implements Tunable { separatedViewLayoutParams.gravity = rotateGravityLeft(separatedViewLayoutParams.gravity); mSeparatedView.setLayoutParams(separatedViewLayoutParams); - setGravity(p.gravity); + setGravity(rotateGravityLeft(getGravity())); } private int rotateGravityLeft(int gravity) { @@ -447,6 +446,46 @@ public class HardwareUiLayout extends LinearLayout implements Tunable { mAnimator.start(); } + // If current power menu height larger then screen height, remove padding to break power menu + // alignment and set menu center vertical within the screen. + private void updatePaddingAndGravityIfTooTall() { + int defaultTopPadding; + int viewsTotalHeight; + int separatedViewTopMargin; + int screenHeight; + int totalHeight; + int targetGravity; + MarginLayoutParams params = (MarginLayoutParams) mSeparatedView.getLayoutParams(); + switch (RotationUtils.getRotation(getContext())) { + case RotationUtils.ROTATION_LANDSCAPE: + defaultTopPadding = getPaddingLeft(); + viewsTotalHeight = mList.getMeasuredWidth() + mSeparatedView.getMeasuredWidth(); + separatedViewTopMargin = mHasSeparatedButton ? params.leftMargin : 0; + screenHeight = getMeasuredWidth(); + targetGravity = Gravity.CENTER_HORIZONTAL|Gravity.TOP; + break; + case RotationUtils.ROTATION_SEASCAPE: + defaultTopPadding = getPaddingRight(); + viewsTotalHeight = mList.getMeasuredWidth() + mSeparatedView.getMeasuredWidth(); + separatedViewTopMargin = mHasSeparatedButton ? params.leftMargin : 0; + screenHeight = getMeasuredWidth(); + targetGravity = Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM; + break; + default: // Portrait + defaultTopPadding = getPaddingTop(); + viewsTotalHeight = mList.getMeasuredHeight() + mSeparatedView.getMeasuredHeight(); + separatedViewTopMargin = mHasSeparatedButton ? params.topMargin : 0; + screenHeight = getMeasuredHeight(); + targetGravity = Gravity.CENTER_VERTICAL|Gravity.RIGHT; + break; + } + totalHeight = defaultTopPadding + viewsTotalHeight + separatedViewTopMargin; + if (totalHeight >= screenHeight) { + setPadding(0, 0, 0, 0); + setGravity(targetGravity); + } + } + @Override public ViewOutlineProvider getOutlineProvider() { return super.getOutlineProvider();