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

Commit e24fec8b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make clock in lockscreen preview use the correct overlayed resources" into main

parents 762ae6a7 0b295451
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@
    <dimen name="small_clock_height">114dp</dimen>
    <dimen name="small_clock_height">114dp</dimen>
    <dimen name="small_clock_padding_top">28dp</dimen>
    <dimen name="small_clock_padding_top">28dp</dimen>
    <dimen name="clock_padding_start">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 -->
    <!-- When large clock is showing, offset the smartspace by this amount -->
    <dimen name="keyguard_smartspace_top_offset">12dp</dimen>
    <dimen name="keyguard_smartspace_top_offset">12dp</dimen>
+25 −0
Original line number Original line 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 Original line Diff line number Diff line
@@ -160,7 +160,10 @@ interface ClockFaceLayout {


    @ProtectedReturn("return constraints;")
    @ProtectedReturn("return constraints;")
    /** Custom constraints to apply to preview ConstraintLayout. */
    /** 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)
    fun applyAodBurnIn(aodBurnInModel: AodClockBurnInModel)
}
}
@@ -181,10 +184,10 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout {
    }
    }


    override fun applyPreviewConstraints(
    override fun applyPreviewConstraints(
        context: Context,
        clockPreviewConfig: ClockPreviewConfig,
        constraints: ConstraintSet,
        constraints: ConstraintSet,
    ): ConstraintSet {
    ): ConstraintSet {
        return applyDefaultPreviewConstraints(context, constraints)
        return applyDefaultPreviewConstraints(clockPreviewConfig, constraints)
    }
    }


    override fun applyAodBurnIn(aodBurnInModel: AodClockBurnInModel) {
    override fun applyAodBurnIn(aodBurnInModel: AodClockBurnInModel) {
@@ -193,10 +196,11 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout {


    companion object {
    companion object {
        fun applyDefaultPreviewConstraints(
        fun applyDefaultPreviewConstraints(
            context: Context,
            clockPreviewConfig: ClockPreviewConfig,
            constraints: ConstraintSet,
            constraints: ConstraintSet,
        ): ConstraintSet {
        ): ConstraintSet {
            constraints.apply {
            constraints.apply {
                val context = clockPreviewConfig.previewContext
                val lockscreenClockViewLargeId = getId(context, "lockscreen_clock_view_large")
                val lockscreenClockViewLargeId = getId(context, "lockscreen_clock_view_large")
                constrainWidth(lockscreenClockViewLargeId, WRAP_CONTENT)
                constrainWidth(lockscreenClockViewLargeId, WRAP_CONTENT)
                constrainHeight(lockscreenClockViewLargeId, WRAP_CONTENT)
                constrainHeight(lockscreenClockViewLargeId, WRAP_CONTENT)
@@ -237,8 +241,10 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout {
                        getDimen(context, "status_view_margin_horizontal"),
                        getDimen(context, "status_view_margin_horizontal"),
                )
                )
                val smallClockTopMargin =
                val smallClockTopMargin =
                    getDimen(context, "keyguard_clock_top_margin") +
                    getSmallClockTopPadding(
                        SystemBarUtils.getStatusBarHeight(context)
                        clockPreviewConfig = clockPreviewConfig,
                        SystemBarUtils.getStatusBarHeight(context),
                    )
                connect(smallClockViewId, TOP, PARENT_ID, TOP, smallClockTopMargin)
                connect(smallClockViewId, TOP, PARENT_ID, TOP, smallClockTopMargin)
            }
            }
            return constraints
            return constraints
@@ -253,10 +259,23 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout {


        fun getDimen(context: Context, name: String): Int {
        fun getDimen(context: Context, name: String): Int {
            val packageName = context.packageName
            val packageName = context.packageName
            val res = context.packageManager.getResourcesForApplication(packageName)
            val res = context.resources
            val id = res.getIdentifier(name, "dimen", packageName)
            val id = res.getIdentifier(name, "dimen", packageName)
            return if (id == 0) 0 else res.getDimensionPixelSize(id)
            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 Original line Diff line number Diff line
@@ -17,7 +17,7 @@


package com.android.systemui.keyguard.ui.binder
package com.android.systemui.keyguard.ui.binder


import android.content.Context
import android.content.res.Resources
import android.view.View
import android.view.View
import android.view.View.INVISIBLE
import android.view.View.INVISIBLE
import android.view.View.VISIBLE
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.keyguard.ui.viewmodel.KeyguardPreviewClockViewModel
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.plugins.clocks.ClockController
import com.android.systemui.plugins.clocks.ClockController
import com.android.systemui.plugins.clocks.ClockPreviewConfig
import com.android.systemui.shared.clocks.ClockRegistry
import com.android.systemui.shared.clocks.ClockRegistry
import kotlin.reflect.KSuspendFunction1


/** Binder for the small clock view, large clock view. */
/** Binder for the small clock view, large clock view. */
object KeyguardPreviewClockViewBinder {
object KeyguardPreviewClockViewBinder {
@@ -66,11 +66,11 @@ object KeyguardPreviewClockViewBinder {


    @JvmStatic
    @JvmStatic
    fun bind(
    fun bind(
        context: Context,
        rootView: ConstraintLayout,
        rootView: ConstraintLayout,
        viewModel: KeyguardPreviewClockViewModel,
        viewModel: KeyguardPreviewClockViewModel,
        clockRegistry: ClockRegistry,
        clockRegistry: ClockRegistry,
        updateClockAppearance: KSuspendFunction1<ClockController, Unit>,
        updateClockAppearance: suspend (ClockController, Resources) -> Unit,
        clockPreviewConfig: ClockPreviewConfig,
    ) {
    ) {
        rootView.repeatWhenAttached {
        rootView.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
@@ -82,7 +82,10 @@ object KeyguardPreviewClockViewBinder {
                                    .forEach { rootView.removeView(it) }
                                    .forEach { rootView.removeView(it) }
                            }
                            }
                            lastClock = currentClock
                            lastClock = currentClock
                            updateClockAppearance(currentClock)
                            updateClockAppearance(
                                currentClock,
                                clockPreviewConfig.previewContext.resources,
                            )


                            if (viewModel.shouldHighlightSelectedAffordance) {
                            if (viewModel.shouldHighlightSelectedAffordance) {
                                (currentClock.largeClock.layout.views +
                                (currentClock.largeClock.layout.views +
@@ -98,7 +101,12 @@ object KeyguardPreviewClockViewBinder {
                                (it.parent as? ViewGroup)?.removeView(it)
                                (it.parent as? ViewGroup)?.removeView(it)
                                rootView.addView(it)
                                rootView.addView(it)
                            }
                            }
                            applyPreviewConstraints(context, rootView, currentClock, viewModel)
                            applyPreviewConstraints(
                                clockPreviewConfig,
                                rootView,
                                currentClock,
                                viewModel,
                            )
                        }
                        }
                    }
                    }
                    .invokeOnCompletion {
                    .invokeOnCompletion {
@@ -121,14 +129,14 @@ object KeyguardPreviewClockViewBinder {
    }
    }


    private fun applyPreviewConstraints(
    private fun applyPreviewConstraints(
        context: Context,
        clockPreviewConfig: ClockPreviewConfig,
        rootView: ConstraintLayout,
        rootView: ConstraintLayout,
        previewClock: ClockController,
        previewClock: ClockController,
        viewModel: KeyguardPreviewClockViewModel,
        viewModel: KeyguardPreviewClockViewModel,
    ) {
    ) {
        val cs = ConstraintSet().apply { clone(rootView) }
        val cs = ConstraintSet().apply { clone(rootView) }
        previewClock.largeClock.layout.applyPreviewConstraints(context, cs)
        previewClock.largeClock.layout.applyPreviewConstraints(clockPreviewConfig, cs)
        previewClock.smallClock.layout.applyPreviewConstraints(context, cs)
        previewClock.smallClock.layout.applyPreviewConstraints(clockPreviewConfig, cs)


        // When selectedClockSize is the initial value, make both clocks invisible to avoid
        // When selectedClockSize is the initial value, make both clocks invisible to avoid
        // flickering
        // flickering
+4 −11
Original line number Original line Diff line number Diff line
@@ -17,7 +17,6 @@


package com.android.systemui.keyguard.ui.binder
package com.android.systemui.keyguard.ui.binder


import android.content.Context
import android.view.View
import android.view.View
import androidx.core.view.isInvisible
import androidx.core.view.isInvisible
import androidx.lifecycle.Lifecycle
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.shared.model.ClockSizeSetting
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewModel
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.plugins.clocks.ClockPreviewConfig


/** Binder for the small clock view, large clock view and smartspace. */
/** Binder for the small clock view, large clock view and smartspace. */
object KeyguardPreviewSmartspaceViewBinder {
object KeyguardPreviewSmartspaceViewBinder {


    @JvmStatic
    @JvmStatic
    fun bind(
    fun bind(
        previewContext: Context,
        smartspace: View,
        smartspace: View,
        splitShadePreview: Boolean,
        viewModel: KeyguardPreviewSmartspaceViewModel,
        viewModel: KeyguardPreviewSmartspaceViewModel,
        clockPreviewConfig: ClockPreviewConfig,
    ) {
    ) {
        smartspace.repeatWhenAttached {
        smartspace.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
@@ -44,15 +43,9 @@ object KeyguardPreviewSmartspaceViewBinder {
                        val topPadding =
                        val topPadding =
                            when (it) {
                            when (it) {
                                ClockSizeSetting.DYNAMIC ->
                                ClockSizeSetting.DYNAMIC ->
                                    viewModel.getLargeClockSmartspaceTopPadding(
                                    viewModel.getLargeClockSmartspaceTopPadding(clockPreviewConfig)
                                        splitShadePreview,
                                        previewContext,
                                    )
                                ClockSizeSetting.SMALL ->
                                ClockSizeSetting.SMALL ->
                                    viewModel.getSmallClockSmartspaceTopPadding(
                                    viewModel.getSmallClockSmartspaceTopPadding(clockPreviewConfig)
                                        splitShadePreview,
                                        previewContext,
                                    )
                            }
                            }
                        smartspace.setTopPadding(topPadding)
                        smartspace.setTopPadding(topPadding)
                    }
                    }
Loading