diff options
| author | 2025-02-07 07:30:14 -0800 | |
|---|---|---|
| committer | 2025-02-07 07:30:14 -0800 | |
| commit | ef8fa67a87cf92b7fa03e78f021f375c3087d23c (patch) | |
| tree | 7701aa0fd32eb9e507588635dfa5bef2e232d867 | |
| parent | e26ca8e87e09eba87cde255eaff78b09e836647a (diff) | |
| parent | e05e0fadbf023c5a150d71ec35fe3b6408ac7df1 (diff) | |
Merge "Prevent duplicated insets from causing relayout" into main
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/scene/ui/view/WindowRootView.kt | 41 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java | 13 |
2 files changed, 22 insertions, 32 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/scene/ui/view/WindowRootView.kt b/packages/SystemUI/src/com/android/systemui/scene/ui/view/WindowRootView.kt index f0f476e65e2f..364da5f8e80d 100644 --- a/packages/SystemUI/src/com/android/systemui/scene/ui/view/WindowRootView.kt +++ b/packages/SystemUI/src/com/android/systemui/scene/ui/view/WindowRootView.kt @@ -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() } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java index a339bc98457e..58326dbb3a34 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java @@ -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,9 +288,12 @@ public class KeyguardStatusBarView extends RelativeLayout { WindowInsets updateWindowInsets( WindowInsets insets, StatusBarContentInsetsProvider insetsProvider) { - mLayoutState = LAYOUT_NONE; - if (updateLayoutConsideringCutout(insetsProvider)) { - requestLayout(); + if (!Objects.equals(mPreviousInsets, insets)) { + mLayoutState = LAYOUT_NONE; + if (updateLayoutConsideringCutout(insetsProvider)) { + requestLayout(); + } + mPreviousInsets = new WindowInsets(insets); } return super.onApplyWindowInsets(insets); } |