pull/14/head
Tim Su 14 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"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/annotations.jar"/>
<classpathentry kind="lib" path="lib/jsr305.jar"/>
<classpathentry kind="output" path="ecbuild"/>
</classpath>

@ -15,8 +15,8 @@ import android.content.Context;
import android.widget.Toast;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
@ -53,7 +53,7 @@ public abstract class SynchronizationProvider<TYPE extends TaskContainer> {
* @param context
* @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

@ -9,9 +9,9 @@ import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;
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!
*/
public <TYPE> TYPE getValue(Property<TYPE> property) {
public synchronized <TYPE> TYPE getValue(Property<TYPE> property) {
Object value;
if(setValues != null && setValues.containsKey(property.name))
value = setValues.get(property.name);

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

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

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

@ -1,6 +1,5 @@
package com.todoroo.andlib.utility;
import java.io.Serializable;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
@ -17,8 +16,7 @@ import java.util.Set;
* @param <K>
* @param <V>
*/
public class SoftHashMap<K, V> extends AbstractMap<K, V> implements
Serializable {
public class SoftHashMap<K, V> extends AbstractMap<K, V> {
private static final long serialVersionUID = -3796460667941300642L;
/** 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.
*/
public UserTask() {
if (sHandler == null) {
sHandler = new InternalHandler();
synchronized(UserTask.class) {
if (sHandler == null) {
sHandler = new InternalHandler();
}
}
mWorker = new WorkerRunnable<Params, Result>() {
@ -201,7 +203,7 @@ public abstract class UserTask<Params, Progress, Result> {
protected void done() {
Result result = null;
try {
result = get();
result = mFuture.get();
} catch (InterruptedException e) {
android.util.Log.w(LOG_TAG, e);
} catch (ExecutionException e) {

Binary file not shown.

Binary file not shown.

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

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

@ -45,8 +45,8 @@ public class ReminderPreferences extends TodorooPreferences {
}
} 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);
Integer quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart);
if(index == -1 || quietHoursStart == null)
int quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart, -1);
if(index == -1 || quietHoursStart == -1)
preference.setSummary(r.getString(R.string.rmd_EPr_quiet_hours_desc_none));
else {
String setting = r.getStringArray(R.array.EPr_quiet_hours_end)[index];

@ -209,7 +209,7 @@ public final class ReminderService {
else {
// return notification time on this day
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);
return date.getTime();
}
@ -272,7 +272,7 @@ public final class ReminderService {
return scheduler;
}
private class ReminderAlarmScheduler implements AlarmScheduler {
private static class ReminderAlarmScheduler implements AlarmScheduler {
/**
* 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
*/
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();
if(syncFrequencySeconds == null) {
if(syncFrequencySeconds <= 0) {
unscheduleService(context);
return;
}

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

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

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

@ -36,7 +36,6 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.SoftHashMap;
import com.todoroo.astrid.activity.TaskEditActivity;
import com.todoroo.astrid.api.AstridApiConstants;
@ -91,20 +90,17 @@ public class TaskAdapter extends CursorAdapter {
// --- instance variables
@Autowired
ExceptionService exceptionService;
private ExceptionService exceptionService;
@Autowired
TaskService taskService;
@Autowired
DialogUtilities dialogUtilities;
private TaskService taskService;
protected final ListActivity activity;
protected final HashMap<Long, Boolean> completedItems;
private OnCompletedTaskListener onCompletedTaskListener = null;
public boolean isFling = false;
private final int resource;
private final LayoutInflater inflater;
protected OnCompletedTaskListener onCompletedTaskListener = null;
private int fontSize;
// the task that's expanded
@ -145,9 +141,12 @@ public class TaskAdapter extends CursorAdapter {
this.onCompletedTaskListener = onCompletedTaskListener;
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>
*
*/
public class ViewHolder {
public static class ViewHolder {
public Task task;
public View view;
public TextView nameView;
@ -544,7 +543,7 @@ public class TaskAdapter extends CursorAdapter {
@Override
public void 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() {

@ -63,7 +63,7 @@ public class Database extends AbstractDatabase {
* Create indices
*/
@Override
protected void onCreateTables() {
protected synchronized void onCreateTables() {
StringBuilder sql = new StringBuilder();
sql.append("CREATE INDEX IF NOT EXISTS md_tid ON ").
append(Metadata.TABLE).append('(').
@ -73,7 +73,8 @@ public class Database extends AbstractDatabase {
}
@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) {
case 1: {
SqlConstructorVisitor visitor = new SqlConstructorVisitor();

@ -169,18 +169,21 @@ public class TaskDao extends GenericDao<Task> {
// set up task defaults
if(!item.containsValue(Task.IMPORTANCE))
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)) {
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));
}
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));
}
if(!item.containsValue(Task.REMINDER_PERIOD)) {
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)) {
item.setValue(Task.REMINDER_FLAGS, Task.NOTIFY_AT_DEADLINE);

@ -172,13 +172,12 @@ public class Astrid2To3UpgradeHelper {
// --- upgrade properties
SharedPreferences prefs = Preferences.getPrefs(context);
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
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();
if(dialog != null)
@ -493,32 +492,32 @@ public class Astrid2To3UpgradeHelper {
/** 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";
private static 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";
private static class Alert {
static final String TASK = "task";
static final String DATE = "date";
}
}

@ -9,6 +9,8 @@ import android.preference.PreferenceManager;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.ContextManager;
import edu.umd.cs.findbugs.annotations.CheckForNull;
public class Preferences {
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_importance_key, 2);
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();
}
@ -109,43 +111,24 @@ public class Preferences {
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
* if the value is not set or not an integer.
*
* @param keyResource resource from string.xml
* @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();
Resources r = context.getResources();
String value = getPrefs(context).getString(r.getString(keyResource), null);
if(value == null)
return null;
return defaultValue;
try {
return Integer.parseInt(value);
} catch (Exception e) {
return null;
return defaultValue;
}
}
@ -155,6 +138,7 @@ public class Preferences {
* @param keyResource resource from string.xml
* @return
*/
@CheckForNull
public static Float getFloatFromString(int keyResource) {
Context context = ContextManager.getContext();
Resources r = context.getResources();

Loading…
Cancel
Save