summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaiyiz <kaiyiz@codeaurora.org>2014-04-24 10:18:05 +0800
committerAdnan <adnan@cyngn.com>2014-08-26 14:46:52 -0700
commitf5d63e3e69d9341052e9b5ebbfcd17fa3c8f94dd (patch)
tree3a4e169962abc4e9c499c6a730f160290bcc10f3
parente1f2fccfd9ff54966e0979e17bdfbf06daa273dd (diff)
downloadandroid_packages_apps_Calendar-f5d63e3e69d9341052e9b5ebbfcd17fa3c8f94dd.tar.gz
android_packages_apps_Calendar-f5d63e3e69d9341052e9b5ebbfcd17fa3c8f94dd.tar.bz2
android_packages_apps_Calendar-f5d63e3e69d9341052e9b5ebbfcd17fa3c8f94dd.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
-rw-r--r--src/com/android/calendar/AllInOneActivity.java55
1 files changed, 31 insertions, 24 deletions
diff --git a/src/com/android/calendar/AllInOneActivity.java b/src/com/android/calendar/AllInOneActivity.java
index 51b6342b..5bd86042 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);
+ }
+ }
}
}