1717package com .android .internal .policy .impl .keyguard ;
1818
1919import android .content .Context ;
20+ import android .content .res .Resources ;
21+ import android .graphics .Typeface ;
22+ import android .text .TextUtils ;
23+ import android .text .format .DateFormat ;
2024import android .util .AttributeSet ;
25+ import android .util .Slog ;
26+ import android .view .View ;
2127import android .widget .GridLayout ;
28+ import android .widget .TextView ;
2229
30+ import com .android .internal .R ;
2331import com .android .internal .widget .LockPatternUtils ;
2432
33+ import java .util .Date ;
34+
2535public class KeyguardStatusView extends GridLayout {
26- @ SuppressWarnings ("unused" )
27- private KeyguardStatusViewManager mStatusViewManager ;
36+ private static final boolean DEBUG = KeyguardViewMediator .DEBUG ;
37+ private static final String TAG = "KeyguardStatusView" ;
38+
39+ public static final int LOCK_ICON = 0 ; // R.drawable.ic_lock_idle_lock;
40+ public static final int ALARM_ICON = com .android .internal .R .drawable .ic_lock_idle_alarm ;
41+ public static final int CHARGING_ICON = 0 ; //R.drawable.ic_lock_idle_charging;
42+ public static final int BATTERY_LOW_ICON = 0 ; //R.drawable.ic_lock_idle_low_battery;
43+
44+ private CharSequence mDateFormatString ;
45+ private LockPatternUtils mLockPatternUtils ;
46+
47+ private TextView mDateView ;
48+ private TextView mAlarmStatusView ;
49+ private ClockView mClockView ;
50+
51+ private KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback () {
52+
53+ @ Override
54+ public void onTimeChanged () {
55+ refresh ();
56+ }
57+
58+ @ Override
59+ void onKeyguardVisibilityChanged (boolean showing ) {
60+ if (showing ) {
61+ if (DEBUG ) Slog .v (TAG , "refresh statusview showing:" + showing );
62+ refresh ();
63+ }
64+ };
65+ };
2866
2967 public KeyguardStatusView (Context context ) {
3068 this (context , null , 0 );
@@ -38,19 +76,76 @@ public KeyguardStatusView(Context context, AttributeSet attrs, int defStyle) {
3876 super (context , attrs , defStyle );
3977 }
4078
41- public int getAppWidgetId () {
42- return LockPatternUtils .ID_DEFAULT_STATUS_WIDGET ;
43- }
44-
4579 @ Override
4680 protected void onFinishInflate () {
4781 super .onFinishInflate ();
82+ Resources res = getContext ().getResources ();
83+ mDateFormatString =
84+ res .getText (com .android .internal .R .string .abbrev_wday_month_day_no_year );
85+ mDateView = (TextView ) findViewById (R .id .date );
86+ mAlarmStatusView = (TextView ) findViewById (R .id .alarm_status );
87+ mClockView = (ClockView ) findViewById (R .id .clock_view );
88+ mLockPatternUtils = new LockPatternUtils (getContext ());
89+
90+ // Use custom font in mDateView
91+ mDateView .setTypeface (Typeface .SANS_SERIF , Typeface .BOLD );
92+
93+ // Required to get Marquee to work.
94+ final View marqueeViews [] = { mDateView , mAlarmStatusView };
95+ for (int i = 0 ; i < marqueeViews .length ; i ++) {
96+ View v = marqueeViews [i ];
97+ if (v == null ) {
98+ throw new RuntimeException ("Can't find widget at index " + i );
99+ }
100+ v .setSelected (true );
101+ }
102+ refresh ();
103+ }
48104
49- // StatusView manages all of the widgets in this view.
50- mStatusViewManager = new KeyguardStatusViewManager (this );
105+ protected void refresh () {
106+ mClockView .updateTime ();
107+ refreshDate ();
108+ refreshAlarmStatus (); // might as well
109+ }
110+
111+ void refreshAlarmStatus () {
112+ // Update Alarm status
113+ String nextAlarm = mLockPatternUtils .getNextAlarm ();
114+ if (!TextUtils .isEmpty (nextAlarm )) {
115+ maybeSetUpperCaseText (mAlarmStatusView , nextAlarm );
116+ mAlarmStatusView .setCompoundDrawablesWithIntrinsicBounds (ALARM_ICON , 0 , 0 , 0 );
117+ mAlarmStatusView .setVisibility (View .VISIBLE );
118+ } else {
119+ mAlarmStatusView .setVisibility (View .GONE );
120+ }
121+ }
122+
123+ void refreshDate () {
124+ maybeSetUpperCaseText (mDateView , DateFormat .format (mDateFormatString , new Date ()));
125+ }
126+
127+ @ Override
128+ protected void onAttachedToWindow () {
129+ super .onAttachedToWindow ();
130+ KeyguardUpdateMonitor .getInstance (mContext ).registerCallback (mInfoCallback );
131+ }
132+
133+ @ Override
134+ protected void onDetachedFromWindow () {
135+ super .onDetachedFromWindow ();
136+ KeyguardUpdateMonitor .getInstance (mContext ).removeCallback (mInfoCallback );
137+ }
138+
139+ public int getAppWidgetId () {
140+ return LockPatternUtils .ID_DEFAULT_STATUS_WIDGET ;
51141 }
52142
53- KeyguardStatusViewManager getManager () {
54- return mStatusViewManager ;
143+ private void maybeSetUpperCaseText (TextView textView , CharSequence text ) {
144+ if (KeyguardViewManager .USE_UPPER_CASE
145+ && textView .getId () != R .id .owner_info ) { // currently only required for date view
146+ textView .setText (text != null ? text .toString ().toUpperCase () : null );
147+ } else {
148+ textView .setText (text );
149+ }
55150 }
56151}
0 commit comments