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

Commit fbedf58b authored by Sherry Zhou's avatar Sherry Zhou Committed by Android (Google) Code Review
Browse files

Merge "Move apply preview constraints for clocks in clock plugin" into main

parents dbb43b32 3b469b45
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ 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.
  -->

<resources>
    <dimen name="keyguard_smartspace_top_offset">0dp</dimen>
</resources>
 No newline at end of file
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ 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.
  -->

<resources>
    <!-- For portrait direction in unfold foldable device, we don't need keyguard_smartspace_top_offset-->
    <dimen name="keyguard_smartspace_top_offset">0dp</dimen>
</resources>
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
@@ -33,4 +33,10 @@
    <dimen name="small_clock_height">114dp</dimen>
    <dimen name="small_clock_padding_top">28dp</dimen>
    <dimen name="clock_padding_start">28dp</dimen>

    <!-- When large clock is showing, offset the smartspace by this amount -->
    <dimen name="keyguard_smartspace_top_offset">12dp</dimen>
    <!--Dimens used in both lockscreen  preview and smartspace -->
    <dimen name="date_weather_view_height">24dp</dimen>
    <dimen name="enhanced_smartspace_height">104dp</dimen>
</resources>
 No newline at end of file
+3 −1
Original line number Diff line number Diff line
@@ -69,7 +69,9 @@ class ClockSectionTest : SysuiTestCase() {
        get() =
            kosmos.fakeSystemBarUtilsProxy.getStatusBarHeight() +
                context.resources.getDimensionPixelSize(customR.dimen.small_clock_padding_top) +
                context.resources.getDimensionPixelSize(R.dimen.keyguard_smartspace_top_offset)
                context.resources.getDimensionPixelSize(
                    customR.dimen.keyguard_smartspace_top_offset
                )

    private val LARGE_CLOCK_TOP
        get() =
+83 −3
Original line number Diff line number Diff line
@@ -13,11 +13,20 @@
 */
package com.android.systemui.plugins.clocks

import android.content.Context
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.util.DisplayMetrics
import android.view.View
import androidx.constraintlayout.widget.ConstraintSet
import androidx.constraintlayout.widget.ConstraintSet.BOTTOM
import androidx.constraintlayout.widget.ConstraintSet.END
import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID
import androidx.constraintlayout.widget.ConstraintSet.START
import androidx.constraintlayout.widget.ConstraintSet.TOP
import androidx.constraintlayout.widget.ConstraintSet.WRAP_CONTENT
import com.android.internal.annotations.Keep
import com.android.internal.policy.SystemBarUtils
import com.android.systemui.log.core.MessageBuffer
import com.android.systemui.plugins.Plugin
import com.android.systemui.plugins.annotations.GeneratedImport
@@ -149,7 +158,7 @@ interface ClockFaceLayout {

    @ProtectedReturn("return constraints;")
    /** Custom constraints to apply to preview ConstraintLayout. */
    fun applyPreviewConstraints(constraints: ConstraintSet): ConstraintSet
    fun applyPreviewConstraints(context: Context, constraints: ConstraintSet): ConstraintSet

    fun applyAodBurnIn(aodBurnInModel: AodClockBurnInModel)
}
@@ -169,13 +178,84 @@ class DefaultClockFaceLayout(val view: View) : ClockFaceLayout {
        return constraints
    }

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

    override fun applyAodBurnIn(aodBurnInModel: AodClockBurnInModel) {
        // Default clock doesn't need detailed control of view
    }

    companion object {
        fun applyDefaultPreviewConstraints(
            context: Context,
            constraints: ConstraintSet,
        ): ConstraintSet {
            constraints.apply {
                val lockscreenClockViewLargeId = getId(context, "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")
                connect(lockscreenClockViewLargeId, TOP, PARENT_ID, TOP, largeClockTopMargin)
                connect(lockscreenClockViewLargeId, START, PARENT_ID, START)
                connect(lockscreenClockViewLargeId, END, PARENT_ID, END)

                // In preview, we'll show UDFPS icon for UDFPS devices
                // and nothing for non-UDFPS devices,
                // and we're not planning to add this vide in clockHostView
                // so we only need position of device entry icon to constrain clock
                // Copied calculation codes from applyConstraints in DefaultDeviceEntrySection
                val bottomPaddingPx = getDimen(context, "lock_icon_margin_bottom")
                val defaultDensity =
                    DisplayMetrics.DENSITY_DEVICE_STABLE.toFloat() /
                        DisplayMetrics.DENSITY_DEFAULT.toFloat()
                val lockIconRadiusPx = (defaultDensity * 36).toInt()
                val clockBottomMargin = bottomPaddingPx + 2 * lockIconRadiusPx

                connect(lockscreenClockViewLargeId, BOTTOM, PARENT_ID, BOTTOM, clockBottomMargin)
                val smallClockViewId = getId(context, "lockscreen_clock_view")
                constrainWidth(smallClockViewId, WRAP_CONTENT)
                constrainHeight(smallClockViewId, getDimen(context, "small_clock_height"))
                connect(
                    smallClockViewId,
                    START,
                    PARENT_ID,
                    START,
                    getDimen(context, "clock_padding_start") +
                        getDimen(context, "status_view_margin_horizontal"),
                )
                val smallClockTopMargin =
                    getDimen(context, "keyguard_clock_top_margin") +
                        SystemBarUtils.getStatusBarHeight(context)
                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.packageManager.getResourcesForApplication(packageName)
            val id = res.getIdentifier(name, "dimen", packageName)
            return if (id == 0) 0 else res.getDimensionPixelSize(id)
        }
    }
}

/** Events that should call when various rendering parameters change */
Loading