Skip to content

Commit 54a77c8

Browse files
sjp0728Anik1199
authored andcommitted
FWB: Second Clock (1/2)
Dokdo-Project/platform_frameworks_base@6ab5d62#diff-1fa71c270d063a48f921f0760d10c7f3R122 AICPfy: Bring back to L Modified for AICP source Change-Id: Ie04942ae1bb1649d18db51086b46666b56ef1ea0 Signed-off-by: Anik1199 <[email protected]> Conflicts: core/java/android/provider/Settings.java packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java
1 parent 195a8cd commit 54a77c8

File tree

2 files changed

+116
-2
lines changed

2 files changed

+116
-2
lines changed

core/java/android/provider/Settings.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,8 +4211,13 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
42114211
public static final String STATUS_BAR_SHOW_TICKER = "status_bar_show_show_ticker";
42124212

42134213
/**
4214-
* Heads Up Notifications
4215-
*
4214+
* Display second in the Clock
4215+
* @hide
4216+
*/
4217+
public static final String CLOCK_USE_SECOND = "clock_use_second";
4218+
4219+
/**
4220+
* Whether the notification light will be allowed when in zen mode during downtime
42164221
* @hide
42174222
*/
42184223
public static final String HEADS_UP_NOTIFICATION = "heads_up_enabled";

packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@
4141
import com.android.systemui.cm.UserContentObserver;
4242

4343
import java.text.SimpleDateFormat;
44+
import java.util.GregorianCalendar;
4445
import java.util.Calendar;
4546
import java.util.Date;
4647
import java.util.Locale;
4748
import java.util.TimeZone;
49+
import java.util.Timer;
50+
import java.util.TimerTask;
4851

4952
import libcore.icu.LocaleData;
5053

