Methods Summary |
---|
public synchronized void | close()
if (mContentObserver != null) {
mCursor.unregisterContentObserver(mContentObserver);
mContentObserver = null;
}
mCursor.close();
mCursor = null;
|
protected void | finalize()
if (mCursor != null) close();
super.finalize();
|
public synchronized java.util.Map | getRows()
if (mDirty) requery();
return mValues;
|
public synchronized ContentValues | getValues(java.lang.String rowName)Access the ContentValues for the row specified by rowName
if (mDirty) requery();
return mValues.get(rowName);
|
private synchronized void | readCursorIntoCache(android.database.Cursor cursor)
// Make a new map so old values returned by getRows() are undisturbed.
int capacity = mValues != null ? mValues.size() : 0;
mValues = new HashMap<String, ContentValues>(capacity);
while (cursor.moveToNext()) {
ContentValues values = new ContentValues();
for (int i = 0; i < mColumnNames.length; i++) {
if (i != mKeyColumn) {
values.put(mColumnNames[i], cursor.getString(i));
}
}
mValues.put(cursor.getString(mKeyColumn), values);
}
|
public void | requery()Requeries the cursor and reads the contents into the cache
final Cursor cursor = mCursor;
if (cursor == null) {
// If mCursor is null then it means there was a requery() in flight
// while another thread called close(), which nulls out mCursor.
// If this happens ignore the requery() since we are closed anyways.
return;
}
mDirty = false;
if (!cursor.requery()) {
// again, don't do anything if the cursor is already closed
return;
}
readCursorIntoCache(cursor);
setChanged();
notifyObservers();
|
public void | setKeepUpdated(boolean keepUpdated)Change whether or not the ContentQueryMap will register with the cursor's ContentProvider
for change notifications. If you use a ContentQueryMap in an activity you should call this
with false in onPause(), which means you need to call it with true in onResume()
if want it to be kept updated.
if (keepUpdated == mKeepUpdated) return;
mKeepUpdated = keepUpdated;
if (!mKeepUpdated) {
mCursor.unregisterContentObserver(mContentObserver);
mContentObserver = null;
} else {
if (mHandlerForUpdateNotifications == null) {
mHandlerForUpdateNotifications = new Handler();
}
if (mContentObserver == null) {
mContentObserver = new ContentObserver(mHandlerForUpdateNotifications) {
@Override
public void onChange(boolean selfChange) {
// If anyone is listening, we need to do this now to broadcast
// to the observers. Otherwise, we'll just set mDirty and
// let it query lazily when they ask for the values.
if (countObservers() != 0) {
requery();
} else {
mDirty = true;
}
}
};
}
mCursor.registerContentObserver(mContentObserver);
// mark dirty, since it is possible the cursor's backing data had changed before we
// registered for changes
mDirty = true;
}
|