SetupWizard : Support rotation for date/time picker

Fix crashes

Change-Id: I7d0a7088f2c65949ee15f4f0d05c74ffce45ba64
This commit is contained in:
Danesh M 2015-02-05 19:26:42 -08:00 committed by Gerrit Code Review
parent cb291e170c
commit 8e52f6cac7

View File

@ -181,13 +181,13 @@ public class DateTimePage extends SetupPage {
private void showDatePicker() { private void showDatePicker() {
DatePickerFragment datePickerFragment = DatePickerFragment.newInstance(); DatePickerFragment datePickerFragment = DatePickerFragment.newInstance();
datePickerFragment.setOnDateSetListener(this); datePickerFragment.setTargetFragment(this, 0);
datePickerFragment.show(getFragmentManager(), DatePickerFragment.TAG); datePickerFragment.show(getFragmentManager(), DatePickerFragment.TAG);
} }
private void showTimePicker() { private void showTimePicker() {
TimePickerFragment timePickerFragment = TimePickerFragment.newInstance(); TimePickerFragment timePickerFragment = TimePickerFragment.newInstance();
timePickerFragment.setOnTimeSetListener(this); timePickerFragment.setTargetFragment(this, 0);
timePickerFragment.show(getFragmentManager(), TimePickerFragment.TAG); timePickerFragment.show(getFragmentManager(), TimePickerFragment.TAG);
} }
@ -395,26 +395,18 @@ public class DateTimePage extends SetupPage {
} }
} }
private static class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener { public static class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
private static String TAG = TimePickerFragment.class.getSimpleName(); private static String TAG = TimePickerFragment.class.getSimpleName();
private TimePickerDialog.OnTimeSetListener mOnTimeSetListener;
public static TimePickerFragment newInstance() { public static TimePickerFragment newInstance() {
TimePickerFragment frag = new TimePickerFragment(); TimePickerFragment frag = new TimePickerFragment();
return frag; return frag;
} }
private void setOnTimeSetListener(TimePickerDialog.OnTimeSetListener onTimeSetListener) {
mOnTimeSetListener = onTimeSetListener;
}
@Override @Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) { public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
if (mOnTimeSetListener != null) { ((DateTimeFragment) getTargetFragment()).onTimeSet(view, hourOfDay, minute);
mOnTimeSetListener.onTimeSet(view, hourOfDay, minute);
}
} }
@Override @Override
@ -428,28 +420,21 @@ public class DateTimePage extends SetupPage {
DateFormat.is24HourFormat(getActivity())); DateFormat.is24HourFormat(getActivity()));
} }
} }
private static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
private static String TAG = DatePickerFragment.class.getSimpleName(); private static String TAG = DatePickerFragment.class.getSimpleName();
private DatePickerDialog.OnDateSetListener mOnDateSetListener;
public static DatePickerFragment newInstance() { public static DatePickerFragment newInstance() {
DatePickerFragment frag = new DatePickerFragment(); DatePickerFragment frag = new DatePickerFragment();
return frag; return frag;
} }
private void setOnDateSetListener(DatePickerDialog.OnDateSetListener onDateSetListener) {
mOnDateSetListener = onDateSetListener;
}
@Override @Override
public void onDateSet(DatePicker view, int year, int month, int day) { public void onDateSet(DatePicker view, int year, int month, int day) {
if (mOnDateSetListener != null) { ((DateTimeFragment) getTargetFragment()).onDateSet(view, year, month, day);
mOnDateSetListener.onDateSet(view, year, month, day);
}
} }
@Override @Override