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

Commit 3d00f35c authored by felkachang's avatar felkachang Committed by Felka Chang
Browse files

Fix fullscreen notification to support RTL

In the FullScreen notification condition, HeadsUpStatusBarView
doesn't support RTL funcationality and show nothing on status bar.

There are three part need to support RTL:
* HeadsUpAppearanceController count translationX
* HeadsUpStatusBarView count the new padding start
* Consider more about the SystemWindow(Navigation Bar + cut out)

In normal case(LTR), to count the new padding start needs to know
both of the NavigationBar's width and cut out in the left hand
side. But, in RTL, to count the new Padding start needs to know both
of the NavigationBar's width and cut out in the right hand side.
To change from mLeftInset to mSysWinInset and from mLeftCutOutInset
to mCutOutInset.

Add HeadsUpAppearanceController.getRtlTranslation to count the RTL
tranlationX by the following formula:
  Y = screenSize - (SystemWindow's width + Scroller.getRight())
And, let HeadsUpStatusBarView.setPanelTranslation to handle the
right cut out width and then complete the real
HeadsUpStatusBarView.setTranslationX.

Bug: 79957423
Test: atest SystemUITests
Change-Id: I26b3cf8a73a2bcd2916847d72e66c16ca9063efd
Fix: 79957423
parent d018bc43
Loading
Loading
Loading
Loading
+35 −13
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@ package com.android.systemui.statusbar;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.DisplayCutout;
import android.view.View;
import android.widget.TextView;

@@ -44,9 +46,10 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
    private boolean mPublicMode;
    private int mMaxWidth;
    private View mRootView;
    private int mLeftCutOutInset;
    private int mLeftInset;
    private int mSysWinInset;
    private int mCutOutInset;
    private Rect mIconDrawingRect = new Rect();
    private Point mPoint;
    private Runnable mOnDrawingRectChangedListener;

    public HeadsUpStatusBarView(Context context) {
@@ -137,9 +140,20 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
        int bottom = top + mIconPlaceholder.getHeight();
        mLayoutedIconRect.set(left, top, right, bottom);
        updateDrawingRect();
        int targetPadding = mAbsoluteStartPadding + mLeftInset + mLeftCutOutInset;
        int targetPadding = mAbsoluteStartPadding + mSysWinInset + mCutOutInset;
        if (left != targetPadding) {
            int newPadding = targetPadding - left + getPaddingStart();
            int start;
            if (isLayoutRtl()) {
                if (mPoint == null) {
                    mPoint = new Point();
                }
                getDisplay().getRealSize(mPoint);
                start = (mPoint.x - right);
            } else {
                start = left;
            }

            int newPadding = targetPadding - start + getPaddingStart();
            setPaddingRelative(newPadding, 0, mEndMargin, 0);
        }
        if (mFirstLayout) {
@@ -152,7 +166,11 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
    }

    public void setPanelTranslation(float translationX) {
        setTranslationX(translationX - mLeftCutOutInset);
        if (isLayoutRtl()) {
            setTranslationX(translationX + mCutOutInset);
        } else {
            setTranslationX(translationX - mCutOutInset);
        }
        updateDrawingRect();
    }

@@ -167,15 +185,19 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {

    @Override
    protected boolean fitSystemWindows(Rect insets) {
        mLeftInset = insets.left;
        mLeftCutOutInset = (getRootWindowInsets().getDisplayCutout() != null)
                ? getRootWindowInsets().getDisplayCutout().getSafeInsetLeft() : 0;

        boolean isRtl = isLayoutRtl();
        mSysWinInset = isRtl ? insets.right : insets.left;
        DisplayCutout displayCutout = getRootWindowInsets().getDisplayCutout();
        mCutOutInset = (displayCutout != null)
                ? (isRtl ? displayCutout.getSafeInsetRight() : displayCutout.getSafeInsetLeft())
                : 0;
        // For Double Cut Out mode, the System window navigation bar is at the right
        // hand side of the left cut out. In this condition, mLeftInset include the left cut
        // out width so we set mLeftCutOutInset to be 0.
        if (mLeftInset != 0) {
            mLeftCutOutInset = 0;
        // side of the left cut out. In this condition, mSysWinInset include the left cut
        // out width so we set mCutOutInset to be 0. For RTL, the condition is the same.
        // The navigation bar is at the left side of the right cut out and include the
        // right cut out width.
        if (mSysWinInset != 0) {
            mCutOutInset = 0;
        }

        return super.fitSystemWindows(insets);
+50 −1
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@

package com.android.systemui.statusbar.phone;

import android.graphics.Point;
import android.graphics.Rect;
import android.view.View;
import android.view.WindowInsets;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dependency;
@@ -59,6 +61,7 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
    private final View.OnLayoutChangeListener mStackScrollLayoutChangeListener =
            (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom)
                    -> updatePanelTranslation();
    Point mPoint;

    public HeadsUpAppearanceController(
            NotificationIconAreaController notificationIconAreaController,
@@ -121,8 +124,54 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
        updateHeader(headsUp.getEntry());
    }

    /** To count the distance from the window right boundary to scroller right boundary. The
     * distance formula is the following:
     *     Y = screenSize - (SystemWindow's width + Scroller.getRight())
     * There are four modes MUST to be considered in Cut Out of RTL.
     * No Cut Out:
     *   Scroller + NB
     *   NB + Scroller
     *     => SystemWindow = NavigationBar's width
     *     => Y = screenSize - (SystemWindow's width + Scroller.getRight())
     * Corner Cut Out or Tall Cut Out:
     *   cut out + Scroller + NB
     *   NB + Scroller + cut out
     *     => SystemWindow = NavigationBar's width
     *     => Y = screenSize - (SystemWindow's width + Scroller.getRight())
     * Double Cut Out:
     *   cut out left + Scroller + (NB + cut out right)
     *     SystemWindow = NavigationBar's width + cut out right width
     *     => Y = screenSize - (SystemWindow's width + Scroller.getRight())
     *   (cut out left + NB) + Scroller + cut out right
     *     SystemWindow = NavigationBar's width + cut out left width
     *     => Y = screenSize - (SystemWindow's width + Scroller.getRight())
     * @return the translation X value for RTL. In theory, it should be negative. i.e. -Y
     */
    private int getRtlTranslation() {
        // TODO: Corner Cut Out still need to handle.
        if (mPoint == null) {
            mPoint = new Point();
        }

        int realDisplaySize = 0;
        if (mStackScroller.getDisplay() != null) {
            mStackScroller.getDisplay().getRealSize(mPoint);
            realDisplaySize = mPoint.x;
        }

        WindowInsets windowInset = mStackScroller.getRootWindowInsets();
        return windowInset.getSystemWindowInsetLeft() + mStackScroller.getRight()
                + windowInset.getSystemWindowInsetRight() - realDisplaySize;
    }

    public void updatePanelTranslation() {
        float newTranslation = mStackScroller.getLeft() + mStackScroller.getTranslationX();
        float newTranslation;
        if (mStackScroller.isLayoutRtl()) {
            newTranslation = getRtlTranslation();
        } else {
            newTranslation = mStackScroller.getLeft();
        }
        newTranslation += mStackScroller.getTranslationX();
        mHeadsUpStatusBarView.setPanelTranslation(newTranslation);
    }