diff options
10 files changed, 330 insertions, 102 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 001e3a5fc911..54c7a0823963 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 @@ -49,7 +49,7 @@ import java.util.TimeZone * existing lockscreen clock. */ class DefaultClockController( - ctx: Context, + private val ctx: Context, private val layoutInflater: LayoutInflater, private val resources: Resources, private val settings: ClockSettings?, @@ -121,7 +121,11 @@ class DefaultClockController( protected var targetRegion: Rect? = null override val config = ClockFaceConfig() - override val layout = DefaultClockFaceLayout(view) + override val layout = + DefaultClockFaceLayout(view).apply { + views[0].id = + resources.getIdentifier("lockscreen_clock_view", "id", ctx.packageName) + } override var animations: DefaultClockAnimations = DefaultClockAnimations(view, 0f, 0f) internal set @@ -188,7 +192,11 @@ class DefaultClockController( seedColor: Int?, messageBuffer: MessageBuffer?, ) : DefaultClockFaceController(view, seedColor, messageBuffer) { - override val layout = DefaultClockFaceLayout(view) + override val layout = + DefaultClockFaceLayout(view).apply { + views[0].id = + resources.getIdentifier("lockscreen_clock_view_large", "id", ctx.packageName) + } override val config = ClockFaceConfig(hasCustomPositionUpdatedAnimation = hasStepClockAnimation) 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 4436be7cd7d7..fd7a7f34d258 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 @@ -116,6 +116,8 @@ interface ClockFaceLayout { /** Custom constraints to apply to Lockscreen ConstraintLayout. */ fun applyConstraints(constraints: ConstraintSet): ConstraintSet + + fun applyPreviewConstraints(constraints: ConstraintSet): ConstraintSet } /** A ClockFaceLayout that applies the default lockscreen layout to a single view */ @@ -131,6 +133,10 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout { } return constraints } + + override fun applyPreviewConstraints(constraints: ConstraintSet): ConstraintSet { + return constraints + } } /** Events that should call when various rendering parameters change */ diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardClockRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardClockRepository.kt index 5e3779a1a59d..59288a155666 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardClockRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardClockRepository.kt @@ -60,6 +60,8 @@ interface KeyguardClockRepository { val currentClock: StateFlow<ClockController?> + val previewClock: StateFlow<ClockController> + val clockEventController: ClockEventController fun setClockSize(@ClockSize size: Int) } @@ -120,6 +122,15 @@ constructor( initialValue = clockRegistry.createCurrentClock() ) + override val previewClock: StateFlow<ClockController> = + currentClockId + .map { clockRegistry.createCurrentClock() } + .stateIn( + scope = applicationScope, + started = SharingStarted.WhileSubscribed(), + initialValue = clockRegistry.createCurrentClock() + ) + @VisibleForTesting suspend fun getClockSize(): SettingsClockSize { return withContext(backgroundDispatcher) { diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardClockInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardClockInteractor.kt index 356c4085ab48..196770ae2f9a 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardClockInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardClockInteractor.kt @@ -44,6 +44,8 @@ constructor( val currentClock: StateFlow<ClockController?> = keyguardClockRepository.currentClock + val previewClock: StateFlow<ClockController> = keyguardClockRepository.previewClock + var clock: ClockController? by keyguardClockRepository.clockEventController::clock val clockSize: StateFlow<Int> = keyguardClockRepository.clockSize diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardClockViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardClockViewBinder.kt index f0e89f9695de..62a6e8b45285 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardClockViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardClockViewBinder.kt @@ -18,7 +18,6 @@ package com.android.systemui.keyguard.ui.binder import android.transition.TransitionManager import android.transition.TransitionSet -import android.util.Log import android.view.View.INVISIBLE import androidx.annotation.VisibleForTesting import androidx.constraintlayout.helper.widget.Layer @@ -36,7 +35,6 @@ import com.android.systemui.keyguard.ui.view.layout.sections.ClockSection import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel import com.android.systemui.lifecycle.repeatWhenAttached import com.android.systemui.plugins.clocks.ClockController -import com.android.systemui.res.R import com.android.systemui.shared.clocks.DEFAULT_CLOCK_ID import kotlinx.coroutines.launch @@ -78,10 +76,6 @@ object KeyguardClockViewBinder { launch { if (!migrateClocksToBlueprint()) return@launch viewModel.clockShouldBeCentered.collect { clockShouldBeCentered -> - Log.d( - "ClockViewBinder", - "Sherry clockShouldBeCentered $clockShouldBeCentered" - ) viewModel.clock?.let { // Weather clock also has hasCustomPositionUpdatedAnimation as true // TODO(b/323020908): remove ID check @@ -169,16 +163,12 @@ object KeyguardClockViewBinder { rootView: ConstraintLayout, ) { clockController?.let { clock -> - clock.smallClock.layout.views[0].id = R.id.lockscreen_clock_view - if (clock.largeClock.layout.views.size == 1) { - clock.largeClock.layout.views[0].id = R.id.lockscreen_clock_view_large - } - // small clock should either be a single view or container with id - // `lockscreen_clock_view` clock.smallClock.layout.views.forEach { rootView.addView(it).apply { it.visibility = INVISIBLE } } - clock.largeClock.layout.views.forEach { rootView.addView(it) } + clock.largeClock.layout.views.forEach { + rootView.addView(it).apply { it.visibility = INVISIBLE } + } } } fun applyConstraints( 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 1b5b329f3f7e..b56c99864c0b 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,12 +17,35 @@ package com.android.systemui.keyguard.ui.binder +import android.content.Context import android.view.View +import android.view.View.INVISIBLE +import android.view.View.VISIBLE +import android.view.ViewGroup +import android.view.ViewGroup.LayoutParams.WRAP_CONTENT +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.constraintlayout.widget.ConstraintSet +import androidx.constraintlayout.widget.ConstraintSet.BOTTOM +import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID +import androidx.constraintlayout.widget.ConstraintSet.START +import androidx.constraintlayout.widget.ConstraintSet.TOP import androidx.core.view.isVisible import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle +import com.android.keyguard.ClockEventController +import com.android.systemui.customization.R as customizationR +import com.android.systemui.keyguard.shared.model.SettingsClockSize +import com.android.systemui.keyguard.ui.preview.KeyguardPreviewRenderer +import com.android.systemui.keyguard.ui.view.layout.sections.ClockSection.Companion.getDimen +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.res.R +import com.android.systemui.util.Utils +import kotlin.reflect.KSuspendFunction1 +import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.launch /** Binder for the small clock view, large clock view. */ object KeyguardPreviewClockViewBinder { @@ -45,4 +68,129 @@ object KeyguardPreviewClockViewBinder { } } } + + @JvmStatic + fun bind( + context: Context, + rootView: ConstraintLayout, + viewModel: KeyguardPreviewClockViewModel, + clockEventController: ClockEventController, + updateClockAppearance: KSuspendFunction1<ClockController, Unit> + ) { + rootView.repeatWhenAttached { + repeatOnLifecycle(Lifecycle.State.STARTED) { + launch { + combine(viewModel.selectedClockSize, viewModel.previewClock) { _, clock -> + clock + } + .collect { previewClock -> + viewModel.lastClock?.let { lastClock -> + (lastClock.largeClock.layout.views + + lastClock.smallClock.layout.views) + .forEach { rootView.removeView(it) } + } + viewModel.lastClock = previewClock + clockEventController.clock = previewClock + updateClockAppearance(previewClock) + + if (viewModel.shouldHighlightSelectedAffordance) { + (previewClock.largeClock.layout.views + + previewClock.smallClock.layout.views) + .forEach { it.alpha = KeyguardPreviewRenderer.DIM_ALPHA } + } + previewClock.largeClock.layout.views.forEach { + (it.parent as? ViewGroup)?.removeView(it) + rootView.addView(it) + } + + previewClock.smallClock.layout.views.forEach { + (it.parent as? ViewGroup)?.removeView(it) + rootView.addView(it) + } + applyPreviewConstraints(context, rootView, viewModel) + } + } + } + } + } + + private fun applyClockDefaultConstraints(context: Context, constraints: ConstraintSet) { + constraints.apply { + constrainWidth(R.id.lockscreen_clock_view_large, ConstraintSet.WRAP_CONTENT) + constrainHeight(R.id.lockscreen_clock_view_large, ConstraintSet.WRAP_CONTENT) + val largeClockTopMargin = + context.resources.getDimensionPixelSize(R.dimen.status_bar_height) + + context.resources.getDimensionPixelSize( + customizationR.dimen.small_clock_padding_top + ) + + context.resources.getDimensionPixelSize( + R.dimen.keyguard_smartspace_top_offset + ) + + getDimen(context, DATE_WEATHER_VIEW_HEIGHT) + + getDimen(context, ENHANCED_SMARTSPACE_HEIGHT) + connect(R.id.lockscreen_clock_view_large, TOP, PARENT_ID, TOP, largeClockTopMargin) + connect(R.id.lockscreen_clock_view_large, START, PARENT_ID, START) + connect( + R.id.lockscreen_clock_view_large, + ConstraintSet.END, + PARENT_ID, + ConstraintSet.END + ) + + connect(R.id.lockscreen_clock_view_large, BOTTOM, R.id.lock_icon_view, TOP) + constrainWidth(R.id.lockscreen_clock_view, WRAP_CONTENT) + constrainHeight( + R.id.lockscreen_clock_view, + context.resources.getDimensionPixelSize(customizationR.dimen.small_clock_height) + ) + connect( + R.id.lockscreen_clock_view, + START, + PARENT_ID, + START, + context.resources.getDimensionPixelSize(customizationR.dimen.clock_padding_start) + + context.resources.getDimensionPixelSize(R.dimen.status_view_margin_horizontal) + ) + val smallClockTopMargin = + context.resources.getDimensionPixelSize(R.dimen.keyguard_clock_top_margin) + + Utils.getStatusBarHeaderHeightKeyguard(context) + connect(R.id.lockscreen_clock_view, TOP, PARENT_ID, TOP, smallClockTopMargin) + } + } + + private fun applyPreviewConstraints( + context: Context, + rootView: ConstraintLayout, + viewModel: KeyguardPreviewClockViewModel + ) { + val cs = ConstraintSet().apply { clone(rootView) } + val clock = viewModel.previewClock.value + applyClockDefaultConstraints(context, cs) + clock.largeClock.layout.applyPreviewConstraints(cs) + clock.smallClock.layout.applyPreviewConstraints(cs) + + // When selectedClockSize is the initial value, make both clocks invisible to avoid + // flickering + val largeClockVisibility = + when (viewModel.selectedClockSize.value) { + SettingsClockSize.DYNAMIC -> VISIBLE + SettingsClockSize.SMALL -> INVISIBLE + null -> INVISIBLE + } + val smallClockVisibility = + when (viewModel.selectedClockSize.value) { + SettingsClockSize.DYNAMIC -> INVISIBLE + SettingsClockSize.SMALL -> VISIBLE + null -> INVISIBLE + } + + cs.apply { + setVisibility(clock.largeClock.layout.views, largeClockVisibility) + setVisibility(clock.smallClock.layout.views, smallClockVisibility) + } + cs.applyTo(rootView) + } + + private const val DATE_WEATHER_VIEW_HEIGHT = "date_weather_view_height" + private const val ENHANCED_SMARTSPACE_HEIGHT = "enhanced_smartspace_height" } 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 a0c0095b34a2..c14917b31d0b 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 @@ -46,6 +46,7 @@ import androidx.core.view.isInvisible import com.android.keyguard.ClockEventController import com.android.keyguard.KeyguardClockSwitch import com.android.systemui.Flags.keyguardBottomAreaRefactor +import com.android.systemui.Flags.migrateClocksToBlueprint import com.android.systemui.animation.view.LaunchableImageView import com.android.systemui.biometrics.domain.interactor.UdfpsOverlayInteractor import com.android.systemui.broadcast.BroadcastDispatcher @@ -197,6 +198,9 @@ constructor( shouldHighlightSelectedAffordance = shouldHighlightSelectedAffordance, ) } + if (migrateClocksToBlueprint()) { + clockViewModel.shouldHighlightSelectedAffordance = shouldHighlightSelectedAffordance + } runBlocking(mainDispatcher) { host = SurfaceControlViewHost( @@ -396,11 +400,21 @@ constructor( if (!shouldHideClock) { setUpClock(previewContext, rootView) - KeyguardPreviewClockViewBinder.bind( - largeClockHostView, - smallClockHostView, - clockViewModel, - ) + if (migrateClocksToBlueprint()) { + KeyguardPreviewClockViewBinder.bind( + context, + keyguardRootView, + clockViewModel, + clockController, + ::updateClockAppearance + ) + } else { + KeyguardPreviewClockViewBinder.bind( + largeClockHostView, + smallClockHostView, + clockViewModel, + ) + } } setUpSmartspace(previewContext, rootView) @@ -474,55 +488,61 @@ constructor( private fun setUpClock(previewContext: Context, parentView: ViewGroup) { val resources = parentView.resources - largeClockHostView = FrameLayout(previewContext) - largeClockHostView.layoutParams = - FrameLayout.LayoutParams( - FrameLayout.LayoutParams.MATCH_PARENT, - FrameLayout.LayoutParams.MATCH_PARENT, - ) - parentView.addView(largeClockHostView) - largeClockHostView.isInvisible = true + if (!migrateClocksToBlueprint()) { + largeClockHostView = FrameLayout(previewContext) + largeClockHostView.layoutParams = + FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.MATCH_PARENT, + ) + largeClockHostView.isInvisible = true + parentView.addView(largeClockHostView) - smallClockHostView = FrameLayout(previewContext) - val layoutParams = - FrameLayout.LayoutParams( - FrameLayout.LayoutParams.WRAP_CONTENT, - resources.getDimensionPixelSize( - com.android.systemui.customization.R.dimen.small_clock_height + smallClockHostView = FrameLayout(previewContext) + val layoutParams = + FrameLayout.LayoutParams( + FrameLayout.LayoutParams.WRAP_CONTENT, + resources.getDimensionPixelSize( + com.android.systemui.customization.R.dimen.small_clock_height + ) ) + layoutParams.topMargin = + KeyguardPreviewSmartspaceViewModel.getStatusBarHeight(resources) + + resources.getDimensionPixelSize( + com.android.systemui.customization.R.dimen.small_clock_padding_top + ) + smallClockHostView.layoutParams = layoutParams + smallClockHostView.setPaddingRelative( + /* start = */ resources.getDimensionPixelSize( + com.android.systemui.customization.R.dimen.clock_padding_start + ), + /* top = */ 0, + /* end = */ 0, + /* bottom = */ 0 ) - layoutParams.topMargin = - KeyguardPreviewSmartspaceViewModel.getStatusBarHeight(resources) + - resources.getDimensionPixelSize( - com.android.systemui.customization.R.dimen.small_clock_padding_top - ) - smallClockHostView.layoutParams = layoutParams - smallClockHostView.setPaddingRelative( - resources.getDimensionPixelSize( - com.android.systemui.customization.R.dimen.clock_padding_start - ), - 0, - 0, - 0 - ) - smallClockHostView.clipChildren = false - parentView.addView(smallClockHostView) - smallClockHostView.isInvisible = true + smallClockHostView.clipChildren = false + parentView.addView(smallClockHostView) + smallClockHostView.isInvisible = true + } // TODO (b/283465254): Move the listeners to KeyguardClockRepository - val clockChangeListener = - object : ClockRegistry.ClockChangeListener { - override fun onCurrentClockChanged() { - onClockChanged() + if (!migrateClocksToBlueprint()) { + val clockChangeListener = + object : ClockRegistry.ClockChangeListener { + override fun onCurrentClockChanged() { + onClockChanged() + } } - } - clockRegistry.registerClockChangeListener(clockChangeListener) - disposables.add( - DisposableHandle { clockRegistry.unregisterClockChangeListener(clockChangeListener) } - ) + clockRegistry.registerClockChangeListener(clockChangeListener) + disposables.add( + DisposableHandle { + clockRegistry.unregisterClockChangeListener(clockChangeListener) + } + ) - clockController.registerListeners(parentView) - disposables.add(DisposableHandle { clockController.unregisterListeners() }) + clockController.registerListeners(parentView) + disposables.add(DisposableHandle { clockController.unregisterListeners() }) + } val receiver = object : BroadcastReceiver() { @@ -542,50 +562,61 @@ constructor( ) disposables.add(DisposableHandle { broadcastDispatcher.unregisterReceiver(receiver) }) - val layoutChangeListener = - View.OnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> - if (clockController.clock !is DefaultClockController) { - clockController.clock - ?.largeClock - ?.events - ?.onTargetRegionChanged(KeyguardClockSwitch.getLargeClockRegion(parentView)) - clockController.clock - ?.smallClock - ?.events - ?.onTargetRegionChanged(KeyguardClockSwitch.getSmallClockRegion(parentView)) + if (!migrateClocksToBlueprint()) { + val layoutChangeListener = + View.OnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> + if (clockController.clock !is DefaultClockController) { + clockController.clock + ?.largeClock + ?.events + ?.onTargetRegionChanged( + KeyguardClockSwitch.getLargeClockRegion(parentView) + ) + clockController.clock + ?.smallClock + ?.events + ?.onTargetRegionChanged( + KeyguardClockSwitch.getSmallClockRegion(parentView) + ) + } } - } - parentView.addOnLayoutChangeListener(layoutChangeListener) - disposables.add( - DisposableHandle { parentView.removeOnLayoutChangeListener(layoutChangeListener) } - ) + parentView.addOnLayoutChangeListener(layoutChangeListener) + disposables.add( + DisposableHandle { parentView.removeOnLayoutChangeListener(layoutChangeListener) } + ) + } onClockChanged() } + private suspend fun updateClockAppearance(clock: ClockController) { + clockController.clock = clock + val colors = wallpaperColors + if (clockRegistry.seedColor == null && colors != null) { + // Seed color null means users do not override any color on the clock. The default + // color will need to use wallpaper's extracted color and consider if the + // wallpaper's color is dark or light. + val style = themeStyle ?: fetchThemeStyleFromSetting().also { themeStyle = it } + val wallpaperColorScheme = ColorScheme(colors, darkTheme = false, style) + val lightClockColor = wallpaperColorScheme.accent1.s100 + val darkClockColor = wallpaperColorScheme.accent2.s600 + + // Note that when [wallpaperColors] is null, isWallpaperDark is true. + val isWallpaperDark: Boolean = + (colors.colorHints.and(WallpaperColors.HINT_SUPPORTS_DARK_TEXT)) == 0 + clock.events.onSeedColorChanged( + if (isWallpaperDark) lightClockColor else darkClockColor + ) + } + } private fun onClockChanged() { + if (migrateClocksToBlueprint()) { + return + } coroutineScope.launch { val clock = clockRegistry.createCurrentClock() clockController.clock = clock - - val colors = wallpaperColors - if (clockRegistry.seedColor == null && colors != null) { - // Seed color null means users do not override any color on the clock. The default - // color will need to use wallpaper's extracted color and consider if the - // wallpaper's color is dark or light. - val style = themeStyle ?: fetchThemeStyleFromSetting().also { themeStyle = it } - val wallpaperColorScheme = ColorScheme(colors, darkTheme = false, style) - val lightClockColor = wallpaperColorScheme.accent1.s100 - val darkClockColor = wallpaperColorScheme.accent2.s600 - - // Note that when [wallpaperColors] is null, isWallpaperDark is true. - val isWallpaperDark: Boolean = - (colors.colorHints.and(WallpaperColors.HINT_SUPPORTS_DARK_TEXT)) == 0 - clock.events.onSeedColorChanged( - if (isWallpaperDark) lightClockColor else darkClockColor - ) - } - + updateClockAppearance(clock) updateLargeClock(clock) updateSmallClock(clock) } @@ -626,6 +657,9 @@ constructor( } private fun updateLargeClock(clock: ClockController) { + if (migrateClocksToBlueprint()) { + return + } clock.largeClock.events.onTargetRegionChanged( KeyguardClockSwitch.getLargeClockRegion(largeClockHostView) ) @@ -637,6 +671,9 @@ constructor( } private fun updateSmallClock(clock: ClockController) { + if (migrateClocksToBlueprint()) { + return + } clock.smallClock.events.onTargetRegionChanged( KeyguardClockSwitch.getSmallClockRegion(smallClockHostView) ) @@ -656,6 +693,6 @@ constructor( private const val KEY_DISPLAY_ID = "display_id" private const val KEY_COLORS = "wallpaper_colors" - private const val DIM_ALPHA = 0.3f + const val DIM_ALPHA = 0.3f } } 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 b1178f5aaea5..631b3427dae9 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 @@ -201,13 +201,16 @@ constructor( } private fun getDimen(name: String): Int { - val res = context.packageManager.getResourcesForApplication(context.packageName) - val id = res.getIdentifier(name, "dimen", context.packageName) - return res.getDimensionPixelSize(id) + return getDimen(context, name) } companion object { private const val DATE_WEATHER_VIEW_HEIGHT = "date_weather_view_height" private const val ENHANCED_SMARTSPACE_HEIGHT = "enhanced_smartspace_height" + fun getDimen(context: Context, name: String): Int { + val res = context.packageManager.getResourcesForApplication(context.packageName) + val id = res.getIdentifier(name, "dimen", context.packageName) + return res.getDimensionPixelSize(id) + } } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewClockViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewClockViewModel.kt index 53013026670c..f95a8a727644 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewClockViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewClockViewModel.kt @@ -20,9 +20,14 @@ import android.content.Context import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor import com.android.systemui.keyguard.shared.model.SettingsClockSize +import com.android.systemui.plugins.clocks.ClockController import javax.inject.Inject +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn /** View model for the small clock view, large clock view. */ class KeyguardPreviewClockViewModel @@ -30,11 +35,24 @@ class KeyguardPreviewClockViewModel constructor( @Application private val context: Context, interactor: KeyguardClockInteractor, + @Application private val applicationScope: CoroutineScope, ) { + var shouldHighlightSelectedAffordance: Boolean = false val isLargeClockVisible: Flow<Boolean> = interactor.selectedClockSize.map { it == SettingsClockSize.DYNAMIC } val isSmallClockVisible: Flow<Boolean> = interactor.selectedClockSize.map { it == SettingsClockSize.SMALL } + + var lastClock: ClockController? = null + + val previewClock: StateFlow<ClockController> = interactor.previewClock + + val selectedClockSize: StateFlow<SettingsClockSize?> = + interactor.selectedClockSize.stateIn( + scope = applicationScope, + started = SharingStarted.WhileSubscribed(), + initialValue = null + ) } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardClockRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardClockRepository.kt index 85a233fd3af1..534f773fa334 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardClockRepository.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardClockRepository.kt @@ -20,6 +20,7 @@ import com.android.keyguard.ClockEventController import com.android.keyguard.KeyguardClockSwitch.ClockSize import com.android.keyguard.KeyguardClockSwitch.LARGE import com.android.systemui.keyguard.shared.model.SettingsClockSize +import com.android.systemui.plugins.clocks.ClockController import com.android.systemui.plugins.clocks.ClockId import com.android.systemui.shared.clocks.DEFAULT_CLOCK_ID import com.android.systemui.util.mockito.mock @@ -29,6 +30,7 @@ import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import org.mockito.Mockito class FakeKeyguardClockRepository @Inject constructor() : KeyguardClockRepository { private val _clockSize = MutableStateFlow(LARGE) @@ -42,6 +44,9 @@ class FakeKeyguardClockRepository @Inject constructor() : KeyguardClockRepositor private val _currentClock = MutableStateFlow(null) override val currentClock = _currentClock + + private val _previewClock = MutableStateFlow(Mockito.mock(ClockController::class.java)) + override val previewClock: StateFlow<ClockController> = _previewClock override val clockEventController: ClockEventController get() = mock() |