pull/14/head
Tim Su 16 years ago
parent 728e1bb2f4
commit 1bd704b5d4

@ -15,5 +15,7 @@
<attribute name="javadoc_location" value="http://google-rfc-2445.googlecode.com/svn/trunk/snapshot/docs"/> <attribute name="javadoc_location" value="http://google-rfc-2445.googlecode.com/svn/trunk/snapshot/docs"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="lib/annotations.jar"/>
<classpathentry kind="lib" path="lib/jsr305.jar"/>
<classpathentry kind="output" path="ecbuild"/> <classpathentry kind="output" path="ecbuild"/>
</classpath> </classpath>

@ -15,8 +15,8 @@ import android.content.Context;
import android.widget.Toast; import android.widget.Toast;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.service.ExceptionService;
@ -53,7 +53,7 @@ public abstract class SynchronizationProvider<TYPE extends TaskContainer> {
* @param context * @param context
* @param notification * @param notification
*/ */
abstract protected void updateNotification(Context context, Notification notification); abstract protected void updateNotification(Context context, Notification n);
/** /**
* Deal with an exception that occurs during synchronization * Deal with an exception that occurs during synchronization

@ -9,9 +9,9 @@ import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log; import android.util.Log;
import com.todoroo.andlib.data.Property.PropertyVisitor; import com.todoroo.andlib.data.Property.PropertyVisitor;

@ -149,7 +149,7 @@ public abstract class AbstractModel implements Parcelable {
/** /**
* Reads the given property. Make sure this model has this property! * Reads the given property. Make sure this model has this property!
*/ */
public <TYPE> TYPE getValue(Property<TYPE> property) { public synchronized <TYPE> TYPE getValue(Property<TYPE> property) {
Object value; Object value;
if(setValues != null && setValues.containsKey(property.name)) if(setValues != null && setValues.containsKey(property.name))
value = setValues.get(property.name); value = setValues.get(property.name);

@ -81,7 +81,7 @@ public class DependencyInjectionService {
* field to inject * field to inject
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
private void handleField(Object caller, Field field) private synchronized void handleField(Object caller, Field field)
throws IllegalStateException, IllegalArgumentException, throws IllegalStateException, IllegalArgumentException,
IllegalAccessException { IllegalAccessException {

@ -74,12 +74,16 @@ public class HttpRestClient implements RestClient {
return sb.toString(); return sb.toString();
} }
private synchronized static void initializeHttpClient() { private synchronized static HttpClient getClient() {
if (httpClient == null || httpClient.get() == null) { if (httpClient == null || httpClient.get() == null) {
HttpParams params = new BasicHttpParams(); HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT_MILLIS); HttpConnectionParams.setConnectionTimeout(params, TIMEOUT_MILLIS);
HttpConnectionParams.setSoTimeout(params, TIMEOUT_MILLIS); HttpConnectionParams.setSoTimeout(params, TIMEOUT_MILLIS);
httpClient = new WeakReference<HttpClient>(new DefaultHttpClient(params)); HttpClient client = new DefaultHttpClient(params);
httpClient = new WeakReference<HttpClient>(client);
return client;
} else {
return httpClient.get();
} }
} }
@ -114,14 +118,12 @@ public class HttpRestClient implements RestClient {
* @throws IOException * @throws IOException
*/ */
public synchronized String get(String url) throws IOException { public synchronized String get(String url) throws IOException {
initializeHttpClient();
if(debug) if(debug)
Log.d("http-rest-client-get", url); //$NON-NLS-1$ Log.d("http-rest-client-get", url); //$NON-NLS-1$
try { try {
HttpGet httpGet = new HttpGet(url); HttpGet httpGet = new HttpGet(url);
HttpResponse response = httpClient.get().execute(httpGet); HttpResponse response = getClient().execute(httpGet);
return processHttpResponse(response); return processHttpResponse(response);
} catch (IOException e) { } catch (IOException e) {
@ -142,15 +144,13 @@ public class HttpRestClient implements RestClient {
* @throws IOException * @throws IOException
*/ */
public synchronized String post(String url, String data) throws IOException { public synchronized String post(String url, String data) throws IOException {
initializeHttpClient();
if(debug) if(debug)
Log.d("http-rest-client-post", url + " | " + data); //$NON-NLS-1$ //$NON-NLS-2$ Log.d("http-rest-client-post", url + " | " + data); //$NON-NLS-1$ //$NON-NLS-2$
try { try {
HttpPost httpPost = new HttpPost(url); HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(data)); httpPost.setEntity(new StringEntity(data));
HttpResponse response = httpClient.get().execute(httpPost); HttpResponse response = getClient().execute(httpPost);
return processHttpResponse(response); return processHttpResponse(response);
} catch (IOException e) { } catch (IOException e) {

@ -1627,15 +1627,15 @@ public class Base64
*/ */
public static class InputStream extends java.io.FilterInputStream { public static class InputStream extends java.io.FilterInputStream {
private boolean encode; // Encoding or decoding private final boolean encode; // Encoding or decoding
private int position; // Current position in the buffer private int position; // Current position in the buffer
private byte[] buffer; // Small buffer holding converted data private final byte[] buffer; // Small buffer holding converted data
private int bufferLength; // Length of buffer (3 or 4) private final int bufferLength; // Length of buffer (3 or 4)
private int numSigBytes; // Number of meaningful bytes in the buffer private int numSigBytes; // Number of meaningful bytes in the buffer
private int lineLength; private int lineLength;
private boolean breakLines; // Break lines at less than 80 characters private final boolean breakLines; // Break lines at less than 80 characters
private int options; // Record options used to create the stream. private final int options; // Record options used to create the stream.
private byte[] decodabet; // Local copies to avoid extra method calls private final byte[] decodabet; // Local copies to avoid extra method calls
/** /**
@ -1840,16 +1840,16 @@ public class Base64
*/ */
public static class OutputStream extends java.io.FilterOutputStream { public static class OutputStream extends java.io.FilterOutputStream {
private boolean encode; private final boolean encode;
private int position; private int position;
private byte[] buffer; private byte[] buffer;
private int bufferLength; private final int bufferLength;
private int lineLength; private int lineLength;
private boolean breakLines; private final boolean breakLines;
private byte[] b4; // Scratch used in a few places private final byte[] b4; // Scratch used in a few places
private boolean suspendEncoding; private boolean suspendEncoding;
private int options; // Record for later private final int options; // Record for later
private byte[] decodabet; // Local copies to avoid extra method calls private final byte[] decodabet; // Local copies to avoid extra method calls
/** /**
* Constructs a {@link Base64.OutputStream} in ENCODE mode. * Constructs a {@link Base64.OutputStream} in ENCODE mode.

@ -1,6 +1,5 @@
package com.todoroo.andlib.utility; package com.todoroo.andlib.utility;
import java.io.Serializable;
import java.lang.ref.Reference; import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue; import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
@ -17,8 +16,7 @@ import java.util.Set;
* @param <K> * @param <K>
* @param <V> * @param <V>
*/ */
public class SoftHashMap<K, V> extends AbstractMap<K, V> implements public class SoftHashMap<K, V> extends AbstractMap<K, V> {
Serializable {
private static final long serialVersionUID = -3796460667941300642L; private static final long serialVersionUID = -3796460667941300642L;
/** The internal HashMap that will hold the SoftReference. */ /** The internal HashMap that will hold the SoftReference. */

@ -186,8 +186,10 @@ public abstract class UserTask<Params, Progress, Result> {
* Creates a new user task. This constructor must be invoked on the UI thread. * Creates a new user task. This constructor must be invoked on the UI thread.
*/ */
public UserTask() { public UserTask() {
if (sHandler == null) { synchronized(UserTask.class) {
sHandler = new InternalHandler(); if (sHandler == null) {
sHandler = new InternalHandler();
}
} }
mWorker = new WorkerRunnable<Params, Result>() { mWorker = new WorkerRunnable<Params, Result>() {
@ -201,7 +203,7 @@ public abstract class UserTask<Params, Progress, Result> {
protected void done() { protected void done() {
Result result = null; Result result = null;
try { try {
result = get(); result = mFuture.get();
} catch (InterruptedException e) { } catch (InterruptedException e) {
android.util.Log.w(LOG_TAG, e); android.util.Log.w(LOG_TAG, e);
} catch (ExecutionException e) { } catch (ExecutionException e) {

Binary file not shown.

Binary file not shown.

@ -41,7 +41,7 @@ public class AlarmDatabase extends AbstractDatabase {
// --- implementation // --- implementation
private GenericDao<Alarm> dao = new GenericDao<Alarm>(Alarm.class, this); private final GenericDao<Alarm> dao = new GenericDao<Alarm>(Alarm.class, this);
@Override @Override
protected String getName() { protected String getName() {
@ -63,7 +63,7 @@ public class AlarmDatabase extends AbstractDatabase {
} }
@Override @Override
protected void onCreateTables() { protected synchronized void onCreateTables() {
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.append("CREATE INDEX IF NOT EXISTS a_task ON "). sql.append("CREATE INDEX IF NOT EXISTS a_task ON ").
append(Alarm.TABLE).append('('). append(Alarm.TABLE).append('(').

@ -150,9 +150,9 @@ public class Notifications extends BroadcastReceiver {
// quiet hours? unless alarm clock // quiet hours? unless alarm clock
boolean quietHours = false; boolean quietHours = false;
Integer quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart); int quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart, -1);
Integer quietHoursEnd = Preferences.getIntegerFromString(R.string.p_rmd_quietEnd); int quietHoursEnd = Preferences.getIntegerFromString(R.string.p_rmd_quietEnd, -1);
if(quietHoursStart != null && quietHoursEnd != null && !nonstopMode) { if(quietHoursStart != -1 && quietHoursEnd != -1 && !nonstopMode) {
int hour = new Date().getHours(); int hour = new Date().getHours();
if(quietHoursStart <= quietHoursEnd) { if(quietHoursStart <= quietHoursEnd) {
if(hour >= quietHoursStart && hour < quietHoursEnd) if(hour >= quietHoursStart && hour < quietHoursEnd)
@ -167,11 +167,9 @@ public class Notifications extends BroadcastReceiver {
notificationId, intent, PendingIntent.FLAG_ONE_SHOT); notificationId, intent, PendingIntent.FLAG_ONE_SHOT);
// set up properties (name and icon) for the notification // set up properties (name and icon) for the notification
Integer iconPreference = Preferences.getIntegerFromString(R.string.p_rmd_icon);
if(iconPreference == null)
iconPreference = ICON_SET_ASTRID;
int icon; int icon;
switch(iconPreference) { switch(Preferences.getIntegerFromString(R.string.p_rmd_icon,
ICON_SET_ASTRID)) {
case ICON_SET_PINK: case ICON_SET_PINK:
icon = R.drawable.notif_pink_alarm; icon = R.drawable.notif_pink_alarm;
break; break;

@ -45,8 +45,8 @@ public class ReminderPreferences extends TodorooPreferences {
} }
} else if(r.getString(R.string.p_rmd_quietEnd).equals(preference.getKey())) { } else if(r.getString(R.string.p_rmd_quietEnd).equals(preference.getKey())) {
int index = AndroidUtilities.indexOf(r.getStringArray(R.array.EPr_quiet_hours_end_values), (String)value); int index = AndroidUtilities.indexOf(r.getStringArray(R.array.EPr_quiet_hours_end_values), (String)value);
Integer quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart); int quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart, -1);
if(index == -1 || quietHoursStart == null) if(index == -1 || quietHoursStart == -1)
preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_desc_none)); preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_desc_none));
else { else {
String setting = r.getStringArray(R.array.EPr_quiet_hours_end)[index]; String setting = r.getStringArray(R.array.EPr_quiet_hours_end)[index];

@ -209,7 +209,7 @@ public final class ReminderService {
else { else {
// return notification time on this day // return notification time on this day
Date date = new Date(dueDate); Date date = new Date(dueDate);
date.setHours(Preferences.getIntegerFromString(R.string.p_rmd_time)); date.setHours(Preferences.getIntegerFromString(R.string.p_rmd_time, 12));
date.setMinutes(0); date.setMinutes(0);
return date.getTime(); return date.getTime();
} }
@ -272,7 +272,7 @@ public final class ReminderService {
return scheduler; return scheduler;
} }
private class ReminderAlarmScheduler implements AlarmScheduler { private static class ReminderAlarmScheduler implements AlarmScheduler {
/** /**
* Create an alarm for the given task at the given type * Create an alarm for the given task at the given type
* *

@ -58,9 +58,10 @@ public class MilkBackgroundService extends Service {
* Schedules repeating alarm for auto-synchronization * Schedules repeating alarm for auto-synchronization
*/ */
public static void scheduleService() { public static void scheduleService() {
Integer syncFrequencySeconds = Preferences.getIntegerFromString(R.string.rmilk_MPr_interval_key); int syncFrequencySeconds = Preferences.getIntegerFromString(
R.string.rmilk_MPr_interval_key, -1);
Context context = ContextManager.getContext(); Context context = ContextManager.getContext();
if(syncFrequencySeconds == null) { if(syncFrequencySeconds <= 0) {
unscheduleService(context); unscheduleService(context);
return; return;
} }

@ -27,38 +27,33 @@ import com.todoroo.astrid.rmilk.api.data.RtmData;
* *
* @author Will Ross Jun 21, 2007 * @author Will Ross Jun 21, 2007
*/ */
public class Param @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="EQ_COMPARETO_USE_OBJECT_EQUALS")
implements Comparable<Param> public class Param implements Comparable<Param> {
{
private final String name; private final String name;
private final String value; private final String value;
public Param(String name, String value) public Param(String name, String value) {
{ this.name = name;
this.name = name; this.value = value;
this.value = value; }
}
public Param(String name, Date value) public Param(String name, Date value) {
{ this.name = name;
this.name = name; this.value = RtmData.formatDate(value);
this.value = RtmData.formatDate(value); }
}
public String getName() public String getName() {
{ return name;
return name; }
}
public String getValue() public String getValue() {
{ return value;
return value; }
}
public int compareTo(Param p) {
return name.compareTo(p.getName());
}
public int compareTo(Param p)
{
return name.compareTo(p.getName());
}
} }

@ -67,7 +67,7 @@ public final class TagService {
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
public final class Tag { public static final class Tag {
public String tag; public String tag;
int count; int count;

@ -167,7 +167,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
public void run() { public void run() {
loadContextMenuIntents(); loadContextMenuIntents();
} }
}); }).start();
} }
/** /**

@ -97,7 +97,7 @@ public class FilterAdapter extends BaseExpandableListAdapter {
return convertView; return convertView;
} }
private class ViewHolder { private static class ViewHolder {
public FilterListItem item; public FilterListItem item;
public ImageView expander; public ImageView expander;
public ImageView icon; public ImageView icon;

@ -36,7 +36,6 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.SoftHashMap; import com.todoroo.andlib.utility.SoftHashMap;
import com.todoroo.astrid.activity.TaskEditActivity; import com.todoroo.astrid.activity.TaskEditActivity;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
@ -91,20 +90,17 @@ public class TaskAdapter extends CursorAdapter {
// --- instance variables // --- instance variables
@Autowired @Autowired
ExceptionService exceptionService; private ExceptionService exceptionService;
@Autowired @Autowired
TaskService taskService; private TaskService taskService;
@Autowired
DialogUtilities dialogUtilities;
protected final ListActivity activity; protected final ListActivity activity;
protected final HashMap<Long, Boolean> completedItems; protected final HashMap<Long, Boolean> completedItems;
private OnCompletedTaskListener onCompletedTaskListener = null;
public boolean isFling = false; public boolean isFling = false;
private final int resource; private final int resource;
private final LayoutInflater inflater; private final LayoutInflater inflater;
protected OnCompletedTaskListener onCompletedTaskListener = null;
private int fontSize; private int fontSize;
// the task that's expanded // the task that's expanded
@ -145,9 +141,12 @@ public class TaskAdapter extends CursorAdapter {
this.onCompletedTaskListener = onCompletedTaskListener; this.onCompletedTaskListener = onCompletedTaskListener;
completedItems = new HashMap<Long, Boolean>(); completedItems = new HashMap<Long, Boolean>();
fontSize = Preferences.getIntegerFromString(R.string.p_fontSize); fontSize = Preferences.getIntegerFromString(R.string.p_fontSize, 20);
IMPORTANCE_COLORS = Task.getImportanceColors(activity.getResources()); synchronized(TaskAdapter.class) {
if(IMPORTANCE_COLORS == null)
IMPORTANCE_COLORS = Task.getImportanceColors(activity.getResources());
}
} }
/* ====================================================================== /* ======================================================================
@ -213,7 +212,7 @@ public class TaskAdapter extends CursorAdapter {
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
public class ViewHolder { public static class ViewHolder {
public Task task; public Task task;
public View view; public View view;
public TextView nameView; public TextView nameView;
@ -544,7 +543,7 @@ public class TaskAdapter extends CursorAdapter {
@Override @Override
public void notifyDataSetChanged() { public void notifyDataSetChanged() {
super.notifyDataSetChanged(); super.notifyDataSetChanged();
fontSize = Preferences.getIntegerFromString(R.string.p_fontSize); fontSize = Preferences.getIntegerFromString(R.string.p_fontSize, 20);
} }
private final View.OnClickListener completeBoxListener = new View.OnClickListener() { private final View.OnClickListener completeBoxListener = new View.OnClickListener() {

@ -63,7 +63,7 @@ public class Database extends AbstractDatabase {
* Create indices * Create indices
*/ */
@Override @Override
protected void onCreateTables() { protected synchronized void onCreateTables() {
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.append("CREATE INDEX IF NOT EXISTS md_tid ON "). sql.append("CREATE INDEX IF NOT EXISTS md_tid ON ").
append(Metadata.TABLE).append('('). append(Metadata.TABLE).append('(').
@ -73,7 +73,8 @@ public class Database extends AbstractDatabase {
} }
@Override @Override
protected boolean onUpgrade(int oldVersion, int newVersion) { @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SF_SWITCH_FALLTHROUGH")
protected synchronized boolean onUpgrade(int oldVersion, int newVersion) {
switch(oldVersion) { switch(oldVersion) {
case 1: { case 1: {
SqlConstructorVisitor visitor = new SqlConstructorVisitor(); SqlConstructorVisitor visitor = new SqlConstructorVisitor();

@ -169,18 +169,21 @@ public class TaskDao extends GenericDao<Task> {
// set up task defaults // set up task defaults
if(!item.containsValue(Task.IMPORTANCE)) if(!item.containsValue(Task.IMPORTANCE))
item.setValue(Task.IMPORTANCE, Preferences.getIntegerFromString( item.setValue(Task.IMPORTANCE, Preferences.getIntegerFromString(
R.string.p_default_importance_key)); R.string.p_default_importance_key, Task.IMPORTANCE_SHOULD_DO));
if(!item.containsValue(Task.DUE_DATE)) { if(!item.containsValue(Task.DUE_DATE)) {
int setting = Preferences.getIntegerFromString(R.string.p_default_urgency_key); int setting = Preferences.getIntegerFromString(R.string.p_default_urgency_key,
Task.URGENCY_NONE);
item.setValue(Task.DUE_DATE, item.createDueDate(setting, 0)); item.setValue(Task.DUE_DATE, item.createDueDate(setting, 0));
} }
if(!item.containsValue(Task.HIDE_UNTIL)) { if(!item.containsValue(Task.HIDE_UNTIL)) {
int setting = Preferences.getIntegerFromString(R.string.p_default_hideUntil_key); int setting = Preferences.getIntegerFromString(R.string.p_default_hideUntil_key,
Task.HIDE_UNTIL_NONE);
item.setValue(Task.HIDE_UNTIL, item.createHideUntil(setting, 0)); item.setValue(Task.HIDE_UNTIL, item.createHideUntil(setting, 0));
} }
if(!item.containsValue(Task.REMINDER_PERIOD)) { if(!item.containsValue(Task.REMINDER_PERIOD)) {
item.setValue(Task.REMINDER_PERIOD, DateUtilities.ONE_HOUR * item.setValue(Task.REMINDER_PERIOD, DateUtilities.ONE_HOUR *
Preferences.getIntegerFromString(R.string.p_rmd_default_random_hours)); Preferences.getIntegerFromString(R.string.p_rmd_default_random_hours,
0));
} }
if(!item.containsValue(Task.REMINDER_FLAGS)) { if(!item.containsValue(Task.REMINDER_FLAGS)) {
item.setValue(Task.REMINDER_FLAGS, Task.NOTIFY_AT_DEADLINE); item.setValue(Task.REMINDER_FLAGS, Task.NOTIFY_AT_DEADLINE);

@ -172,13 +172,12 @@ public class Astrid2To3UpgradeHelper {
// --- upgrade properties // --- upgrade properties
SharedPreferences prefs = Preferences.getPrefs(context); SharedPreferences prefs = Preferences.getPrefs(context);
Editor editor = prefs.edit(); Editor editor = prefs.edit();
if(prefs.contains(context.getString(R.string.p_rmd_default_random_hours))) { int random = Preferences.getIntegerFromString(R.string.p_rmd_default_random_hours, -1);
if(random != -1) {
// convert days => hours // convert days => hours
editor.putString(context.getString(R.string.p_rmd_default_random_hours), editor.putString(context.getString(R.string.p_rmd_default_random_hours),
Integer.toString(Preferences.getIntegerFromString(R.string.p_rmd_default_random_hours) * 24)); Integer.toString(random * 24));
} }
database.close(); database.close();
if(dialog != null) if(dialog != null)
@ -493,32 +492,32 @@ public class Astrid2To3UpgradeHelper {
/** Legacy task class */ /** Legacy task class */
@SuppressWarnings("nls") @SuppressWarnings("nls")
private abstract class AbstractTaskModel { private static abstract class AbstractTaskModel {
public static final String NAME = "name"; public static final String NAME = "name";
public static final String NOTES = "notes"; public static final String NOTES = "notes";
public static final String IMPORTANCE = "importance"; public static final String IMPORTANCE = "importance";
public static final String ESTIMATED_SECONDS = "estimatedSeconds"; public static final String ESTIMATED_SECONDS = "estimatedSeconds";
public static final String ELAPSED_SECONDS = "elapsedSeconds"; public static final String ELAPSED_SECONDS = "elapsedSeconds";
public static final String TIMER_START = "timerStart"; public static final String TIMER_START = "timerStart";
public static final String DEFINITE_DUE_DATE = "definiteDueDate"; public static final String DEFINITE_DUE_DATE = "definiteDueDate";
public static final String PREFERRED_DUE_DATE = "preferredDueDate"; public static final String PREFERRED_DUE_DATE = "preferredDueDate";
public static final String HIDDEN_UNTIL = "hiddenUntil"; public static final String HIDDEN_UNTIL = "hiddenUntil";
public static final String POSTPONE_COUNT = "postponeCount"; public static final String POSTPONE_COUNT = "postponeCount";
public static final String NOTIFICATIONS = "notifications"; public static final String NOTIFICATIONS = "notifications";
public static final String NOTIFICATION_FLAGS = "notificationFlags"; public static final String NOTIFICATION_FLAGS = "notificationFlags";
public static final String LAST_NOTIFIED = "lastNotified"; public static final String LAST_NOTIFIED = "lastNotified";
public static final String REPEAT = "repeat"; public static final String REPEAT = "repeat";
public static final String CREATION_DATE = "creationDate"; public static final String CREATION_DATE = "creationDate";
public static final String COMPLETION_DATE = "completionDate"; public static final String COMPLETION_DATE = "completionDate";
public static final String CALENDAR_URI = "calendarUri"; public static final String CALENDAR_URI = "calendarUri";
public static final String FLAGS = "flags"; public static final String FLAGS = "flags";
} }
/** Legacy alert class */ /** Legacy alert class */
@SuppressWarnings("nls") @SuppressWarnings("nls")
private class Alert { private static class Alert {
static final String TASK = "task"; static final String TASK = "task";
static final String DATE = "date"; static final String DATE = "date";
} }
} }

@ -9,6 +9,8 @@ import android.preference.PreferenceManager;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import edu.umd.cs.findbugs.annotations.CheckForNull;
public class Preferences { public class Preferences {
private static final String P_CURRENT_VERSION = "cv"; //$NON-NLS-1$ private static final String P_CURRENT_VERSION = "cv"; //$NON-NLS-1$
@ -23,7 +25,7 @@ public class Preferences {
setIfUnset(prefs, editor, r, R.string.p_default_urgency_key, 0); setIfUnset(prefs, editor, r, R.string.p_default_urgency_key, 0);
setIfUnset(prefs, editor, r, R.string.p_default_importance_key, 2); setIfUnset(prefs, editor, r, R.string.p_default_importance_key, 2);
setIfUnset(prefs, editor, r, R.string.p_default_hideUntil_key, 0); setIfUnset(prefs, editor, r, R.string.p_default_hideUntil_key, 0);
setIfUnset(prefs, editor, r, R.string.p_fontSize, 22); setIfUnset(prefs, editor, r, R.string.p_fontSize, 20);
editor.commit(); editor.commit();
} }
@ -109,43 +111,24 @@ public class Preferences {
return getPrefs(context).getString(context.getResources().getString(keyResource), null); return getPrefs(context).getString(context.getResources().getString(keyResource), null);
} }
/** Gets an integer value from a string key. Returns null
* if the value is not set or not an integer.
*
* @param context
* @param key
* @return integer value, or null on error
*/
public static Integer getIntegerFromString(String key) {
Context context = ContextManager.getContext();
String value = getPrefs(context).getString(key, null);
if(value == null)
return null;
try {
return Integer.parseInt(value);
} catch (Exception e) {
return null;
}
}
/** Gets an integer value from a string preference. Returns null /** Gets an integer value from a string preference. Returns null
* if the value is not set or not an integer. * if the value is not set or not an integer.
* *
* @param keyResource resource from string.xml * @param keyResource resource from string.xml
* @return integer value, or null on error * @return integer value, or null on error
*/ */
public static Integer getIntegerFromString(int keyResource) { @CheckForNull
public static int getIntegerFromString(int keyResource, int defaultValue) {
Context context = ContextManager.getContext(); Context context = ContextManager.getContext();
Resources r = context.getResources(); Resources r = context.getResources();
String value = getPrefs(context).getString(r.getString(keyResource), null); String value = getPrefs(context).getString(r.getString(keyResource), null);
if(value == null) if(value == null)
return null; return defaultValue;
try { try {
return Integer.parseInt(value); return Integer.parseInt(value);
} catch (Exception e) { } catch (Exception e) {
return null; return defaultValue;
} }
} }
@ -155,6 +138,7 @@ public class Preferences {
* @param keyResource resource from string.xml * @param keyResource resource from string.xml
* @return * @return
*/ */
@CheckForNull
public static Float getFloatFromString(int keyResource) { public static Float getFloatFromString(int keyResource) {
Context context = ContextManager.getContext(); Context context = ContextManager.getContext();
Resources r = context.getResources(); Resources r = context.getResources();

Loading…
Cancel
Save