From f400d32813b21c384668b8955be7d06880602d9d Mon Sep 17 00:00:00 2001 From: Hawkwood Glazier Date: Wed, 7 Dec 2022 20:19:11 +0000 Subject: [PATCH] Fix Positioning of large custom clocks within frame This reverts Iaeddce2d99a2b8db5afb6ac8ca508eeab3ae223e without reintroducing b/259758161. It does this by compensating for the change in margin in KeyguardClockSwitchController.getClockBottom(). This maintains existing functionality for the aod behaviour in KeyguardClockPositionAlgorithm. As part of validation I confirmed that the arguments to KeyguardClockPositionAlgorithm.setup did not change with this patch. Bug: 259758161 Fixes: 261754025 Test: Manually checked KeyguardClockPositionAlgorithm Change-Id: I119abb49a018f6fb505100ea985d3b4121ac59f7 --- .../shared/clocks/DefaultClockController.kt | 11 ++- .../layout/keyguard_clock_switch.xml | 1 - .../KeyguardClockSwitchController.java | 19 ++++- .../KeyguardClockSwitchControllerTest.java | 78 +++++++++++++++---- 4 files changed, 89 insertions(+), 20 deletions(-) diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt index e1f21742bf93d..869884474ffe3 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt @@ -20,6 +20,7 @@ import android.graphics.Rect import android.icu.text.NumberFormat import android.util.TypedValue import android.view.LayoutInflater +import android.view.View import android.widget.FrameLayout import androidx.annotation.VisibleForTesting import com.android.systemui.customization.R @@ -151,9 +152,15 @@ class DefaultClockController( view: AnimatableClockView, ) : DefaultClockFaceController(view) { override fun recomputePadding(targetRegion: Rect?) { - // Ignore Target Region until top padding fixed in aod + // We center the view within the targetRegion instead of within the parent + // view by computing the difference and adding that to the padding. + val parent = view.parent + val yDiff = + if (targetRegion != null && parent is View && parent.isLaidOut()) + targetRegion.centerY() - parent.height / 2f + else 0f val lp = view.getLayoutParams() as FrameLayout.LayoutParams - lp.topMargin = (-0.5f * view.bottom).toInt() + lp.topMargin = (-0.5f * view.bottom + yDiff).toInt() view.setLayoutParams(lp) } diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml b/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml index 218c5cc9b7fec..b49afeef09f3b 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml @@ -35,7 +35,6 @@ android:visibility="invisible" />