blob: c4651149521cb73624a34fd68ae32216cc411672 [file] [log] [blame]
Robert Snoeberger496916b2019-01-15 18:00:58 -05001/*
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 */
16package com.android.keyguard.clock;
17
18import android.graphics.Paint.Style;
19import android.view.LayoutInflater;
20import android.view.View;
21import android.widget.TextClock;
22
23import com.android.keyguard.R;
24import com.android.systemui.plugins.ClockPlugin;
25
26import java.util.TimeZone;
27
28/**
29 * Controller for Stretch clock that can appear on lock screen and AOD.
30 */
31public 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 Snoeberger0397c842019-02-07 14:25:46 -050092 }
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 Snoeberger496916b2019-01-15 18:00:58 -0500103 }
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}