diff options
author | kaiyiz <kaiyiz@codeaurora.org> | 2014-04-24 10:18:05 +0800 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-18 13:52:40 -0700 |
commit | fdbb9d8987eaf0672e91ded376bd7d43e8613c01 (patch) | |
tree | e615b96897d4fcbb247549169d03c649249752a4 /src/com/android/calendar | |
parent | b498ee2f039333c62ca66a952087a894569c5a3f (diff) | |
download | android_packages_apps_Calendar-fdbb9d8987eaf0672e91ded376bd7d43e8613c01.tar.gz android_packages_apps_Calendar-fdbb9d8987eaf0672e91ded376bd7d43e8613c01.tar.bz2 android_packages_apps_Calendar-fdbb9d8987eaf0672e91ded376bd7d43e8613c01.zip |
Calendar: Handle the date set action in the onDateSet callback
When the user press the done button on the dialog, it maybe couldn't
get the right date. For example, the user input the date value by
keyboard, and press the done before keyboard exit.
So we need handle the date set action in the onDateSet callback.
And if the user cancel the date set action, we will do nothing.
CRs-Fixed: 652859
Change-Id: I124cbd7998cdb167cd4a94b9fc0926fef03a230d
Diffstat (limited to 'src/com/android/calendar')
-rw-r--r-- | src/com/android/calendar/AllInOneActivity.java | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/src/com/android/calendar/AllInOneActivity.java b/src/com/android/calendar/AllInOneActivity.java index 48613706..bb32ac2e 100644 --- a/src/com/android/calendar/AllInOneActivity.java +++ b/src/com/android/calendar/AllInOneActivity.java @@ -1433,8 +1433,10 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH return; } - public static class GoToDialogFragment extends DialogFragment { + public static class GoToDialogFragment extends DialogFragment implements + DatePickerDialog.OnDateSetListener { private static final String KEY_TIMEZONE = "timezone"; + private static final String KEY_IS_CLICKED_DONE = "done"; public static GoToDialogFragment newInstance(String timeZone) { GoToDialogFragment goToFrg = new GoToDialogFragment(); @@ -1446,36 +1448,41 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - final String timeZone = getArguments().getString(KEY_TIMEZONE); - final CalendarController controller = CalendarController.getInstance(getActivity()); - Time t = null; - t = new Time(timeZone); + String timeZone = getArguments().getString(KEY_TIMEZONE); + Time t = new Time(timeZone); Calendar calendar = Calendar.getInstance(); t.year = calendar.get(Calendar.YEAR); t.month = calendar.get(Calendar.MONTH); t.monthDay = calendar.get(Calendar.DATE); - DatePickerDialog dialog = new DatePickerDialog(getActivity(), null, + DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, t.year, t.month, t.monthDay) { + + @Override + public void onClick(DialogInterface dialog, int which) { + if (which == DialogInterface.BUTTON_POSITIVE) { + // Avoid touching dialog box outside cause it disappears also perform + // actions. Limit perform only after the user confirms by click done. + getArguments().putBoolean(KEY_IS_CLICKED_DONE, true); + } + super.onClick(dialog, which); + } }; - final DatePicker datePicker = dialog.getDatePicker(); - dialog.setButton(DialogInterface.BUTTON_POSITIVE, - getResources().getString(R.string.save_label), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Time t = null; - t = new Time(timeZone); - int year = datePicker.getYear(); - int monthOfYear = datePicker.getMonth(); - int dayOfMonth = datePicker.getDayOfMonth(); - t.set(dayOfMonth, monthOfYear, year); - t.set(t.toMillis(false)); - controller.sendEvent(this, EventType.GO_TO, null, null, t, -1, - ViewType.CURRENT, CalendarController.EXTRA_GOTO_TIME, - null, null); - } - }); + return dialog; } + + @Override + public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { + if (getArguments().getBoolean(KEY_IS_CLICKED_DONE)) { + CalendarController controller = CalendarController.getInstance(getActivity()); + String timeZone = getArguments().getString(KEY_TIMEZONE); + Time t = new Time(timeZone); + t.set(dayOfMonth, monthOfYear, year); + t.set(t.toMillis(false)); + controller.sendEvent(this, EventType.GO_TO, null, null, t, -1, + ViewType.CURRENT, CalendarController.EXTRA_GOTO_TIME, + null, null); + } + } } } |