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

Commit 1f106516 authored by Hawkwood Glazier's avatar Hawkwood Glazier Committed by Android (Google) Code Review
Browse files

Merge "Additional clock interface method for region target and font sizes" into tm-qpr-dev

parents 3c410d04 1b35ce6d
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
-packages/SystemUI/checks/tests/com/android/systemui/lint/RegisterReceiverViaContextDetectorTest.kt
-packages/SystemUI/checks/tests/com/android/systemui/lint/SoftwareBitmapDetectorTest.kt
-packages/SystemUI/monet/src/com/android/systemui/monet/ColorScheme.kt
-packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt
-packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSContainerController.kt
-packages/SystemUI/shared/src/com/android/systemui/flags/Flag.kt
-packages/SystemUI/shared/src/com/android/systemui/flags/FlagListenable.kt
+29 −17
Original line number Diff line number Diff line
@@ -99,9 +99,6 @@ interface ClockEvents {
    /** Call whenever the locale changes */
    fun onLocaleChanged(locale: Locale) {}

    /** Call whenever font settings change */
    fun onFontSettingChanged() { }

    /** Call whenever the color palette should update */
    fun onColorPaletteChanged(resources: Resources) {}
}
@@ -136,10 +133,25 @@ interface ClockAnimations {
interface ClockFaceEvents {
    /** Region Darkness specific to the clock face */
    fun onRegionDarknessChanged(isDark: Boolean) {}

    /**
     * Call whenever font settings change. Pass in a target font size in pixels. The specific clock
     * design is allowed to ignore this target size on a case-by-case basis.
     */
    fun onFontSettingChanged(fontSizePx: Float) {}

    /**
     * Target region information for the clock face. For small clock, this will match the bounds of
     * the parent view mostly, but have a target height based on the height of the default clock.
     * For large clocks, the parent view is the entire device size, but most clocks will want to
     * render within the centered targetRect to avoid obstructing other elements. The specified
     * targetRegion is relative to the parent view.
     */
    fun onTargetRegionChanged(targetRegion: Rect?) {}
}

/** Some data about a clock design */
data class ClockMetadata(
    val clockId: ClockId,
    val name: String
    val name: String,
)
+0 −1
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@
        android:id="@+id/lockscreen_clock_view_large"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="@dimen/keyguard_large_clock_top_margin"
        android:clipChildren="false"
        android:visibility="gone" />

+24 −15
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.graphics.Rect
import android.icu.text.NumberFormat
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.VisibleForTesting
import com.android.systemui.plugins.ClockAnimations
@@ -80,7 +81,7 @@ class DefaultClockController(
    }

    override fun initialize(resources: Resources, dozeFraction: Float, foldFraction: Float) {
        largeClock.recomputePadding()
        largeClock.recomputePadding(null)
        animations = DefaultClockAnimations(dozeFraction, foldFraction)
        events.onColorPaletteChanged(resources)
        events.onTimeZoneChanged(TimeZone.getDefault())
@@ -101,6 +102,7 @@ class DefaultClockController(
        // MAGENTA is a placeholder, and will be assigned correctly in initialize
        private var currentColor = Color.MAGENTA
        private var isRegionDark = false
        protected var targetRegion: Rect? = null

        init {
            view.setColors(currentColor, currentColor)
@@ -112,7 +114,19 @@ class DefaultClockController(
                    this@DefaultClockFaceController.isRegionDark = isRegionDark
                    updateColor()
                }

                override fun onTargetRegionChanged(targetRegion: Rect?) {
                    this@DefaultClockFaceController.targetRegion = targetRegion
                    recomputePadding(targetRegion)
                }

                override fun onFontSettingChanged(fontSizePx: Float) {
                    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSizePx)
                    recomputePadding(targetRegion)
                }
            }

        open fun recomputePadding(targetRegion: Rect?) {}

        fun updateColor() {
            val color =
@@ -135,9 +149,16 @@ class DefaultClockController(
    inner class LargeClockFaceController(
        view: AnimatableClockView,
    ) : DefaultClockFaceController(view) {
        fun recomputePadding() {
        override fun recomputePadding(targetRegion: Rect?) {
            // We center the view within the targetRegion instead of within the parent
            // view by computing the difference and adding that to the padding.
            val parent = view.parent
            val yDiff =
                if (targetRegion != null && parent is View && parent.isLaidOut())
                    targetRegion.centerY() - parent.height / 2f
                else 0f
            val lp = view.getLayoutParams() as FrameLayout.LayoutParams
            lp.topMargin = (-0.5f * view.bottom).toInt()
            lp.topMargin = (-0.5f * view.bottom + yDiff).toInt()
            view.setLayoutParams(lp)
        }

@@ -155,18 +176,6 @@ class DefaultClockController(
        override fun onTimeZoneChanged(timeZone: TimeZone) =
            clocks.forEach { it.onTimeZoneChanged(timeZone) }

        override fun onFontSettingChanged() {
            smallClock.view.setTextSize(
                TypedValue.COMPLEX_UNIT_PX,
                resources.getDimensionPixelSize(R.dimen.small_clock_text_size).toFloat()
            )
            largeClock.view.setTextSize(
                TypedValue.COMPLEX_UNIT_PX,
                resources.getDimensionPixelSize(R.dimen.large_clock_text_size).toFloat()
            )
            largeClock.recomputePadding()
        }

        override fun onColorPaletteChanged(resources: Resources) {
            largeClock.updateColor()
            smallClock.updateColor()
+16 −7
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.R
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
@@ -43,6 +44,11 @@ import com.android.systemui.shared.regionsampling.RegionSampler
import com.android.systemui.statusbar.policy.BatteryController
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback
import com.android.systemui.statusbar.policy.ConfigurationController
import java.io.PrintWriter
import java.util.Locale
import java.util.TimeZone
import java.util.concurrent.Executor
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.Job
@@ -50,11 +56,6 @@ import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch
import java.io.PrintWriter
import java.util.Locale
import java.util.TimeZone
import java.util.concurrent.Executor
import javax.inject.Inject

/**
 * Controller for a Clock provided by the registry and used on the keyguard. Instantiated by
@@ -84,6 +85,7 @@ open class ClockEventController @Inject constructor(

                value.initialize(resources, dozeAmount, 0f)
                updateRegionSamplers(value)
                updateFontSizes()
            }
        }

@@ -150,7 +152,7 @@ open class ClockEventController @Inject constructor(
            mainExecutor,
            bgExecutor,
            regionSamplingEnabled,
            updateFun = { updateColors() } )
            updateColors)
    }

    var smallRegionSampler: RegionSampler? = null
@@ -166,7 +168,7 @@ open class ClockEventController @Inject constructor(
        }

        override fun onDensityOrFontScaleChanged() {
            clock?.events?.onFontSettingChanged()
            updateFontSizes()
        }
    }

@@ -251,6 +253,13 @@ open class ClockEventController @Inject constructor(
        largeRegionSampler?.stopRegionSampler()
    }

    private fun updateFontSizes() {
        clock?.smallClock?.events?.onFontSettingChanged(
            resources.getDimensionPixelSize(R.dimen.small_clock_text_size).toFloat())
        clock?.largeClock?.events?.onFontSettingChanged(
            resources.getDimensionPixelSize(R.dimen.large_clock_text_size).toFloat())
    }

    /**
     * Dump information for debugging
     */
Loading