From e4fb15ad7fab87f31ae9af7bcfe2d4f71c150125 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Wed, 14 Aug 2013 18:51:39 +0300 Subject: [PATCH] Make pickers start at the displayed value --- src/ro/ieval/unical/AddEventActivity.java | 22 +++++++++++++++++---- src/ro/ieval/unical/DatePickerFragment.java | 13 +++++++++--- src/ro/ieval/unical/Event.java | 5 ++++- src/ro/ieval/unical/TimePickerFragment.java | 11 ++++++++--- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/ro/ieval/unical/AddEventActivity.java b/src/ro/ieval/unical/AddEventActivity.java index 8b80656..512b689 100644 --- a/src/ro/ieval/unical/AddEventActivity.java +++ b/src/ro/ieval/unical/AddEventActivity.java @@ -93,10 +93,24 @@ public final class AddEventActivity extends Activity implements OnDateSetListene 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 diff --git a/src/ro/ieval/unical/DatePickerFragment.java b/src/ro/ieval/unical/DatePickerFragment.java index 956277d..3387644 100644 --- a/src/ro/ieval/unical/DatePickerFragment.java +++ b/src/ro/ieval/unical/DatePickerFragment.java @@ -9,9 +9,16 @@ import android.app.DialogFragment; 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 +} diff --git a/src/ro/ieval/unical/Event.java b/src/ro/ieval/unical/Event.java index 9e4fef8..65d35bf 100644 --- a/src/ro/ieval/unical/Event.java +++ b/src/ro/ieval/unical/Event.java @@ -55,7 +55,10 @@ final class Event implements Parcelable{ /** 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; diff --git a/src/ro/ieval/unical/TimePickerFragment.java b/src/ro/ieval/unical/TimePickerFragment.java index 2b84962..0176066 100644 --- a/src/ro/ieval/unical/TimePickerFragment.java +++ b/src/ro/ieval/unical/TimePickerFragment.java @@ -10,11 +10,16 @@ import android.os.Bundle; 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 +} -- 2.39.2