1 /* 2 * 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.content.Context 17 import android.graphics.Rect 18 import com.android.systemui.plugins.annotations.ProtectedInterface 19 20 /** Events that have specific data about the related face */ 21 @ProtectedInterface 22 interface ClockFaceEvents { 23 /** Call every tick to update the rendered time */ onTimeTicknull24 fun onTimeTick() 25 26 /** 27 * Call whenever the theme or seedColor is updated 28 * 29 * Theme can be specific to the clock face. 30 * - isDarkTheme -> clock should be light 31 * - !isDarkTheme -> clock should be dark 32 */ 33 fun onThemeChanged(theme: ThemeConfig) 34 35 /** 36 * Call whenever font settings change. Pass in a target font size in pixels. The specific clock 37 * design is allowed to ignore this target size on a case-by-case basis. 38 */ 39 fun onFontSettingChanged(fontSizePx: Float) 40 41 /** 42 * Target region information for the clock face. For small clock, this will match the bounds of 43 * the parent view mostly, but have a target height based on the height of the default clock. 44 * For large clocks, the parent view is the entire device size, but most clocks will want to 45 * render within the centered targetRect to avoid obstructing other elements. The specified 46 * targetRegion is relative to the parent view. 47 */ 48 @Deprecated("No longer necessary, pending removal") 49 fun onTargetRegionChanged(targetRegion: Rect?) 50 51 /** Called to notify the clock about its display. */ 52 fun onSecondaryDisplayChanged(onSecondaryDisplay: Boolean) 53 } 54 55 /** Contains Theming information for the clock face */ 56 data class ThemeConfig( 57 /** True if the clock should use dark theme (light text on dark background) */ 58 val isDarkTheme: Boolean, 59 60 /** 61 * A clock specific seed color to use when theming, if any was specified by the user. A null 62 * value denotes that we should use the seed color for the current system theme. 63 */ 64 val seedColor: Int?, 65 ) { 66 fun getDefaultColor(context: Context): Int { 67 return when { 68 seedColor != null -> seedColor!! 69 isDarkTheme -> context.resources.getColor(android.R.color.system_accent1_100) 70 else -> context.resources.getColor(android.R.color.system_accent2_600) 71 } 72 } 73 } 74