Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b0aa461 authored by Wesley.CW Wang's avatar Wesley.CW Wang Committed by Leo Hsu
Browse files

Fix Power menu background vanish

 - Separated button & origin button use same HardwareBgDrawable caused
power menu background vanish when keyboard showing.
 - Let separated button use mSeparatedViewBackground & origin button use
 mListBackground to fix this bug.
 - Rename View mChild to mList.

Test: Manually, long press power key to launch power menu when keyboard
showing, power menu background should display normally.

Bug: 112168722
Bug: 111101759

Change-Id: I7122ff52fd14021ac01b1ab9d64e7dde71fa7ab1
Merged-In: Ic08cabc63daebc4001c8eda751857d11cb0e6352
Merged-In: I7122ff52fd14021ac01b1ab9d64e7dde71fa7ab1
parent b44f2e52
Loading
Loading
Loading
Loading
+52 −45
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.ViewOutlineProvider;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.LinearLayout;

import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable;
import com.android.systemui.tuner.TunerService.Tunable;
import com.android.systemui.util.leak.RotationUtils;
import com.android.systemui.util.leak.RotationUtils;
@@ -41,14 +42,15 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {
    private static final String EDGE_BLEED = "sysui_hwui_edge_bleed";
    private static final String EDGE_BLEED = "sysui_hwui_edge_bleed";
    private static final String ROUNDED_DIVIDER = "sysui_hwui_rounded_divider";
    private static final String ROUNDED_DIVIDER = "sysui_hwui_rounded_divider";
    private final int[] mTmp2 = new int[2];
    private final int[] mTmp2 = new int[2];
    private View mChild;
    private View mList;
    private View mSeparatedView;
    private View mSeparatedView;
    private int mOldHeight;
    private int mOldHeight;
    private boolean mAnimating;
    private boolean mAnimating;
    private AnimatorSet mAnimation;
    private AnimatorSet mAnimation;
    private View mDivision;
    private View mDivision;
    private boolean mHasOutsideTouch;
    private boolean mHasOutsideTouch;
    private HardwareBgDrawable mBackground;
    private HardwareBgDrawable mListBackground;
    private HardwareBgDrawable mSeparatedViewBackground;
    private Animator mAnimator;
    private Animator mAnimator;
    private boolean mCollapse;
    private boolean mCollapse;
    private boolean mHasSeparatedButton;
    private boolean mHasSeparatedButton;
@@ -90,17 +92,19 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {
        mRoundedDivider = Settings.Secure.getInt(getContext().getContentResolver(),
        mRoundedDivider = Settings.Secure.getInt(getContext().getContentResolver(),
                ROUNDED_DIVIDER, 0) != 0;
                ROUNDED_DIVIDER, 0) != 0;
        updateEdgeMargin(mEdgeBleed ? 0 : getEdgePadding());
        updateEdgeMargin(mEdgeBleed ? 0 : getEdgePadding());
        mBackground = new HardwareBgDrawable(mRoundedDivider, !mEdgeBleed, getContext());
        mListBackground = new HardwareBgDrawable(mRoundedDivider, !mEdgeBleed, getContext());
        if (mChild != null) {
        mSeparatedViewBackground = new HardwareBgDrawable(mRoundedDivider, !mEdgeBleed,
            mChild.setBackground(mBackground);
                getContext());
            mSeparatedView.setBackground(mBackground);
        if (mList != null) {
            mList.setBackground(mListBackground);
            mSeparatedView.setBackground(mSeparatedViewBackground);
            requestLayout();
            requestLayout();
        }
        }
    }
    }


    private void updateEdgeMargin(int edge) {
    private void updateEdgeMargin(int edge) {
        if (mChild != null) {
        if (mList != null) {
            MarginLayoutParams params = (MarginLayoutParams) mChild.getLayoutParams();
            MarginLayoutParams params = (MarginLayoutParams) mList.getLayoutParams();
            if (mRotation == ROTATION_LANDSCAPE) {
            if (mRotation == ROTATION_LANDSCAPE) {
                params.topMargin = edge;
                params.topMargin = edge;
            } else if (mRotation == ROTATION_SEASCAPE) {
            } else if (mRotation == ROTATION_SEASCAPE) {
@@ -108,7 +112,7 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {
            } else {
            } else {
                params.rightMargin = edge;
                params.rightMargin = edge;
            }
            }
            mChild.setLayoutParams(params);
            mList.setLayoutParams(params);
        }
        }


        if (mSeparatedView != null) {
        if (mSeparatedView != null) {
@@ -131,15 +135,15 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {
    @Override
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (mChild == null) {
        if (mList == null) {
            if (getChildCount() != 0) {
            if (getChildCount() != 0) {
                mChild = getChildAt(0);
                mList = getChildAt(0);
                mChild.setBackground(mBackground);
                mList.setBackground(mListBackground);
                mSeparatedView = getChildAt(1);
                mSeparatedView = getChildAt(1);
                mSeparatedView.setBackground(mBackground);
                mSeparatedView.setBackground(mSeparatedViewBackground);
                updateEdgeMargin(mEdgeBleed ? 0 : getEdgePadding());
                updateEdgeMargin(mEdgeBleed ? 0 : getEdgePadding());
                mOldHeight = mChild.getMeasuredHeight();
                mOldHeight = mList.getMeasuredHeight();
                mChild.addOnLayoutChangeListener(
                mList.addOnLayoutChangeListener(
                        (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) ->
                        (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) ->
                                updatePosition());
                                updatePosition());
                updateRotation();
                updateRotation();
@@ -147,7 +151,7 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {
                return;
                return;
            }
            }
        }
        }
        int newHeight = mChild.getMeasuredHeight();
        int newHeight = mList.getMeasuredHeight();
        if (newHeight != mOldHeight) {
        if (newHeight != mOldHeight) {
            animateChild(mOldHeight, newHeight);
            animateChild(mOldHeight, newHeight);
        }
        }
@@ -196,27 +200,29 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {
            }
            }
        }
        }
        if (to != ROTATION_NONE) {
        if (to != ROTATION_NONE) {
            if (mChild instanceof LinearLayout) {
            if (mList instanceof LinearLayout) {
                mRotatedBackground = true;
                mRotatedBackground = true;
                mBackground.setRotatedBackground(true);
                mListBackground.setRotatedBackground(true);
                LinearLayout linearLayout = (LinearLayout) mChild;
                mSeparatedViewBackground.setRotatedBackground(true);
                LinearLayout linearLayout = (LinearLayout) mList;
                if (mSwapOrientation) {
                if (mSwapOrientation) {
                    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                    setOrientation(LinearLayout.HORIZONTAL);
                    setOrientation(LinearLayout.HORIZONTAL);
                }
                }
                swapDimens(mChild);
                swapDimens(mList);
                swapDimens(mSeparatedView);
                swapDimens(mSeparatedView);
            }
            }
        } else {
        } else {
            if (mChild instanceof LinearLayout) {
            if (mList instanceof LinearLayout) {
                mRotatedBackground = false;
                mRotatedBackground = false;
                mBackground.setRotatedBackground(false);
                mListBackground.setRotatedBackground(false);
                LinearLayout linearLayout = (LinearLayout) mChild;
                mSeparatedViewBackground.setRotatedBackground(false);
                LinearLayout linearLayout = (LinearLayout) mList;
                if (mSwapOrientation) {
                if (mSwapOrientation) {
                    linearLayout.setOrientation(LinearLayout.VERTICAL);
                    linearLayout.setOrientation(LinearLayout.VERTICAL);
                    setOrientation(LinearLayout.VERTICAL);
                    setOrientation(LinearLayout.VERTICAL);
                }
                }
                swapDimens(mChild);
                swapDimens(mList);
                swapDimens(mSeparatedView);
                swapDimens(mSeparatedView);
            }
            }
        }
        }
@@ -224,12 +230,12 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {


    private void rotateRight() {
    private void rotateRight() {
        rotateRight(this);
        rotateRight(this);
        rotateRight(mChild);
        rotateRight(mList);
        swapDimens(this);
        swapDimens(this);


        LayoutParams p = (LayoutParams) mChild.getLayoutParams();
        LayoutParams p = (LayoutParams) mList.getLayoutParams();
        p.gravity = rotateGravityRight(p.gravity);
        p.gravity = rotateGravityRight(p.gravity);
        mChild.setLayoutParams(p);
        mList.setLayoutParams(p);


        LayoutParams separatedViewLayoutParams = (LayoutParams) mSeparatedView.getLayoutParams();
        LayoutParams separatedViewLayoutParams = (LayoutParams) mSeparatedView.getLayoutParams();
        separatedViewLayoutParams.gravity = rotateGravityRight(separatedViewLayoutParams.gravity);
        separatedViewLayoutParams.gravity = rotateGravityRight(separatedViewLayoutParams.gravity);
@@ -282,12 +288,12 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {


    private void rotateLeft() {
    private void rotateLeft() {
        rotateLeft(this);
        rotateLeft(this);
        rotateLeft(mChild);
        rotateLeft(mList);
        swapDimens(this);
        swapDimens(this);


        LayoutParams p = (LayoutParams) mChild.getLayoutParams();
        LayoutParams p = (LayoutParams) mList.getLayoutParams();
        p.gravity = rotateGravityLeft(p.gravity);
        p.gravity = rotateGravityLeft(p.gravity);
        mChild.setLayoutParams(p);
        mList.setLayoutParams(p);


        LayoutParams separatedViewLayoutParams = (LayoutParams) mSeparatedView.getLayoutParams();
        LayoutParams separatedViewLayoutParams = (LayoutParams) mSeparatedView.getLayoutParams();
        separatedViewLayoutParams.gravity = rotateGravityLeft(separatedViewLayoutParams.gravity);
        separatedViewLayoutParams.gravity = rotateGravityLeft(separatedViewLayoutParams.gravity);
@@ -379,14 +385,14 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {
                mAnimating = false;
                mAnimating = false;
            }
            }
        });
        });
        int fromTop = mChild.getTop();
        int fromTop = mList.getTop();
        int fromBottom = mChild.getBottom();
        int fromBottom = mList.getBottom();
        int toTop = fromTop - ((newHeight - oldHeight) / 2);
        int toTop = fromTop - ((newHeight - oldHeight) / 2);
        int toBottom = fromBottom + ((newHeight - oldHeight) / 2);
        int toBottom = fromBottom + ((newHeight - oldHeight) / 2);
        ObjectAnimator top = ObjectAnimator.ofInt(mChild, "top", fromTop, toTop);
        ObjectAnimator top = ObjectAnimator.ofInt(mList, "top", fromTop, toTop);
        top.addUpdateListener(animation -> mBackground.invalidateSelf());
        top.addUpdateListener(animation -> mListBackground.invalidateSelf());
        mAnimation.playTogether(top,
        mAnimation.playTogether(top,
                ObjectAnimator.ofInt(mChild, "bottom", fromBottom, toBottom));
                ObjectAnimator.ofInt(mList, "bottom", fromBottom, toBottom));
    }
    }


    public void setDivisionView(View v) {
    public void setDivisionView(View v) {
@@ -400,29 +406,30 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {
    }
    }


    private void updatePosition() {
    private void updatePosition() {
        if (mChild == null) return;
        if (mList == null) return;
        // If got separated button, setRotatedBackground to false,
        // If got separated button, setRotatedBackground to false,
        // all items won't get white background.
        // all items won't get white background.
        mBackground.setRotatedBackground(mHasSeparatedButton);
        mListBackground.setRotatedBackground(mHasSeparatedButton);
        mSeparatedViewBackground.setRotatedBackground(mHasSeparatedButton);
        if (mDivision != null && mDivision.getVisibility() == VISIBLE) {
        if (mDivision != null && mDivision.getVisibility() == VISIBLE) {
            int index = mRotatedBackground ? 0 : 1;
            int index = mRotatedBackground ? 0 : 1;
            mDivision.getLocationOnScreen(mTmp2);
            mDivision.getLocationOnScreen(mTmp2);
            float trans = mRotatedBackground ? mDivision.getTranslationX()
            float trans = mRotatedBackground ? mDivision.getTranslationX()
                    : mDivision.getTranslationY();
                    : mDivision.getTranslationY();
            int viewTop = (int) (mTmp2[index] + trans);
            int viewTop = (int) (mTmp2[index] + trans);
            mChild.getLocationOnScreen(mTmp2);
            mList.getLocationOnScreen(mTmp2);
            viewTop -= mTmp2[index];
            viewTop -= mTmp2[index];
            setCutPoint(viewTop);
            setCutPoint(viewTop);
        } else {
        } else {
            setCutPoint(mChild.getMeasuredHeight());
            setCutPoint(mList.getMeasuredHeight());
        }
        }
    }
    }


    private void setCutPoint(int point) {
    private void setCutPoint(int point) {
        int curPoint = mBackground.getCutPoint();
        int curPoint = mListBackground.getCutPoint();
        if (curPoint == point) return;
        if (curPoint == point) return;
        if (getAlpha() == 0 || curPoint == 0) {
        if (getAlpha() == 0 || curPoint == 0) {
            mBackground.setCutPoint(point);
            mListBackground.setCutPoint(point);
            return;
            return;
        }
        }
        if (mAnimator != null) {
        if (mAnimator != null) {
@@ -432,7 +439,7 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {
            mAnimator.cancel();
            mAnimator.cancel();
        }
        }
        mEndPoint = point;
        mEndPoint = point;
        mAnimator = ObjectAnimator.ofInt(mBackground, "cutPoint", curPoint, point);
        mAnimator = ObjectAnimator.ofInt(mListBackground, "cutPoint", curPoint, point);
        if (mCollapse) {
        if (mCollapse) {
            mAnimator.setStartDelay(300);
            mAnimator.setStartDelay(300);
            mCollapse = false;
            mCollapse = false;
@@ -470,14 +477,14 @@ public class HardwareUiLayout extends LinearLayout implements Tunable {
    }
    }


    private final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsListener = inoutInfo -> {
    private final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsListener = inoutInfo -> {
        if (mHasOutsideTouch || (mChild == null)) {
        if (mHasOutsideTouch || (mList == null)) {
            inoutInfo.setTouchableInsets(
            inoutInfo.setTouchableInsets(
                    ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME);
                    ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME);
            return;
            return;
        }
        }
        inoutInfo.setTouchableInsets(
        inoutInfo.setTouchableInsets(
                ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT);
                ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT);
        inoutInfo.contentInsets.set(mChild.getLeft(), mChild.getTop(),
        inoutInfo.contentInsets.set(mList.getLeft(), mList.getTop(),
                0, getBottom() - mChild.getBottom());
                0, getBottom() - mList.getBottom());
    };
    };
}
}