From 90e57d3391ef7beec7a223861befd1670102501e Mon Sep 17 00:00:00 2001 From: Tim Su Date: Sun, 8 Mar 2009 11:32:23 +0000 Subject: [PATCH] Saving context when screen rotating, also some tweaks from the profiler. --- res/anim/fade_in.xml | 21 ++ res/anim/fade_out.xml | 21 ++ .../timsu/astrid/activities/SubActivity.java | 8 + src/com/timsu/astrid/activities/TaskList.java | 44 ++-- .../activities/TaskListSubActivity.java | 219 ++++++++++-------- src/com/timsu/astrid/data/AbstractModel.java | 28 ++- .../astrid/data/task/TaskModelForList.java | 8 + 7 files changed, 225 insertions(+), 124 deletions(-) create mode 100644 res/anim/fade_in.xml create mode 100644 res/anim/fade_out.xml diff --git a/res/anim/fade_in.xml b/res/anim/fade_in.xml new file mode 100644 index 000000000..516f9eb8d --- /dev/null +++ b/res/anim/fade_in.xml @@ -0,0 +1,21 @@ + + + + + + diff --git a/res/anim/fade_out.xml b/res/anim/fade_out.xml new file mode 100644 index 000000000..82956b720 --- /dev/null +++ b/res/anim/fade_out.xml @@ -0,0 +1,21 @@ + + + + + + diff --git a/src/com/timsu/astrid/activities/SubActivity.java b/src/com/timsu/astrid/activities/SubActivity.java index e587c2ad3..ddb122218 100644 --- a/src/com/timsu/astrid/activities/SubActivity.java +++ b/src/com/timsu/astrid/activities/SubActivity.java @@ -81,6 +81,10 @@ abstract public class SubActivity { // } + Object onRetainNonConfigurationInstance() { + return null; + } + // --- pass-through to activity methods public Resources getResources() { @@ -107,6 +111,10 @@ abstract public class SubActivity { parent.startActivityForResult(intent, requestCode); } + public Object getLastNonConfigurationInstance() { + return parent.getLastNonConfigurationInstance(); + } + // --- helper methods public Activity getParent() { diff --git a/src/com/timsu/astrid/activities/TaskList.java b/src/com/timsu/astrid/activities/TaskList.java index 153e8ee5e..bf25ce192 100644 --- a/src/com/timsu/astrid/activities/TaskList.java +++ b/src/com/timsu/astrid/activities/TaskList.java @@ -68,7 +68,7 @@ public class TaskList extends Activity { public static final String VARIABLES_TAG = "v"; /** Minimum distance a fling must cover to trigger motion */ - private static final int FLING_DIST_THRESHOLD = 120; + private static final int FLING_DIST_THRESHOLD = 160; /** Maximum distance in the other axis for a fling */ private static final int MAX_FLING_OTHER_AXIS = 60; @@ -86,10 +86,8 @@ public class TaskList extends Activity { private Bundle lastActivityBundle; // animations - private Animation mInAnimationForward; - private Animation mOutAnimationForward; - private Animation mInAnimationBackward; - private Animation mOutAnimationBackward; + private Animation mFadeInAnim; + private Animation mFadeOutAnim; // data controllers TaskController taskController; @@ -158,10 +156,10 @@ public class TaskList extends Activity { taskListWTag = new TaskListSubActivity(this, AC_TASK_LIST_W_TAG, findViewById(R.id.tasklistwtag_layout)); - mInAnimationForward = AnimationUtils.loadAnimation(this, R.anim.slide_left_in); - mOutAnimationForward = AnimationUtils.loadAnimation(this, R.anim.slide_left_out); - mInAnimationBackward = AnimationUtils.loadAnimation(this, R.anim.slide_right_in); - mOutAnimationBackward = AnimationUtils.loadAnimation(this, R.anim.slide_right_out); + mFadeInAnim = AnimationUtils.loadAnimation(this, R.anim.fade_in); + mFadeOutAnim = AnimationUtils.loadAnimation(this, R.anim.fade_out); + viewFlipper.setInAnimation(mFadeInAnim); + viewFlipper.setOutAnimation(mFadeOutAnim); gestureListener = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { @@ -178,16 +176,15 @@ public class TaskList extends Activity { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { - if(Constants.DEBUG) - Log.i("astrid", "Got fling. X: " + (e2.getX() - e1.getX()) + - ", vel: " + velocityX); - if(Math.abs(e1.getY() - e2.getY()) > MAX_FLING_OTHER_AXIS) return false; + Log.i("astrid", "Got fling. X: " + (e2.getX() - e1.getX()) + + ", vel: " + velocityX); + // flick R to L if(e1.getX() - e2.getX() > FLING_DIST_THRESHOLD && - Math.abs((int)velocityX) > FLING_VEL_THRESHOLD) { + Math.abs(velocityX) > FLING_VEL_THRESHOLD) { switch(getCurrentSubActivity().getActivityCode()) { case AC_TASK_LIST: @@ -200,7 +197,7 @@ public class TaskList extends Activity { // flick L to R else if(e2.getX() - e1.getX() > FLING_DIST_THRESHOLD && - Math.abs((int)velocityX) > FLING_VEL_THRESHOLD) { + Math.abs(velocityX) > FLING_VEL_THRESHOLD) { switch(getCurrentSubActivity().getActivityCode()) { case AC_TASK_LIST_W_TAG: @@ -232,8 +229,6 @@ public class TaskList extends Activity { // and flip to them switch(getCurrentSubActivity().getActivityCode()) { case AC_TASK_LIST: - //viewFlipper.setInAnimation(mInAnimationForward); - //viewFlipper.setOutAnimation(mOutAnimationForward); switch(activity) { case AC_TAG_LIST: viewFlipper.showNext(); @@ -246,21 +241,15 @@ public class TaskList extends Activity { case AC_TAG_LIST: switch(activity) { case AC_TASK_LIST: - //viewFlipper.setInAnimation(mInAnimationBackward); - //viewFlipper.setOutAnimation(mOutAnimationBackward); viewFlipper.showPrevious(); break; case AC_TASK_LIST_W_TAG: - //viewFlipper.setInAnimation(mInAnimationForward); - //viewFlipper.setOutAnimation(mOutAnimationForward); viewFlipper.showNext(); break; } break; case AC_TASK_LIST_W_TAG: - //viewFlipper.setInAnimation(mInAnimationBackward); - //viewFlipper.setOutAnimation(mOutAnimationBackward); switch(activity) { case AC_TAG_LIST: viewFlipper.showPrevious(); @@ -332,8 +321,8 @@ public class TaskList extends Activity { if(hasFocus && shouldCloseInstance) { // user wants to quit finish(); - }/* else - getCurrentSubActivity().onWindowFocusChanged(hasFocus);*/ + } else + getCurrentSubActivity().onWindowFocusChanged(hasFocus); } @Override @@ -352,6 +341,11 @@ public class TaskList extends Activity { return false; } + @Override + public Object onRetainNonConfigurationInstance() { + return getCurrentSubActivity().onRetainNonConfigurationInstance(); + } + @Override protected void onDestroy() { super.onDestroy(); diff --git a/src/com/timsu/astrid/activities/TaskListSubActivity.java b/src/com/timsu/astrid/activities/TaskListSubActivity.java index 24a6494d7..2a34aa4ee 100644 --- a/src/com/timsu/astrid/activities/TaskListSubActivity.java +++ b/src/com/timsu/astrid/activities/TaskListSubActivity.java @@ -25,7 +25,6 @@ import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.Random; @@ -125,23 +124,27 @@ public class TaskListSubActivity extends SubActivity { private TextView loadingText; // other instance variables - private Map tagMap; - private ArrayList taskArray; - private HashMap tasksById; - private HashMap taskTags; - private Long selectedTaskId = null; - private TaskModelForList selectedTask = null; - private Handler handler = null; - private Thread loadingThread = null; - private Runnable reLoadRunnable = null; - private TaskListAdapter listAdapter = null; + class TaskListContext { + Map tagMap; + ArrayList taskArray; + HashMap tasksById; + HashMap taskTags; + TaskModelForList selectedTask = null; + Thread loadingThread = null; + TaskListAdapter listAdapter = null; + TagModelForView filterTag = null; + CharSequence windowTitle; + } + Handler handler = null; + Long selectedTaskId = null; + Runnable reLoadRunnable = null; + private TaskListContext context; // display filters private static boolean filterShowHidden = false; private static boolean filterShowDone = false; private static SortMode sortMode = SortMode.AUTO; private static boolean sortReverse = false; - private TagModelForView filterTag = null; /* ====================================================================== * ======================================================= initialization @@ -154,21 +157,12 @@ public class TaskListSubActivity extends SubActivity { @Override /** Called when loading up the activity */ public void onDisplay(final Bundle variables) { - // process tag to filter, if any - if(variables != null && variables.containsKey(TAG_TOKEN)) { - TagIdentifier identifier = new TagIdentifier(variables.getLong(TAG_TOKEN)); - tagMap = getTagController().getAllTagsAsMap(getParent()); - filterTag = tagMap.get(identifier); - } - // process task that's selected, if any if(variables != null && variables.containsKey(LOAD_INSTANCE_TOKEN)) { selectedTaskId = variables.getLong(LOAD_INSTANCE_TOKEN); } else { selectedTaskId = null; - selectedTask = null; } - setupUIComponents(); reLoadRunnable = new Runnable() { @@ -185,8 +179,26 @@ public class TaskListSubActivity extends SubActivity { } }; + if(getLastNonConfigurationInstance() != null) { + context = (TaskListContext)getLastNonConfigurationInstance(); + listView.setAdapter(context.listAdapter); + onTaskListLoaded(); + return; + } + + context = new TaskListContext(); + if(selectedTaskId == null) + context.selectedTask = null; + + // process tag to filter, if any + if(variables != null && variables.containsKey(TAG_TOKEN)) { + TagIdentifier identifier = new TagIdentifier(variables.getLong(TAG_TOKEN)); + context.tagMap = getTagController().getAllTagsAsMap(getParent()); + context.filterTag = context.tagMap.get(identifier); + } + // time to go! - loadingThread = new Thread(new Runnable() { + context.loadingThread = new Thread(new Runnable() { @Override public void run() { handler.post(new Runnable() { @@ -201,7 +213,7 @@ public class TaskListSubActivity extends SubActivity { // open up reminder box if(variables != null && variables.containsKey(NOTIF_FLAGS_TOKEN) && - selectedTask != null) { + context.selectedTask != null) { handler.post(new Runnable() { @Override public void run() { @@ -211,14 +223,14 @@ public class TaskListSubActivity extends SubActivity { if(variables.containsKey(NOTIF_REPEAT_TOKEN)) repeatInterval = variables.getLong(NOTIF_REPEAT_TOKEN); flags = variables.getInt(NOTIF_FLAGS_TOKEN); - showNotificationAlert(selectedTask, + showNotificationAlert(context.selectedTask, repeatInterval, flags); } }); } } }); - loadingThread.start(); + context.loadingThread.start(); } /** Initialize UI components */ @@ -412,14 +424,14 @@ public class TaskListSubActivity extends SubActivity { /** Helper method returns true if the task is considered 'hidden' */ private boolean isTaskHidden(TaskModelForList task) { - if(task == selectedTask) + if(task == context.selectedTask) return false; if(task.isHidden()) return true; - if(filterTag == null) { - if(taskTags.get(task).contains(TagModelForView.HIDDEN_FROM_MAIN_LIST_PREFIX)) + if(context.filterTag == null) { + if(context.taskTags.get(task).contains(TagModelForView.HIDDEN_FROM_MAIN_LIST_PREFIX)) return true; } @@ -441,9 +453,9 @@ public class TaskListSubActivity extends SubActivity { try { // get a cursor to the task list Cursor tasksCursor; - if(filterTag != null) { - List tasks = getTagController().getTaggedTasks(getParent(), - filterTag.getTagIdentifier()); + if(context.filterTag != null) { + LinkedList tasks = getTagController().getTaggedTasks(getParent(), + context.filterTag.getTagIdentifier()); tasksCursor = getTaskController().getTaskListCursorById(tasks); } else { if(filterShowDone) @@ -452,14 +464,14 @@ public class TaskListSubActivity extends SubActivity { tasksCursor = getTaskController().getActiveTaskListCursor(); } startManagingCursor(tasksCursor); - taskArray = getTaskController().createTaskListFromCursor(tasksCursor); + context.taskArray = getTaskController().createTaskListFromCursor(tasksCursor); // read tags and apply filters - tagMap = getTagController().getAllTagsAsMap(getParent()); - taskTags = new HashMap(); + context.tagMap = getTagController().getAllTagsAsMap(getParent()); + context.taskTags = new HashMap(); StringBuilder tagBuilder = new StringBuilder(); - tasksById = new HashMap(); - for(Iterator i = taskArray.iterator(); i.hasNext();) { + context.tasksById = new HashMap(); + for(Iterator i = context.taskArray.iterator(); i.hasNext();) { if(Thread.interrupted()) return; @@ -473,7 +485,7 @@ public class TaskListSubActivity extends SubActivity { } if(selectedTaskId != null && task.getTaskIdentifier().getId() == selectedTaskId) { - selectedTask = task; + context.selectedTask = task; } // get list of tags @@ -481,12 +493,12 @@ public class TaskListSubActivity extends SubActivity { task.getTaskIdentifier()); tagBuilder.delete(0, tagBuilder.length()); for(Iterator j = tagIds.iterator(); j.hasNext(); ) { - TagModelForView tag = tagMap.get(j.next()); + TagModelForView tag = context.tagMap.get(j.next()); tagBuilder.append(tag.getName()); if(j.hasNext()) tagBuilder.append(", "); } - taskTags.put(task, tagBuilder.toString()); + context.taskTags.put(task, tagBuilder.toString()); // hide hidden if(!filterShowHidden) { @@ -497,7 +509,7 @@ public class TaskListSubActivity extends SubActivity { } } - tasksById.put(task.getTaskIdentifier().getId(), task); + context.tasksById.put(task.getTaskIdentifier().getId(), task); if(task.isTaskCompleted()) completedTasks++; @@ -525,59 +537,71 @@ public class TaskListSubActivity extends SubActivity { return; } - int activeTasks = taskArray.size() - completedTasks; + int activeTasks = context.taskArray.size() - completedTasks; // sort task list - Collections.sort(taskArray, new Comparator() { + Collections.sort(context.taskArray, new Comparator() { @Override public int compare(TaskModelForList arg0, TaskModelForList arg1) { return sortMode.compareTo(arg0, arg1); } }); if(sortReverse) - Collections.reverse(taskArray); + Collections.reverse(context.taskArray); - handler.post(new Runnable() { - @Override - public void run() { - // hide "add" button if we have too many tasks - int threshold = HIDE_ADD_BTN_PORTRAIT; - if(getParent().getResources().getConfiguration().orientation == - Configuration.ORIENTATION_LANDSCAPE) - threshold = HIDE_ADD_BTN_LANDSCPE; - - if(taskArray.size() > threshold) - addButton.setVisibility(View.GONE); - else - addButton.setVisibility(View.VISIBLE); - } - }); - - // set up the title final int finalCompleted = completedTasks; final int finalActive = activeTasks; final int finalHidden = hiddenTasks; + handler.post(new Runnable() { @Override public void run() { Resources r = getResources(); StringBuilder title = new StringBuilder(). append(r.getString(R.string.taskList_titlePrefix)).append(" "); - if(filterTag != null) { + if(context.filterTag != null) { title.append(r.getString(R.string.taskList_titleTagPrefix, - filterTag.getName())).append(" "); + context.filterTag.getName())).append(" "); } if(finalCompleted > 0) title.append(r.getQuantityString(R.plurals.NactiveTasks, - finalActive, finalActive, taskArray.size())); + finalActive, finalActive, context.taskArray.size())); else title.append(r.getQuantityString(R.plurals.Ntasks, - taskArray.size(), taskArray.size())); + context.taskArray.size(), context.taskArray.size())); if(finalHidden > 0) title.append(" (+").append(finalHidden).append(" "). append(r.getString(R.string.taskList_hiddenSuffix)).append(")"); + context.windowTitle = title; + } + }); + + onTaskListLoaded(); + } - setTitle(title); + /** Sets up the interface after everything has been loaded */ + private void onTaskListLoaded() { + handler.post(new Runnable() { + @Override + public void run() { + // hide "add" button if we have too many tasks + int threshold = HIDE_ADD_BTN_PORTRAIT; + if(getParent().getResources().getConfiguration().orientation == + Configuration.ORIENTATION_LANDSCAPE) + threshold = HIDE_ADD_BTN_LANDSCPE; + + if(context.taskArray.size() > threshold) + addButton.setVisibility(View.GONE); + else + addButton.setVisibility(View.VISIBLE); + } + }); + + // set up the title + handler.post(new Runnable() { + @Override + public void run() { + setTitle(context.windowTitle); setUpListUI(); loadingText.setVisibility(View.GONE); } @@ -590,8 +614,8 @@ public class TaskListSubActivity extends SubActivity { private ArrayList myTaskArray; public TaskListHooks() { - this.myTaskTags = taskTags; - this.myTaskArray = taskArray; + this.myTaskTags = context.taskTags; + this.myTaskArray = context.taskArray; } @Override @@ -637,7 +661,7 @@ public class TaskListSubActivity extends SubActivity { public void setSelectedItem(TaskIdentifier taskId) { if(taskId == null) { selectedTaskId = null; - selectedTask = null; + context.selectedTask = null; } else selectedTaskId = taskId.getId(); } @@ -646,16 +670,16 @@ public class TaskListSubActivity extends SubActivity { /** Set up the adapter for our task list */ private void setUpListUI() { // set up our adapter - listAdapter = new TaskListAdapter(getParent(), - R.layout.task_list_row, taskArray, new TaskListHooks()); - listView.setAdapter(listAdapter); + context.listAdapter = new TaskListAdapter(getParent(), + R.layout.task_list_row, context.taskArray, new TaskListHooks()); + listView.setAdapter(context.listAdapter); listView.setItemsCanFocus(true); - if(selectedTask != null) { + if(context.selectedTask != null) { try { - int selectedPosition = listAdapter.getPosition(selectedTask); + int selectedPosition = context.listAdapter.getPosition(context.selectedTask); View v = listView.getChildAt(selectedPosition); - listAdapter.setExpanded(v, selectedTask, true); + context.listAdapter.setExpanded(v, context.selectedTask, true); listView.setSelection(selectedPosition); } catch (Exception e) { Log.e("astrid", "error with selected task", e); @@ -682,10 +706,10 @@ public class TaskListSubActivity extends SubActivity { item.setCheckable(true); item.setChecked(filterShowDone); - if(filterTag != null) { + if(context.filterTag != null) { item = menu.add(Menu.NONE, CONTEXT_FILTER_TAG, Menu.NONE, r.getString(R.string.taskList_filter_tagged, - filterTag.getName())); + context.filterTag.getName())); item.setCheckable(true); item.setChecked(true); } @@ -712,22 +736,27 @@ public class TaskListSubActivity extends SubActivity { } private void reloadList() { - if(loadingThread != null && loadingThread.isAlive()) { - loadingThread.interrupt(); - loadingThread.stop(); + if(context.loadingThread != null && context.loadingThread.isAlive()) { + context.loadingThread.interrupt(); + context.loadingThread.stop(); } - loadingThread = new Thread(reLoadRunnable); - loadingThread.start(); + context.loadingThread = new Thread(reLoadRunnable); + context.loadingThread.start(); } /* ====================================================================== * ======================================================= event handlers * ====================================================================== */ + @Override + protected Object onRetainNonConfigurationInstance() { + return context; + } + @Override protected boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK) { - if(filterTag != null) { + if(context.filterTag != null) { showTagsView(); return true; } @@ -743,8 +772,8 @@ public class TaskListSubActivity extends SubActivity { @Override protected void onSaveInstanceState(Bundle outState) { - if(loadingThread != null && loadingThread.isAlive()) - loadingThread.stop(); + if(context.loadingThread != null && context.loadingThread.isAlive()) + context.loadingThread.stop(); } @Override @@ -774,8 +803,8 @@ public class TaskListSubActivity extends SubActivity { /** Call an activity to create the given task */ private void createTask(Character startCharacter) { Intent intent = new Intent(getParent(), TaskEdit.class); - if(filterTag != null) - intent.putExtra(TaskEdit.TAG_NAME_TOKEN, filterTag.getName()); + if(context.filterTag != null) + intent.putExtra(TaskEdit.TAG_NAME_TOKEN, context.filterTag.getName()); if(startCharacter != null) intent.putExtra(TaskEdit.START_CHAR_TOKEN, startCharacter); launchActivity(intent, ACTIVITY_CREATE); @@ -791,8 +820,8 @@ public class TaskListSubActivity extends SubActivity { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - listAdapter.remove(task); - taskArray.remove(task); + context.listAdapter.remove(task); + context.taskArray.remove(task); getTaskController().deleteTask(task.getTaskIdentifier()); } }) @@ -816,7 +845,7 @@ public class TaskListSubActivity extends SubActivity { task.stopTimerAndUpdateElapsedTime(); } getTaskController().saveTask(task); - listAdapter.refreshItem(listView, taskArray.indexOf(task)); + context.listAdapter.refreshItem(listView, context.taskArray.indexOf(task)); } /** Show the tags view */ @@ -921,19 +950,19 @@ public class TaskListSubActivity extends SubActivity { // --- list context menu items case TaskListAdapter.CONTEXT_EDIT_ID: - task = tasksById.get((long)item.getGroupId()); + task = context.tasksById.get((long)item.getGroupId()); editTask(task); return true; case TaskListAdapter.CONTEXT_DELETE_ID: - task = tasksById.get((long)item.getGroupId()); + task = context.tasksById.get((long)item.getGroupId()); deleteTask(task); return true; case TaskListAdapter.CONTEXT_TIMER_ID: - task = tasksById.get((long)item.getGroupId()); + task = context.tasksById.get((long)item.getGroupId()); toggleTimer(task); return true; case TaskListAdapter.CONTEXT_POSTPONE_ID: - task = tasksById.get((long)item.getGroupId()); + task = context.tasksById.get((long)item.getGroupId()); DialogUtilities.dayHourPicker(getParent(), r.getString(R.string.taskList_postpone_dialog), new OnNNumberPickedListener() { @@ -948,7 +977,7 @@ public class TaskListSubActivity extends SubActivity { task.getHiddenUntil(), postponeMillis, false)); getTaskController().saveTask(task); - listAdapter.refreshItem(listView, taskArray.indexOf(task)); + context.listAdapter.refreshItem(listView, context.taskArray.indexOf(task)); } }); return true; @@ -1006,6 +1035,6 @@ public class TaskListSubActivity extends SubActivity { * ====================================================================== */ public TagModelForView getFilterTag() { - return filterTag; + return context.filterTag; } } \ No newline at end of file diff --git a/src/com/timsu/astrid/data/AbstractModel.java b/src/com/timsu/astrid/data/AbstractModel.java index 35a941a19..4f3d5ed19 100644 --- a/src/com/timsu/astrid/data/AbstractModel.java +++ b/src/com/timsu/astrid/data/AbstractModel.java @@ -20,6 +20,7 @@ package com.timsu.astrid.data; import java.util.Date; +import java.util.HashMap; import android.content.ContentValues; import android.database.Cursor; @@ -132,6 +133,25 @@ public abstract class AbstractModel { setValues.put(field, newValue); } + protected static HashMap, HashMap> + columnIndexCache = new HashMap, HashMap>(); + private int getColumnIndex(String field) { + HashMap classCache; + classCache = columnIndexCache.get(getClass()); + if(classCache == null) { + classCache = new HashMap(); + columnIndexCache.put(getClass(), classCache); + } + + Integer index = classCache.get(field); + if(index == null) { + index = cursor.getColumnIndexOrThrow(field); + classCache.put(field, index); + } + + return index; + } + // --- data retrieval for the different object types protected String retrieveString(String field) { @@ -143,7 +163,7 @@ public abstract class AbstractModel { // if we have a database to hit, do that now if(cursor != null) { - String value = cursor.getString(cursor.getColumnIndexOrThrow(field)); + String value = cursor.getString(getColumnIndex(field)); values.put(field, value); return value; } @@ -165,7 +185,7 @@ public abstract class AbstractModel { // if we have a database to hit, do that now if(cursor != null) { - Integer value = cursor.getInt(cursor.getColumnIndexOrThrow(field)); + Integer value = cursor.getInt(getColumnIndex(field)); values.put(field, value); return value; } @@ -187,7 +207,7 @@ public abstract class AbstractModel { // if we have a database to hit, do that now if(cursor != null) { - Long value = cursor.getLong(cursor.getColumnIndexOrThrow(field)); + Long value = cursor.getLong(getColumnIndex(field)); values.put(field, value); return value; } @@ -209,7 +229,7 @@ public abstract class AbstractModel { // if we have a database to hit, do that now if(cursor != null) { - Double value = cursor.getDouble(cursor.getColumnIndexOrThrow(field)); + Double value = cursor.getDouble(getColumnIndex(field)); values.put(field, value); return value; } diff --git a/src/com/timsu/astrid/data/task/TaskModelForList.java b/src/com/timsu/astrid/data/task/TaskModelForList.java index 2b9cca30c..1fecfb2ef 100644 --- a/src/com/timsu/astrid/data/task/TaskModelForList.java +++ b/src/com/timsu/astrid/data/task/TaskModelForList.java @@ -51,6 +51,14 @@ public class TaskModelForList extends AbstractTaskModel { REPEAT, }; + // pre-load the cache for our column keys + static { + HashMap indexCache = new HashMap(); + columnIndexCache.put(TaskModelForList.class, indexCache); + for(int i = 0; i < FIELD_LIST.length; i++) + indexCache.put(FIELD_LIST[i], i); + } + /** Get the weighted score for this task. Smaller is more important */ public int getTaskWeight() { int weight = 0;