Deleted and moved around a bunch of legacy things

pull/14/head
Tim Su 14 years ago
parent 9727604d2f
commit 2a88772ae8

@ -14,11 +14,9 @@
<booleanAttribute key="com.android.ide.eclipse.adt.wipedata" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/astrid"/>
<listEntry value="/astrid/AndroidManifest.xml"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
<listEntry value="1"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>

@ -19,6 +19,11 @@ import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.text.InputType;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
@ -59,6 +64,19 @@ public class AndroidUtilities {
}
}
/** Suppress virtual keyboard until user's first tap */
public static void suppressVirtualKeyboard(final TextView editor) {
final int inputType = editor.getInputType();
editor.setInputType(InputType.TYPE_NULL);
editor.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
editor.setInputType(inputType);
editor.setOnTouchListener(null);
return false;
}
});
}
/**
* @return true if we're connected to the internet
*/

@ -0,0 +1,82 @@
/*
* ASTRID: Android's Simple Task Recording Dashboard
*
* Copyright (c) 2009 Tim Su
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.todoroo.astrid.backup;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.util.Log;
public class BackupDateUtilities {
private static final String ISO_8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ssz";
/* Format a Date into ISO 8601 Compliant format.
*/
public static String getIso8601String(Date d) {
SimpleDateFormat sdf = new SimpleDateFormat(ISO_8601_FORMAT);
String result = "";
if (d != null) {
result = sdf.format(d);
}
return result;
}
/* Take an ISO 8601 string and return a Date object.
On failure, returns null.
*/
public static Date getDateFromIso8601String(String s) {
SimpleDateFormat df = new SimpleDateFormat(ISO_8601_FORMAT);
try {
return df.parse(s);
} catch (ParseException e) {
Log.e("DateUtilities", "Error parsing ISO 8601 date");
return null;
}
}
/* Get current date and time as a string.
Used in TasksXmlExporter
*/
public static String getDateForExport() {
DateFormat df = new SimpleDateFormat("yyMMdd-HHmm");
return df.format(new Date());
}
public static boolean wasCreatedBefore(String s, int daysAgo) {
DateFormat df = new SimpleDateFormat("yyMMdd");
Date date;
try {
date = df.parse(s);
} catch (ParseException e) {
return false;
}
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -daysAgo);
Date calDate = cal.getTime();
return date.before(calDate);
}
}

