Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -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 | import android.widget.TextClock; |
| 22 | |
| 23 | import com.android.keyguard.R; |
| 24 | import com.android.systemui.plugins.ClockPlugin; |
| 25 | |
| 26 | import java.util.TimeZone; |
| 27 | |
| 28 | /** |
| 29 | * Controller for Stretch clock that can appear on lock screen and AOD. |
| 30 | */ |
| 31 | public class StretchAnalogClockController implements ClockPlugin { |
| 32 | |
| 33 | /** |
| 34 | * Custom clock shown on AOD screen and behind stack scroller on lock. |
| 35 | */ |
| 36 | private View mBigClockView; |
| 37 | private TextClock mDigitalClock; |
| 38 | private StretchAnalogClock mAnalogClock; |
| 39 | |
| 40 | /** |
| 41 | * Small clock shown on lock screen above stack scroller. |
| 42 | */ |
| 43 | private View mView; |
| 44 | private TextClock mLockClock; |
| 45 | |
| 46 | /** |
| 47 | * Controller for transition to dark state. |
| 48 | */ |
| 49 | private CrossFadeDarkController mDarkController; |
| 50 | |
| 51 | private StretchAnalogClockController() { } |
| 52 | |
| 53 | /** |
| 54 | * Create a BubbleClockController instance. |
| 55 | * |
| 56 | * @param layoutInflater Inflater used to inflate custom clock views. |
| 57 | */ |
| 58 | public static StretchAnalogClockController build(LayoutInflater layoutInflater) { |
| 59 | StretchAnalogClockController controller = new StretchAnalogClockController(); |
| 60 | controller.createViews(layoutInflater); |
| 61 | return controller; |
| 62 | } |
| 63 | |
| 64 | private void createViews(LayoutInflater layoutInflater) { |
| 65 | mBigClockView = layoutInflater.inflate(R.layout.stretchanalog_clock, null); |
| 66 | mAnalogClock = mBigClockView.findViewById(R.id.analog_clock); |
| 67 | mDigitalClock = mBigClockView.findViewById(R.id.digital_clock); |
| 68 | |
| 69 | mView = layoutInflater.inflate(R.layout.digital_clock, null); |
| 70 | mLockClock = mView.findViewById(R.id.lock_screen_clock); |
| 71 | mLockClock.setVisibility(View.GONE); |
| 72 | |
| 73 | mDarkController = new CrossFadeDarkController(mDigitalClock, mLockClock); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public View getView() { |
| 78 | return mView; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public View getBigClockView() { |
| 83 | return mBigClockView; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void setStyle(Style style) {} |
| 88 | |
| 89 | @Override |
| 90 | public void setTextColor(int color) { |
| 91 | mLockClock.setTextColor(color); |
Robert Snoeberger | 0397c84 | 2019-02-07 14:25:46 -0500 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public void setColorPalette(boolean supportsDarkText, int[] colorPalette) { |
| 96 | if (colorPalette == null || colorPalette.length == 0) { |
| 97 | return; |
| 98 | } |
| 99 | final int length = colorPalette.length; |
| 100 | mDigitalClock.setTextColor(colorPalette[Math.max(0, length - 5)]); |
| 101 | mAnalogClock.setClockColor(colorPalette[Math.max(0, length - 5)], |
| 102 | colorPalette[Math.max(0, length - 2)]); |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void dozeTimeTick() { |
| 107 | mAnalogClock.onTimeChanged(); |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public void setDarkAmount(float darkAmount) { |
| 112 | mDarkController.setDarkAmount(darkAmount); |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public void onTimeZoneChanged(TimeZone timeZone) { |
| 117 | mAnalogClock.onTimeZoneChanged(timeZone); |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public boolean shouldShowStatusArea() { |
| 122 | return false; |
| 123 | } |
| 124 | } |