Fixing lots of crashes and stuff generated by monkey... super ugly. I hope the product works... =x

pull/14/head
Tim Su 17 years ago
parent 36ca13ae8d
commit cf290c89f2

@ -30,6 +30,7 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.database.StaleDataException;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
@ -121,7 +122,7 @@ public class TagListSubActivity extends SubActivity {
abstract int compareTo(TagListSubActivity self, TagModelForView arg0, TagModelForView arg1); abstract int compareTo(TagListSubActivity self, TagModelForView arg0, TagModelForView arg1);
}; };
private void sortTagArray() { private synchronized void sortTagArray() {
// get all tasks // get all tasks
Cursor taskCursor = getTaskController().getActiveTaskListCursor(); Cursor taskCursor = getTaskController().getActiveTaskListCursor();
startManagingCursor(taskCursor); startManagingCursor(taskCursor);
@ -161,10 +162,15 @@ public class TagListSubActivity extends SubActivity {
// --- fill data // --- fill data
/** Fill in the Tag List with our tags */ /** Fill in the Tag List with our tags */
private void fillData() { private synchronized void fillData() {
try { try {
tagArray = getTagController().getAllTags(getParent()); tagArray = getTagController().getAllTags(getParent());
sortTagArray(); sortTagArray();
} catch (StaleDataException e) {
// happens when you rotate the screen while the thread is
// still running. i don't think it's avoidable?
Log.w("astrid", "StaleDataException", e);
return;
} catch (Exception e) { } catch (Exception e) {
Log.e("astrid", "Error loading list", e); Log.e("astrid", "Error loading list", e);
} }
@ -352,7 +358,7 @@ public class TagListSubActivity extends SubActivity {
// --------------------------------------------------- tag list adapter // --------------------------------------------------- tag list adapter
private class TagListAdapter extends ArrayAdapter<TagModelForView> { class TagListAdapter extends ArrayAdapter<TagModelForView> {
private List<TagModelForView> objects; private List<TagModelForView> objects;
private int resource; private int resource;
@ -377,23 +383,30 @@ public class TagListSubActivity extends SubActivity {
if(view == null) { if(view == null) {
view = inflater.inflate(resource, parent, false); view = inflater.inflate(resource, parent, false);
} }
setupView(view, objects.get(position)); setupView(view, objects.get(position), false);
return view; return view;
} }
public void setupView(View view, final TagModelForView tag) { public void setupView(View view, final TagModelForView tag, boolean retry) {
Resources r = getResources(); Resources r = getResources();
view.setTag(tag); view.setTag(tag);
final TextView name = ((TextView)view.findViewById(android.R.id.text1)); final TextView name = ((TextView)view.findViewById(android.R.id.text1));
name.setText(new StringBuilder(tag.getName()). try {
append(" (").append(tagCount.get(tag)).append(")")); if(tagCount == null)
tagCount = tagToTaskCount;
name.setText(new StringBuilder(tag.getName()).
append(" (").append(tagCount.get(tag)).append(")"));
if(tagCount.get(tag) == 0) if(tagCount.get(tag) == 0)
name.setTextColor(r.getColor(R.color.task_list_done)); name.setTextColor(r.getColor(R.color.task_list_done));
else else
name.setTextColor(r.getColor(android.R.color.white)); name.setTextColor(r.getColor(android.R.color.white));
} catch (Exception e) {
Log.e("astrid", "Error loading tag list", e);
}
} }
} }

@ -494,7 +494,7 @@ public class TaskListAdapter extends ArrayAdapter<TaskModelForList> {
String cachedResult = task.getCachedLabel(KEY_TAGS); String cachedResult = task.getCachedLabel(KEY_TAGS);
if(cachedResult == null) { if(cachedResult == null) {
String tagString = hooks.getTagsFor(task); String tagString = hooks.getTagsFor(task);
if(!tagString.equals("")) if(tagString != null && !tagString.equals(""))
cachedResult = r.getString(R.string.taskList_tagsPrefix) + cachedResult = r.getString(R.string.taskList_tagsPrefix) +
" " + tagString; " " + tagString;
else else

@ -507,6 +507,16 @@ public class TaskListSubActivity extends SubActivity {
// still running. i don't think it's avoidable? // still running. i don't think it's avoidable?
Log.w("astrid", "StaleDataException", e); Log.w("astrid", "StaleDataException", e);
return; return;
} catch (IllegalStateException e) {
// happens when you run out of memory usually
Log.e("astrid", "Error loading task list", e);
handler.post(new Runnable() {
@Override
public void run() {
DialogUtilities.okDialog(getParent(), "Ran out of memory! " +
"Try restarting Astrid...", null);
}
});
} catch (final Exception e) { } catch (final Exception e) {
Log.e("astrid", "Error loading task list", e); Log.e("astrid", "Error loading task list", e);
return; return;

@ -225,9 +225,14 @@ public abstract class AbstractModel {
// --- retrieving composite objects // --- retrieving composite objects
protected Date retrieveDate(String field) { protected Date retrieveDate(String field) {
Long time = retrieveLong(field); Long time;
if(time == null || time == 0) try {
time = retrieveLong(field);
if(time == null || time == 0)
return null;
} catch (NullPointerException e) {
return null; return null;
}
return new Date(time); return new Date(time);
} }

@ -448,7 +448,7 @@ public class RTMSyncService extends SynchronizationService {
// --- helper classes // --- helper classes
/** SynchronizeHelper for remember the milk */ /** SynchronizeHelper for remember the milk */
private class RtmSyncHelper implements SynchronizeHelper { class RtmSyncHelper implements SynchronizeHelper {
private String timeline; private String timeline;
private String lastCreatedTask = null; private String lastCreatedTask = null;

@ -390,7 +390,7 @@ public abstract class SynchronizationService {
// --- helper classes // --- helper classes
/** data structure builder */ /** data structure builder */
private class SyncData { class SyncData {
HashSet<SyncMapping> mappings; HashSet<SyncMapping> mappings;
HashSet<TaskIdentifier> activeTasks; HashSet<TaskIdentifier> activeTasks;
HashSet<TaskIdentifier> allTasks; HashSet<TaskIdentifier> allTasks;

@ -82,7 +82,8 @@ public class Notifications extends BroadcastReceiver {
reminder = getRandomReminder(r); reminder = getRandomReminder(r);
long repeatInterval = intent.getLongExtra(REPEAT_KEY, 0); long repeatInterval = intent.getLongExtra(REPEAT_KEY, 0);
Log.e("ALARM", "Alarm triggered id " + id +", flags " + flags + if(Constants.DEBUG)
Log.e("ALARM", "Alarm triggered id " + id +", flags " + flags +
", repeat " + repeatInterval); ", repeat " + repeatInterval);
if(!showNotification(context, id, flags, repeatInterval, reminder)) { if(!showNotification(context, id, flags, repeatInterval, reminder)) {
@ -292,7 +293,8 @@ public class Notifications extends BroadcastReceiver {
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
createAlarmIntent(context, id, flags), 0); createAlarmIntent(context, id, flags), 0);
Log.e("Astrid", "Alarm (" + id + ", " + flags + ") set for " + new Date(when)); if(Constants.DEBUG)
Log.e("Astrid", "Alarm (" + id + ", " + flags + ") set for " + new Date(when));
am.set(AlarmManager.RTC_WAKEUP, when, pendingIntent); am.set(AlarmManager.RTC_WAKEUP, when, pendingIntent);
} }
@ -308,7 +310,8 @@ public class Notifications extends BroadcastReceiver {
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
alarmIntent, 0); alarmIntent, 0);
Log.e("Astrid", "Alarm (" + id + ", " + flags + ") set for " + if(Constants.DEBUG)
Log.e("Astrid", "Alarm (" + id + ", " + flags + ") set for " +
new Date(when) + " every " + interval/1000 + " s"); new Date(when) + " every " + interval/1000 + " s");
am.setRepeating(AlarmManager.RTC_WAKEUP, when, interval, pendingIntent); am.setRepeating(AlarmManager.RTC_WAKEUP, when, interval, pendingIntent);
} }
@ -456,7 +459,8 @@ public class Notifications extends BroadcastReceiver {
} }
} }
Log.w("Astrid", "Logging notification: " + reminder); if(Constants.DEBUG)
Log.w("Astrid", "Logging notification: " + reminder);
nm.notify((int)id, notification); nm.notify((int)id, notification);
return true; return true;
@ -502,7 +506,8 @@ public class Notifications extends BroadcastReceiver {
Notification.FLAG_NO_CLEAR; Notification.FLAG_NO_CLEAR;
notification.flags &= ~Notification.FLAG_AUTO_CANCEL; notification.flags &= ~Notification.FLAG_AUTO_CANCEL;
Log.w("Astrid", "Logging timing notification: " + text); if(Constants.DEBUG)
Log.w("Astrid", "Logging timing notification: " + text);
nm.notify((int)taskId.getId(), notification); nm.notify((int)taskId.getId(), notification);
return true; return true;

@ -345,7 +345,7 @@ public class NumberPicker extends LinearLayout implements OnClickListener,
private NumberPickerButton mIncrementButton; private NumberPickerButton mIncrementButton;
private NumberPickerButton mDecrementButton; private NumberPickerButton mDecrementButton;
private class NumberPickerInputFilter implements InputFilter { class NumberPickerInputFilter implements InputFilter {
public CharSequence filter(CharSequence source, int start, int end, public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) { Spanned dest, int dstart, int dend) {
if (mDisplayedValues == null) { if (mDisplayedValues == null) {
@ -367,7 +367,7 @@ public class NumberPicker extends LinearLayout implements OnClickListener,
} }
} }
private class NumberRangeKeyListener extends NumberKeyListener { class NumberRangeKeyListener extends NumberKeyListener {
@Override @Override
protected char[] getAcceptedChars() { protected char[] getAcceptedChars() {

Loading…
Cancel
Save