Methods Summary |
---|
public java.lang.CharSequence | convertToString(android.database.Cursor cursor)Converts the cursor into a CharSequence. Subclasses should override this
method to convert their results. The default implementation returns an
empty String for null values or the default String representation of
the value.
return cursor == null ? "" : cursor.toString();
|
public void | destroyItem(android.view.View container, int position, java.lang.Object object)
mObjectRowMap.remove(object);
super.destroyItem(container, position, object);
|
public int | getCount()
if (mCursor != null) {
return mCursor.getCount();
} else {
return 0;
}
|
public android.database.Cursor | getCursor()Returns the cursor.
return mCursor;
|
public java.lang.Object | getDataItem(int position)Returns the data item associated with the specified position in the data set.
if (mCursor != null && moveCursorTo(position)) {
return mCursor;
} else {
return null;
}
|
public abstract android.support.v4.app.Fragment | getItem(android.content.Context context, android.database.Cursor cursor, int position)Makes a fragment for the data pointed to by the cursor
|
public android.support.v4.app.Fragment | getItem(int position)
if (mCursor != null && moveCursorTo(position)) {
return getItem(mContext, mCursor, position);
}
return null;
|
public long | getItemId(int position)Returns the row id associated with the specified position in the list.
if (mCursor != null && moveCursorTo(position)) {
return mCursor.getString(mRowIDColumn).hashCode();
} else {
return 0;
}
|
public int | getItemPosition(java.lang.Object object)
final Integer rowId = mObjectRowMap.get(object);
if (rowId == null || mItemPosition == null) {
return POSITION_NONE;
}
final int position = mItemPosition.get(rowId, POSITION_NONE);
return position;
|
private void | init(android.content.Context context, android.database.Cursor c)Initialize the adapter.
boolean cursorPresent = c != null;
mCursor = c;
mContext = context;
mRowIDColumn = cursorPresent
? mCursor.getColumnIndex(PhotoContract.PhotoViewColumns.URI) : -1;
|
public java.lang.Object | instantiateItem(android.view.View container, int position)
if (mCursor == null) {
throw new IllegalStateException("this should only be called when the cursor is valid");
}
final Integer rowId;
if (moveCursorTo(position)) {
rowId = mCursor.getString(mRowIDColumn).hashCode();
} else {
rowId = null;
}
// Create the fragment and bind cursor data
final Object obj = super.instantiateItem(container, position);
if (obj != null) {
mObjectRowMap.put(obj, rowId);
}
return obj;
|
public boolean | isDataValid()
return mCursor != null;
|
protected java.lang.String | makeFragmentName(int viewId, int index)
if (moveCursorTo(index)) {
return "android:pager:" + viewId + ":" + mCursor.getString(mRowIDColumn).hashCode();
} else {
return super.makeFragmentName(viewId, index);
}
|
private boolean | moveCursorTo(int position)Moves the cursor to the given position
if (mCursor != null && !mCursor.isClosed()) {
return mCursor.moveToPosition(position);
}
return false;
|
private void | setItemPosition()Sets the {@link #mItemPosition} instance variable with the current mapping of
row id to cursor position.
if (mCursor == null || mCursor.isClosed()) {
mItemPosition = null;
return;
}
SparseIntArray itemPosition = new SparseIntArray(mCursor.getCount());
mCursor.moveToPosition(-1);
while (mCursor.moveToNext()) {
final int rowId = mCursor.getString(mRowIDColumn).hashCode();
final int position = mCursor.getPosition();
itemPosition.append(rowId, position);
}
mItemPosition = itemPosition;
|
public android.database.Cursor | swapCursor(android.database.Cursor newCursor)Swap in a new Cursor, returning the old Cursor.
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "swapCursor old=" + (mCursor == null ? -1 : mCursor.getCount()) +
"; new=" + (newCursor == null ? -1 : newCursor.getCount()));
}
if (newCursor == mCursor) {
return null;
}
Cursor oldCursor = mCursor;
mCursor = newCursor;
if (newCursor != null) {
mRowIDColumn = newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.URI);
} else {
mRowIDColumn = -1;
}
setItemPosition();
notifyDataSetChanged(); // notify the observers about the new cursor
return oldCursor;
|