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

Commit 0c473095 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Ignore insets on status_bar_container" into rvc-dev

parents 4af7ee3e 2e628f36
Loading
Loading
Loading
Loading
+16 −19
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import com.android.systemui.R;
import com.android.systemui.plugins.DarkIconDispatcher;
import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.util.leak.RotationUtils;

import java.util.Objects;

@@ -47,7 +48,6 @@ public class PhoneStatusBarView extends PanelBar {
    private static final String TAG = "PhoneStatusBarView";
    private static final boolean DEBUG = StatusBar.DEBUG;
    private static final boolean DEBUG_GESTURES = false;
    private static final int NO_VALUE = Integer.MIN_VALUE;
    private final CommandQueue mCommandQueue;

    StatusBar mBar;
@@ -64,13 +64,14 @@ public class PhoneStatusBarView extends PanelBar {
        }
    };
    private DarkReceiver mBattery;
    private int mLastOrientation;
    private int mRotationOrientation;
    @Nullable
    private View mCenterIconSpace;
    @Nullable
    private View mCutoutSpace;
    @Nullable
    private DisplayCutout mDisplayCutout;
    private int mStatusBarHeight;

    /**
     * Draw this many pixels into the left/right side of the cutout to optimally use the space
@@ -107,7 +108,7 @@ public class PhoneStatusBarView extends PanelBar {
        super.onAttachedToWindow();
        // Always have Battery meters in the status bar observe the dark/light modes.
        Dependency.get(DarkIconDispatcher.class).addDarkReceiver(mBattery);
        if (updateOrientationAndCutout(getResources().getConfiguration().orientation)) {
        if (updateOrientationAndCutout()) {
            updateLayoutForCutout();
        }
    }
@@ -124,7 +125,7 @@ public class PhoneStatusBarView extends PanelBar {
        super.onConfigurationChanged(newConfig);

        // May trigger cutout space layout-ing
        if (updateOrientationAndCutout(newConfig.orientation)) {
        if (updateOrientationAndCutout()) {
            updateLayoutForCutout();
            requestLayout();
        }
@@ -132,7 +133,7 @@ public class PhoneStatusBarView extends PanelBar {

    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        if (updateOrientationAndCutout(mLastOrientation)) {
        if (updateOrientationAndCutout()) {
            updateLayoutForCutout();
            requestLayout();
        }
@@ -140,17 +141,14 @@ public class PhoneStatusBarView extends PanelBar {
    }

    /**
     *
     * @param newOrientation may pass NO_VALUE for no change
     * @return boolean indicating if we need to update the cutout location / margins
     */
    private boolean updateOrientationAndCutout(int newOrientation) {
    private boolean updateOrientationAndCutout() {
        boolean changed = false;
        if (newOrientation != NO_VALUE) {
            if (mLastOrientation != newOrientation) {
        int newRotation = RotationUtils.getExactRotation(mContext);
        if (newRotation != mRotationOrientation) {
            changed = true;
                mLastOrientation = newOrientation;
            }
            mRotationOrientation = newRotation;
        }

        if (!Objects.equals(getRootWindowInsets().getDisplayCutout(), mDisplayCutout)) {
@@ -293,17 +291,16 @@ public class PhoneStatusBarView extends PanelBar {
        final int waterfallTopInset =
                mDisplayCutout == null ? 0 : mDisplayCutout.getWaterfallInsets().top;
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        layoutParams.height =
                getResources().getDimensionPixelSize(R.dimen.status_bar_height) - waterfallTopInset;
        mStatusBarHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_height);
        layoutParams.height = mStatusBarHeight - waterfallTopInset;
        setLayoutParams(layoutParams);
    }

    private void updateLayoutForCutout() {
        updateStatusBarHeight();
        Pair<Integer, Integer> cornerCutoutMargins =
                StatusBarWindowView.cornerCutoutMargins(mDisplayCutout, getDisplay());
        updateCutoutLocation(cornerCutoutMargins);
        updateSafeInsets(cornerCutoutMargins);
        updateCutoutLocation(StatusBarWindowView.cornerCutoutMargins(mDisplayCutout, getDisplay()));
        updateSafeInsets(StatusBarWindowView.statusBarCornerCutoutMargins(mDisplayCutout,
                getDisplay(), mRotationOrientation, mStatusBarHeight));
    }

    private void updateCutoutLocation(Pair<Integer, Integer> cornerCutoutMargins) {
+39 −33
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.view.View;
import android.view.WindowInsets;
import android.widget.FrameLayout;

import com.android.systemui.util.leak.RotationUtils;

/**
 * Status bar view.
 */
@@ -52,17 +54,13 @@ public class StatusBarWindowView extends FrameLayout {
    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets windowInsets) {
        final Insets insets = windowInsets.getInsetsIgnoringVisibility(systemBars());
        mLeftInset = 0;
        mRightInset = 0;
        mLeftInset = insets.left;
        mRightInset = insets.right;
        mTopInset = 0;
        DisplayCutout displayCutout = getRootWindowInsets().getDisplayCutout();
        if (displayCutout != null) {
            mTopInset = displayCutout.getWaterfallInsets().top;
            mLeftInset = displayCutout.getSafeInsetLeft();
            mRightInset = displayCutout.getSafeInsetRight();
        }
        mLeftInset = Math.max(insets.left, mLeftInset);
        mRightInset = Math.max(insets.right, mRightInset);
        applyMargins();
        return windowInsets;
    }
@@ -100,44 +98,33 @@ public class StatusBarWindowView extends FrameLayout {
            return new Pair<>(roundedCornerContentPadding, roundedCornerContentPadding);
        }

        // compute the padding needed for corner cutout.
        final int leftMargin = cutout.getSafeInsetLeft();
        final int rightMargin = cutout.getSafeInsetRight();
        // padding needed for corner cutout.
        int leftCornerCutoutPadding = 0;
        int rightCornerCutoutPadding = 0;
        if (cornerCutoutPadding != null) {
            if (cornerCutoutPadding.first > leftMargin) {
                leftCornerCutoutPadding = cornerCutoutPadding.first - leftMargin;
            }
            if (cornerCutoutPadding.second > rightMargin) {
                rightCornerCutoutPadding = cornerCutoutPadding.second - rightMargin;
            }
        }

        // compute the padding needed for rounded corner
        int leftRoundedCornerPadding = 0;
        int rightRoundedCornerPadding = 0;
        if (roundedCornerContentPadding > leftMargin) {
            leftRoundedCornerPadding = roundedCornerContentPadding - leftMargin;
        }
        if (roundedCornerContentPadding > rightMargin) {
            rightRoundedCornerPadding = roundedCornerContentPadding - rightMargin;
            leftCornerCutoutPadding = cornerCutoutPadding.first;
            rightCornerCutoutPadding = cornerCutoutPadding.second;
        }

        return new Pair<>(
                Math.max(leftCornerCutoutPadding, leftRoundedCornerPadding),
                Math.max(rightCornerCutoutPadding, rightRoundedCornerPadding));
                Math.max(leftCornerCutoutPadding, roundedCornerContentPadding),
                Math.max(rightCornerCutoutPadding, roundedCornerContentPadding));
    }


    /**
     * Compute the corner cutout margins
     *
     * @param cutout
     * @param display
     * @return
     * Compute the corner cutout margins in portrait mode
     */
    public static Pair<Integer, Integer> cornerCutoutMargins(DisplayCutout cutout,
            Display display) {
        return statusBarCornerCutoutMargins(cutout, display, RotationUtils.ROTATION_NONE, 0);
    }

    /**
     * Compute the corner cutout margins in the given orientation (exactRotation)
     */
    public static Pair<Integer, Integer> statusBarCornerCutoutMargins(DisplayCutout cutout,
            Display display, int exactRotation, int statusBarHeight) {
        if (cutout == null) {
            return null;
        }
@@ -145,14 +132,33 @@ public class StatusBarWindowView extends FrameLayout {
        display.getRealSize(size);

        Rect bounds = new Rect();
        switch (exactRotation) {
            case RotationUtils.ROTATION_LANDSCAPE:
                boundsFromDirection(cutout, Gravity.LEFT, bounds);
                break;
            case RotationUtils.ROTATION_SEASCAPE:
                boundsFromDirection(cutout, Gravity.RIGHT, bounds);
                break;
            case RotationUtils.ROTATION_NONE:
                boundsFromDirection(cutout, Gravity.TOP, bounds);
                break;
            case RotationUtils.ROTATION_UPSIDE_DOWN:
                // we assume the cutout is always on top in portrait mode
                return null;
        }

        if (statusBarHeight >= 0 && bounds.top > statusBarHeight) {
            return null;
        }

        if (bounds.left <= 0) {
            return new Pair<>(bounds.right, 0);
        }

        if (bounds.right >= size.x) {
            return new Pair<>(0, size.x - bounds.left);
        }

        return null;
    }
}