Making the timer controls easier to use for rapid changing.

pull/14/head
Tim Su 14 years ago
parent e7447982b1
commit 4a269279a4

@ -10,7 +10,6 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.activity.TaskEditActivity.TaskEditControlSet;
import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.ui.TimeDurationControlSet;
import com.todoroo.astrid.ui.TimeDurationControlSet.TimeDurationType;
/**
* Control Set for managing repeats
@ -31,11 +30,11 @@ public class TimerControlSet implements TaskEditControlSet {
LayoutInflater.from(activity).inflate(R.layout.timer_control, parent, true);
estimated = new TimeDurationTaskEditControlSet(Task.ESTIMATED_SECONDS,
R.id.estimatedDuration, 0, R.string.DLG_hour_minutes,
TimeDurationType.HOURS_MINUTES);
R.id.estimatedDuration, 0, R.string.DLG_hour_minutes
);
elapsed = new TimeDurationTaskEditControlSet(Task.ELAPSED_SECONDS, R.id.elapsedDuration,
0, R.string.DLG_hour_minutes,
TimeDurationType.HOURS_MINUTES);
0, R.string.DLG_hour_minutes
);
}
@Override
@ -62,10 +61,10 @@ public class TimerControlSet implements TaskEditControlSet {
private final IntegerProperty property;
public TimeDurationTaskEditControlSet(IntegerProperty property, int timeButtonId,
int prefixResource, int titleResource, TimeDurationType type) {
int prefixResource, int titleResource) {
this.property = property;
this.controlSet = new TimeDurationControlSet(activity,
timeButtonId, prefixResource, titleResource, type);
timeButtonId, prefixResource, titleResource);
}
@Override

@ -29,9 +29,9 @@ import android.content.DialogInterface.OnClickListener;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.FrameLayout.LayoutParams;
import com.timsu.astrid.R;
@ -102,6 +102,10 @@ public class NNumberPickerDialog extends AlertDialog implements OnClickListener
}
}
public NumberPicker getPicker(int index) {
return pickers.get(index);
}
public void setInitialValues(int[] values) {
for(int i = 0; i < pickers.size(); i++)
pickers.get(i).setCurrent(values[i]);

@ -44,7 +44,8 @@ public class NumberPicker extends LinearLayout implements OnClickListener,
OnFocusChangeListener, OnLongClickListener {
public interface OnChangedListener {
void onChanged(NumberPicker picker, int oldVal, int newVal);
/** return new value */
int onChanged(NumberPicker picker, int oldVal, int newVal);
}
public interface Formatter {
@ -253,6 +254,7 @@ public class NumberPicker extends LinearLayout implements OnClickListener,
}
private void changeCurrent(int current, Animation in, Animation out) {
current = notifyChange();
// Wrap around the values if we go past the start or end
if (current > mEnd) {
@ -262,14 +264,15 @@ public class NumberPicker extends LinearLayout implements OnClickListener,
}
mPrevious = mCurrent;
mCurrent = current;
notifyChange();
updateView();
}
private void notifyChange() {
private int notifyChange() {
if (mListener != null) {
mListener.onChanged(this, mPrevious, mCurrent);
}
return mListener.onChanged(this, mPrevious, mCurrent);
} else
return mCurrent;
}
private void updateView() {

@ -37,47 +37,49 @@ public class TimeDurationControlSet implements OnNNumberPickedListener,
@Autowired
DateUtilities dateUtilities;
public enum TimeDurationType {
DAYS_HOURS,
HOURS_MINUTES;
}
private final Activity activity;
private final Button timeButton;
private final NNumberPickerDialog dialog;
private final int prefixResource;
private final TimeDurationType type;
private int timeDuration;
public TimeDurationControlSet(Activity activity, int timeButtonId,
int prefixResource, int titleResource, TimeDurationType type) {
int prefixResource, int titleResource) {
DependencyInjectionService.getInstance().inject(this);
this.activity = activity;
this.prefixResource = prefixResource;
this.type = type;
timeButton = (Button)activity.findViewById(timeButtonId);
timeButton.setOnClickListener(this);
switch(type) {
case DAYS_HOURS:
dialog = new NNumberPickerDialog(activity, this,
activity.getResources().getString(titleResource),
new int[] {0, 0}, new int[] {1, 1}, new int[] {0, 0},
new int[] {31, 23}, new String[] {
"d\na\ny\ns",
"h\nr\ns"
});
break;
case HOURS_MINUTES:
default:
dialog = new NNumberPickerDialog(activity, this,
activity.getResources().getString(titleResource),
new int[] {0, 0}, new int[] {1, 5}, new int[] {0, 0},
new int[] {99, 59}, new String[] {":", null});
break;
}
dialog = new NNumberPickerDialog(activity, this,
activity.getResources().getString(titleResource),
new int[] {0, 0}, new int[] {1, 5}, new int[] {0, 0},
new int[] {99, 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() {
@ -97,33 +99,20 @@ public class TimeDurationControlSet implements OnNNumberPickedListener,
}
String prefix = "";
if(prefixResource != 0)
if (prefixResource != 0)
prefix = r.getString(prefixResource);
timeButton.setText(prefix + " " + dateUtilities.getDurationString(
timeDurationInSeconds * 1000L, 2));
switch(type) {
case DAYS_HOURS:
int days = timeDuration / 24 / 3600;
int hours = timeDuration / 3600 - 24 * days;
dialog.setInitialValues(new int[] {days, hours});
break;
case HOURS_MINUTES:
hours = timeDuration / 3600;
int minutes = timeDuration/60 - 60 * hours;
dialog.setInitialValues(new int[] {hours, minutes});
}
timeButton.setText(prefix
+ " "
+ dateUtilities.getDurationString(
timeDurationInSeconds * 1000L, 2));
int hours = timeDuration / 3600;
int minutes = timeDuration / 60 - 60 * hours;
dialog.setInitialValues(new int[] { hours, minutes });
}
/** Called when NumberPicker activity is completed */
public void onNumbersPicked(int[] values) {
switch(type) {
case DAYS_HOURS:
setTimeDuration(values[0] * 24 * 3600 + values[1] * 3600);
break;
case HOURS_MINUTES:
setTimeDuration(values[0] * 3600 + values[1] * 60);
break;
}
setTimeDuration(values[0] * 3600 + values[1] * 60);
}
/** Called when time button is clicked */

Loading…
Cancel
Save