Robert Snoeberger | ce8c204 | 2019-01-17 10:36:02 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.keyguard.clock; |
| 17 | |
| 18 | import android.graphics.Paint.Style; |
| 19 | import android.view.LayoutInflater; |
| 20 | import android.view.View; |
| 21 | |
| 22 | import com.android.keyguard.R; |
| 23 | import com.android.systemui.plugins.ClockPlugin; |
| 24 | |
| 25 | import java.util.TimeZone; |
| 26 | |
| 27 | /** |
| 28 | * Plugin for a custom Typographic clock face that displays the time in words. |
| 29 | */ |
| 30 | public class TypeClockController implements ClockPlugin { |
| 31 | |
| 32 | /** |
| 33 | * Custom clock shown on AOD screen and behind stack scroller on lock. |
| 34 | */ |
| 35 | private View mView; |
| 36 | private TypographicClock mTypeClock; |
| 37 | |
| 38 | /** |
| 39 | * Small clock shown on lock screen above stack scroller. |
| 40 | */ |
| 41 | private View mLockClockContainer; |
| 42 | |
| 43 | /** |
| 44 | * Controller for transition into dark state. |
| 45 | */ |
| 46 | private CrossFadeDarkController mDarkController; |
| 47 | |
| 48 | private TypeClockController() {} |
| 49 | |
| 50 | /** |
| 51 | * Create a TypeClockController instance. |
| 52 | * |
| 53 | * @param inflater Inflater used to inflate custom clock views. |
| 54 | */ |
| 55 | public static TypeClockController build(LayoutInflater inflater) { |
| 56 | TypeClockController controller = new TypeClockController(); |
| 57 | controller.createViews(inflater); |
| 58 | return controller; |
| 59 | } |
| 60 | |
| 61 | private void createViews(LayoutInflater inflater) { |
| 62 | mView = inflater.inflate(R.layout.type_clock, null); |
| 63 | mTypeClock = mView.findViewById(R.id.type_clock); |
| 64 | |
| 65 | // For now, this view is used to hide the default digital clock. |
| 66 | // Need better transition to lock screen. |
| 67 | mLockClockContainer = inflater.inflate(R.layout.digital_clock, null); |
| 68 | mLockClockContainer.setVisibility(View.GONE); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public View getView() { |
| 73 | return mLockClockContainer; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public View getBigClockView() { |
| 78 | return mView; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public void setStyle(Style style) {} |
| 83 | |
| 84 | @Override |
| 85 | public void setTextColor(int color) { |
| 86 | mTypeClock.setTextColor(color); |
| 87 | } |
| 88 | |
| 89 | @Override |
Robert Snoeberger | 0397c84 | 2019-02-07 14:25:46 -0500 | [diff] [blame] | 90 | public void setColorPalette(boolean supportsDarkText, int[] colorPalette) { |
| 91 | if (colorPalette == null || colorPalette.length == 0) { |
| 92 | return; |
| 93 | } |
| 94 | final int length = colorPalette.length; |
| 95 | mTypeClock.setClockColor(colorPalette[Math.max(0, length - 5)]); |
| 96 | } |
| 97 | |
| 98 | @Override |
Robert Snoeberger | ce8c204 | 2019-01-17 10:36:02 -0500 | [diff] [blame] | 99 | public void dozeTimeTick() { |
| 100 | mTypeClock.onTimeChanged(); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public void setDarkAmount(float darkAmount) {} |
| 105 | |
| 106 | @Override |
| 107 | public void onTimeZoneChanged(TimeZone timeZone) { |
| 108 | mTypeClock.onTimeZoneChanged(timeZone); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public boolean shouldShowStatusArea() { |
| 113 | return false; |
| 114 | } |
| 115 | } |