@ -1,4 +1,4 @@
package com.timsu.astrid.utilities;
package com.todoroo.astrid.backup;
import java.io.File;
import java.io.FileFilter;
@ -73,7 +73,7 @@ public class BackupService extends Service {
exporter.exportTasks(backupDirectorySetting.getBackupDirectory());
Preferences.setBackupSummary(ctx,
ctx.getString(R.string.prefs_backup_desc_success,
DateUtilities.getFormattedDate(ctx, new Date())));
BackupDateUtilities.getFormattedDate(ctx, new Date())));
} catch (Exception e) {
// unable to backup.
if (e == null || e.getMessage() == null) {

@ -1,4 +1,4 @@
package com.timsu.astrid.utilities;
package com.todoroo.astrid.backup;
import java.io.File;
import java.io.FileOutputStream;
@ -19,15 +19,15 @@ import android.util.Xml;
import android.widget.Toast;
import com.timsu.astrid.R;
import com.timsu.astrid.data.TaskController;
import com.timsu.astrid.data.TaskIdentifier;
import com.timsu.astrid.data.TaskModelForXml;
import com.timsu.astrid.data.alerts.AlertController;
import com.timsu.astrid.data.sync.SyncDataController;
import com.timsu.astrid.data.sync.SyncMapping;
import com.timsu.astrid.data.tag.TagController;
import com.timsu.astrid.data.tag.TagIdentifier;
import com.timsu.astrid.data.tag.TagModelForView;
import com.timsu.astrid.data.task.TaskController;
import com.timsu.astrid.data.task.TaskIdentifier;
import com.timsu.astrid.data.task.TaskModelForXml;
public class TasksXmlExporter {
@ -97,7 +97,7 @@ public class TasksXmlExporter {
List<Date> alerts = alertController.getTaskAlerts(task);
for (Date alert : alerts) {
xml.startTag(null, ALERT_TAG);
xml.attribute(null, ALERT_ATTR_DATE, DateUtilities.getIso8601String(alert));
xml.attribute(null, ALERT_ATTR_DATE, BackupDateUtilities.getIso8601String(alert));
xml.endTag(null, ALERT_TAG);
}
}
@ -212,7 +212,7 @@ public class TasksXmlExporter {
} else {
fileName = EXPORT_FILE_NAME;
}
fileName = String.format(fileName, DateUtilities.getDateForExport());
fileName = String.format(fileName, BackupDateUtilities.getDateForExport());
setOutput(astridDir.getAbsolutePath() + "/" + fileName);
return true;
} else {

@ -1,4 +1,4 @@
package com.timsu.astrid.utilities;
package com.todoroo.astrid.backup;
import java.io.FileNotFoundException;
import java.io.FileReader;
@ -18,15 +18,15 @@ import android.util.Log;
import com.timsu.astrid.R;
import com.timsu.astrid.data.AbstractController;
import com.timsu.astrid.data.TaskController;
import com.timsu.astrid.data.TaskIdentifier;
import com.timsu.astrid.data.TaskModelForXml;
import com.timsu.astrid.data.alerts.AlertController;
import com.timsu.astrid.data.sync.SyncDataController;
import com.timsu.astrid.data.sync.SyncMapping;
import com.timsu.astrid.data.tag.TagController;
import com.timsu.astrid.data.tag.TagIdentifier;
import com.timsu.astrid.data.tag.TagModelForView;
import com.timsu.astrid.data.task.TaskController;
import com.timsu.astrid.data.task.TaskIdentifier;
import com.timsu.astrid.data.task.TaskModelForXml;
public class TasksXmlImporter {
public static final String TAG = "TasksXmlImporter";
@ -170,7 +170,7 @@ public class TasksXmlImporter {
private boolean parseAlert(TaskIdentifier taskId) {
String alert = xpp.getAttributeValue(null, ALERT_ATTR_DATE);
if (alert != null) {
Date alertDate = DateUtilities.getDateFromIso8601String(alert);
Date alertDate = BackupDateUtilities.getDateFromIso8601String(alert);
if (alertDate != null) {
if (! alertController.addAlert(taskId, alertDate)) {
return false;
@ -214,7 +214,7 @@ public class TasksXmlImporter {
Date creationDate = null;
String createdString = xpp.getAttributeValue(null, TASK_CREATION_DATE);
if (createdString != null) {
creationDate = DateUtilities.getDateFromIso8601String(createdString);
creationDate = BackupDateUtilities.getDateFromIso8601String(createdString);
}
// If the task's name and creation date match an existing task, skip it.
if (creationDate != null && taskName != null) {

@ -1,4 +1,4 @@
package com.todoroo.astrid.activity;
package com.todoroo.astrid.locale;
import java.util.LinkedList;

@ -1,4 +1,4 @@
package com.timsu.astrid.utilities;
package com.todoroo.astrid.locale;
import java.util.HashSet;
import java.util.LinkedList;
@ -10,11 +10,10 @@ import android.content.res.Resources;
import android.util.Log;
import com.timsu.astrid.R;
import com.timsu.astrid.data.TaskController;
import com.timsu.astrid.data.TaskIdentifier;
import com.timsu.astrid.data.tag.TagController;
import com.timsu.astrid.data.tag.TagIdentifier;
import com.timsu.astrid.data.task.TaskController;
import com.timsu.astrid.data.task.TaskIdentifier;
import com.todoroo.astrid.activity.LocaleEditAlerts;
/**
* Receiver is activated when Locale conditions are triggered

@ -24,14 +24,14 @@ import com.google.ical.values.RRule;
import com.google.ical.values.Weekday;
import com.google.ical.values.WeekdayNum;
import com.timsu.astrid.R;
import com.timsu.astrid.widget.NumberPicker;
import com.timsu.astrid.widget.NumberPickerDialog;
import com.timsu.astrid.widget.NumberPickerDialog.OnNumberPickedListener;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.astrid.activity.TaskEditActivity.TaskEditControlSet;
import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.ui.NumberPicker;
import com.todoroo.astrid.ui.NumberPickerDialog;
import com.todoroo.astrid.ui.NumberPickerDialog.OnNumberPickedListener;
/**
* Control Set for managing repeats

@ -17,17 +17,25 @@
*/
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
android:orientation="vertical">
<TimePicker android:id="@+id/timePicker"
<TimePicker android:id="@+id/timePicker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<CheckBox android:id="@+id/hasTime"
<CheckBox android:id="@+id/hasTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/TEA_urgency_specific_time"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

@ -1,633 +0,0 @@
/*
* ASTRID: Android's Simple Task Recording Dashboard
*
* Copyright (c) 2009 Tim Su
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.timsu.astrid.data.task;
import java.util.Date;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.timsu.astrid.R;
import com.timsu.astrid.data.AbstractController;
import com.timsu.astrid.data.AbstractModel;
import com.timsu.astrid.data.enums.Importance;
import com.timsu.astrid.data.enums.RepeatInterval;
import com.timsu.astrid.utilities.DialogUtilities;
import com.timsu.astrid.utilities.Preferences;
/** Abstract model of a task. Subclasses implement the getters and setters
* they are interested in.
*
* @author timsu
*
*/
public abstract class AbstractTaskModel extends AbstractModel {
/** Version number of this model */
static final int VERSION = 8;
public static final int COMPLETE_PERCENTAGE = 100;
// field names
public static final String NAME = "name";
public static final String NOTES = "notes";
public static final String PROGRESS_PERCENTAGE = "progressPercentage";
public static final String IMPORTANCE = "importance";
public static final String ESTIMATED_SECONDS = "estimatedSeconds";
public static final String ELAPSED_SECONDS = "elapsedSeconds";
public static final String TIMER_START = "timerStart";
public static final String DEFINITE_DUE_DATE = "definiteDueDate";
public static final String PREFERRED_DUE_DATE = "preferredDueDate";
public static final String HIDDEN_UNTIL = "hiddenUntil";
public static final String POSTPONE_COUNT = "postponeCount";
public static final String NOTIFICATIONS = "notifications";
public static final String NOTIFICATION_FLAGS = "notificationFlags";
public static final String LAST_NOTIFIED = "lastNotified";
public static final String REPEAT = "repeat";
public static final String CREATION_DATE = "creationDate";
public static final String COMPLETION_DATE = "completionDate";
public static final String CALENDAR_URI = "calendarUri";
public static final String FLAGS = "flags";
// reserved fields ---
public static final String BLOCKING_ON = "blockingOn";
// notification flags
public static final int NOTIFY_BEFORE_DEADLINE = 1 << 0;
public static final int NOTIFY_AT_DEADLINE = 1 << 1;
public static final int NOTIFY_AFTER_DEADLINE = 1 << 2;
public static final int NOTIFY_NONSTOP = 1 << 3;
// other flags
public static final int FLAG_SYNC_ON_COMPLETE = 1 << 0;
/** Number of bits to shift repeat value by */
public static final int REPEAT_VALUE_OFFSET = 3;
/** Default values container */
private static final ContentValues defaultValues = new ContentValues();
static {
defaultValues.put(NAME, "");
defaultValues.put(NOTES, "");
defaultValues.put(PROGRESS_PERCENTAGE, 0);
defaultValues.put(IMPORTANCE, Importance.DEFAULT.ordinal());
defaultValues.put(ESTIMATED_SECONDS, 0);
defaultValues.put(ELAPSED_SECONDS, 0);
defaultValues.put(TIMER_START, 0);
defaultValues.put(DEFINITE_DUE_DATE, 0);
defaultValues.put(PREFERRED_DUE_DATE, 0);
defaultValues.put(HIDDEN_UNTIL, 0);
defaultValues.put(BLOCKING_ON, 0);
defaultValues.put(POSTPONE_COUNT, 0);
defaultValues.put(NOTIFICATIONS, 0);
defaultValues.put(NOTIFICATION_FLAGS, NOTIFY_AT_DEADLINE);
defaultValues.put(LAST_NOTIFIED, 0);
defaultValues.put(REPEAT, 0);
defaultValues.put(COMPLETION_DATE, 0);
defaultValues.put(CALENDAR_URI, (String)null);
defaultValues.put(FLAGS, 0);
}
// --- database helper
/** Database Helper manages creating new tables and updating old ones */
public static class TaskModelDatabaseHelper extends SQLiteOpenHelper {
String tableName;
Context context;
public TaskModelDatabaseHelper(Context context, String databaseName, String tableName) {
super(context, databaseName, null, VERSION);
this.tableName = tableName;
this.context = context;
}
@Override
public synchronized void onCreate(SQLiteDatabase db) {
String sql = new StringBuilder().
append("CREATE TABLE IF NOT EXISTS ").append(tableName).append(" (").
append(AbstractController.KEY_ROWID).append(" integer primary key autoincrement, ").
append(NAME).append(" text not null,").
append(NOTES).append(" text not null,").
append(PROGRESS_PERCENTAGE).append(" integer not null,").
append(IMPORTANCE).append(" integer not null,").
append(ESTIMATED_SECONDS).append(" integer,").
append(ELAPSED_SECONDS).append(" integer,").
append(TIMER_START).append(" integer,").
append(DEFINITE_DUE_DATE).append(" integer,").
append(PREFERRED_DUE_DATE).append(" integer,").
append(HIDDEN_UNTIL).append(" integer,").
append(BLOCKING_ON).append(" integer,").
append(POSTPONE_COUNT).append(" integer,").
append(NOTIFICATIONS).append(" integer,").
append(NOTIFICATION_FLAGS).append(" integer,").
append(LAST_NOTIFIED).append(" integer,").
append(REPEAT).append(" integer,").
append(FLAGS).append(" integer,").
append(CREATION_DATE).append(" integer,").
append(COMPLETION_DATE).append(" integer,").
append(CALENDAR_URI).append(" text").
append(");").toString();
db.execSQL(sql);
}
@Override
@SuppressWarnings("fallthrough")
public synchronized void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(getClass().getSimpleName(), "Upgrading database from version " +
oldVersion + " to " + newVersion + ".");
String sql;
// note: we execute sql statements in their own try block to be more
// graceful if an upgrade dies halfway or something
switch(oldVersion) {
case 1:
sql = new StringBuilder().append("ALTER TABLE ").
append(tableName).append(" ADD COLUMN ").
append(LAST_NOTIFIED).append(" integer").toString();
try {
db.execSQL(sql);
} catch (Exception e) {
Log.e("astrid", "Error updating table!", e);
}
sql = new StringBuilder().append("ALTER TABLE ").
append(tableName).append(" ADD COLUMN ").
append(NOTIFICATION_FLAGS).append(" integer").toString();
try {
db.execSQL(sql);
} catch (Exception e) {
Log.e("astrid", "Error updating table!", e);
}
case 2:
sql = new StringBuilder().append("ALTER TABLE ").
append(tableName).append(" ADD COLUMN ").
append(REPEAT).append(" integer").toString();
try {
db.execSQL(sql);
} catch (Exception e) {
Log.e("astrid", "Error updating table!", e);
}
case 3:
sql = new StringBuilder().append("ALTER TABLE ").
append(tableName).append(" ADD COLUMN ").
append(CALENDAR_URI).append(" text").toString();
try {
db.execSQL(sql);
} catch (Exception e) {
Log.e("astrid", "Error updating table!", e);
}
case 4:
sql = new StringBuilder().append("ALTER TABLE ").
append(tableName).append(" ADD COLUMN ").
append(POSTPONE_COUNT).append(" integer").toString();
try {
db.execSQL(sql);
} catch (Exception e) {
Log.e("astrid", "Error updating table!", e);
}
case 5:
case 6:
// apparently some people didn't get the flags column
// from version 5 to version 6, so we try again
sql = new StringBuilder().append("ALTER TABLE ").
append(tableName).append(" ADD COLUMN ").
append(FLAGS).append(" integer").toString();
try {
db.execSQL(sql);
} catch (Exception e) {
Log.e("astrid", "Error updating table!", e);
}
case 7:
// not a real change, but make sure that columns that are null
// are converted into zeros, which was my previous assumption
for(String column : new String[] {
ESTIMATED_SECONDS,
ELAPSED_SECONDS,
TIMER_START,
DEFINITE_DUE_DATE,
PREFERRED_DUE_DATE,
HIDDEN_UNTIL,
POSTPONE_COUNT,
LAST_NOTIFIED,
REPEAT,
CREATION_DATE,
COMPLETION_DATE }) {
sql = String.format("UPDATE %s SET %s = 0 WHERE %s ISNULL",
tableName, column, column);
try {
db.execSQL(sql);
} catch (Exception e) {
Log.e("astrid", "Error updating table!", e);
}
}
// --- break point
break;
default:
// we don't know how to handle it... show an error
Log.e(getClass().getSimpleName(), "Unsupported migration from " + oldVersion + " to " + newVersion);
DialogUtilities.okDialog(context, "There was a database error reading from Alerts. Data may have been corrupted.", null);
}
}
}
// --- utility methods
/** Gets task color. Requires definiteDueDate and importance */
protected int getTaskColorResource(Context context) {
if(getDefiniteDueDate() != null && getDefiniteDueDate().getTime() <
System.currentTimeMillis()) {
return R.color.task_list_overdue;
} else if(Preferences.isColorize(context)) {
return getImportance().getTaskListColor();
} else {
return R.color.task_list_normal;
}
}
/** Checks whether task is done. Requires progressPercentage */
protected boolean isTaskCompleted() {
return getProgressPercentage() >= COMPLETE_PERCENTAGE;
}
/** Stops the timer & increments elapsed time. Requires timerStart and
* elapsedSeconds */
protected void stopTimerAndUpdateElapsedTime() {
if(getTimerStart() == null)
return;
long start = getTimerStart().getTime();
setTimerStart(null);
long secondsElapsed = (System.currentTimeMillis() - start)/1000;
setElapsedSeconds((int) (getElapsedSeconds() + secondsElapsed));
}
protected void prefetchData(String[] fields) {
for(String field : fields) {
if(field.equals(NAME))
getName();
else if(field.equals(NOTES))
getNotes();
else if(field.equals(PROGRESS_PERCENTAGE))
getProgressPercentage();
else if(field.equals(IMPORTANCE))
getImportance();
else if(field.equals(ESTIMATED_SECONDS))
getEstimatedSeconds();
else if(field.equals(ELAPSED_SECONDS))
getElapsedSeconds();
else if(field.equals(TIMER_START))
getTimerStart();
else if(field.equals(DEFINITE_DUE_DATE))
getDefiniteDueDate();
else if(field.equals(PREFERRED_DUE_DATE))
getPreferredDueDate();
else if(field.equals(HIDDEN_UNTIL))
getHiddenUntil();
else if(field.equals(BLOCKING_ON))
getBlockingOn();
else if(field.equals(POSTPONE_COUNT))
getPostponeCount();
else if(field.equals(NOTIFICATIONS))
getNotificationIntervalSeconds();
else if(field.equals(CREATION_DATE))
getCreationDate();
else if(field.equals(COMPLETION_DATE))
getCompletionDate();
else if(field.equals(NOTIFICATION_FLAGS))
getNotificationFlags();
else if(field.equals(LAST_NOTIFIED))
getLastNotificationDate();
else if(field.equals(REPEAT))
getRepeat();
else if(field.equals(FLAGS))
getFlags();
}
}
// --- helper classes
public static class RepeatInfo {
private final RepeatInterval interval;
private final int value;
public RepeatInfo(RepeatInterval repeatInterval, int value) {
this.interval = repeatInterval;
this.value = value;
}
public Date shiftDate(Date input) {
Date newDate = (Date)input.clone();
interval.offsetDateBy(newDate, value);
return newDate;
}
public RepeatInterval getInterval() {
return interval;
}
public int getValue() {
return value;
}
public static int toSingleField(RepeatInfo repeatInfo) {
int repeat;
if(repeatInfo == null)
repeat = 0;
else
repeat = (repeatInfo.value << REPEAT_VALUE_OFFSET) +
repeatInfo.interval.ordinal();
return repeat;
}
public static RepeatInfo fromSingleField(int repeat) {
if(repeat == 0)
return null;
int value = repeat >> REPEAT_VALUE_OFFSET;
RepeatInterval interval = RepeatInterval.values()
[repeat - (value << REPEAT_VALUE_OFFSET)];
return new RepeatInfo(interval, value);
}
}
// --- task identifier
private TaskIdentifier identifier = null;
public TaskIdentifier getTaskIdentifier() {
return identifier;
}
void setTaskIdentifier(TaskIdentifier identifier) {
this.identifier = identifier;
}
// --- constructors and abstract methods
AbstractTaskModel() {
super();
}
/** Read identifier from database */
AbstractTaskModel(Cursor cursor) {
super(cursor);
Integer id = retrieveInteger(AbstractController.KEY_ROWID);
setTaskIdentifier(new TaskIdentifier(id));
}
/** Get identifier from argument */
AbstractTaskModel(TaskIdentifier identifier, Cursor cursor) {
super(cursor);
setTaskIdentifier(identifier);
}
@Override
public ContentValues getDefaultValues() {
return defaultValues;
}
// --- getters and setters: expose them as you see fit
protected String getName() {
return retrieveString(NAME);
}
protected String getNotes() {
return retrieveString(NOTES);
}
protected int getProgressPercentage() {
return retrieveInteger(PROGRESS_PERCENTAGE);
}
protected Importance getImportance() {
Integer value = retrieveInteger(IMPORTANCE);
if(value == null)
return null;
return Importance.values()[value];
}
protected Integer getEstimatedSeconds() {
return retrieveInteger(ESTIMATED_SECONDS);
}
protected Integer getElapsedSeconds() {
return retrieveInteger(ELAPSED_SECONDS);
}
protected Date getTimerStart() {
return retrieveDate(TIMER_START);
}
protected Date getDefiniteDueDate() {
return retrieveDate(DEFINITE_DUE_DATE);
}
protected Date getPreferredDueDate() {
return retrieveDate(PREFERRED_DUE_DATE);
}
protected Date getHiddenUntil() {
return retrieveDate(HIDDEN_UNTIL);
}
protected boolean isHidden() {
if(getHiddenUntil() == null)
return false;
return getHiddenUntil().getTime() > System.currentTimeMillis();
}
protected Date getCreationDate() {
return retrieveDate(CREATION_DATE);
}
protected Date getCompletionDate() {
return retrieveDate(COMPLETION_DATE);
}
protected TaskIdentifier getBlockingOn() {
Long value = retrieveLong(BLOCKING_ON);
if(value == null)
return null;
return new TaskIdentifier(value);
}
protected Integer getPostponeCount() {
return retrieveInteger(POSTPONE_COUNT);
}
protected Integer getNotificationIntervalSeconds() {
return retrieveInteger(NOTIFICATIONS);
}
protected int getNotificationFlags() {
return retrieveInteger(NOTIFICATION_FLAGS);
}
protected Date getLastNotificationDate() {
return retrieveDate(LAST_NOTIFIED);
}
protected RepeatInfo getRepeat() {
int repeat = retrieveInteger(REPEAT);
if(repeat == 0)
return null;
int value = repeat >> REPEAT_VALUE_OFFSET;
RepeatInterval interval = RepeatInterval.values()
[repeat - (value << REPEAT_VALUE_OFFSET)];
return new RepeatInfo(interval, value);
}
protected String getCalendarUri() {
String uri = retrieveString(CALENDAR_URI);
if(uri != null && uri.length() == 0)
return null;
else
return uri;
}
protected int getFlags() {
return retrieveInteger(FLAGS);
}
// --- setters
protected void setName(String name) {
putIfChangedFromDatabase(NAME, name);
}
protected void setNotes(String notes) {
putIfChangedFromDatabase(NOTES, notes);
}
protected void setProgressPercentage(int progressPercentage) {
putIfChangedFromDatabase(PROGRESS_PERCENTAGE, progressPercentage);
if(getProgressPercentage() != progressPercentage &&
progressPercentage == COMPLETE_PERCENTAGE)
setCompletionDate(new Date());
}
protected void setImportance(Importance importance) {
putIfChangedFromDatabase(IMPORTANCE, importance.ordinal());
}
protected void setEstimatedSeconds(Integer estimatedSeconds) {
putIfChangedFromDatabase(ESTIMATED_SECONDS, estimatedSeconds);
}
protected void setElapsedSeconds(int elapsedSeconds) {
putIfChangedFromDatabase(ELAPSED_SECONDS, elapsedSeconds);
}
protected void setTimerStart(Date timerStart) {
putDate(TIMER_START, timerStart);
}
protected void setDefiniteDueDate(Date definiteDueDate) {
putDate(DEFINITE_DUE_DATE, definiteDueDate);
}
protected void setPreferredDueDate(Date preferredDueDate) {
putDate(PREFERRED_DUE_DATE, preferredDueDate);
}
protected void setHiddenUntil(Date hiddenUntil) {
putDate(HIDDEN_UNTIL, hiddenUntil);
}
protected void setBlockingOn(TaskIdentifier blockingOn) {
if(blockingOn == null || blockingOn.equals(getTaskIdentifier()))
putIfChangedFromDatabase(BLOCKING_ON, (Integer)null);
else
putIfChangedFromDatabase(BLOCKING_ON, blockingOn.getId());
}
protected void setPostponeCount(int postponeCount) {
putIfChangedFromDatabase(POSTPONE_COUNT, postponeCount);
}
protected void setCreationDate(Date creationDate) {
putDate(CREATION_DATE, creationDate);
}
protected void setCompletionDate(Date completionDate) {
putDate(COMPLETION_DATE, completionDate);
}
protected void setNotificationIntervalSeconds(Integer intervalInSeconds) {
putIfChangedFromDatabase(NOTIFICATIONS, intervalInSeconds);
}
protected void setNotificationFlags(int flags) {
putIfChangedFromDatabase(NOTIFICATION_FLAGS, flags);
}
protected void setLastNotificationTime(Date date) {
putDate(LAST_NOTIFIED, date);
}
protected void setRepeat(RepeatInfo repeatInfo) {
int repeat;
if(repeatInfo == null)
repeat = 0;
else
repeat = (repeatInfo.value << REPEAT_VALUE_OFFSET) +
repeatInfo.interval.ordinal();
putIfChangedFromDatabase(REPEAT, repeat);
}
protected void setCalendarUri(String uri) {
putIfChangedFromDatabase(CALENDAR_URI, uri);
}
protected void setFlags(int flags) {
putIfChangedFromDatabase(FLAGS, flags);
}
// --- utility methods
protected void putDate(String fieldName, Date date) {
if(date == null)
putIfChangedFromDatabase(fieldName, 0);
else
putIfChangedFromDatabase(fieldName, date.getTime());
}
}

@ -12,11 +12,11 @@ import android.database.MatrixCursor;
import android.net.Uri;
import android.util.Log;
import com.timsu.astrid.data.TaskController;
import com.timsu.astrid.data.TaskModelForProvider;
import com.timsu.astrid.data.tag.TagController;
import com.timsu.astrid.data.tag.TagIdentifier;
import com.timsu.astrid.data.tag.TagModelForView;
import com.timsu.astrid.data.task.TaskController;
import com.timsu.astrid.data.task.TaskModelForProvider;
import com.todoroo.astrid.service.AstridDependencyInjector;
public class TasksProvider extends ContentProvider {

@ -1,246 +0,0 @@
/*
* ASTRID: Android's Simple Task Recording Dashboard
*
* Copyright (c) 2009 Tim Su
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.timsu.astrid.utilities;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
import com.timsu.astrid.R;
public class DateUtilities {
private static SimpleDateFormat format = null;
private static final String ISO_8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ssz";
/** Format a time into a medium length absolute format */
public static String getFormattedDate(Context context, Date date) {
if(format == null)
format = Preferences.getDateFormat(context);
return format.format(date);
}
/**
* Convenience method for dropping the preopsition argument.
*/
public static String getDurationString(Resources r, int timeInSeconds,
int unitsToShow) {
return getDurationString(r, timeInSeconds, unitsToShow, false);
}
/**
* Format a time into the format: 5 days, 3 hours, 2 minutes
*
* @param r Resources to get strings from
* @param timeInSeconds
* @param unitsToShow number of units to show (i.e. if 2, then 5 hours
* 3 minutes 2 seconds is truncated to 5 hours 3 minutes)
* @param withPreposition whether there is a preceeding preposition
* @return
*/
public static String getDurationString(Resources r, int timeInSeconds,
int unitsToShow, boolean withPreposition) {
short days, hours, minutes, seconds;
short unitsDisplayed = 0;
if(timeInSeconds == 0)
return r.getQuantityString(R.plurals.Nseconds, 0, 0);
days = (short)(timeInSeconds / 24 / 3600);
timeInSeconds -= days*24*3600;
hours = (short)(timeInSeconds / 3600);
timeInSeconds -= hours * 3600;
minutes = (short)(timeInSeconds / 60);
timeInSeconds -= minutes * 60;
seconds = (short)timeInSeconds;
StringBuilder result = new StringBuilder();
if(days > 0) {
int daysPlural = withPreposition ? R.plurals.NdaysPreposition : R.plurals.Ndays;
result.append(r.getQuantityString(daysPlural, days, days)).
append(" ");
unitsDisplayed++;
}
if(unitsDisplayed < unitsToShow && hours > 0) {
result.append(r.getQuantityString(R.plurals.Nhours, hours,
hours)).
append(" ");
unitsDisplayed++;
}
if(unitsDisplayed < unitsToShow && minutes > 0) {
result.append(r.getQuantityString(R.plurals.Nminutes, minutes,
minutes)).append(" ");
unitsDisplayed++;
}
if(unitsDisplayed < unitsToShow && seconds > 0) {
result.append(r.getQuantityString(R.plurals.Nseconds, seconds,
seconds)).append(" ");
}
return result.toString().trim();
}
/**
* Format a time into the format: 5 days, 3 hrs, 2 min
*
* @param r Resources to get strings from
* @param timeInSeconds
* @param unitsToShow number of units to show (i.e. if 2, then 5 hours
* 3 minutes 2 seconds is truncated to 5 hours 3 minutes)
* @return
*/
public static String getAbbreviatedDurationString(Resources r, int timeInSeconds,
int unitsToShow) {
short days, hours, minutes, seconds;
short unitsDisplayed = 0;
if(timeInSeconds == 0)
return r.getQuantityString(R.plurals.Nseconds, 0, 0);
days = (short)(timeInSeconds / 24 / 3600);
timeInSeconds -= days*24*3600;
hours = (short)(timeInSeconds / 3600);
timeInSeconds -= hours * 3600;
minutes = (short)(timeInSeconds / 60);
timeInSeconds -= minutes * 60;
seconds = (short)timeInSeconds;
StringBuilder result = new StringBuilder();
if(days > 0) {
result.append(r.getQuantityString(R.plurals.Ndays, days, days)).
append(" ");
unitsDisplayed++;
}
if(unitsDisplayed < unitsToShow && hours > 0) {
result.append(r.getQuantityString(R.plurals.NhoursShort, hours,
hours)).
append(" ");
unitsDisplayed++;
}
if(unitsDisplayed < unitsToShow && minutes > 0) {
result.append(r.getQuantityString(R.plurals.NminutesShort, minutes,
minutes)).append(" ");
unitsDisplayed++;
}
if(unitsDisplayed < unitsToShow && seconds > 0) {
result.append(r.getQuantityString(R.plurals.NsecondsShort, seconds,
seconds)).append(" ");
}
return result.toString().trim();
}
/**
* Format a time into the format: 5 d, 3 h, 2 m
*
* @param r Resources to get strings from
* @param timeInSeconds
* @param unitsToShow number of units to show
* @return
*/
public static String getShortDurationString(Resources r, int timeInSeconds,
int unitsToShow) {
short days, hours, minutes, seconds;
short unitsDisplayed = 0;
if(timeInSeconds == 0)
return "0 s";
days = (short)(timeInSeconds / 24 / 3600);
timeInSeconds -= days*24*3600;
hours = (short)(timeInSeconds / 3600);
timeInSeconds -= hours * 3600;
minutes = (short)(timeInSeconds / 60);
timeInSeconds -= minutes * 60;
seconds = (short)timeInSeconds;
StringBuilder result = new StringBuilder();
if(days > 0) {
result.append(days).append(" d ");
unitsDisplayed++;
}
if(unitsDisplayed < unitsToShow && hours > 0) {
result.append(hours).append(" h ");
unitsDisplayed++;
}
if(unitsDisplayed < unitsToShow && minutes > 0) {
result.append(minutes).append(" m ");
unitsDisplayed++;
}
if(unitsDisplayed < unitsToShow && seconds > 0) {
result.append(seconds).append(" s ");
}
return result.toString();
}
/* Format a Date into ISO 8601 Compliant format.
*/
public static String getIso8601String(Date d) {
SimpleDateFormat sdf = new SimpleDateFormat(ISO_8601_FORMAT);
String result = "";
if (d != null) {
result = sdf.format(d);
}
return result;
}
/* Take an ISO 8601 string and return a Date object.
On failure, returns null.
*/
public static Date getDateFromIso8601String(String s) {
SimpleDateFormat df = new SimpleDateFormat(ISO_8601_FORMAT);
try {
return df.parse(s);
} catch (ParseException e) {
Log.e("DateUtilities", "Error parsing ISO 8601 date");
return null;
}
}
/* Get current date and time as a string.
Used in TasksXmlExporter
*/
public static String getDateForExport() {
DateFormat df = new SimpleDateFormat("yyMMdd-HHmm");
return df.format(new Date());
}
public static boolean wasCreatedBefore(String s, int daysAgo) {
DateFormat df = new SimpleDateFormat("yyMMdd");
Date date;
try {
date = df.parse(s);
} catch (ParseException e) {
return false;
}
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -daysAgo);
Date calDate = cal.getTime();
return date.before(calDate);
}
}

@ -0,0 +1,278 @@
package com.timsu.astrid.utilities;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import org.xmlpull.v1.XmlSerializer;
import android.content.Context;
import android.database.Cursor;
import android.os.Environment;
import android.util.Log;
import android.util.Xml;
import android.widget.Toast;
import com.timsu.astrid.R;
import com.timsu.astrid.data.TaskController;
import com.timsu.astrid.data.TaskIdentifier;
import com.timsu.astrid.data.TaskModelForXml;
import com.timsu.astrid.data.alerts.AlertController;
import com.timsu.astrid.data.sync.SyncDataController;
import com.timsu.astrid.data.sync.SyncMapping;
import com.timsu.astrid.data.tag.TagController;
import com.timsu.astrid.data.tag.TagIdentifier;
import com.timsu.astrid.data.tag.TagModelForView;
import com.todoroo.astrid.backup.BackupDateUtilities;
public class LegacyTasksXmlExporter {
private TaskController taskController;
private TagController tagController;
private AlertController alertController;
private SyncDataController syncDataController;
private Context ctx;
private String output;
private final boolean isService;
private int exportCount;
private XmlSerializer xml;
private HashMap<TagIdentifier, TagModelForView> tagMap;
public static final String ASTRID_TAG = "astrid";
public static final String ASTRID_ATTR_VERSION = "version";
public static final String TASK_TAG = "task";
public static final String TAG_TAG = "tag";
public static final String TAG_ATTR_NAME = "name";
public static final String ALERT_TAG = "alert";
public static final String ALERT_ATTR_DATE = "date";
public static final String SYNC_TAG = "sync";
public static final String SYNC_ATTR_SERVICE = "service";
public static final String SYNC_ATTR_REMOTE_ID = "remote_id";
public static final String XML_ENCODING = "utf-8";
public static final String ASTRID_DIR = "/astrid";
private static final String EXPORT_FILE_NAME = "user.%s.xml";
private static final String BACKUP_FILE_NAME = "auto.%s.xml";
public static final int FILENAME_DATE_BEGIN_INDEX = 5;
public static final int FILENAME_DATE_END_INDEX = 11;
public LegacyTasksXmlExporter(boolean isService) {
this.isService = isService;
this.exportCount = 0;
}
private void initTagMap() {
tagMap = tagController.getAllTagsAsMap();
}
private void serializeTags(TaskIdentifier task)
throws IOException {
LinkedList<TagIdentifier> tags = tagController.getTaskTags(task);
for (TagIdentifier tag : tags) {
if(!tagMap.containsKey(tag) || tagMap.get(tag) == null)
continue;
xml.startTag(null, TAG_TAG);
xml.attribute(null, TAG_ATTR_NAME, tagMap.get(tag).toString());
xml.endTag(null, TAG_TAG);
}
}
private void serializeSyncMappings(TaskIdentifier task)
throws IOException {
HashSet<SyncMapping> syncMappings = syncDataController.getSyncMappings(task);
for (SyncMapping sync : syncMappings) {
xml.startTag(null, SYNC_TAG);
xml.attribute(null, SYNC_ATTR_SERVICE,
Integer.toString(sync.getSyncServiceId()));
xml.attribute(null, SYNC_ATTR_REMOTE_ID, sync.getRemoteId());
xml.endTag(null, SYNC_TAG);
}
}
private void serializeAlerts(TaskIdentifier task)
throws IOException {
List<Date> alerts = alertController.getTaskAlerts(task);
for (Date alert : alerts) {
xml.startTag(null, ALERT_TAG);
xml.attribute(null, ALERT_ATTR_DATE, BackupDateUtilities.getIso8601String(alert));
xml.endTag(null, ALERT_TAG);
}
}
private void serializeTasks()
throws IOException {
Cursor c = taskController.getBackupTaskListCursor();
if (! c.moveToFirst()) {
return; // No tasks.
}
do {
TaskModelForXml task = new TaskModelForXml(c);
TaskIdentifier taskId = task.getTaskIdentifier();
xml.startTag(null, TASK_TAG);
HashMap<String, String> taskAttributes = task.getTaskAttributes();
for (String key : taskAttributes.keySet()) {
String value = taskAttributes.get(key);
xml.attribute(null, key, value);
}
serializeTags(taskId);
serializeAlerts(taskId);
serializeSyncMappings(taskId);
xml.endTag(null, TASK_TAG);
this.exportCount++;
} while (c.moveToNext());
c.close();
}
private void doTasksExport() throws IOException {
File xmlFile = new File(this.output);
xmlFile.createNewFile();
FileOutputStream fos = new FileOutputStream(xmlFile);
xml = Xml.newSerializer();
xml.setOutput(fos, XML_ENCODING);
xml.startDocument(null, null);
xml.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
xml.startTag(null, ASTRID_TAG);
xml.attribute(null, ASTRID_ATTR_VERSION,
Integer.toString(Preferences.getCurrentVersion(ctx)));
openControllers();
initTagMap();
serializeTasks();
closeControllers();
xml.endTag(null, ASTRID_TAG);
xml.endDocument();
xml.flush();
fos.close();
if (!isService) {
displayToast();
}
}
private void displayToast() {
CharSequence text = String.format(ctx.getString(R.string.export_toast),
ctx.getResources().getQuantityString(R.plurals.Ntasks, exportCount,
exportCount), output);
Toast.makeText(ctx, text, Toast.LENGTH_LONG).show();
}
private void displayErrorToast(String error) {
Toast.makeText(ctx, error, Toast.LENGTH_LONG).show();
}
private void closeControllers() {
tagController.close();
taskController.close();
alertController.close();
syncDataController.close();
}
private void openControllers() {
taskController.open();
tagController.open();
alertController.open();
syncDataController.open();
}
public void exportTasks(File directory) {
if (isService && !Preferences.isBackupEnabled(ctx)) {
// Automatic backups are disabled.
return;
}
if (setupFile(directory)) {
Thread thread = new Thread(doBackgroundExport);
thread.start();
}
}
public static File getExportDirectory() {
String storageState = Environment.getExternalStorageState();
if (storageState.equals(Environment.MEDIA_MOUNTED)) {
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
path = path + ASTRID_DIR;
return new File(path);
}
return null;
}
private boolean setupFile(File directory) {
File astridDir = directory;
if (astridDir != null) {
// Check for /sdcard/astrid directory. If it doesn't exist, make it.
if (astridDir.exists() || astridDir.mkdir()) {
String fileName;
if (isService) {
fileName = BACKUP_FILE_NAME;
} else {
fileName = EXPORT_FILE_NAME;
}
fileName = String.format(fileName, BackupDateUtilities.getDateForExport());
setOutput(astridDir.getAbsolutePath() + "/" + fileName);
return true;
} else {
// Unable to make the /sdcard/astrid directory.
String error = ctx.getString(R.string.error_sdcard, astridDir.getAbsolutePath());
Log.e("TasksXmlExporter", error);
if (!isService) {
displayErrorToast(error);
}
return false;
}
} else {
// Unable to access the sdcard because it's not in the mounted state.
String error = ctx.getString(R.string.error_sdcard_general);
Log.e("TasksXmlExporter", error);
if (!isService) {
displayErrorToast(error);
}
return false;
}
}
private void setOutput(String file) {
this.output = file;
}
private final Runnable doBackgroundExport = new Runnable() {
public void run() {
/*Looper.prepare();
try {
doTasksExport();
} catch (IOException e) {
Log.e("TasksXmlExporter", "IOException in doTasksExport " + e.getMessage());
}
Looper.loop();*/
}
};
public void setTaskController(TaskController taskController) {
this.taskController = taskController;
}
public void setTagController(TagController tagController) {
this.tagController = tagController;
}
public void setAlertController(AlertController alertController) {
this.alertController = alertController;
}
public void setSyncDataController(SyncDataController syncDataController) {
this.syncDataController = syncDataController;
}
public void setContext(Context ctx) {
this.ctx = ctx;
setTaskController(new TaskController(ctx));
setTagController(new TagController(ctx));
setAlertController(new AlertController(ctx));
setSyncDataController(new SyncDataController(ctx));
}
}

@ -27,8 +27,8 @@ import java.util.List;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.TabActivity;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.TabActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@ -42,6 +42,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
@ -55,19 +56,15 @@ import android.widget.TabHost;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.AdapterView.OnItemSelectedListener;
import com.flurry.android.FlurryAgent;
import com.timsu.astrid.R;
import com.timsu.astrid.data.task.TaskModelForEdit;
import com.timsu.astrid.utilities.AstridUtilities;
import com.timsu.astrid.widget.TimeDurationControlSet;
import com.timsu.astrid.widget.TimeDurationControlSet.TimeDurationType;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.dao.Database;
@ -77,9 +74,11 @@ import com.todoroo.astrid.repeats.RepeatControlSet;
import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.tags.TagsControlSet;
import com.todoroo.astrid.ui.DeadlineTimePickerDialog;
import com.todoroo.astrid.ui.TimeDurationControlSet;
import com.todoroo.astrid.ui.DeadlineTimePickerDialog.OnDeadlineTimeSetListener;
import com.todoroo.astrid.ui.TimeDurationControlSet.TimeDurationType;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.widget.DeadlineTimePickerDialog;
import com.todoroo.astrid.widget.DeadlineTimePickerDialog.OnDeadlineTimeSetListener;
/**
* This activity is responsible for creating new tasks and editing existing
@ -162,7 +161,7 @@ public final class TaskEditActivity extends TabActivity {
setUpUIComponents();
// disable keyboard until user requests it
AstridUtilities.suppressVirtualKeyboard(title);
AndroidUtilities.suppressVirtualKeyboard(title);
}
/* ======================================================================
@ -1030,7 +1029,7 @@ public final class TaskEditActivity extends TabActivity {
after.setChecked((flags &
Task.NOTIFY_AFTER_DEADLINE) > 0);
mode.setSelection((flags &
TaskModelForEdit.NOTIFY_NONSTOP) > 0 ? 1 : 0);
Task.NOTIFY_NONSTOP) > 0 ? 1 : 0);
}
public int getValue() {

@ -21,11 +21,6 @@ import android.util.Log;
import com.google.ical.values.Frequency;
import com.google.ical.values.RRule;
import com.timsu.astrid.R;
import com.timsu.astrid.data.AbstractController;
import com.timsu.astrid.data.alerts.Alert;
import com.timsu.astrid.data.enums.RepeatInterval;
import com.timsu.astrid.data.task.AbstractTaskModel;
import com.timsu.astrid.utilities.TasksXmlExporter;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.GenericDao;
import com.todoroo.andlib.data.Property;
@ -37,6 +32,7 @@ import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.alarms.Alarm;
import com.todoroo.astrid.alarms.AlarmDatabase;
import com.todoroo.astrid.backup.TasksXmlExporter;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.TaskDao;
@ -136,10 +132,10 @@ public class Astrid2To3UpgradeHelper {
// --- upgrade tasks table
HashMap<String, Property<?>> propertyMap =
new HashMap<String, Property<?>>();
propertyMap.put(AbstractController.KEY_ROWID, Task.ID);
propertyMap.put("_id", Task.ID); //$NON-NLS-1$
propertyMap.put(AbstractTaskModel.NAME, Task.TITLE);
propertyMap.put(AbstractTaskModel.NOTES, Task.NOTES);
// don't update progress percentage, we don't use this anymore
// (don't update progress percentage, we don't use this anymore)
propertyMap.put(AbstractTaskModel.IMPORTANCE, Task.IMPORTANCE);
propertyMap.put(AbstractTaskModel.ESTIMATED_SECONDS, Task.ESTIMATED_SECONDS);
propertyMap.put(AbstractTaskModel.ELAPSED_SECONDS, Task.ELAPSED_SECONDS);
@ -165,7 +161,7 @@ public class Astrid2To3UpgradeHelper {
AlarmDatabase alarmsDatabase = new AlarmDatabase();
alarmsDatabase.openForWriting();
propertyMap.clear();
propertyMap.put(AbstractController.KEY_ROWID, Alarm.ID);
propertyMap.put("_id", Alarm.ID); //$NON-NLS-1$
propertyMap.put(Alert.TASK, Alarm.TASK);
propertyMap.put(Alert.DATE, Alarm.TIME);
upgradeTable(context, alertsTable, propertyMap, new Alarm(),
@ -203,38 +199,6 @@ public class Astrid2To3UpgradeHelper {
public StringBuilder upgradeNotes;
}
/** Legacy repeatInfo class */
private static class RepeatInfo {
public static final int REPEAT_VALUE_OFFSET = 3;
private final RepeatInterval interval;
private final int value;
public RepeatInfo(RepeatInterval repeatInterval, int value) {
this.interval = repeatInterval;
this.value = value;
}
public RepeatInterval getInterval() {
return interval;
}
public int getValue() {
return value;
}
public static RepeatInfo fromSingleField(int repeat) {
if(repeat == 0)
return null;
int value = repeat >> REPEAT_VALUE_OFFSET;
RepeatInterval interval = RepeatInterval.values()
[repeat - (value << REPEAT_VALUE_OFFSET)];
return new RepeatInfo(interval, value);
}
}
/**
* Visitor that reads from a visitor container and writes to the model
* @author Tim Su <tim@todoroo.com>
@ -477,5 +441,76 @@ public class Astrid2To3UpgradeHelper {
}
}
// --- legacy data structures
/** Legacy repeatInfo class */
private static class RepeatInfo {
public static final int REPEAT_VALUE_OFFSET = 3;
private final RepeatInterval interval;
private final int value;
public RepeatInfo(RepeatInterval repeatInterval, int value) {
this.interval = repeatInterval;
this.value = value;
}
public RepeatInterval getInterval() {
return interval;
}
public int getValue() {
return value;
}
public static RepeatInfo fromSingleField(int repeat) {
if(repeat == 0)
return null;
int value = repeat >> REPEAT_VALUE_OFFSET;
RepeatInterval interval = RepeatInterval.values()
[repeat - (value << REPEAT_VALUE_OFFSET)];
return new RepeatInfo(interval, value);
}
}
/** Legacy repeat interval class */
private enum RepeatInterval {
DAYS,
WEEKS,
MONTHS,
HOURS
}
/** Legacy task class */
@SuppressWarnings("nls")
private abstract class AbstractTaskModel {
public static final String NAME = "name";
public static final String NOTES = "notes";
public static final String IMPORTANCE = "importance";
public static final String ESTIMATED_SECONDS = "estimatedSeconds";
public static final String ELAPSED_SECONDS = "elapsedSeconds";
public static final String TIMER_START = "timerStart";
public static final String DEFINITE_DUE_DATE = "definiteDueDate";
public static final String PREFERRED_DUE_DATE = "preferredDueDate";
public static final String HIDDEN_UNTIL = "hiddenUntil";
public static final String POSTPONE_COUNT = "postponeCount";
public static final String NOTIFICATIONS = "notifications";
public static final String NOTIFICATION_FLAGS = "notificationFlags";
public static final String LAST_NOTIFIED = "lastNotified";
public static final String REPEAT = "repeat";
public static final String CREATION_DATE = "creationDate";
public static final String COMPLETION_DATE = "completionDate";
public static final String CALENDAR_URI = "calendarUri";
public static final String FLAGS = "flags";
}
/** Legacy alert class */
@SuppressWarnings("nls")
private class Alert {
static final String TASK = "task";
static final String DATE = "date";
}
}

@ -14,12 +14,12 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import com.timsu.astrid.R;
import com.timsu.astrid.utilities.BackupService;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.service.ExceptionService.TodorooUncaughtExceptionHandler;
import com.todoroo.astrid.backup.BackupService;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.reminders.ReminderService;
import com.todoroo.astrid.utility.Constants;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.todoroo.astrid.widget;
package com.todoroo.astrid.ui;
import java.util.Calendar;

@ -1,4 +1,4 @@
package com.timsu.astrid.widget;
package com.todoroo.astrid.ui;
import java.io.File;
import java.io.FilenameFilter;
@ -13,6 +13,7 @@ import android.util.Log;
import com.timsu.astrid.R;
@SuppressWarnings("nls")
public class FilePickerBuilder extends AlertDialog.Builder implements DialogInterface.OnClickListener {
public interface OnFilePickedListener {

@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.timsu.astrid.widget;
package com.todoroo.astrid.ui;
import java.util.LinkedList;
import java.util.List;

@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.timsu.astrid.widget;
package com.todoroo.astrid.ui;
import android.content.Context;
import android.os.Handler;
@ -37,8 +37,9 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import com.timsu.astrid.R;
import com.timsu.astrid.utilities.AstridUtilities;
import com.todoroo.andlib.utility.AndroidUtilities;
@SuppressWarnings({"nls","unused"})
public class NumberPicker extends LinearLayout implements OnClickListener,
OnFocusChangeListener, OnLongClickListener {
@ -139,7 +140,7 @@ public class NumberPicker extends LinearLayout implements OnClickListener,
mText.setFilters(new InputFilter[] { mInputFilter });
// disable keyboard until user requests it
AstridUtilities.suppressVirtualKeyboard(mText);
AndroidUtilities.suppressVirtualKeyboard(mText);
mSlideUpOutAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
@ -347,8 +348,8 @@ public class NumberPicker extends LinearLayout implements OnClickListener,
private static final char[] DIGIT_CHARACTERS = new char[] { '0', '1', '2',
'3', '4', '5', '6', '7', '8', '9' };
private NumberPickerButton mIncrementButton;
private NumberPickerButton mDecrementButton;
private final NumberPickerButton mIncrementButton;
private final NumberPickerButton mDecrementButton;
class NumberPickerInputFilter implements InputFilter {
public CharSequence filter(CharSequence source, int start, int end,

@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.timsu.astrid.widget;
package com.todoroo.astrid.ui;
import android.content.Context;
import android.util.AttributeSet;

@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.timsu.astrid.widget;
package com.todoroo.astrid.ui;
import android.app.AlertDialog;
import android.content.Context;

@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.timsu.astrid.widget;
package com.todoroo.astrid.ui;
import android.app.Activity;
import android.content.res.Resources;
@ -25,12 +25,18 @@ import android.view.View;
import android.widget.Button;
import com.timsu.astrid.R;
import com.timsu.astrid.utilities.DateUtilities;
import com.timsu.astrid.widget.NNumberPickerDialog.OnNNumberPickedListener;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.ui.NNumberPickerDialog.OnNNumberPickedListener;
@SuppressWarnings("nls")
public class TimeDurationControlSet implements OnNNumberPickedListener,
View.OnClickListener {
@Autowired
DateUtilities dateUtilities;
public enum TimeDurationType {
DAYS_HOURS,
HOURS_MINUTES;
@ -46,6 +52,7 @@ public class TimeDurationControlSet implements OnNNumberPickedListener,
public TimeDurationControlSet(Activity activity, int timeButtonId,
int prefixResource, int titleResource, TimeDurationType type) {
Resources r = activity.getResources();
DependencyInjectionService.getInstance().inject(this);
this.activity = activity;
this.prefixResource = prefixResource;
@ -93,8 +100,8 @@ public class TimeDurationControlSet implements OnNNumberPickedListener,
String prefix = "";
if(prefixResource != 0)
prefix = r.getString(prefixResource);
timeButton.setText(prefix + " " + DateUtilities.getDurationString(r,
timeDurationInSeconds, 2));
timeButton.setText(prefix + " " + dateUtilities.getDurationString(
timeDurationInSeconds * 1000L, 2));
switch(type) {
case DAYS_HOURS:
int days = timeDuration / 24 / 3600;

@ -28,7 +28,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.timsu.astrid.data.task.AbstractTaskModel.RepeatInfo;
import com.timsu.astrid.data.AbstractTaskModel.RepeatInfo;
import com.todoroo.astrid.legacy.data.AbstractController;
import com.todoroo.astrid.legacy.data.AbstractModel;
import com.todoroo.astrid.legacy.data.enums.Importance;

@ -7,7 +7,7 @@ import android.database.Cursor;
import android.util.Log;
import com.timsu.astrid.R;
import com.timsu.astrid.utilities.DateUtilities;
import com.timsu.astrid.utilities.BackupDateUtilities;
import com.todoroo.astrid.legacy.data.AbstractController;
import com.todoroo.astrid.legacy.data.enums.Importance;
import com.todoroo.astrid.legacy.data.enums.RepeatInterval;
@ -64,7 +64,7 @@ public class TaskModelForXml extends AbstractTaskModel {
*/
private void safePutDate(String field, Date value) {
if (value != null) {
taskAttributesMap.put(field, DateUtilities.getIso8601String(value));
taskAttributesMap.put(field, BackupDateUtilities.getIso8601String(value));
}
}
@ -132,16 +132,16 @@ public class TaskModelForXml extends AbstractTaskModel {
setElapsedSeconds(Integer.parseInt(value));
}
else if(field.equals(TIMER_START)) {
setTimerStart(DateUtilities.getDateFromIso8601String(value));
setTimerStart(BackupDateUtilities.getDateFromIso8601String(value));
}
else if(field.equals(DEFINITE_DUE_DATE)) {
setDefiniteDueDate(DateUtilities.getDateFromIso8601String(value));
setDefiniteDueDate(BackupDateUtilities.getDateFromIso8601String(value));
}
else if(field.equals(PREFERRED_DUE_DATE)) {
setPreferredDueDate(DateUtilities.getDateFromIso8601String(value));
setPreferredDueDate(BackupDateUtilities.getDateFromIso8601String(value));
}
else if(field.equals(HIDDEN_UNTIL)) {
setHiddenUntil(DateUtilities.getDateFromIso8601String(value));
setHiddenUntil(BackupDateUtilities.getDateFromIso8601String(value));
}
else if(field.equals(BLOCKING_ON)) {
setBlockingOn(new TaskIdentifier(Long.parseLong(value)));
@ -153,16 +153,16 @@ public class TaskModelForXml extends AbstractTaskModel {
setNotificationIntervalSeconds(Integer.parseInt(value));
}
else if(field.equals(CREATION_DATE)) {
setCreationDate(DateUtilities.getDateFromIso8601String(value));
setCreationDate(BackupDateUtilities.getDateFromIso8601String(value));
}
else if(field.equals(COMPLETION_DATE)) {
setCompletionDate(DateUtilities.getDateFromIso8601String(value));
setCompletionDate(BackupDateUtilities.getDateFromIso8601String(value));
}
else if(field.equals(NOTIFICATION_FLAGS)) {
setNotificationFlags(Integer.parseInt(value));
}
else if(field.equals(LAST_NOTIFIED)) {
setLastNotificationTime(DateUtilities.getDateFromIso8601String(value));
setLastNotificationTime(BackupDateUtilities.getDateFromIso8601String(value));
}
else if(field.equals(REPEAT_INTERVAL)) {
try {

@ -5,9 +5,9 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import com.timsu.astrid.data.task.TaskController;
import com.timsu.astrid.data.task.TaskModelForEdit;
import com.timsu.astrid.data.task.TaskModelForList;
import com.timsu.astrid.data.TaskController;
import com.timsu.astrid.data.TaskModelForEdit;
import com.timsu.astrid.data.TaskModelForList;
import com.timsu.astrid.provider.TasksProvider;
import com.todoroo.astrid.test.DatabaseTestCase;

@ -6,10 +6,10 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.timsu.astrid.utilities.BackupService;
import com.timsu.astrid.utilities.Preferences;
import com.timsu.astrid.utilities.BackupService.BackupDirectorySetting;
import com.todoroo.andlib.test.TodorooTestCase;
import com.todoroo.astrid.backup.BackupService;
import com.todoroo.astrid.backup.BackupService.BackupDirectorySetting;
public class BackupServiceTests extends TodorooTestCase {

Loading…
Cancel
Save