diff options
author | Svetoslav Ganov <svetoslavganov@google.com> | 2012-05-02 17:46:34 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-05-02 17:46:34 -0700 |
commit | fb58a6d93c954a956e0b6c9929d2baf45e8867ae (patch) | |
tree | 70fca1b74dbca60885be5eee42413502473e0757 /core/java/android/app | |
parent | 7a5f3e4048b0af08606b689b4f4a39d6040c3c23 (diff) | |
parent | 42c5cb3028aeac3f31b954c74a39c26e24821ff7 (diff) | |
download | frameworks_base-fb58a6d93c954a956e0b6c9929d2baf45e8867ae.zip frameworks_base-fb58a6d93c954a956e0b6c9929d2baf45e8867ae.tar.gz frameworks_base-fb58a6d93c954a956e0b6c9929d2baf45e8867ae.tar.bz2 |
Merge "Adding title for the date picker dialog if the calendar is not shown." into jb-dev
Diffstat (limited to 'core/java/android/app')
-rw-r--r-- | core/java/android/app/DatePickerDialog.java | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/core/java/android/app/DatePickerDialog.java b/core/java/android/app/DatePickerDialog.java index c62e5cf..3f0b4d4 100644 --- a/core/java/android/app/DatePickerDialog.java +++ b/core/java/android/app/DatePickerDialog.java @@ -16,17 +16,20 @@ package android.app; -import com.android.internal.R; - import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.Bundle; +import android.text.format.DateUtils; import android.view.LayoutInflater; import android.view.View; import android.widget.DatePicker; import android.widget.DatePicker.OnDateChangedListener; +import com.android.internal.R; + +import java.util.Calendar; + /** * A simple dialog containing an {@link android.widget.DatePicker}. * @@ -42,6 +45,9 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener, private final DatePicker mDatePicker; private final OnDateSetListener mCallBack; + private final Calendar mCalendar; + + private boolean mTitleNeedsUpdate = true; /** * The callback used to indicate the user is done filling in the date. @@ -91,10 +97,11 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener, mCallBack = callBack; + mCalendar = Calendar.getInstance(); + Context themeContext = getContext(); setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_done), this); setIcon(0); - setTitle(R.string.date_picker_dialog_title); LayoutInflater inflater = (LayoutInflater) themeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); @@ -102,6 +109,7 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener, setView(view); mDatePicker = (DatePicker) view.findViewById(R.id.datePicker); mDatePicker.init(year, monthOfYear, dayOfMonth, this); + updateTitle(year, monthOfYear, dayOfMonth); } public void onClick(DialogInterface dialog, int which) { @@ -110,7 +118,8 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener, public void onDateChanged(DatePicker view, int year, int month, int day) { - mDatePicker.init(year, month, day, null); + mDatePicker.init(year, month, day, this); + updateTitle(year, month, day); } /** @@ -147,6 +156,28 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener, super.onStop(); } + private void updateTitle(int year, int month, int day) { + if (!mDatePicker.getCalendarViewShown()) { + mCalendar.set(Calendar.YEAR, year); + mCalendar.set(Calendar.MONTH, month); + mCalendar.set(Calendar.DAY_OF_MONTH, day); + String title = DateUtils.formatDateTime(mContext, + mCalendar.getTimeInMillis(), + DateUtils.FORMAT_SHOW_DATE + | DateUtils.FORMAT_SHOW_WEEKDAY + | DateUtils.FORMAT_SHOW_YEAR + | DateUtils.FORMAT_ABBREV_MONTH + | DateUtils.FORMAT_ABBREV_WEEKDAY); + setTitle(title); + mTitleNeedsUpdate = true; + } else { + if (mTitleNeedsUpdate) { + mTitleNeedsUpdate = false; + setTitle(R.string.date_picker_dialog_title); + } + } + } + @Override public Bundle onSaveInstanceState() { Bundle state = super.onSaveInstanceState(); |