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

Commit 3f016660 authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Add Axis options to clock interface

Test: NONE
Bug: 364673977
Flag: NONE Api only change, callsites flagged
Change-Id: I5ed57023db4a3abe814917db3b7fec247333f5ce
parent ba505abd
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.systemui.plugins.clocks.ClockFaceConfig
import com.android.systemui.plugins.clocks.ClockFaceController
import com.android.systemui.plugins.clocks.ClockFaceEvents
import com.android.systemui.plugins.clocks.ClockMessageBuffers
import com.android.systemui.plugins.clocks.ClockReactiveSetting
import com.android.systemui.plugins.clocks.ClockSettings
import com.android.systemui.plugins.clocks.DefaultClockFaceLayout
import com.android.systemui.plugins.clocks.WeatherData
@@ -73,7 +74,7 @@ class DefaultClockController(
        ClockConfig(
            DEFAULT_CLOCK_ID,
            resources.getString(R.string.clock_default_name),
            resources.getString(R.string.clock_default_description)
            resources.getString(R.string.clock_default_description),
        )
    }

@@ -84,14 +85,14 @@ class DefaultClockController(
                layoutInflater.inflate(R.layout.clock_default_small, parent, false)
                    as AnimatableClockView,
                settings?.seedColor,
                messageBuffers?.smallClockMessageBuffer
                messageBuffers?.smallClockMessageBuffer,
            )
        largeClock =
            LargeClockFaceController(
                layoutInflater.inflate(R.layout.clock_default_large, parent, false)
                    as AnimatableClockView,
                settings?.seedColor,
                messageBuffers?.largeClockMessageBuffer
                messageBuffers?.largeClockMessageBuffer,
            )
        clocks = listOf(smallClock.view, largeClock.view)

@@ -272,8 +273,12 @@ class DefaultClockController(
        }

        override fun onWeatherDataChanged(data: WeatherData) {}

        override fun onAlarmDataChanged(data: AlarmData) {}

        override fun onZenDataChanged(data: ZenData) {}

        override fun onReactiveAxesChanged(axes: List<ClockReactiveSetting>) {}
    }

    open inner class DefaultClockAnimations(
@@ -340,10 +345,9 @@ class DefaultClockController(
        }
    }

    class AnimationState(
        var fraction: Float,
    ) {
    class AnimationState(var fraction: Float) {
        var isActive: Boolean = fraction > 0.5f

        fun update(newFraction: Float): Pair<Boolean, Boolean> {
            if (newFraction == fraction) {
                return Pair(isActive, false)
+60 −16
Original line number Diff line number Diff line
@@ -69,11 +69,7 @@ interface ClockController {
    val events: ClockEvents

    /** Initializes various rendering parameters. If never called, provides reasonable defaults. */
    fun initialize(
        resources: Resources,
        dozeFraction: Float,
        foldFraction: Float,
    )
    fun initialize(resources: Resources, dozeFraction: Float, foldFraction: Float)

    /** Optional method for dumping debug information */
    fun dump(pw: PrintWriter)
@@ -109,11 +105,7 @@ data class ClockMessageBuffers(
    val largeClockMessageBuffer: MessageBuffer,
)

data class AodClockBurnInModel(
    val scale: Float,
    val translationX: Float,
    val translationY: Float,
)
data class AodClockBurnInModel(val scale: Float, val translationX: Float, val translationY: Float)

/** Specifies layout information for the */
interface ClockFaceLayout {
@@ -180,8 +172,20 @@ interface ClockEvents {

    /** Call with zen/dnd information */
    fun onZenDataChanged(data: ZenData)

    /** Update reactive axes for this clock */
    fun onReactiveAxesChanged(axes: List<ClockReactiveSetting>)
}

/** Axis setting value for a clock */
data class ClockReactiveSetting(
    /** Axis key; matches ClockReactiveAxis.key */
    val key: String,

    /** Value to set this axis to */
    val value: Float,
)

/** Methods which trigger various clock animations */
interface ClockAnimations {
    /** Runs an enter animation (if any) */
@@ -264,9 +268,7 @@ enum class ClockTickRate(val value: Int) {
}

/** Some data about a clock design */
data class ClockMetadata(
    val clockId: ClockId,
)
data class ClockMetadata(val clockId: ClockId)

data class ClockPickerConfig(
    val id: String,
@@ -283,10 +285,46 @@ data class ClockPickerConfig(
    /** True if the clock will react to tone changes in the seed color */
    val isReactiveToTone: Boolean = true,

    /** True if the clock is capable of chagning style in reaction to touches */
    /** True if the clock is capable of changing style in reaction to touches */
    val isReactiveToTouch: Boolean = false,

    /** Font axes that can be modified on this clock */
    val axes: List<ClockReactiveAxis> = listOf(),
)

/** Represents an Axis that can be modified */
data class ClockReactiveAxis(
    /** Axis key, not user renderable */
    val key: String,

    /** Intended mode of user interaction */
    val type: AxisType,

    /** Maximum value the axis supports */
    val maxValue: Float,

    /** Minimum value the axis supports */
    val minValue: Float,

    /** Current value the axis is set to */
    val currentValue: Float,

    /** User-renderable name of the axis */
    val name: String,

    /** Description of the axis */
    val description: String,
)

/** Axis user interaction modes */
enum class AxisType {
    /** Boolean toggle. Swaps between minValue & maxValue */
    Toggle,

    /** Continuous slider between minValue & maxValue */
    Slider,
}

/** Render configuration for the full clock. Modifies the way systemUI behaves with this clock. */
data class ClockConfig(
    val id: String,
@@ -300,7 +338,8 @@ data class ClockConfig(
    /** Transition to AOD should move smartspace like large clock instead of small clock */
    val useAlternateSmartspaceAODTransition: Boolean = false,

    @Deprecated("TODO(b/352049256): Remove")
    /** Use ClockPickerConfig.isReactiveToTone instead */
    @Deprecated("TODO(b/352049256): Remove in favor of ClockPickerConfig.isReactiveToTone")
    val isReactiveToTone: Boolean = true,

    /** True if the clock is large frame clock, which will use weather in compose. */
@@ -331,6 +370,7 @@ data class ClockFaceConfig(
data class ClockSettings(
    val clockId: ClockId? = null,
    val seedColor: Int? = null,
    val axes: List<ClockReactiveSetting>? = null,
) {
    // Exclude metadata from equality checks
    var metadata: JSONObject = JSONObject()
@@ -345,6 +385,8 @@ data class ClockSettings(
                return ""
            }

            // TODO(b/364673977): Serialize axes

            return JSONObject()
                .put(KEY_CLOCK_ID, setting.clockId)
                .put(KEY_SEED_COLOR, setting.seedColor)
@@ -357,11 +399,13 @@ data class ClockSettings(
                return null
            }

            // TODO(b/364673977): Deserialize axes

            val json = JSONObject(jsonStr)
            val result =
                ClockSettings(
                    if (!json.isNull(KEY_CLOCK_ID)) json.getString(KEY_CLOCK_ID) else null,
                    if (!json.isNull(KEY_SEED_COLOR)) json.getInt(KEY_SEED_COLOR) else null
                    if (!json.isNull(KEY_SEED_COLOR)) json.getInt(KEY_SEED_COLOR) else null,
                )
            if (!json.isNull(KEY_METADATA)) {
                result.metadata = json.getJSONObject(KEY_METADATA)