|
|
@ -35,9 +35,11 @@ public class TimeDurationControlSet implements OnNNumberPickedListener,
|
|
|
|
|
|
|
|
|
|
|
|
private final Activity activity;
|
|
|
|
private final Activity activity;
|
|
|
|
private final Button timeButton;
|
|
|
|
private final Button timeButton;
|
|
|
|
private final NNumberPickerDialog dialog;
|
|
|
|
|
|
|
|
private final int prefixResource;
|
|
|
|
private final int prefixResource;
|
|
|
|
private int timeDuration;
|
|
|
|
private int timeDuration;
|
|
|
|
|
|
|
|
private int[] initialValues = null;
|
|
|
|
|
|
|
|
private final int titleResource;
|
|
|
|
|
|
|
|
private NNumberPickerDialog dialog = null;
|
|
|
|
|
|
|
|
|
|
|
|
public TimeDurationControlSet(Activity activity, int timeButtonId,
|
|
|
|
public TimeDurationControlSet(Activity activity, int timeButtonId,
|
|
|
|
int prefixResource, int titleResource) {
|
|
|
|
int prefixResource, int titleResource) {
|
|
|
@ -45,37 +47,10 @@ public class TimeDurationControlSet implements OnNNumberPickedListener,
|
|
|
|
|
|
|
|
|
|
|
|
this.activity = activity;
|
|
|
|
this.activity = activity;
|
|
|
|
this.prefixResource = prefixResource;
|
|
|
|
this.prefixResource = prefixResource;
|
|
|
|
|
|
|
|
this.titleResource = titleResource;
|
|
|
|
|
|
|
|
|
|
|
|
timeButton = (Button)activity.findViewById(timeButtonId);
|
|
|
|
timeButton = (Button)activity.findViewById(timeButtonId);
|
|
|
|
timeButton.setOnClickListener(this);
|
|
|
|
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() {
|
|
|
|
public int getTimeDurationInSeconds() {
|
|
|
@ -100,7 +75,7 @@ public class TimeDurationControlSet implements OnNNumberPickedListener,
|
|
|
|
timeButton.setText(prefix + DateUtils.formatElapsedTime(timeDuration));
|
|
|
|
timeButton.setText(prefix + DateUtils.formatElapsedTime(timeDuration));
|
|
|
|
int hours = timeDuration / 3600;
|
|
|
|
int hours = timeDuration / 3600;
|
|
|
|
int minutes = timeDuration / 60 - 60 * hours;
|
|
|
|
int minutes = timeDuration / 60 - 60 * hours;
|
|
|
|
dialog.setInitialValues(new int[] { hours, minutes });
|
|
|
|
initialValues = new int[] { hours, minutes };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Called when NumberPicker activity is completed */
|
|
|
|
/** Called when NumberPicker activity is completed */
|
|
|
@ -110,6 +85,39 @@ public class TimeDurationControlSet implements OnNNumberPickedListener,
|
|
|
|
|
|
|
|
|
|
|
|
/** Called when time button is clicked */
|
|
|
|
/** Called when time button is clicked */
|
|
|
|
public void onClick(View v) {
|
|
|
|
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();
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|