Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b295451 authored by Sherry Zhou's avatar Sherry Zhou
Browse files

Make clock in lockscreen preview use the correct overlayed resources

Bug: 379347594
Test: manual test position of layout matching the layout of actual
lockscreen
Flag: EXEMPT bugfix + refactor

Change-Id: I34ecee11831b23651b2d08990196900e4475e059
parent b9a5d99b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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>
+25 −0
Original line number Diff line number Diff line
/*
 * 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,
)
+26 −7
Original line number Diff line number Diff line
@@ -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
            }
        }
    }
}

+17 −9
Original line number Diff line number Diff line
@@ -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
+4 −11
Original line number Diff line number Diff line
@@ -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)
                    }
Loading