4141import com .android .systemui .cm .UserContentObserver ;
4242
4343import java .text .SimpleDateFormat ;
44+ import java .util .GregorianCalendar ;
4445import java .util .Calendar ;
4546import java .util .Date ;
4647import java .util .Locale ;
4748import java .util .TimeZone ;
49+ import java .util .Timer ;
50+ import java .util .TimerTask ;
4851
4952import 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