public void showDateTimePickerDialog(final View v) {
dateTimeTextView=(TextView) v;
- if(v.getId()==R.id.date_start || v.getId()==R.id.date_end || v.getId() == R.id.repeat_until)
- new DatePickerFragment().show(getFragmentManager(), "datePicker");
- else
- new TimePickerFragment().show(getFragmentManager(), "timePicker");
+ if(v.getId()==R.id.date_start || v.getId()==R.id.date_end || v.getId() == R.id.repeat_until){
+ final String[] parts = dateTimeTextView.getText().toString().split("-");
+ final DatePickerFragment fragment = new DatePickerFragment();
+ final Bundle args = new Bundle();
+ args.putInt(DatePickerFragment.ARGUMENT_YEAR, Integer.parseInt(parts[0]));
+ args.putInt(DatePickerFragment.ARGUMENT_MONTH, Integer.parseInt(parts[1]));
+ args.putInt(DatePickerFragment.ARGUMENT_DAY, Integer.parseInt(parts[2]));
+ fragment.setArguments(args);
+ fragment.show(getFragmentManager(), "datePicker");
+ } else {
+ final String[] parts = dateTimeTextView.getText().toString().split(":");
+ final TimePickerFragment fragment = new TimePickerFragment();
+ final Bundle args = new Bundle();
+ args.putInt(TimePickerFragment.ARGUMENT_HOUR, Integer.parseInt(parts[0]));
+ args.putInt(TimePickerFragment.ARGUMENT_MINUTE, Integer.parseInt(parts[1]));
+ fragment.setArguments(args);
+ fragment.show(getFragmentManager(), "timePicker");
+ }
}
@Override
import android.os.Bundle;
public class DatePickerFragment extends DialogFragment {
+ public static final String ARGUMENT_YEAR = "year";
+ public static final String ARGUMENT_MONTH = "month";
+ public static final String ARGUMENT_DAY = "day";
+
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
- final Calendar c = Calendar.getInstance();
- return new DatePickerDialog(getActivity(), (OnDateSetListener) getActivity(), c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
+ final Bundle args = getArguments();
+ return new DatePickerDialog(getActivity(), (OnDateSetListener) getActivity(),
+ args.getInt(ARGUMENT_YEAR),
+ args.getInt(ARGUMENT_MONTH),
+ args.getInt(ARGUMENT_DAY));
}
-}
\ No newline at end of file
+}
/** Calendar ID */
public long calendarID;
- public Event() {}
+ public Event() {
+ dtstart = System.currentTimeMillis();
+ dtend = dtstart + 60*60*1000;
+ }
public Event(final long _id, final String organizer, final String title, final String eventLocation, final String description, final int eventColor, final long dtstart, final long dtend, final long calendarID) {
this._id=_id;
import android.text.format.DateFormat;
public class TimePickerFragment extends DialogFragment {
+ public static final String ARGUMENT_HOUR = "hour";
+ public static final String ARGUMENT_MINUTE = "minute";
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
- final Calendar c = Calendar.getInstance();
- return new TimePickerDialog(getActivity(), (OnTimeSetListener) getActivity(), c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), DateFormat.is24HourFormat(getActivity()));
+ final Bundle args = getArguments();
+ return new TimePickerDialog(getActivity(), (OnTimeSetListener) getActivity(),
+ args.getInt(ARGUMENT_HOUR),
+ args.getInt(ARGUMENT_MINUTE),
+ DateFormat.is24HourFormat(getActivity()));
}
-}
\ No newline at end of file
+}