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

Commit 1b35ce6d authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Additional clock interface method for region target and font sizes

Bug: 242332467
Bug: 242332371
Test: Manually checked existing clock positions and sizes
Change-Id: I3feea196bf348630697385e010a13955cdb0a897
parent d8251475
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line 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/RegisterReceiverViaContextDetectorTest.kt
-packages/SystemUI/checks/tests/com/android/systemui/lint/SoftwareBitmapDetectorTest.kt
-packages/SystemUI/checks/tests/com/android/systemui/lint/SoftwareBitmapDetectorTest.kt
-packages/SystemUI/monet/src/com/android/systemui/monet/ColorScheme.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/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/Flag.kt
-packages/SystemUI/shared/src/com/android/systemui/flags/FlagListenable.kt
-packages/SystemUI/shared/src/com/android/systemui/flags/FlagListenable.kt
+29 −17
Original line number Original line Diff line number Diff line
@@ -99,9 +99,6 @@ interface ClockEvents {
    /** Call whenever the locale changes */
    /** Call whenever the locale changes */
    fun onLocaleChanged(locale: Locale) {}
    fun onLocaleChanged(locale: Locale) {}


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

    /** Call whenever the color palette should update */
    /** Call whenever the color palette should update */
    fun onColorPaletteChanged(resources: Resources) {}
    fun onColorPaletteChanged(resources: Resources) {}
}
}
@@ -136,10 +133,25 @@ interface ClockAnimations {
interface ClockFaceEvents {
interface ClockFaceEvents {
    /** Region Darkness specific to the clock face */
    /** Region Darkness specific to the clock face */
    fun onRegionDarknessChanged(isDark: Boolean) {}
    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 */
/** Some data about a clock design */
data class ClockMetadata(
data class ClockMetadata(
    val clockId: ClockId,
    val clockId: ClockId,
    val name: String
    val name: String,
)
)
+0 −1
Original line number Original line Diff line number Diff line
@@ -37,7 +37,6 @@
        android:id="@+id/lockscreen_clock_view_large"
        android:id="@+id/lockscreen_clock_view_large"
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="@dimen/keyguard_large_clock_top_margin"
        android:clipChildren="false"
        android:clipChildren="false"
        android:visibility="gone" />
        android:visibility="gone" />


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


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


        init {
        init {
            view.setColors(currentColor, currentColor)
            view.setColors(currentColor, currentColor)
@@ -112,7 +114,19 @@ class DefaultClockController(
                    this@DefaultClockFaceController.isRegionDark = isRegionDark
                    this@DefaultClockFaceController.isRegionDark = isRegionDark
                    updateColor()
                    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() {
        fun updateColor() {
            val color =
            val color =
@@ -135,9 +149,16 @@ class DefaultClockController(
    inner class LargeClockFaceController(
    inner class LargeClockFaceController(
        view: AnimatableClockView,
        view: AnimatableClockView,
    ) : DefaultClockFaceController(view) {
    ) : 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
            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)
            view.setLayoutParams(lp)
        }
        }


@@ -155,18 +176,6 @@ class DefaultClockController(
        override fun onTimeZoneChanged(timeZone: TimeZone) =
        override fun onTimeZoneChanged(timeZone: TimeZone) =
            clocks.forEach { it.onTimeZoneChanged(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) {
        override fun onColorPaletteChanged(resources: Resources) {
            largeClock.updateColor()
            largeClock.updateColor()
            smallClock.updateColor()
            smallClock.updateColor()
+16 −7
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.R
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
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
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback
import com.android.systemui.statusbar.policy.ConfigurationController
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.CoroutineScope
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.Job
import kotlinx.coroutines.Job
@@ -50,11 +56,6 @@ import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch
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
 * 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)
                value.initialize(resources, dozeAmount, 0f)
                updateRegionSamplers(value)
                updateRegionSamplers(value)
                updateFontSizes()
            }
            }
        }
        }


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


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


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


@@ -251,6 +253,13 @@ open class ClockEventController @Inject constructor(
        largeRegionSampler?.stopRegionSampler()
        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
     * Dump information for debugging
     */
     */
Loading