diff --git a/astrid/src/com/todoroo/astrid/service/StartupService.java b/astrid/src/com/todoroo/astrid/service/StartupService.java index 1ac954808..7a7ac016a 100644 --- a/astrid/src/com/todoroo/astrid/service/StartupService.java +++ b/astrid/src/com/todoroo/astrid/service/StartupService.java @@ -9,8 +9,8 @@ import android.app.AlertDialog; import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.content.Intent; +import android.content.DialogInterface.OnClickListener; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.util.Log; @@ -133,17 +133,17 @@ public class StartupService { DependencyInjectionService.getInstance().inject(this); exceptionService.reportError("reminder-startup", e); //$NON-NLS-1$ } + + // if sync ongoing flag was set, clear it + ProducteevUtilities.INSTANCE.stopOngoing(); + + ProducteevBackgroundService.scheduleService(); + BackupService.scheduleService(context); } }).start(); Preferences.setPreferenceDefaults(); - // if sync ongoing flag was set, clear it - ProducteevUtilities.INSTANCE.stopOngoing(); - - ProducteevBackgroundService.scheduleService(); - BackupService.scheduleService(context); - // check for task killers if(!Constants.OEM) showTaskKillerHelp(context); diff --git a/astrid/src/com/todoroo/astrid/ui/TimeDurationControlSet.java b/astrid/src/com/todoroo/astrid/ui/TimeDurationControlSet.java index 409edd2e3..9ece5937b 100644 --- a/astrid/src/com/todoroo/astrid/ui/TimeDurationControlSet.java +++ b/astrid/src/com/todoroo/astrid/ui/TimeDurationControlSet.java @@ -35,9 +35,11 @@ public class TimeDurationControlSet implements OnNNumberPickedListener, private final Activity activity; private final Button timeButton; - private final NNumberPickerDialog dialog; private final int prefixResource; private int timeDuration; + private int[] initialValues = null; + private final int titleResource; + private NNumberPickerDialog dialog = null; public TimeDurationControlSet(Activity activity, int timeButtonId, int prefixResource, int titleResource) { @@ -45,37 +47,10 @@ public class TimeDurationControlSet implements OnNNumberPickedListener, this.activity = activity; this.prefixResource = prefixResource; + this.titleResource = titleResource; timeButton = (Button)activity.findViewById(timeButtonId); timeButton.setOnClickListener(this); - - dialog = new NNumberPickerDialog(activity, this, - activity.getResources().getString(titleResource), - new int[] {0, 0}, new int[] {1, 5}, new int[] {0, 0}, - new int[] {999, 59}, new String[] {":", null}); - final NumberPicker hourPicker = dialog.getPicker(0); - final NumberPicker minutePicker = dialog.getPicker(1); - minutePicker.setFormatter(new NumberPicker.Formatter() { - @Override - public String toString(int value) { - return String.format("%02d", value); - } - }); - minutePicker.setOnChangeListener(new NumberPicker.OnChangedListener() { - @Override - public int onChanged(NumberPicker picker, int oldVal, int newVal) { - if(newVal < 0) { - if(hourPicker.getCurrent() == 0) - return 0; - hourPicker.setCurrent(hourPicker.getCurrent() - 1); - return 60 + newVal; - } else if(newVal > 59) { - hourPicker.setCurrent(hourPicker.getCurrent() + 1); - return newVal % 60; - } - return newVal; - } - }); } public int getTimeDurationInSeconds() { @@ -100,7 +75,7 @@ public class TimeDurationControlSet implements OnNNumberPickedListener, timeButton.setText(prefix + DateUtils.formatElapsedTime(timeDuration)); int hours = timeDuration / 3600; int minutes = timeDuration / 60 - 60 * hours; - dialog.setInitialValues(new int[] { hours, minutes }); + initialValues = new int[] { hours, minutes }; } /** Called when NumberPicker activity is completed */ @@ -110,6 +85,39 @@ public class TimeDurationControlSet implements OnNNumberPickedListener, /** Called when time button is clicked */ public void onClick(View v) { + if(dialog == null) { + dialog = new NNumberPickerDialog(activity, this, + activity.getResources().getString(titleResource), + new int[] {0, 0}, new int[] {1, 5}, new int[] {0, 0}, + new int[] {999, 59}, new String[] {":", null}); + final NumberPicker hourPicker = dialog.getPicker(0); + final NumberPicker minutePicker = dialog.getPicker(1); + minutePicker.setFormatter(new NumberPicker.Formatter() { + @Override + public String toString(int value) { + return String.format("%02d", value); + } + }); + minutePicker.setOnChangeListener(new NumberPicker.OnChangedListener() { + @Override + public int onChanged(NumberPicker picker, int oldVal, int newVal) { + if(newVal < 0) { + if(hourPicker.getCurrent() == 0) + return 0; + hourPicker.setCurrent(hourPicker.getCurrent() - 1); + return 60 + newVal; + } else if(newVal > 59) { + hourPicker.setCurrent(hourPicker.getCurrent() + 1); + return newVal % 60; + } + return newVal; + } + }); + } + + if(initialValues != null) + dialog.setInitialValues(initialValues); + dialog.show(); }