diff options
6 files changed, 69 insertions, 60 deletions
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockFaceLayout.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockFaceLayout.kt index 843afb8d74a8..a075d0d5b249 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockFaceLayout.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockFaceLayout.kt @@ -13,7 +13,6 @@ */ package com.android.systemui.plugins.clocks -import android.content.Context import android.util.DisplayMetrics import android.view.View import androidx.constraintlayout.widget.ConstraintSet @@ -27,6 +26,8 @@ import com.android.internal.policy.SystemBarUtils import com.android.systemui.plugins.annotations.GeneratedImport import com.android.systemui.plugins.annotations.ProtectedInterface import com.android.systemui.plugins.annotations.ProtectedReturn +import com.android.systemui.plugins.clocks.ContextExt.getDimen +import com.android.systemui.plugins.clocks.ContextExt.getId /** Specifies layout information for the clock face */ @ProtectedInterface @@ -94,18 +95,18 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout { constraints: ConstraintSet, ): ConstraintSet { constraints.apply { - val context = clockPreviewConfig.previewContext - val lockscreenClockViewLargeId = getId(context, "lockscreen_clock_view_large") + val context = clockPreviewConfig.context + val lockscreenClockViewLargeId = context.getId("lockscreen_clock_view_large") constrainWidth(lockscreenClockViewLargeId, WRAP_CONTENT) constrainHeight(lockscreenClockViewLargeId, WRAP_CONTENT) constrainMaxHeight(lockscreenClockViewLargeId, 0) val largeClockTopMargin = SystemBarUtils.getStatusBarHeight(context) + - getDimen(context, "small_clock_padding_top") + - getDimen(context, "keyguard_smartspace_top_offset") + - getDimen(context, "date_weather_view_height") + - getDimen(context, "enhanced_smartspace_height") + context.getDimen("small_clock_padding_top") + + context.getDimen("keyguard_smartspace_top_offset") + + context.getDimen("date_weather_view_height") + + context.getDimen("enhanced_smartspace_height") connect(lockscreenClockViewLargeId, TOP, PARENT_ID, TOP, largeClockTopMargin) connect(lockscreenClockViewLargeId, START, PARENT_ID, START) connect(lockscreenClockViewLargeId, END, PARENT_ID, END) @@ -119,7 +120,7 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout { connect(lockscreenClockViewLargeId, BOTTOM, lockId, TOP) } ?: run { - val bottomPaddingPx = getDimen(context, "lock_icon_margin_bottom") + val bottomPaddingPx = context.getDimen("lock_icon_margin_bottom") val defaultDensity = DisplayMetrics.DENSITY_DEVICE_STABLE.toFloat() / DisplayMetrics.DENSITY_DEFAULT.toFloat() @@ -134,52 +135,22 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout { ) } - val smallClockViewId = getId(context, "lockscreen_clock_view") + val smallClockViewId = context.getId("lockscreen_clock_view") constrainWidth(smallClockViewId, WRAP_CONTENT) - constrainHeight(smallClockViewId, getDimen(context, "small_clock_height")) + constrainHeight(smallClockViewId, context.getDimen("small_clock_height")) connect( smallClockViewId, START, PARENT_ID, START, - getDimen(context, "clock_padding_start") + - getDimen(context, "status_view_margin_horizontal"), + context.getDimen("clock_padding_start") + + context.getDimen("status_view_margin_horizontal"), ) - val smallClockTopMargin = - getSmallClockTopPadding( - clockPreviewConfig = clockPreviewConfig, - SystemBarUtils.getStatusBarHeight(context), - ) + + val smallClockTopMargin = clockPreviewConfig.getSmallClockTopPadding() connect(smallClockViewId, TOP, PARENT_ID, TOP, smallClockTopMargin) } return constraints } - - fun getId(context: Context, name: String): Int { - val packageName = context.packageName - val res = context.packageManager.getResourcesForApplication(packageName) - val id = res.getIdentifier(name, "id", packageName) - return id - } - - fun getDimen(context: Context, name: String): Int { - val packageName = context.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/plugin/src/com/android/systemui/plugins/clocks/ClockPreviewConfig.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockPreviewConfig.kt index 94e669fc0ea2..c705c51a00d5 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockPreviewConfig.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockPreviewConfig.kt @@ -17,10 +17,24 @@ package com.android.systemui.plugins.clocks import android.content.Context +import com.android.internal.policy.SystemBarUtils +import com.android.systemui.plugins.clocks.ContextExt.getDimen data class ClockPreviewConfig( - val previewContext: Context, + val context: Context, val isShadeLayoutWide: Boolean, val isSceneContainerFlagEnabled: Boolean = false, val lockId: Int? = null, -) +) { + fun getSmallClockTopPadding( + statusBarHeight: Int = SystemBarUtils.getStatusBarHeight(context) + ): Int { + return if (isShadeLayoutWide) { + context.getDimen("keyguard_split_shade_top_margin") - + if (isSceneContainerFlagEnabled) statusBarHeight else 0 + } else { + context.getDimen("keyguard_clock_top_margin") + + if (!isSceneContainerFlagEnabled) statusBarHeight else 0 + } + } +} diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ContextExt.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ContextExt.kt new file mode 100644 index 000000000000..17a1bfc66a97 --- /dev/null +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ContextExt.kt @@ -0,0 +1,28 @@ +/* + * 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 + +object ContextExt { + fun Context.getId(name: String): Int { + val res = packageManager.getResourcesForApplication(packageName) + return res.getIdentifier(name, "id", packageName) + } + + fun Context.getDimen(name: String): Int { + val id = resources.getIdentifier(name, "dimen", packageName) + return if (id == 0) 0 else resources.getDimensionPixelSize(id) + } +} 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 1964cb2f811f..d3b76a576a0f 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 @@ -84,7 +84,7 @@ object KeyguardPreviewClockViewBinder { lastClock = currentClock updateClockAppearance( currentClock, - clockPreviewConfig.previewContext.resources, + clockPreviewConfig.context.resources, ) if (viewModel.shouldHighlightSelectedAffordance) { 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 6e30e482bda0..8fe225a8b93f 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 @@ -29,7 +29,6 @@ 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.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 @@ -161,15 +160,14 @@ constructor( ) /** Calculates the top margin for the small clock. */ - fun getSmallClockTopMargin(): Int = - getSmallClockTopPadding( - ClockPreviewConfig( + fun getSmallClockTopMargin(): Int { + return ClockPreviewConfig( context, shadeInteractor.isShadeLayoutWide.value, SceneContainerFlag.isEnabled, - ), - systemBarUtils.getStatusBarHeaderHeightKeyguard(), - ) + ) + .getSmallClockTopPadding(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 15b696e71164..f6c66d534a04 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 @@ -21,7 +21,6 @@ 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.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 @@ -74,14 +73,13 @@ constructor( * SmallClockTopPadding decides the top position of smartspace */ fun getSmallClockSmartspaceTopPadding(config: ClockPreviewConfig): Int { - return getSmallClockTopPadding(config, systemBarUtils.getStatusBarHeaderHeightKeyguard()) + - config.previewContext.resources.getDimensionPixelSize(customR.dimen.small_clock_height) + return config.getSmallClockTopPadding(systemBarUtils.getStatusBarHeaderHeightKeyguard()) + + config.context.resources.getDimensionPixelSize(customR.dimen.small_clock_height) } fun getLargeClockSmartspaceTopPadding(clockPreviewConfig: ClockPreviewConfig): Int { - return getSmallClockTopPadding( - clockPreviewConfig, - systemBarUtils.getStatusBarHeaderHeightKeyguard(), + return clockPreviewConfig.getSmallClockTopPadding( + systemBarUtils.getStatusBarHeaderHeightKeyguard() ) } } |