-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ClockController.java
140 lines (115 loc) · 4.67 KB
/
ClockController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package com.android.systemui.statusbar.phone;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import com.android.systemui.FontSizeUtils;
import com.android.systemui.R;
import com.android.systemui.statusbar.policy.Clock;
import com.android.systemui.tuner.TunerService;
import static com.android.systemui.statusbar.policy.Clock.AM_PM_STYLE_GONE;
import static com.android.systemui.statusbar.policy.Clock.CLOCK_SECONDS;
/**
* To control your...clock
*/
public class ClockController implements TunerService.Tunable {
private static final String TAG = "ClockController";
public static final int CLOCK_POSITION_RIGHT = 0;
public static final int CLOCK_POSITION_CENTER = 1;
public static final int CLOCK_POSITION_LEFT = 2;
public static final String CLOCK_POSITION = "cmsystem:status_bar_clock";
public static final String CLOCK_STYLE = "cmsystem:status_bar_am_pm";
private final NotificationIconAreaController mNotificationIconAreaController;
private final Context mContext;
private Clock mRightClock, mCenterClock, mLeftClock, mActiveClock;
private int mAmPmStyle = AM_PM_STYLE_GONE;
private int mClockPosition = CLOCK_POSITION_RIGHT;
private boolean mClockVisible = true;
private boolean mShowSeconds = false;
private int mIconTint = Color.WHITE;
public ClockController(View statusBar,
NotificationIconAreaController notificationIconAreaController, Handler handler) {
mRightClock = (Clock) statusBar.findViewById(R.id.clock);
mCenterClock = (Clock) statusBar.findViewById(R.id.center_clock);
mLeftClock = (Clock) statusBar.findViewById(R.id.left_clock);
mNotificationIconAreaController = notificationIconAreaController;
mContext = statusBar.getContext();
mActiveClock = mRightClock;
TunerService.get(mContext).addTunable(this, CLOCK_POSITION, CLOCK_STYLE, CLOCK_SECONDS);
}
private Clock getClockForCurrentLocation() {
Clock clockForAlignment;
switch (mClockPosition) {
case CLOCK_POSITION_CENTER:
clockForAlignment = mCenterClock;
break;
case CLOCK_POSITION_LEFT:
clockForAlignment = mLeftClock;
break;
case CLOCK_POSITION_RIGHT:
default:
clockForAlignment = mRightClock;
break;
}
return clockForAlignment;
}
private void updateActiveClock() {
mActiveClock.setVisibility(View.GONE);
if (!mClockVisible) {
return;
}
mActiveClock = getClockForCurrentLocation();
mActiveClock.setVisibility(View.VISIBLE);
mActiveClock.setAmPmStyle(mAmPmStyle);
mActiveClock.setShowSeconds(mShowSeconds);
setClockAndDateStatus();
setTextColor(mIconTint);
updateFontSize();
}
@Override
public void onTuningChanged(String key, String newValue) {
Log.d(TAG, "onTuningChanged key=" + key + " value=" + newValue);
if (CLOCK_POSITION.equals(key)) {
mClockPosition = newValue == null ? CLOCK_POSITION_RIGHT : Integer.valueOf(newValue);
} else if (CLOCK_STYLE.equals(key)) {
mAmPmStyle = newValue == null ? AM_PM_STYLE_GONE : Integer.valueOf(newValue);
} else if (CLOCK_SECONDS.equals(key)) {
mShowSeconds = newValue != null && Integer.parseInt(newValue) != 0;
}
updateActiveClock();
}
private void setClockAndDateStatus() {
if (mNotificationIconAreaController != null) {
mNotificationIconAreaController.setClockAndDateStatus(mClockPosition);
}
}
public void setVisibility(boolean visible) {
if (mActiveClock != null) {
mActiveClock.setVisibility(visible ? View.VISIBLE : View.GONE);
}
mClockVisible = visible;
}
public void setTextColor(int iconTint) {
mIconTint = iconTint;
if (mActiveClock != null) {
mActiveClock.setTextColor(iconTint);
}
}
public void setTextColor(Rect tintArea, int iconTint) {
if (mActiveClock != null) {
setTextColor(StatusBarIconController.getTint(tintArea, mActiveClock, iconTint));
}
}
public void updateFontSize() {
if (mActiveClock != null) {
FontSizeUtils.updateFontSize(mActiveClock, R.dimen.status_bar_clock_size);
}
}
public void setPaddingRelative(int start, int top, int end, int bottom) {
if (mActiveClock != null) {
mActiveClock.setPaddingRelative(start, top, end, bottom);
}
}
}