diff --git a/astrid/res/layout/astrid_time_picker.xml b/astrid/res/layout/astrid_time_picker.xml index 195203c61..87dbb9063 100644 --- a/astrid/res/layout/astrid_time_picker.xml +++ b/astrid/res/layout/astrid_time_picker.xml @@ -6,69 +6,74 @@ --> - - + - - + + + + + + - - - + android:layout_marginBottom="4dip"> + + + + - + android:textColor="@color/task_edit_toggle_button_text"/> - - \ No newline at end of file diff --git a/astrid/res/layout/astrid_time_picker_horizontal.xml b/astrid/res/layout/astrid_time_picker_horizontal.xml new file mode 100644 index 000000000..070c6686a --- /dev/null +++ b/astrid/res/layout/astrid_time_picker_horizontal.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/astrid/src/com/todoroo/astrid/ui/AstridTimePicker.java b/astrid/src/com/todoroo/astrid/ui/AstridTimePicker.java index f1ff5f43d..b980f1953 100644 --- a/astrid/src/com/todoroo/astrid/ui/AstridTimePicker.java +++ b/astrid/src/com/todoroo/astrid/ui/AstridTimePicker.java @@ -34,6 +34,7 @@ public class AstridTimePicker extends LinearLayout { private boolean is24Hour; private boolean lastSelectionWasPm; // false for AM, true for PM + private final boolean useShortcuts; public interface TimePickerEnabledChangedListener { public void timePickerEnabledChanged(boolean hasTime); @@ -44,11 +45,13 @@ public class AstridTimePicker extends LinearLayout { public AstridTimePicker(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.astrid_time_picker, this, true); + useShortcuts = false; //Preferences.getBoolean(R.string.p_use_date_shortcuts, true); + int layout = useShortcuts ? R.layout.astrid_time_picker : R.layout.astrid_time_picker_horizontal; + inflater.inflate(layout, this, true); noTimeCheck = (ToggleButton) findViewById(R.id.hasTime); - amButton= (ToggleButton) findViewById(R.id.am_button); - pmButton= (ToggleButton) findViewById(R.id.pm_button); + amButton = (ToggleButton) findViewById(R.id.am_button); + pmButton = (ToggleButton) findViewById(R.id.pm_button); hours = (NumberPicker) findViewById(R.id.hours); minutes = (NumberPicker) findViewById(R.id.minutes); @@ -89,6 +92,15 @@ public class AstridTimePicker extends LinearLayout { CustomBorderDrawable.customButton(0, cornerRadius, 0, 0, onColorValue, offColorValue, borderColorValue, strokeWidth)); minutes.findViewById(R.id.decrement).setBackgroundDrawable( CustomBorderDrawable.customButton(0, 0, cornerRadius, 0, onColorValue, offColorValue, borderColorValue, strokeWidth)); + + if (!useShortcuts) { + View[] pickers = new View[] { hours, minutes }; + for (View view : pickers) { + View v = view.findViewById(R.id.timepicker_input); + LayoutParams lp = (LinearLayout.LayoutParams) v.getLayoutParams(); + lp.height = (int) (46 * r.getDisplayMetrics().density); + } + } } private void initialize(Context context) { @@ -111,9 +123,6 @@ public class AstridTimePicker extends LinearLayout { } }; -// hours.findViewById(R.id.timepicker_left_border).setVisibility(View.VISIBLE); -// minutes.findViewById(R.id.timepicker_right_border).setVisibility(View.VISIBLE); - String amString = DateUtils.getAMPMString(Calendar.AM).toUpperCase(); amButton.setTextOff(amString); amButton.setTextOn(amString); diff --git a/astrid/src/com/todoroo/astrid/ui/DateAndTimePicker.java b/astrid/src/com/todoroo/astrid/ui/DateAndTimePicker.java index 46160f5e8..8b457c79a 100644 --- a/astrid/src/com/todoroo/astrid/ui/DateAndTimePicker.java +++ b/astrid/src/com/todoroo/astrid/ui/DateAndTimePicker.java @@ -57,15 +57,26 @@ public class DateAndTimePicker extends LinearLayout { private final AstridTimePicker timePicker; private final LinearLayout dateShortcuts; private OnDateChangedListener listener; + private final boolean useShortcuts; + private UrgencyValue todayUrgency; public DateAndTimePicker(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.date_time_picker, this, true); + useShortcuts = false; //Preferences.getBoolean(R.string.p_use_date_shortcuts, true); + calendarView = (CalendarView) findViewById(R.id.calendar); timePicker = (AstridTimePicker) findViewById(R.id.time_picker); - dateShortcuts = (LinearLayout) findViewById(R.id.date_shortcuts); + + if (useShortcuts) + dateShortcuts = (LinearLayout) findViewById(R.id.date_shortcuts); + else { + findViewById(R.id.date_shortcuts).setVisibility(View.GONE); + dateShortcuts = (LinearLayout) timePicker.findViewById(R.id.date_shortcuts); + } + setUpListeners(); constructShortcutList(context, attrs); @@ -121,7 +132,13 @@ public class DateAndTimePicker extends LinearLayout { private void forceDateSelected() { ToggleButton none = (ToggleButton) dateShortcuts.getChildAt(dateShortcuts.getChildCount() - 1); if (none.isChecked()) { - dateShortcuts.getChildAt(0).performClick(); + Date date = new Date(todayUrgency.dueDate); + calendarView.setCalendarDate(date); + calendarView.invalidate(); + if (todayUrgency.setting == Task.URGENCY_NONE) + timePicker.forceNoTime(); + updateShortcutView(date); + otherCallbacks(); } } @@ -138,14 +155,17 @@ public class DateAndTimePicker extends LinearLayout { String[] labels = context.getResources().getStringArray(arrayResource); urgencyValues = new ArrayList(); - urgencyValues.add(new UrgencyValue(labels[2], - Task.URGENCY_TODAY)); - urgencyValues.add(new UrgencyValue(labels[3], - Task.URGENCY_TOMORROW)); - urgencyValues.add(new UrgencyValue(labels[5], - Task.URGENCY_NEXT_WEEK)); - urgencyValues.add(new UrgencyValue(labels[7], - Task.URGENCY_NEXT_MONTH)); + todayUrgency = new UrgencyValue(labels[2], + Task.URGENCY_TODAY); + if (useShortcuts) { + urgencyValues.add(todayUrgency); + urgencyValues.add(new UrgencyValue(labels[3], + Task.URGENCY_TOMORROW)); + urgencyValues.add(new UrgencyValue(labels[5], + Task.URGENCY_NEXT_WEEK)); + urgencyValues.add(new UrgencyValue(labels[7], + Task.URGENCY_NEXT_MONTH)); + } urgencyValues.add(new UrgencyValue(labels[0], Task.URGENCY_NONE)); @@ -161,7 +181,7 @@ public class DateAndTimePicker extends LinearLayout { int strokeWidth = (int) (1 * r.getDisplayMetrics().density); for (int i = 0; i < urgencyValues.size(); i++) { - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, (int) (42 * metrics.density), 0); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, (int) ((useShortcuts ? 42 : 38) * metrics.density), 0); UrgencyValue uv = urgencyValues.get(i); ToggleButton tb = new ToggleButton(context); @@ -170,7 +190,10 @@ public class DateAndTimePicker extends LinearLayout { tb.setTextOn(label); tb.setTag(uv); if (i == 0) { - tb.setBackgroundDrawable(CustomBorderDrawable.customButton(cornerRadius, cornerRadius, 0, 0, onColorValue, offColorValue, borderColorValue, strokeWidth)); + if (useShortcuts) + tb.setBackgroundDrawable(CustomBorderDrawable.customButton(cornerRadius, cornerRadius, 0, 0, onColorValue, offColorValue, borderColorValue, strokeWidth)); + else + tb.setBackgroundDrawable(CustomBorderDrawable.customButton(cornerRadius, cornerRadius, cornerRadius, cornerRadius, onColorValue, offColorValue, borderColorValue, strokeWidth)); } else if (i == urgencyValues.size() - 2) { lp.topMargin = (int) (-1 * metrics.density); tb.setBackgroundDrawable(CustomBorderDrawable.customButton(0, 0, cornerRadius, cornerRadius, onColorValue, offColorValue, borderColorValue, strokeWidth)); @@ -207,12 +230,17 @@ public class DateAndTimePicker extends LinearLayout { private void updateShortcutView(Date date) { for (int i = 0; i < dateShortcuts.getChildCount(); i++) { - ToggleButton tb = (ToggleButton) dateShortcuts.getChildAt(i); - UrgencyValue uv = (UrgencyValue) tb.getTag(); - if (uv.dueDate == date.getTime()) { - tb.setChecked(true); - } else { - tb.setChecked(false); + View child = dateShortcuts.getChildAt(i); + if (child instanceof ToggleButton) { + ToggleButton tb = (ToggleButton) child; + UrgencyValue uv = (UrgencyValue) tb.getTag(); + if (uv != null) { + if (uv.dueDate == date.getTime()) { + tb.setChecked(true); + } else { + tb.setChecked(false); + } + } } } }