summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Parks <jparks@google.com>2010-07-01 14:38:02 -0500
committerJason Parks <jparks@google.com>2010-07-08 09:02:48 -0500
commitbca909c0a592051e9acfc41737bc341910f0c7d1 (patch)
treed7d7b1ce9200c2d7d85665f1277a26a9cd38cc4a
parent98738272e3b680559e1e0a7b665a0ebb4038f684 (diff)
downloadframeworks_base-bca909c0a592051e9acfc41737bc341910f0c7d1.zip
frameworks_base-bca909c0a592051e9acfc41737bc341910f0c7d1.tar.gz
frameworks_base-bca909c0a592051e9acfc41737bc341910f0c7d1.tar.bz2
Change CursorTreeAdapter to close the cursors rather than deactivating them. Fix SimpleCursorTreeAdapter to allow a null cursor as an argument.
Not closing the cursors was a bit of a bug since the documenation explicitly says that it would close the cursors. This will get rid of all the warnings that are printed out in the finalizer about the cursor not being closed.
-rw-r--r--core/java/android/widget/CursorTreeAdapter.java8
-rw-r--r--core/java/android/widget/SimpleCursorTreeAdapter.java55
2 files changed, 31 insertions, 32 deletions
diff --git a/core/java/android/widget/CursorTreeAdapter.java b/core/java/android/widget/CursorTreeAdapter.java
index 7b9b7bd..3fadf4c 100644
--- a/core/java/android/widget/CursorTreeAdapter.java
+++ b/core/java/android/widget/CursorTreeAdapter.java
@@ -134,14 +134,16 @@ public abstract class CursorTreeAdapter extends BaseExpandableListAdapter implem
/**
* Sets the group Cursor.
*
- * @param cursor The Cursor to set for the group.
+ * @param cursor The Cursor to set for the group. If there is an existing cursor
+ * it will be closed.
*/
public void setGroupCursor(Cursor cursor) {
mGroupCursorHelper.changeCursor(cursor, false);
}
/**
- * Sets the children Cursor for a particular group.
+ * Sets the children Cursor for a particular group. If there is an existing cursor
+ * it will be closed.
* <p>
* This is useful when asynchronously querying to prevent blocking the UI.
*
@@ -476,7 +478,7 @@ public abstract class CursorTreeAdapter extends BaseExpandableListAdapter implem
mCursor.unregisterContentObserver(mContentObserver);
mCursor.unregisterDataSetObserver(mDataSetObserver);
- mCursor.deactivate();
+ mCursor.close();
mCursor = null;
}
diff --git a/core/java/android/widget/SimpleCursorTreeAdapter.java b/core/java/android/widget/SimpleCursorTreeAdapter.java
index a1c65f0..a033542 100644
--- a/core/java/android/widget/SimpleCursorTreeAdapter.java
+++ b/core/java/android/widget/SimpleCursorTreeAdapter.java
@@ -38,6 +38,10 @@ import android.view.View;
* binding can be found, an {@link IllegalStateException} is thrown.
*/
public abstract class SimpleCursorTreeAdapter extends ResourceCursorTreeAdapter {
+
+ /** The name of the columns that contain the data to display for a group. */
+ private String[] mGroupFromNames;
+
/** The indices of columns that contain data to display for a group. */
private int[] mGroupFrom;
/**
@@ -46,6 +50,9 @@ public abstract class SimpleCursorTreeAdapter extends ResourceCursorTreeAdapter
*/
private int[] mGroupTo;
+ /** The name of the columns that contain the data to display for a child. */
+ private String[] mChildFromNames;
+
/** The indices of columns that contain data to display for a child. */
private int[] mChildFrom;
/**
@@ -171,38 +178,12 @@ public abstract class SimpleCursorTreeAdapter extends ResourceCursorTreeAdapter
private void init(String[] groupFromNames, int[] groupTo, String[] childFromNames,
int[] childTo) {
+
+ mGroupFromNames = groupFromNames;
mGroupTo = groupTo;
+ mChildFromNames = childFromNames;
mChildTo = childTo;
-
- // Get the group cursor column indices, the child cursor column indices will come
- // when needed
- initGroupFromColumns(groupFromNames);
-
- // Get a temporary child cursor to init the column indices
- if (getGroupCount() > 0) {
- MyCursorHelper tmpCursorHelper = getChildrenCursorHelper(0, true);
- if (tmpCursorHelper != null) {
- initChildrenFromColumns(childFromNames, tmpCursorHelper.getCursor());
- deactivateChildrenCursorHelper(0);
- }
- }
- }
-
- private void initFromColumns(Cursor cursor, String[] fromColumnNames, int[] fromColumns) {
- for (int i = fromColumnNames.length - 1; i >= 0; i--) {
- fromColumns[i] = cursor.getColumnIndexOrThrow(fromColumnNames[i]);
- }
- }
-
- private void initGroupFromColumns(String[] groupFromNames) {
- mGroupFrom = new int[groupFromNames.length];
- initFromColumns(mGroupCursorHelper.getCursor(), groupFromNames, mGroupFrom);
- }
-
- private void initChildrenFromColumns(String[] childFromNames, Cursor childCursor) {
- mChildFrom = new int[childFromNames.length];
- initFromColumns(childCursor, childFromNames, mChildFrom);
}
/**
@@ -257,13 +238,29 @@ public abstract class SimpleCursorTreeAdapter extends ResourceCursorTreeAdapter
}
}
+ private void initFromColumns(Cursor cursor, String[] fromColumnNames, int[] fromColumns) {
+ for (int i = fromColumnNames.length - 1; i >= 0; i--) {
+ fromColumns[i] = cursor.getColumnIndexOrThrow(fromColumnNames[i]);
+ }
+ }
+
@Override
protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) {
+ if (mChildFrom == null) {
+ mChildFrom = new int[mChildFromNames.length];
+ initFromColumns(cursor, mChildFromNames, mChildFrom);
+ }
+
bindView(view, context, cursor, mChildFrom, mChildTo);
}
@Override
protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) {
+ if (mGroupFrom == null) {
+ mGroupFrom = new int[mGroupFromNames.length];
+ initFromColumns(cursor, mGroupFromNames, mGroupFrom);
+ }
+
bindView(view, context, cursor, mGroupFrom, mGroupTo);
}