summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/customization/res/values/dimens.xml1
-rw-r--r--packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockPreviewConfig.kt25
-rw-r--r--packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockProviderPlugin.kt33
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt26
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewSmartspaceViewBinder.kt15
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt62
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModel.kt24
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewSmartspaceViewModel.kt37
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModelKosmos.kt4
10 files changed, 143 insertions, 88 deletions
diff --git a/packages/SystemUI/customization/res/values/dimens.xml b/packages/SystemUI/customization/res/values/dimens.xml
index 21b4c7165226..2bb5541f4b0a 100644
--- a/packages/SystemUI/customization/res/values/dimens.xml
+++ b/packages/SystemUI/customization/res/values/dimens.xml
@@ -33,6 +33,7 @@
<dimen name="small_clock_height">114dp</dimen>
<dimen name="small_clock_padding_top">28dp</dimen>
<dimen name="clock_padding_start">28dp</dimen>
+ <dimen name="weather_date_icon_padding">28dp</dimen>
<!-- When large clock is showing, offset the smartspace by this amount -->
<dimen name="keyguard_smartspace_top_offset">12dp</dimen>
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockPreviewConfig.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockPreviewConfig.kt
new file mode 100644
index 000000000000..544b705c55c5
--- /dev/null
+++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockPreviewConfig.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.plugins.clocks
+
+import android.content.Context
+
+data class ClockPreviewConfig(
+ val previewContext: Context,
+ val isShadeLayoutWide: Boolean,
+ val isSceneContainerFlagEnabled: Boolean = false,
+)
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockProviderPlugin.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockProviderPlugin.kt
index fb9e96c820cf..8ea5725b3509 100644
--- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockProviderPlugin.kt
+++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockProviderPlugin.kt
@@ -160,7 +160,10 @@ interface ClockFaceLayout {
@ProtectedReturn("return constraints;")
/** Custom constraints to apply to preview ConstraintLayout. */
- fun applyPreviewConstraints(context: Context, constraints: ConstraintSet): ConstraintSet
+ fun applyPreviewConstraints(
+ clockPreviewConfig: ClockPreviewConfig,
+ constraints: ConstraintSet,
+ ): ConstraintSet
fun applyAodBurnIn(aodBurnInModel: AodClockBurnInModel)
}
@@ -181,10 +184,10 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout {
}
override fun applyPreviewConstraints(
- context: Context,
+ clockPreviewConfig: ClockPreviewConfig,
constraints: ConstraintSet,
): ConstraintSet {
- return applyDefaultPreviewConstraints(context, constraints)
+ return applyDefaultPreviewConstraints(clockPreviewConfig, constraints)
}
override fun applyAodBurnIn(aodBurnInModel: AodClockBurnInModel) {
@@ -193,10 +196,11 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout {
companion object {
fun applyDefaultPreviewConstraints(
- context: Context,
+ clockPreviewConfig: ClockPreviewConfig,
constraints: ConstraintSet,
): ConstraintSet {
constraints.apply {
+ val context = clockPreviewConfig.previewContext
val lockscreenClockViewLargeId = getId(context, "lockscreen_clock_view_large")
constrainWidth(lockscreenClockViewLargeId, WRAP_CONTENT)
constrainHeight(lockscreenClockViewLargeId, WRAP_CONTENT)
@@ -237,8 +241,10 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout {
getDimen(context, "status_view_margin_horizontal"),
)
val smallClockTopMargin =
- getDimen(context, "keyguard_clock_top_margin") +
- SystemBarUtils.getStatusBarHeight(context)
+ getSmallClockTopPadding(
+ clockPreviewConfig = clockPreviewConfig,
+ SystemBarUtils.getStatusBarHeight(context),
+ )
connect(smallClockViewId, TOP, PARENT_ID, TOP, smallClockTopMargin)
}
return constraints
@@ -253,10 +259,23 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout {
fun getDimen(context: Context, name: String): Int {
val packageName = context.packageName
- val res = context.packageManager.getResourcesForApplication(packageName)
+ val res = context.resources
val id = res.getIdentifier(name, "dimen", packageName)
return if (id == 0) 0 else res.getDimensionPixelSize(id)
}
+
+ fun getSmallClockTopPadding(
+ clockPreviewConfig: ClockPreviewConfig,
+ statusBarHeight: Int,
+ ): Int {
+ return if (clockPreviewConfig.isShadeLayoutWide) {
+ getDimen(clockPreviewConfig.previewContext, "keyguard_split_shade_top_margin") -
+ if (clockPreviewConfig.isSceneContainerFlagEnabled) statusBarHeight else 0
+ } else {
+ getDimen(clockPreviewConfig.previewContext, "keyguard_clock_top_margin") +
+ if (!clockPreviewConfig.isSceneContainerFlagEnabled) statusBarHeight else 0
+ }
+ }
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt
index 6c03b2489380..ac302dd26365 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt
@@ -17,7 +17,7 @@
package com.android.systemui.keyguard.ui.binder
-import android.content.Context
+import android.content.res.Resources
import android.view.View
import android.view.View.INVISIBLE
import android.view.View.VISIBLE
@@ -34,8 +34,8 @@ import com.android.systemui.keyguard.ui.view.layout.sections.setVisibility
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewClockViewModel
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.plugins.clocks.ClockController
+import com.android.systemui.plugins.clocks.ClockPreviewConfig
import com.android.systemui.shared.clocks.ClockRegistry
-import kotlin.reflect.KSuspendFunction1
/** Binder for the small clock view, large clock view. */
object KeyguardPreviewClockViewBinder {
@@ -66,11 +66,11 @@ object KeyguardPreviewClockViewBinder {
@JvmStatic
fun bind(
- context: Context,
rootView: ConstraintLayout,
viewModel: KeyguardPreviewClockViewModel,
clockRegistry: ClockRegistry,
- updateClockAppearance: KSuspendFunction1<ClockController, Unit>,
+ updateClockAppearance: suspend (ClockController, Resources) -> Unit,
+ clockPreviewConfig: ClockPreviewConfig,
) {
rootView.repeatWhenAttached {
repeatOnLifecycle(Lifecycle.State.STARTED) {
@@ -82,7 +82,10 @@ object KeyguardPreviewClockViewBinder {
.forEach { rootView.removeView(it) }
}
lastClock = currentClock
- updateClockAppearance(currentClock)
+ updateClockAppearance(
+ currentClock,
+ clockPreviewConfig.previewContext.resources,
+ )
if (viewModel.shouldHighlightSelectedAffordance) {
(currentClock.largeClock.layout.views +
@@ -98,7 +101,12 @@ object KeyguardPreviewClockViewBinder {
(it.parent as? ViewGroup)?.removeView(it)
rootView.addView(it)
}
- applyPreviewConstraints(context, rootView, currentClock, viewModel)
+ applyPreviewConstraints(
+ clockPreviewConfig,
+ rootView,
+ currentClock,
+ viewModel,
+ )
}
}
.invokeOnCompletion {
@@ -121,14 +129,14 @@ object KeyguardPreviewClockViewBinder {
}
private fun applyPreviewConstraints(
- context: Context,
+ clockPreviewConfig: ClockPreviewConfig,
rootView: ConstraintLayout,
previewClock: ClockController,
viewModel: KeyguardPreviewClockViewModel,
) {
val cs = ConstraintSet().apply { clone(rootView) }
- previewClock.largeClock.layout.applyPreviewConstraints(context, cs)
- previewClock.smallClock.layout.applyPreviewConstraints(context, cs)
+ previewClock.largeClock.layout.applyPreviewConstraints(clockPreviewConfig, cs)
+ previewClock.smallClock.layout.applyPreviewConstraints(clockPreviewConfig, cs)
// When selectedClockSize is the initial value, make both clocks invisible to avoid
// flickering
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewSmartspaceViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewSmartspaceViewBinder.kt
index baa681282a0b..e89be5d6ae4c 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewSmartspaceViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewSmartspaceViewBinder.kt
@@ -17,7 +17,6 @@
package com.android.systemui.keyguard.ui.binder
-import android.content.Context
import android.view.View
import androidx.core.view.isInvisible
import androidx.lifecycle.Lifecycle
@@ -26,16 +25,16 @@ import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.systemui.keyguard.shared.model.ClockSizeSetting
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewModel
import com.android.systemui.lifecycle.repeatWhenAttached
+import com.android.systemui.plugins.clocks.ClockPreviewConfig
/** Binder for the small clock view, large clock view and smartspace. */
object KeyguardPreviewSmartspaceViewBinder {
@JvmStatic
fun bind(
- previewContext: Context,
smartspace: View,
- splitShadePreview: Boolean,
viewModel: KeyguardPreviewSmartspaceViewModel,
+ clockPreviewConfig: ClockPreviewConfig,
) {
smartspace.repeatWhenAttached {
repeatOnLifecycle(Lifecycle.State.STARTED) {
@@ -44,15 +43,9 @@ object KeyguardPreviewSmartspaceViewBinder {
val topPadding =
when (it) {
ClockSizeSetting.DYNAMIC ->
- viewModel.getLargeClockSmartspaceTopPadding(
- splitShadePreview,
- previewContext,
- )
+ viewModel.getLargeClockSmartspaceTopPadding(clockPreviewConfig)
ClockSizeSetting.SMALL ->
- viewModel.getSmallClockSmartspaceTopPadding(
- splitShadePreview,
- previewContext,
- )
+ viewModel.getSmallClockSmartspaceTopPadding(clockPreviewConfig)
}
smartspace.setTopPadding(topPadding)
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt
index ab9cffc05667..9924a3bcdd6a 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt
@@ -22,6 +22,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
+import android.content.res.Resources
import android.graphics.Rect
import android.hardware.display.DisplayManager
import android.os.Bundle
@@ -47,6 +48,7 @@ import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID
import androidx.constraintlayout.widget.ConstraintSet.START
import androidx.constraintlayout.widget.ConstraintSet.TOP
import androidx.core.view.isInvisible
+import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.internal.policy.SystemBarUtils
import com.android.keyguard.ClockEventController
import com.android.keyguard.KeyguardClockSwitch
@@ -57,6 +59,7 @@ import com.android.systemui.common.ui.ConfigurationState
import com.android.systemui.communal.ui.binder.CommunalTutorialIndicatorViewBinder
import com.android.systemui.communal.ui.viewmodel.CommunalTutorialIndicatorViewModel
import com.android.systemui.coroutines.newTracingContext
+import com.android.systemui.customization.R as customR
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
@@ -80,9 +83,11 @@ import com.android.systemui.keyguard.ui.viewmodel.OccludingAppDeviceEntryMessage
import com.android.systemui.monet.ColorScheme
import com.android.systemui.monet.Style
import com.android.systemui.plugins.clocks.ClockController
+import com.android.systemui.plugins.clocks.ClockPreviewConfig
import com.android.systemui.plugins.clocks.ThemeConfig
import com.android.systemui.plugins.clocks.WeatherData
import com.android.systemui.res.R
+import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shared.clocks.ClockRegistry
import com.android.systemui.shared.clocks.DefaultClockController
@@ -105,7 +110,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.flowOf
-import com.android.app.tracing.coroutines.launchTraced as launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.json.JSONException
@@ -352,8 +356,11 @@ constructor(
val topPadding: Int =
smartspaceViewModel.getLargeClockSmartspaceTopPadding(
- previewInSplitShade(),
- previewContext,
+ ClockPreviewConfig(
+ previewContext,
+ getPreviewShadeLayoutWide(display!!),
+ SceneContainerFlag.isEnabled,
+ )
)
val startPadding: Int = smartspaceViewModel.getSmartspaceStartPadding(previewContext)
val endPadding: Int = smartspaceViewModel.getSmartspaceEndPadding(previewContext)
@@ -436,11 +443,15 @@ constructor(
setUpClock(previewContext, rootView)
if (MigrateClocksToBlueprint.isEnabled) {
KeyguardPreviewClockViewBinder.bind(
- previewContext,
keyguardRootView,
clockViewModel,
clockRegistry,
::updateClockAppearance,
+ ClockPreviewConfig(
+ previewContext,
+ getPreviewShadeLayoutWide(display!!),
+ SceneContainerFlag.isEnabled,
+ ),
)
} else {
KeyguardPreviewClockViewBinder.bind(
@@ -455,10 +466,14 @@ constructor(
smartSpaceView?.let {
KeyguardPreviewSmartspaceViewBinder.bind(
- previewContext,
it,
- previewInSplitShade(),
smartspaceViewModel,
+ clockPreviewConfig =
+ ClockPreviewConfig(
+ previewContext,
+ getPreviewShadeLayoutWide(display!!),
+ SceneContainerFlag.isEnabled,
+ ),
)
}
setupCommunalTutorialIndicator(keyguardRootView)
@@ -552,20 +567,14 @@ constructor(
val layoutParams =
FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
- resources.getDimensionPixelSize(
- com.android.systemui.customization.R.dimen.small_clock_height
- ),
+ resources.getDimensionPixelSize(customR.dimen.small_clock_height),
)
layoutParams.topMargin =
SystemBarUtils.getStatusBarHeight(previewContext) +
- resources.getDimensionPixelSize(
- com.android.systemui.customization.R.dimen.small_clock_padding_top
- )
+ resources.getDimensionPixelSize(customR.dimen.small_clock_padding_top)
smallClockHostView.layoutParams = layoutParams
smallClockHostView.setPaddingRelative(
- /* start = */ resources.getDimensionPixelSize(
- com.android.systemui.customization.R.dimen.clock_padding_start
- ),
+ /* start = */ resources.getDimensionPixelSize(customR.dimen.clock_padding_start),
/* top = */ 0,
/* end = */ 0,
/* bottom = */ 0,
@@ -637,7 +646,7 @@ constructor(
onClockChanged()
}
- private suspend fun updateClockAppearance(clock: ClockController) {
+ private suspend fun updateClockAppearance(clock: ClockController, resources: Resources) {
if (!MigrateClocksToBlueprint.isEnabled) {
clockController.clock = clock
}
@@ -667,6 +676,11 @@ constructor(
if (MigrateClocksToBlueprint.isEnabled) {
clockController.clock = clock
}
+ // When set clock to clockController,it will reset fontsize based on context.resources
+ // We need to override it with overlaid resources
+ clock.largeClock.events.onFontSettingChanged(
+ resources.getDimensionPixelSize(customR.dimen.large_clock_text_size).toFloat()
+ )
}
private fun onClockChanged() {
@@ -676,7 +690,7 @@ constructor(
coroutineScope.launch {
val clock = clockRegistry.createCurrentClock()
clockController.clock = clock
- updateClockAppearance(clock)
+ updateClockAppearance(clock, context.resources)
updateLargeClock(clock)
updateSmallClock(clock)
}
@@ -742,12 +756,14 @@ constructor(
smallClockHostView.addView(clock.smallClock.view)
}
- /*
- * When multi_crop_preview_ui_flag is on, we can preview portrait in split shadow direction
- * or vice versa. So we need to decide preview direction by width and height
- */
- private fun previewInSplitShade(): Boolean {
- return width > height
+ private fun getPreviewShadeLayoutWide(display: Display): Boolean {
+ return if (display.displayId == 0) {
+ shadeInteractor.isShadeLayoutWide.value
+ } else {
+ // For the unfolded preview in a folded screen; it's landscape by default
+ // For the folded preview in an unfolded screen; it's portrait by default
+ display.name == "Inner Display"
+ }
}
companion object {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt
index 6c98d5b01e4e..70bf8bca55b9 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt
@@ -235,9 +235,7 @@ constructor(
val smallClockBottom =
keyguardClockViewModel.getSmallClockTopMargin() +
- context.resources.getDimensionPixelSize(
- com.android.systemui.customization.R.dimen.small_clock_height
- )
+ context.resources.getDimensionPixelSize(customR.dimen.small_clock_height)
val dateWeatherSmartspaceHeight = getDimen(context, DATE_WEATHER_VIEW_HEIGHT).toFloat()
val marginBetweenSmartspaceAndNotification =
context.resources.getDimensionPixelSize(
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModel.kt
index 3a7a640be85f..6e30e482bda0 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModel.kt
@@ -16,6 +16,7 @@
package com.android.systemui.keyguard.ui.viewmodel
+import android.content.Context
import android.content.res.Resources
import androidx.annotation.VisibleForTesting
import androidx.constraintlayout.helper.widget.Layer
@@ -27,7 +28,8 @@ import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.keyguard.shared.model.ClockSize
import com.android.systemui.keyguard.shared.model.ClockSizeSetting
-import com.android.systemui.res.R
+import com.android.systemui.plugins.clocks.ClockPreviewConfig
+import com.android.systemui.plugins.clocks.DefaultClockFaceLayout.Companion.getSmallClockTopPadding
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.shade.domain.interactor.ShadeInteractor
@@ -46,6 +48,7 @@ import kotlinx.coroutines.flow.stateIn
class KeyguardClockViewModel
@Inject
constructor(
+ val context: Context,
keyguardClockInteractor: KeyguardClockInteractor,
@Application private val applicationScope: CoroutineScope,
aodNotificationIconViewModel: NotificationIconContainerAlwaysOnDisplayViewModel,
@@ -158,16 +161,15 @@ constructor(
)
/** Calculates the top margin for the small clock. */
- fun getSmallClockTopMargin(): Int {
- val statusBarHeight = systemBarUtils.getStatusBarHeaderHeightKeyguard()
- return if (shadeInteractor.isShadeLayoutWide.value) {
- resources.getDimensionPixelSize(R.dimen.keyguard_split_shade_top_margin) -
- if (SceneContainerFlag.isEnabled) statusBarHeight else 0
- } else {
- resources.getDimensionPixelSize(R.dimen.keyguard_clock_top_margin) +
- if (!SceneContainerFlag.isEnabled) statusBarHeight else 0
- }
- }
+ fun getSmallClockTopMargin(): Int =
+ getSmallClockTopPadding(
+ ClockPreviewConfig(
+ context,
+ shadeInteractor.isShadeLayoutWide.value,
+ SceneContainerFlag.isEnabled,
+ ),
+ systemBarUtils.getStatusBarHeaderHeightKeyguard(),
+ )
val smallClockTopMargin =
combine(
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewSmartspaceViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewSmartspaceViewModel.kt
index 65c0f57b76f5..1c4498212502 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewSmartspaceViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewSmartspaceViewModel.kt
@@ -17,11 +17,12 @@
package com.android.systemui.keyguard.ui.viewmodel
import android.content.Context
-import com.android.internal.policy.SystemBarUtils
import com.android.systemui.customization.R as customR
import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.keyguard.shared.model.ClockSizeSetting
-import com.android.systemui.res.R
+import com.android.systemui.plugins.clocks.ClockPreviewConfig
+import com.android.systemui.plugins.clocks.DefaultClockFaceLayout.Companion.getSmallClockTopPadding
+import com.android.systemui.statusbar.ui.SystemBarUtilsProxy
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
@@ -35,6 +36,7 @@ constructor(
interactor: KeyguardClockInteractor,
val smartspaceViewModel: KeyguardSmartspaceViewModel,
val clockViewModel: KeyguardClockViewModel,
+ private val systemBarUtils: SystemBarUtilsProxy,
) {
val selectedClockSize: StateFlow<ClockSizeSetting> = interactor.selectedClockSize
@@ -59,29 +61,18 @@ constructor(
return KeyguardSmartspaceViewModel.getSmartspaceEndMargin(context)
}
- fun getSmallClockSmartspaceTopPadding(splitShadePreview: Boolean, context: Context): Int {
- return getSmallClockTopPadding(splitShadePreview, context) +
- context.resources.getDimensionPixelSize(
- com.android.systemui.customization.R.dimen.small_clock_height
- )
- }
-
- fun getLargeClockSmartspaceTopPadding(splitShadePreview: Boolean, context: Context): Int {
- return getSmallClockTopPadding(splitShadePreview, context)
- }
-
/*
* SmallClockTopPadding decides the top position of smartspace
*/
- private fun getSmallClockTopPadding(splitShadePreview: Boolean, context: Context): Int {
- return with(context.resources) {
- if (splitShadePreview) {
- getDimensionPixelSize(R.dimen.keyguard_split_shade_top_margin)
- } else {
- getDimensionPixelSize(R.dimen.keyguard_clock_top_margin) +
- SystemBarUtils.getStatusBarHeight(context) +
- getDimensionPixelSize(customR.dimen.keyguard_smartspace_top_offset)
- }
- }
+ fun getSmallClockSmartspaceTopPadding(config: ClockPreviewConfig): Int {
+ return getSmallClockTopPadding(config, systemBarUtils.getStatusBarHeaderHeightKeyguard()) +
+ config.previewContext.resources.getDimensionPixelSize(customR.dimen.small_clock_height)
+ }
+
+ fun getLargeClockSmartspaceTopPadding(clockPreviewConfig: ClockPreviewConfig): Int {
+ return getSmallClockTopPadding(
+ clockPreviewConfig,
+ systemBarUtils.getStatusBarHeaderHeightKeyguard(),
+ )
}
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModelKosmos.kt
index b5e6f75c7915..c0b39b1df7d5 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardClockViewModelKosmos.kt
@@ -16,6 +16,7 @@
package com.android.systemui.keyguard.ui.viewmodel
+import android.content.applicationContext
import android.content.res.mainResources
import com.android.systemui.common.ui.domain.interactor.configurationInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardClockInteractor
@@ -28,12 +29,13 @@ import com.android.systemui.statusbar.ui.systemBarUtilsProxy
val Kosmos.keyguardClockViewModel by
Kosmos.Fixture {
KeyguardClockViewModel(
+ context = applicationContext,
keyguardClockInteractor = keyguardClockInteractor,
applicationScope = applicationCoroutineScope,
aodNotificationIconViewModel = notificationIconContainerAlwaysOnDisplayViewModel,
shadeInteractor = shadeInteractor,
systemBarUtils = systemBarUtilsProxy,
configurationInteractor = configurationInteractor,
- resources = mainResources
+ resources = mainResources,
)
}