@@ -93,6 +96,18 @@ public class Clock implements DemoMode {
9396
private int mClockFontStyle = FONT_NORMAL;
9497
private boolean mDemoMode;
9598
private boolean mAttached;
99+
protected int mClockDateDisplay = CLOCK_DATE_DISPLAY_GONE;
100+
protected int mClockDateStyle = CLOCK_DATE_STYLE_REGULAR;
101+
protected int mClockStyle = STYLE_CLOCK_RIGHT;
102+
protected int mClockFontStyle = FONT_NORMAL;
103+
protected boolean mShowClock;
104+
private int mClockAndDateWidth;
105+
protected boolean mShowClockSeconds = false;
106+
107+
private int mAmPmStyle;
108+
109+
private SettingsObserver mSettingsObserver;
110+
private PhoneStatusBar mStatusBar;
96111

97112
class SettingsObserver extends UserContentObserver {
98113
SettingsObserver(Handler handler) {
@@ -118,12 +133,50 @@ protected void observe() {
118133
Settings.System.STATUSBAR_CLOCK_COLOR), false, this, UserHandle.USER_ALL);
119134
resolver.registerContentObserver(Settings.System.getUriFor(
120135
Settings.System.STATUSBAR_CLOCK_FONT_STYLE), false, this, UserHandle.USER_ALL);
136+
resolver.registerContentObserver(Settings.System
137+
.getUriFor(Settings.System.STATUS_BAR_CLOCK),
138+
false, this, UserHandle.USER_ALL);
139+
resolver.registerContentObserver(Settings.System
140+
.getUriFor(Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE),
141+
false, this, UserHandle.USER_ALL);
142+
resolver.registerContentObserver(Settings.System
143+
.getUriFor(Settings.System.STATUSBAR_CLOCK_STYLE), false,
144+
this, UserHandle.USER_ALL);
145+
resolver.registerContentObserver(Settings.System
146+
.getUriFor(Settings.System.STATUSBAR_CLOCK_COLOR), false,
147+
this, UserHandle.USER_ALL);
148+
resolver.registerContentObserver(Settings.System
149+
.getUriFor(Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY), false,
150+
this, UserHandle.USER_ALL);
151+
resolver.registerContentObserver(Settings.System
152+
.getUriFor(Settings.System.STATUSBAR_CLOCK_DATE_STYLE), false,
153+
this, UserHandle.USER_ALL);
154+
resolver.registerContentObserver(Settings.System
155+
.getUriFor(Settings.System.STATUSBAR_CLOCK_DATE_FORMAT), false,
156+
this, UserHandle.USER_ALL);
157+
resolver.registerContentObserver(Settings.System
158+
.getUriFor(Settings.System.STATUSBAR_CLOCK_FONT_STYLE), false,
159+
mSettingsObserver);
160+
resolver.registerContentObserver(Settings.System
161+
.getUriFor(Settings.System.CLOCK_USE_SECOND), false,
162+
mSettingsObserver);
121163
updateSettings();
122164
}
123165

124166
@Override
125167
protected void unobserve() {
126168
super.unobserve();
169+
public void onChange(boolean selfChange) {
170+
updateSettings();
171+
}
172+
}
173+
174+
private final Handler handler = new Handler();
175+
TimerTask second;
176+
177+
public Clock(Context context) {
178+
this(context, null);
179+
}
127180

128181
mContext.getContentResolver().unregisterContentObserver(this);
129182
}
@@ -241,6 +294,18 @@ private final CharSequence getSmallTime() {
241294
String clockDateFormat = Settings.System.getString(mContext.getContentResolver(),
242295
Settings.System.STATUS_BAR_DATE_FORMAT);
243296

297+
mShowClockSeconds = Settings.System.getInt(mContext.getContentResolver(),
298+
Settings.System.CLOCK_USE_SECOND, 0) == 1;
299+
if (mShowClockSeconds) {
300+
String temp = result;
301+
result = String.format("%s:%02d", temp, new GregorianCalendar().get(Calendar.SECOND));
302+
}
303+
304+
if (mClockDateDisplay != CLOCK_DATE_DISPLAY_GONE) {
305+
Date now = new Date();
306+
307+
String clockDateFormat = Settings.System.getString(getContext().getContentResolver(),
308+
Settings.System.STATUSBAR_CLOCK_DATE_FORMAT);
244309
if (clockDateFormat == null || clockDateFormat.isEmpty()) {
245310
// Set dateString to short uppercase Weekday (Default for AOKP) if empty
246311
dateString = DateFormat.format("EEE", now) + " ";
@@ -377,6 +442,50 @@ void updateSettings() {
377442
Settings.System.STATUS_BAR_DATE_STYLE, CLOCK_DATE_STYLE_REGULAR,
378443
UserHandle.USER_CURRENT));
379444
updateClock();
445+
mClockFontStyle = Settings.System.getInt(resolver,
446+
Settings.System.STATUSBAR_CLOCK_FONT_STYLE, FONT_NORMAL);
447+
448+
mShowClockSeconds = Settings.System.getIntForUser(resolver,
449+
Settings.System.CLOCK_USE_SECOND, 0,
450+
UserHandle.USER_CURRENT) == 1;
451+
452+
if (mShowClockSeconds) {
453+
second = new TimerTask()
454+
{
455+
@Override
456+
public void run() {
457+
Runnable updater = new Runnable()
458+
{
459+
public void run() {
460+
updateClock();
461+
}
462+
};
463+
handler.post(updater);
464+
}
465+
};
466+
Timer timer = new Timer();
467+
timer.schedule(second, 0, 1001);
468+
}
469+
470+
if (mAttached) {
471+
setTextColor(clockColor);
472+
getFontStyle(mClockFontStyle);
473+
updateClockVisibility();
474+
updateClock();
475+
}
476+
477+
if (mStatusBar != null) {
478+
mStatusBar.setClockAndDateStatus(mClockAndDateWidth, mClockStyle, mShowClock);
479+
}
480+
481+
}
482+
483+
protected void updateClockVisibility() {
484+
if (mClockStyle == STYLE_CLOCK_RIGHT && mShowClock) {
485+
setVisibility(View.VISIBLE);
486+
} else {
487+
setVisibility(View.GONE);
488+
}
380489
}
381490

382491
public void getFontStyle(int font) {

0 commit comments

Comments
 (0)