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 Original line Diff line number Diff line
@@ -30,19 +30,14 @@ import com.android.systemui.compose.ComposeInitializer
import com.android.systemui.res.R
import com.android.systemui.res.R


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


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


    private var previousInsets: WindowInsets? = null

    override fun onAttachedToWindow() {
    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        super.onAttachedToWindow()


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


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


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


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


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


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


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


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


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


    @Nullable
    private WindowInsets mPreviousInsets = null;

    private DisplayCutout mDisplayCutout;
    private DisplayCutout mDisplayCutout;
    private int mRoundedCornerPadding = 0;
    private int mRoundedCornerPadding = 0;
    // right and left padding applied to this view to account for cutouts and rounded corners
    // 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 updateWindowInsets(
            WindowInsets insets,
            WindowInsets insets,
            StatusBarContentInsetsProvider insetsProvider) {
            StatusBarContentInsetsProvider insetsProvider) {
        if (!Objects.equals(mPreviousInsets, insets)) {
            mLayoutState = LAYOUT_NONE;
            mLayoutState = LAYOUT_NONE;
            if (updateLayoutConsideringCutout(insetsProvider)) {
            if (updateLayoutConsideringCutout(insetsProvider)) {
                requestLayout();
                requestLayout();
            }
            }
            mPreviousInsets = new WindowInsets(insets);
        }
        return super.onApplyWindowInsets(insets);
        return super.onApplyWindowInsets(insets);
    }
    }