1 /* 2 * Copyright (C) 2022 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.shared.clocks 15 16 import android.content.Context 17 import android.content.res.Resources 18 import android.graphics.drawable.Drawable 19 import android.view.LayoutInflater 20 import com.android.systemui.customization.R 21 import com.android.systemui.plugins.ClockController 22 import com.android.systemui.plugins.ClockId 23 import com.android.systemui.plugins.ClockMetadata 24 import com.android.systemui.plugins.ClockProvider 25 import com.android.systemui.plugins.ClockSettings 26 27 private val TAG = DefaultClockProvider::class.simpleName 28 const val DEFAULT_CLOCK_NAME = "Default Clock" 29 const val DEFAULT_CLOCK_ID = "DEFAULT" 30 31 /** Provides the default system clock */ 32 class DefaultClockProvider( 33 val ctx: Context, 34 val layoutInflater: LayoutInflater, 35 val resources: Resources, 36 val hasStepClockAnimation: Boolean = false 37 ) : ClockProvider { 38 override fun getClocks(): List<ClockMetadata> = 39 listOf(ClockMetadata(DEFAULT_CLOCK_ID, DEFAULT_CLOCK_NAME)) 40 41 override fun createClock(settings: ClockSettings): ClockController { 42 if (settings.clockId != DEFAULT_CLOCK_ID) { 43 throw IllegalArgumentException("${settings.clockId} is unsupported by $TAG") 44 } 45 46 return DefaultClockController( 47 ctx, 48 layoutInflater, 49 resources, 50 settings, 51 hasStepClockAnimation, 52 ) 53 } 54 55 override fun getClockThumbnail(id: ClockId): Drawable? { 56 if (id != DEFAULT_CLOCK_ID) { 57 throw IllegalArgumentException("$id is unsupported by $TAG") 58 } 59 60 // TODO: Update placeholder to actual resource 61 return resources.getDrawable(R.drawable.clock_default_thumbnail, null) 62 } 63 } 64