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
This commit is contained in:
Wesley.CW Wang
2018-09-27 20:41:31 +08:00
parent 757cc2cded
commit 1096c62fd8

View File

@@ -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();