Lots of work on making the horizontal layout for the timepicker work

pull/14/head
Sam Bosley 13 years ago
parent 3887a6eec0
commit e67e7aa96e

@ -6,69 +6,74 @@
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/timeComponents"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dip"
android:orientation="horizontal">
<com.todoroo.astrid.ui.DeadlineNumberPicker
android:id="@+id/hours"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/timeComponents"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:text=":"
android:textColor="?attr/asTextColor"
android:gravity="center"
/>
<com.todoroo.astrid.ui.DeadlineNumberPicker
android:id="@+id/minutes"
android:layout_marginBottom="8dip"
android:orientation="horizontal">
<com.todoroo.astrid.ui.DeadlineNumberPicker
android:id="@+id/hours"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:text=":"
android:textColor="?attr/asTextColor"
android:gravity="center"
/>
<com.todoroo.astrid.ui.DeadlineNumberPicker
android:id="@+id/minutes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/am_pm_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/am_pm_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip">
android:layout_marginBottom="4dip">
<ToggleButton
android:id="@+id/am_button"
android:layout_width="fill_parent"
android:layout_height="42dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:textSize="18sp"
android:gravity="center"
android:textColor="@color/task_edit_toggle_button_text"
android:layout_weight="1"
android:layout_marginRight="-1dip"/>
<ToggleButton
android:id="@+id/pm_button"
android:layout_width="fill_parent"
android:layout_height="42dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:textSize="18sp"
android:gravity="center"
android:textColor="@color/task_edit_toggle_button_text"
android:layout_weight="1"
android:layout_marginLeft="-1dip"/>
</LinearLayout>
<ToggleButton
android:id="@+id/am_button"
android:id="@+id/hasTime"
android:layout_width="fill_parent"
android:layout_height="42dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:textSize="18sp"
android:gravity="center"
android:textColor="@color/task_edit_toggle_button_text"
android:layout_weight="1"
android:layout_marginRight="-1dip"/>
<ToggleButton
android:id="@+id/pm_button"
android:layout_width="fill_parent"
android:layout_height="42dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:textSize="18sp"
android:gravity="center"
android:textColor="@color/task_edit_toggle_button_text"
android:layout_weight="1"
android:layout_marginLeft="-1dip"/>
android:textColor="@color/task_edit_toggle_button_text"/>
</LinearLayout>
<ToggleButton
android:id="@+id/hasTime"
android:layout_width="fill_parent"
android:layout_height="42dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:textSize="18sp"
android:gravity="center"
android:textColor="@color/task_edit_toggle_button_text"/>
</merge>

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
** Copyright (c) 2012 Todoroo Inc
**
** See the file "LICENSE" for the full license governing this code.
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/timeComponents"
android:layout_width="fill_parent"
android:layout_height="122dip"
android:layout_weight="1"
android:layout_marginBottom="5dip"
android:layout_marginRight="4dip"
android:orientation="horizontal">
<com.todoroo.astrid.ui.DeadlineNumberPicker
android:id="@+id/hours"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:text=":"
android:textColor="?attr/asTextColor"
android:gravity="center"
/>
<com.todoroo.astrid.ui.DeadlineNumberPicker
android:id="@+id/minutes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/date_shortcuts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="4dip"
android:orientation="vertical">
<LinearLayout
android:id="@+id/am_pm_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip">
<ToggleButton
android:id="@+id/am_button"
android:layout_width="fill_parent"
android:layout_height="38dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:textSize="18sp"
android:gravity="center"
android:textColor="@color/task_edit_toggle_button_text"
android:layout_weight="1"
android:layout_marginRight="-1dip"/>
<ToggleButton
android:id="@+id/pm_button"
android:layout_width="fill_parent"
android:layout_height="38dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:textSize="18sp"
android:gravity="center"
android:textColor="@color/task_edit_toggle_button_text"
android:layout_weight="1"
android:layout_marginLeft="-1dip"/>
</LinearLayout>
<ToggleButton
android:id="@+id/hasTime"
android:layout_width="fill_parent"
android:layout_marginBottom="4dip"
android:layout_height="38dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:textSize="18sp"
android:gravity="center"
android:textColor="@color/task_edit_toggle_button_text"/>
</LinearLayout>
</LinearLayout>
</merge>

@ -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);

@ -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<UrgencyValue>();
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);
}
}
}
}
}

Loading…
Cancel
Save