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 | |
Robert Snoeberger | 9ad03f4 | 2019-02-28 14:47:49 -0500 | [diff] [blame] | 18 | import android.content.res.Resources; |
| 19 | import android.graphics.Bitmap; |
| 20 | import android.graphics.BitmapFactory; |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 21 | import android.graphics.Paint.Style; |
| 22 | import android.view.LayoutInflater; |
| 23 | import android.view.View; |
| 24 | import android.widget.TextClock; |
| 25 | |
| 26 | import com.android.keyguard.R; |
| 27 | import com.android.systemui.plugins.ClockPlugin; |
| 28 | |
| 29 | import java.util.TimeZone; |
| 30 | |
| 31 | /** |
| 32 | * Controller for Stretch clock that can appear on lock screen and AOD. |
| 33 | */ |
| 34 | public class StretchAnalogClockController implements ClockPlugin { |
| 35 | |
| 36 | /** |
Robert Snoeberger | 9ad03f4 | 2019-02-28 14:47:49 -0500 | [diff] [blame] | 37 | * Resources used to get title and thumbnail. |
| 38 | */ |
| 39 | private final Resources mResources; |
| 40 | |
| 41 | /** |
| 42 | * LayoutInflater used to inflate custom clock views. |
| 43 | */ |
| 44 | private final LayoutInflater mLayoutInflater; |
| 45 | |
| 46 | /** |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 47 | * Custom clock shown on AOD screen and behind stack scroller on lock. |
| 48 | */ |
| 49 | private View mBigClockView; |
| 50 | private TextClock mDigitalClock; |
| 51 | private StretchAnalogClock mAnalogClock; |
| 52 | |
| 53 | /** |
| 54 | * Small clock shown on lock screen above stack scroller. |
| 55 | */ |
| 56 | private View mView; |
| 57 | private TextClock mLockClock; |
| 58 | |
| 59 | /** |
| 60 | * Controller for transition to dark state. |
| 61 | */ |
| 62 | private CrossFadeDarkController mDarkController; |
| 63 | |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 64 | /** |
| 65 | * Create a BubbleClockController instance. |
| 66 | * |
| 67 | * @param layoutInflater Inflater used to inflate custom clock views. |
| 68 | */ |
Robert Snoeberger | 9ad03f4 | 2019-02-28 14:47:49 -0500 | [diff] [blame] | 69 | public StretchAnalogClockController(Resources res, LayoutInflater inflater) { |
| 70 | mResources = res; |
| 71 | mLayoutInflater = inflater; |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 72 | } |
| 73 | |
Robert Snoeberger | 9ad03f4 | 2019-02-28 14:47:49 -0500 | [diff] [blame] | 74 | private void createViews() { |
| 75 | mBigClockView = mLayoutInflater.inflate(R.layout.stretchanalog_clock, null); |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 76 | mAnalogClock = mBigClockView.findViewById(R.id.analog_clock); |
| 77 | mDigitalClock = mBigClockView.findViewById(R.id.digital_clock); |
| 78 | |
Robert Snoeberger | 9ad03f4 | 2019-02-28 14:47:49 -0500 | [diff] [blame] | 79 | mView = mLayoutInflater.inflate(R.layout.digital_clock, null); |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 80 | mLockClock = mView.findViewById(R.id.lock_screen_clock); |
| 81 | mLockClock.setVisibility(View.GONE); |
| 82 | |
| 83 | mDarkController = new CrossFadeDarkController(mDigitalClock, mLockClock); |
| 84 | } |
| 85 | |
| 86 | @Override |
Robert Snoeberger | 9ad03f4 | 2019-02-28 14:47:49 -0500 | [diff] [blame] | 87 | public String getName() { |
| 88 | return "stretch"; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public String getTitle() { |
| 93 | return mResources.getString(R.string.clock_title_stretch); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public Bitmap getThumbnail() { |
| 98 | return BitmapFactory.decodeResource(mResources, R.drawable.stretch_thumbnail); |
| 99 | } |
| 100 | |
| 101 | @Override |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 102 | public View getView() { |
Robert Snoeberger | 9ad03f4 | 2019-02-28 14:47:49 -0500 | [diff] [blame] | 103 | if (mView == null) { |
| 104 | createViews(); |
| 105 | } |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 106 | return mView; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public View getBigClockView() { |
Robert Snoeberger | 9ad03f4 | 2019-02-28 14:47:49 -0500 | [diff] [blame] | 111 | if (mBigClockView == null) { |
| 112 | createViews(); |
| 113 | } |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 114 | return mBigClockView; |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void setStyle(Style style) {} |
| 119 | |
| 120 | @Override |
| 121 | public void setTextColor(int color) { |
| 122 | mLockClock.setTextColor(color); |
Robert Snoeberger | 0397c84 | 2019-02-07 14:25:46 -0500 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public void setColorPalette(boolean supportsDarkText, int[] colorPalette) { |
| 127 | if (colorPalette == null || colorPalette.length == 0) { |
| 128 | return; |
| 129 | } |
| 130 | final int length = colorPalette.length; |
| 131 | mDigitalClock.setTextColor(colorPalette[Math.max(0, length - 5)]); |
| 132 | mAnalogClock.setClockColor(colorPalette[Math.max(0, length - 5)], |
| 133 | colorPalette[Math.max(0, length - 2)]); |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | @Override |
Robert Snoeberger | 9ad03f4 | 2019-02-28 14:47:49 -0500 | [diff] [blame] | 137 | public void onTimeTick() { |
Robert Snoeberger | 496916b | 2019-01-15 18:00:58 -0500 | [diff] [blame] | 138 | mAnalogClock.onTimeChanged(); |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public void setDarkAmount(float darkAmount) { |
| 143 | mDarkController.setDarkAmount(darkAmount); |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public void onTimeZoneChanged(TimeZone timeZone) { |
| 148 | mAnalogClock.onTimeZoneChanged(timeZone); |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public boolean shouldShowStatusArea() { |
| 153 | return false; |
| 154 | } |
| 155 | } |