mirror of https://github.com/tasks/tasks
Completed step 1 of alarms - the control set
parent
feb6b828a5
commit
8fee29ef55
@ -1,111 +1,34 @@
|
|||||||
/**
|
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.alarms;
|
package com.todoroo.astrid.alarms;
|
||||||
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.data.AbstractModel;
|
|
||||||
import com.todoroo.andlib.data.Property;
|
|
||||||
import com.todoroo.andlib.data.Property.IntegerProperty;
|
import com.todoroo.andlib.data.Property.IntegerProperty;
|
||||||
import com.todoroo.andlib.data.Property.LongProperty;
|
import com.todoroo.andlib.data.Property.LongProperty;
|
||||||
import com.todoroo.andlib.data.Property.StringProperty;
|
import com.todoroo.astrid.model.Metadata;
|
||||||
import com.todoroo.andlib.data.Table;
|
|
||||||
import com.todoroo.andlib.data.TodorooCursor;
|
|
||||||
import com.todoroo.astrid.model.Task;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data Model which represents an alarm
|
* Metadata entry for a task alarm
|
||||||
*
|
*
|
||||||
* @author Tim Su <tim@todoroo.com>
|
* @author Tim Su <tim@todoroo.com>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("nls")
|
public class Alarm {
|
||||||
public class Alarm extends AbstractModel {
|
|
||||||
|
|
||||||
// --- table
|
|
||||||
|
|
||||||
public static final Table TABLE = new Table("alarm", Alarm.class);
|
|
||||||
|
|
||||||
// --- properties
|
/** metadata key */
|
||||||
|
public static final String METADATA_KEY = "alarm"; //$NON-NLS-1$
|
||||||
|
|
||||||
/** ID */
|
/** time of alarm */
|
||||||
public static final LongProperty ID = new LongProperty(
|
public static final LongProperty TIME = new LongProperty(Metadata.TABLE,
|
||||||
TABLE, ID_PROPERTY_NAME);
|
Metadata.VALUE1.name);
|
||||||
|
|
||||||
/** Associated Task */
|
/** alarm type */
|
||||||
public static final LongProperty TASK = new LongProperty(
|
public static final IntegerProperty TYPE = new IntegerProperty(Metadata.TABLE,
|
||||||
TABLE, "task");
|
Metadata.VALUE2.name);
|
||||||
|
|
||||||
/** Alarm Time */
|
|
||||||
public static final LongProperty TIME = new LongProperty(
|
|
||||||
TABLE, "time");
|
|
||||||
|
|
||||||
/** Alarm Type (see constants) */
|
|
||||||
public static final IntegerProperty TYPE = new IntegerProperty(
|
|
||||||
TABLE, "type");
|
|
||||||
|
|
||||||
/** Alarm Ringtone */
|
|
||||||
public static final StringProperty RINGTONE = new StringProperty(
|
|
||||||
TABLE, "ringtone");
|
|
||||||
|
|
||||||
/** List of all properties for this model */
|
|
||||||
public static final Property<?>[] PROPERTIES = generateProperties(Alarm.class);
|
|
||||||
|
|
||||||
// --- constants
|
// --- constants
|
||||||
|
|
||||||
/** this alarm was already triggered */
|
|
||||||
public static final int TYPE_TRIGGERED = 0;
|
|
||||||
|
|
||||||
/** this alarm is single-shot */
|
/** this alarm is single-shot */
|
||||||
public static final int TYPE_SINGLE = 1;
|
public static final int TYPE_SINGLE = 1;
|
||||||
|
|
||||||
/** this alarm repeats itself until turned off */
|
/** this alarm repeats itself until turned off */
|
||||||
public static final int TYPE_REPEATING = 2;
|
public static final int TYPE_REPEATING = 2;
|
||||||
|
|
||||||
// --- defaults
|
|
||||||
|
|
||||||
/** Default values container */
|
|
||||||
private static final ContentValues defaultValues = new ContentValues();
|
|
||||||
|
|
||||||
static {
|
|
||||||
defaultValues.put(TYPE.name, TYPE_SINGLE);
|
|
||||||
defaultValues.put(RINGTONE.name, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContentValues getDefaultValues() {
|
|
||||||
return defaultValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- data access boilerplate
|
|
||||||
|
|
||||||
public Alarm() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Alarm(TodorooCursor<Alarm> cursor) {
|
|
||||||
this();
|
|
||||||
readPropertiesFromCursor(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFromCursor(TodorooCursor<Alarm> cursor) {
|
|
||||||
super.readPropertiesFromCursor(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getId() {
|
|
||||||
return getIdHelper(ID);
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- parcelable helpers
|
|
||||||
|
|
||||||
private static final Creator<Task> CREATOR = new ModelCreator<Task>(Task.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Creator<? extends AbstractModel> getCreator() {
|
|
||||||
return CREATOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,101 @@
|
|||||||
|
package com.todoroo.astrid.alarms;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import com.timsu.astrid.R;
|
||||||
|
import com.todoroo.andlib.data.TodorooCursor;
|
||||||
|
import com.todoroo.andlib.widget.DateControlSet;
|
||||||
|
import com.todoroo.astrid.activity.TaskEditActivity.TaskEditControlSet;
|
||||||
|
import com.todoroo.astrid.model.Metadata;
|
||||||
|
import com.todoroo.astrid.model.Task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Control set to manage adding and removing tags
|
||||||
|
*
|
||||||
|
* @author Tim Su <tim@todoroo.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public final class AlarmControlSet implements TaskEditControlSet {
|
||||||
|
|
||||||
|
// --- constants
|
||||||
|
|
||||||
|
/** Number of alarms a task can have */
|
||||||
|
static final int MAX_ALARMS = 10;
|
||||||
|
|
||||||
|
// --- instance variables
|
||||||
|
|
||||||
|
private final LinearLayout alertsContainer;
|
||||||
|
private final Activity activity;
|
||||||
|
|
||||||
|
public AlarmControlSet(Activity activity, ViewGroup parent) {
|
||||||
|
View v = LayoutInflater.from(activity).inflate(R.layout.alarm_control, parent, true);
|
||||||
|
|
||||||
|
this.activity = activity;
|
||||||
|
this.alertsContainer = (LinearLayout) v.findViewById(R.id.alert_container);
|
||||||
|
v.findViewById(R.id.alarms_add).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View arg0) {
|
||||||
|
addAlarm(new Date());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromTask(Task task) {
|
||||||
|
if(alertsContainer.getChildCount() == 0) {
|
||||||
|
TodorooCursor<Metadata> cursor = AlarmService.getInstance().getAlarms(task.getId());
|
||||||
|
try {
|
||||||
|
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext())
|
||||||
|
addAlarm(new Date(cursor.get(Alarm.TIME)));
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToModel(Task task) {
|
||||||
|
LinkedHashSet<Long> alarms = new LinkedHashSet<Long>();
|
||||||
|
for(int i = 0; i < alertsContainer.getChildCount(); i++) {
|
||||||
|
DateControlSet set = (DateControlSet) alertsContainer.getChildAt(i).getTag();
|
||||||
|
if(set == null)
|
||||||
|
continue;
|
||||||
|
Date date = set.getDate();
|
||||||
|
if(date != null)
|
||||||
|
alarms.add(set.getDate().getTime());
|
||||||
|
}
|
||||||
|
AlarmService.getInstance().synchronizeAlarms(task.getId(), alarms);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean addAlarm(Date alert) {
|
||||||
|
if(alertsContainer.getChildCount() >= MAX_ALARMS)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
final View alertItem = LayoutInflater.from(activity).inflate(R.layout.alarm_edit_row, null);
|
||||||
|
alertsContainer.addView(alertItem);
|
||||||
|
|
||||||
|
DateControlSet dcs = new DateControlSet(activity, (Button)alertItem.findViewById(R.id.date),
|
||||||
|
(Button)alertItem.findViewById(R.id.time));
|
||||||
|
dcs.setDate(alert);
|
||||||
|
alertItem.setTag(dcs);
|
||||||
|
|
||||||
|
ImageButton reminderRemoveButton;
|
||||||
|
reminderRemoveButton = (ImageButton)alertItem.findViewById(R.id.button1);
|
||||||
|
reminderRemoveButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
alertsContainer.removeView(alertItem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,102 @@
|
|||||||
|
/**
|
||||||
|
* See the file "LICENSE" for the full license governing this code.
|
||||||
|
*/
|
||||||
|
package com.todoroo.astrid.alarms;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
|
||||||
|
import com.todoroo.andlib.data.AbstractModel;
|
||||||
|
import com.todoroo.andlib.data.Property;
|
||||||
|
import com.todoroo.andlib.data.Property.LongProperty;
|
||||||
|
import com.todoroo.andlib.data.Table;
|
||||||
|
import com.todoroo.andlib.data.TodorooCursor;
|
||||||
|
import com.todoroo.astrid.model.Task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data Model which represents an alarm. This is a transitional class -
|
||||||
|
* Alarms are moved over to metadata
|
||||||
|
*
|
||||||
|
* @author Tim Su <tim@todoroo.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("nls")
|
||||||
|
@Deprecated
|
||||||
|
public class TransitionalAlarm extends AbstractModel {
|
||||||
|
|
||||||
|
// --- table
|
||||||
|
|
||||||
|
public static final Table TABLE = new Table("alarm", TransitionalAlarm.class);
|
||||||
|
|
||||||
|
// --- properties
|
||||||
|
|
||||||
|
/** ID */
|
||||||
|
public static final LongProperty ID = new LongProperty(
|
||||||
|
TABLE, ID_PROPERTY_NAME);
|
||||||
|
|
||||||
|
/** Associated Task */
|
||||||
|
public static final LongProperty TASK = new LongProperty(
|
||||||
|
TABLE, "task");
|
||||||
|
|
||||||
|
/** Alarm Time */
|
||||||
|
public static final LongProperty TIME = new LongProperty(
|
||||||
|
TABLE, "time");
|
||||||
|
|
||||||
|
/** List of all properties for this model */
|
||||||
|
public static final Property<?>[] PROPERTIES = generateProperties(TransitionalAlarm.class);
|
||||||
|
|
||||||
|
// --- constants
|
||||||
|
|
||||||
|
/** this alarm was already triggered */
|
||||||
|
public static final int TYPE_TRIGGERED = 0;
|
||||||
|
|
||||||
|
/** this alarm is single-shot */
|
||||||
|
public static final int TYPE_SINGLE = 1;
|
||||||
|
|
||||||
|
/** this alarm repeats itself until turned off */
|
||||||
|
public static final int TYPE_REPEATING = 2;
|
||||||
|
|
||||||
|
// --- defaults
|
||||||
|
|
||||||
|
/** Default values container */
|
||||||
|
private static final ContentValues defaultValues = new ContentValues();
|
||||||
|
|
||||||
|
static {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContentValues getDefaultValues() {
|
||||||
|
return defaultValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- data access boilerplate
|
||||||
|
|
||||||
|
public TransitionalAlarm() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransitionalAlarm(TodorooCursor<TransitionalAlarm> cursor) {
|
||||||
|
this();
|
||||||
|
readPropertiesFromCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFromCursor(TodorooCursor<TransitionalAlarm> cursor) {
|
||||||
|
super.readPropertiesFromCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getId() {
|
||||||
|
return getIdHelper(ID);
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- parcelable helpers
|
||||||
|
|
||||||
|
private static final Creator<Task> CREATOR = new ModelCreator<Task>(Task.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Creator<? extends AbstractModel> getCreator() {
|
||||||
|
return CREATOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- See the file "LICENSE" for the full license governing this code. -->
|
||||||
|
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<TextView android:id="@+id/alarms_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/alarm_ACS_label"
|
||||||
|
style="@style/TextAppearance.GEN_EditLabel" />
|
||||||
|
|
||||||
|
<LinearLayout android:id="@+id/alert_container"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<Button android:id="@+id/alarms_add"
|
||||||
|
android:text="@string/alarm_ACS_button"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
</merge>
|
||||||
|
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2008 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<Button android:id="@+id/date"
|
||||||
|
android:layout_weight="0.7"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
<Button android:id="@+id/time"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
<ImageButton android:id="@+id/button1"
|
||||||
|
style="?android:attr/buttonStyleInset"
|
||||||
|
android:src="@android:drawable/ic_delete"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_marginTop="2dip"
|
||||||
|
android:layout_marginRight="2dip"
|
||||||
|
android:layout_marginBottom="2dip"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- See the file "LICENSE" for the full license governing this code. -->
|
||||||
|
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<!-- Resources for built-in timers plug-in -->
|
||||||
|
|
||||||
|
<!-- Task Edit Activity: Container Label -->
|
||||||
|
<string name="alarm_ACS_label">Alarms</string>
|
||||||
|
|
||||||
|
<!-- Task Edit Activity: Add New Alarn -->
|
||||||
|
<string name="alarm_ACS_button">Add an Alarm</string>
|
||||||
|
|
||||||
|
<!-- Android Notification Title (%s => task name) -->
|
||||||
|
<string name="alarm_notification">Alarm! %s</string>
|
||||||
|
|
||||||
|
</resources>
|
||||||
Loading…
Reference in New Issue