Skip to content

Commit 42c5cb3

Browse files
committed
Adding title for the date picker dialog if the calendar is not shown.
1. The date picker dialog shows spinners and a mini calendar on tablet but on on phone the calendar is not show and the user does not know the day of the week otherwise show on the mini calendar. bug:5264972 Change-Id: I06aeb7ba1ad34d4e99628d9586ff2777e981c963
1 parent 3e35030 commit 42c5cb3

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

core/java/android/app/DatePickerDialog.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@
1616

1717
package android.app;
1818

19-
import com.android.internal.R;
20-
2119
import android.content.Context;
2220
import android.content.DialogInterface;
2321
import android.content.DialogInterface.OnClickListener;
2422
import android.os.Bundle;
23+
import android.text.format.DateUtils;
2524
import android.view.LayoutInflater;
2625
import android.view.View;
2726
import android.widget.DatePicker;
2827
import 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

Comments
 (0)