1616
1717package android .app ;
1818
19- import com .android .internal .R ;
20-
2119import android .content .Context ;
2220import android .content .DialogInterface ;
2321import android .content .DialogInterface .OnClickListener ;
2422import android .os .Bundle ;
23+ import android .text .format .DateUtils ;
2524import android .view .LayoutInflater ;
2625import android .view .View ;
2726import android .widget .DatePicker ;
2827import android .widget .DatePicker .OnDateChangedListener ;
2928
29+ import com .android .internal .R ;
30+
31+ import java .util .Calendar ;
32+
3033/**
3134 * A simple dialog containing an {@link android.widget.DatePicker}.
3235 *
@@ -42,6 +45,9 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener,
4245
4346 private final DatePicker mDatePicker ;
4447 private final OnDateSetListener mCallBack ;
48+ private final Calendar mCalendar ;
49+
50+ private boolean mTitleNeedsUpdate = true ;
4551
4652 /**
4753 * The callback used to indicate the user is done filling in the date.
@@ -91,17 +97,19 @@ public DatePickerDialog(Context context,
9197
9298 mCallBack = callBack ;
9399
100+ mCalendar = Calendar .getInstance ();
101+
94102 Context themeContext = getContext ();
95103 setButton (BUTTON_POSITIVE , themeContext .getText (R .string .date_time_done ), this );
96104 setIcon (0 );
97- setTitle (R .string .date_picker_dialog_title );
98105
99106 LayoutInflater inflater =
100107 (LayoutInflater ) themeContext .getSystemService (Context .LAYOUT_INFLATER_SERVICE );
101108 View view = inflater .inflate (R .layout .date_picker_dialog , null );
102109 setView (view );
103110 mDatePicker = (DatePicker ) view .findViewById (R .id .datePicker );
104111 mDatePicker .init (year , monthOfYear , dayOfMonth , this );
112+ updateTitle (year , monthOfYear , dayOfMonth );
105113 }
106114
107115 public void onClick (DialogInterface dialog , int which ) {
@@ -110,7 +118,8 @@ public void onClick(DialogInterface dialog, int which) {
110118
111119 public void onDateChanged (DatePicker view , int year ,
112120 int month , int day ) {
113- mDatePicker .init (year , month , day , null );
121+ mDatePicker .init (year , month , day , this );
122+ updateTitle (year , month , day );
114123 }
115124
116125 /**
@@ -147,6 +156,28 @@ protected void onStop() {
147156 super .onStop ();
148157 }
149158
159+ private void updateTitle (int year , int month , int day ) {
160+ if (!mDatePicker .getCalendarViewShown ()) {
161+ mCalendar .set (Calendar .YEAR , year );
162+ mCalendar .set (Calendar .MONTH , month );
163+ mCalendar .set (Calendar .DAY_OF_MONTH , day );
164+ String title = DateUtils .formatDateTime (mContext ,
165+ mCalendar .getTimeInMillis (),
166+ DateUtils .FORMAT_SHOW_DATE
167+ | DateUtils .FORMAT_SHOW_WEEKDAY
168+ | DateUtils .FORMAT_SHOW_YEAR
169+ | DateUtils .FORMAT_ABBREV_MONTH
170+ | DateUtils .FORMAT_ABBREV_WEEKDAY );
171+ setTitle (title );
172+ mTitleNeedsUpdate = true ;
173+ } else {
174+ if (mTitleNeedsUpdate ) {
175+ mTitleNeedsUpdate = false ;
176+ setTitle (R .string .date_picker_dialog_title );
177+ }
178+ }
179+ }
180+
150181 @ Override
151182 public Bundle onSaveInstanceState () {
152183 Bundle state = super .onSaveInstanceState ();
0 commit comments