]> iEval git - unical.git/commitdiff
Make pickers start at the displayed value
authorMarius Gavrilescu <marius@ieval.ro>
Wed, 14 Aug 2013 15:51:39 +0000 (18:51 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Wed, 14 Aug 2013 15:51:39 +0000 (18:51 +0300)
src/ro/ieval/unical/AddEventActivity.java
src/ro/ieval/unical/DatePickerFragment.java
src/ro/ieval/unical/Event.java
src/ro/ieval/unical/TimePickerFragment.java

index 8b806565d85f04b367209867f6edc43640f9ded1..512b6895e786523fc597a19e88c6f6ddfc1cdc94 100644 (file)
@@ -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
index 956277d718ee2fbe328204efd4186d1591f507a9..3387644f55b0dcf964c44c88cb84280a4b518959 100644 (file)
@@ -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
+}
index 9e4fef80594ab5b7dd5101fa3a99a18b2cbdfd32..65d35bfc795971b5ce48d69cbb17e30ffa878195 100644 (file)
@@ -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;
index 2b84962ccea63f09437f38b87e69ca71a3f069df..01760666c76359ca37df8172f8afd824dcde08a3 100644 (file)
@@ -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
+}
This page took 0.021488 seconds and 4 git commands to generate.