• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 package com.android.systemui.plugins.clocks
15 
16 import android.graphics.drawable.Drawable
17 
18 data class ClockPickerConfig
19 @JvmOverloads
20 constructor(
21     val id: String,
22 
23     /** Localized name of the clock */
24     val name: String,
25 
26     /** Localized accessibility description for the clock */
27     val description: String,
28 
29     /* Static & lightweight thumbnail version of the clock */
30     val thumbnail: Drawable,
31 
32     /** True if the clock will react to tone changes in the seed color */
33     val isReactiveToTone: Boolean = true,
34 
35     /** Font axes that can be modified on this clock */
36     val axes: List<ClockFontAxis> = listOf(),
37 
38     /** Presets for this clock. Null indicates the preset list should be disabled. */
39     val presetConfig: AxisPresetConfig? = null,
40 )
41 
42 data class AxisPresetConfig(
43     /** Groups of Presets. Each group can be used together in a single control. */
44     val groups: List<Group>,
45 
46     /** Preset item currently being used, null when the current style is not a preset */
47     val current: IndexedStyle? = null,
48 ) {
49     /** The selected clock axis style, and its indices */
50     data class IndexedStyle(
51         /** Index of the group that this clock axis style appears in */
52         val groupIndex: Int,
53 
54         /** Index of the preset within the group */
55         val presetIndex: Int,
56 
57         /** Reference to the style in question */
58         val style: ClockAxisStyle,
59     )
60 
61     /** A group of preset styles */
62     data class Group(
63         /* List of preset styles in this group */
64         val presets: List<ClockAxisStyle>,
65 
66         /* Icon to use when this preset-group is active */
67         val icon: Drawable,
68     )
69 
70     fun findStyle(style: ClockAxisStyle): IndexedStyle? {
71         groups.forEachIndexed { groupIndex, group ->
72             group.presets.forEachIndexed { presetIndex, preset ->
73                 if (preset == style) {
74                     return@findStyle IndexedStyle(
75                         groupIndex = groupIndex,
76                         presetIndex = presetIndex,
77                         style = preset,
78                     )
79                 }
80             }
81         }
82         return null
83     }
84 }
85 
86 /** Represents an Axis that can be modified */
87 data class ClockFontAxis(
88     /** Axis key, not user renderable */
89     val key: String,
90 
91     /** Intended mode of user interaction */
92     val type: AxisType,
93 
94     /** Maximum value the axis supports */
95     val maxValue: Float,
96 
97     /** Minimum value the axis supports */
98     val minValue: Float,
99 
100     /** Current value the axis is set to */
101     val currentValue: Float,
102 
103     /** User-renderable name of the axis */
104     val name: String,
105 
106     /** Description of the axis */
107     val description: String,
108 ) {
109     companion object {
mergenull110         fun List<ClockFontAxis>.merge(axisStyle: ClockAxisStyle): List<ClockFontAxis> {
111             return this.map { axis ->
112                     axisStyle.get(axis.key)?.let { axis.copy(currentValue = it) } ?: axis
113                 }
114                 .toList()
115         }
116     }
117 }
118 
119 /** Axis user interaction modes */
120 enum class AxisType {
121     /** Continuous range between minValue & maxValue. */
122     Float,
123 
124     /** Only minValue & maxValue are valid. No intermediate values between them are allowed. */
125     Boolean,
126 }
127