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

Commit ef8fa67a authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Prevent duplicated insets from causing relayout" into main

parents e26ca8e8 e05e0fad
Loading
Loading
Loading
Loading
+12 −29
Original line number Diff line number Diff line
@@ -30,19 +30,14 @@ import com.android.systemui.compose.ComposeInitializer
import com.android.systemui.res.R

/** A view that can serve as the root of the main SysUI window. */
open class WindowRootView(
    context: Context,
    attrs: AttributeSet?,
) :
    FrameLayout(
        context,
        attrs,
    ) {
open class WindowRootView(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) {

    private lateinit var layoutInsetsController: LayoutInsetsController
    private var leftInset = 0
    private var rightInset = 0

    private var previousInsets: WindowInsets? = null

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()

@@ -66,11 +61,14 @@ open class WindowRootView(
    override fun generateDefaultLayoutParams(): FrameLayout.LayoutParams? {
        return LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT
            FrameLayout.LayoutParams.MATCH_PARENT,
        )
    }

    override fun onApplyWindowInsets(windowInsets: WindowInsets): WindowInsets? {
        if (windowInsets == previousInsets) {
            return windowInsets
        }
        val insets = windowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
        if (fitsSystemWindows) {
            val paddingChanged = insets.top != paddingTop || insets.bottom != paddingBottom
@@ -95,7 +93,7 @@ open class WindowRootView(
        leftInset = pairInsets.first
        rightInset = pairInsets.second
        applyMargins()
        return windowInsets
        return windowInsets.also { previousInsets = WindowInsets(it) }
    }

    fun setLayoutInsetsController(layoutInsetsController: LayoutInsetsController) {
@@ -143,37 +141,22 @@ open class WindowRootView(
    interface LayoutInsetsController {

        /** Update the insets and calculate them accordingly. */
        fun getinsets(
            windowInsets: WindowInsets?,
            displayCutout: DisplayCutout?,
        ): Pair<Int, Int>
        fun getinsets(windowInsets: WindowInsets?, displayCutout: DisplayCutout?): Pair<Int, Int>
    }

    private class LayoutParams : FrameLayout.LayoutParams {
        var ignoreRightInset = false

        constructor(
            width: Int,
            height: Int,
        ) : super(
            width,
            height,
        )
        constructor(width: Int, height: Int) : super(width, height)

        @SuppressLint("CustomViewStyleable")
        constructor(
            context: Context,
            attrs: AttributeSet?,
        ) : super(
            context,
            attrs,
        ) {
        constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
            val obtainedAttributes =
                context.obtainStyledAttributes(attrs, R.styleable.StatusBarWindowView_Layout)
            ignoreRightInset =
                obtainedAttributes.getBoolean(
                    R.styleable.StatusBarWindowView_Layout_ignoreRightInset,
                    false
                    false,
                )
            obtainedAttributes.recycle()
        }
+10 −3
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import kotlinx.coroutines.flow.StateFlowKt;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Objects;

/**
 * The header group on Keyguard.
@@ -103,6 +104,9 @@ public class KeyguardStatusBarView extends RelativeLayout {
     */
    private int mCutoutSideNudge = 0;

    @Nullable
    private WindowInsets mPreviousInsets = null;

    private DisplayCutout mDisplayCutout;
    private int mRoundedCornerPadding = 0;
    // right and left padding applied to this view to account for cutouts and rounded corners
@@ -284,10 +288,13 @@ public class KeyguardStatusBarView extends RelativeLayout {
    WindowInsets updateWindowInsets(
            WindowInsets insets,
            StatusBarContentInsetsProvider insetsProvider) {
        if (!Objects.equals(mPreviousInsets, insets)) {
            mLayoutState = LAYOUT_NONE;
            if (updateLayoutConsideringCutout(insetsProvider)) {
                requestLayout();
            }
            mPreviousInsets = new WindowInsets(insets);
        }
        return super.onApplyWindowInsets(insets);
    }