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.clocks.ClockController 22 import com.android.systemui.plugins.clocks.ClockId 23 import com.android.systemui.plugins.clocks.ClockMessageBuffers 24 import com.android.systemui.plugins.clocks.ClockMetadata 25 import com.android.systemui.plugins.clocks.ClockProvider 26 import com.android.systemui.plugins.clocks.ClockSettings 27 28 private val TAG = DefaultClockProvider::class.simpleName 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 val migratedClocks: Boolean = false 38 ) : ClockProvider { 39 private var messageBuffers: ClockMessageBuffers? = null 40 initializenull41 override fun initialize(buffers: ClockMessageBuffers?) { 42 messageBuffers = buffers 43 } 44 getClocksnull45 override fun getClocks(): List<ClockMetadata> = listOf(ClockMetadata(DEFAULT_CLOCK_ID)) 46 47 override fun createClock(settings: ClockSettings): ClockController { 48 if (settings.clockId != DEFAULT_CLOCK_ID) { 49 throw IllegalArgumentException("${settings.clockId} is unsupported by $TAG") 50 } 51 52 return DefaultClockController( 53 ctx, 54 layoutInflater, 55 resources, 56 settings, 57 hasStepClockAnimation, 58 migratedClocks, 59 messageBuffers, 60 ) 61 } 62 getClockThumbnailnull63 override fun getClockThumbnail(id: ClockId): Drawable? { 64 if (id != DEFAULT_CLOCK_ID) { 65 throw IllegalArgumentException("$id is unsupported by $TAG") 66 } 67 68 // TODO: Update placeholder to actual resource 69 return resources.getDrawable(R.drawable.clock_default_thumbnail, null) 70 } 71 } 72