use of android.database.MergeCursor in project android_frameworks_base by DirtyUnicorns.
the class Model method updateModelData.
/**
* Scan over the incoming cursor data, generate Model IDs for each row, and sort the IDs
* according to the current sort order.
*/
private void updateModelData() {
int[] positions = new int[mCursorCount];
mIds = new String[mCursorCount];
boolean[] isDirs = new boolean[mCursorCount];
String[] displayNames = null;
long[] longValues = null;
switch(mSortOrder) {
case SORT_ORDER_DISPLAY_NAME:
displayNames = new String[mCursorCount];
break;
case SORT_ORDER_LAST_MODIFIED:
case SORT_ORDER_SIZE:
longValues = new long[mCursorCount];
break;
}
String mimeType;
mCursor.moveToPosition(-1);
for (int pos = 0; pos < mCursorCount; ++pos) {
if (!mCursor.moveToNext()) {
Log.e(TAG, "Fail to move cursor to next pos: " + pos);
return;
}
positions[pos] = pos;
// with the authority to avoid collisions.
if (mCursor instanceof MergeCursor) {
mIds[pos] = getCursorString(mCursor, RootCursorWrapper.COLUMN_AUTHORITY) + "|" + getCursorString(mCursor, Document.COLUMN_DOCUMENT_ID);
} else {
mIds[pos] = getCursorString(mCursor, Document.COLUMN_DOCUMENT_ID);
}
mimeType = getCursorString(mCursor, Document.COLUMN_MIME_TYPE);
isDirs[pos] = Document.MIME_TYPE_DIR.equals(mimeType);
switch(mSortOrder) {
case SORT_ORDER_DISPLAY_NAME:
final String displayName = getCursorString(mCursor, Document.COLUMN_DISPLAY_NAME);
displayNames[pos] = displayName;
break;
case SORT_ORDER_LAST_MODIFIED:
longValues[pos] = getLastModified(mCursor);
break;
case SORT_ORDER_SIZE:
longValues[pos] = getCursorLong(mCursor, Document.COLUMN_SIZE);
break;
}
}
switch(mSortOrder) {
case SORT_ORDER_DISPLAY_NAME:
binarySort(displayNames, isDirs, positions, mIds);
break;
case SORT_ORDER_LAST_MODIFIED:
case SORT_ORDER_SIZE:
binarySort(longValues, isDirs, positions, mIds);
break;
}
// Populate the positions.
mPositions.clear();
for (int i = 0; i < mCursorCount; ++i) {
mPositions.put(mIds[i], positions[i]);
}
}
use of android.database.MergeCursor in project android_frameworks_base by ResurrectionRemix.
the class Model method updateModelData.
/**
* Scan over the incoming cursor data, generate Model IDs for each row, and sort the IDs
* according to the current sort order.
*/
private void updateModelData() {
int[] positions = new int[mCursorCount];
mIds = new String[mCursorCount];
boolean[] isDirs = new boolean[mCursorCount];
String[] displayNames = null;
long[] longValues = null;
switch(mSortOrder) {
case SORT_ORDER_DISPLAY_NAME:
displayNames = new String[mCursorCount];
break;
case SORT_ORDER_LAST_MODIFIED:
case SORT_ORDER_SIZE:
longValues = new long[mCursorCount];
break;
}
String mimeType;
mCursor.moveToPosition(-1);
for (int pos = 0; pos < mCursorCount; ++pos) {
if (!mCursor.moveToNext()) {
Log.e(TAG, "Fail to move cursor to next pos: " + pos);
return;
}
positions[pos] = pos;
// with the authority to avoid collisions.
if (mCursor instanceof MergeCursor) {
mIds[pos] = getCursorString(mCursor, RootCursorWrapper.COLUMN_AUTHORITY) + "|" + getCursorString(mCursor, Document.COLUMN_DOCUMENT_ID);
} else {
mIds[pos] = getCursorString(mCursor, Document.COLUMN_DOCUMENT_ID);
}
mimeType = getCursorString(mCursor, Document.COLUMN_MIME_TYPE);
isDirs[pos] = Document.MIME_TYPE_DIR.equals(mimeType);
switch(mSortOrder) {
case SORT_ORDER_DISPLAY_NAME:
final String displayName = getCursorString(mCursor, Document.COLUMN_DISPLAY_NAME);
displayNames[pos] = displayName;
break;
case SORT_ORDER_LAST_MODIFIED:
longValues[pos] = getLastModified(mCursor);
break;
case SORT_ORDER_SIZE:
longValues[pos] = getCursorLong(mCursor, Document.COLUMN_SIZE);
break;
}
}
switch(mSortOrder) {
case SORT_ORDER_DISPLAY_NAME:
binarySort(displayNames, isDirs, positions, mIds);
break;
case SORT_ORDER_LAST_MODIFIED:
case SORT_ORDER_SIZE:
binarySort(longValues, isDirs, positions, mIds);
break;
}
// Populate the positions.
mPositions.clear();
for (int i = 0; i < mCursorCount; ++i) {
mPositions.put(mIds[i], positions[i]);
}
}
use of android.database.MergeCursor in project android_frameworks_base by ResurrectionRemix.
the class RecentsLoader method loadInBackgroundLocked.
private DirectoryResult loadInBackgroundLocked() {
if (mFirstPassLatch == null) {
// First time through we kick off all the recent tasks, and wait
// around to see if everyone finishes quickly.
final Collection<RootInfo> roots = mRoots.getMatchingRootsBlocking(mState);
for (RootInfo root : roots) {
if (root.supportsRecents()) {
mTasks.put(root, new RecentsTask(root.authority, root.rootId));
}
}
mFirstPassLatch = new CountDownLatch(mTasks.size());
for (RecentsTask task : mTasks.values()) {
ProviderExecutor.forAuthority(task.authority).execute(task);
}
try {
mFirstPassLatch.await(MAX_FIRST_PASS_WAIT_MILLIS, TimeUnit.MILLISECONDS);
mFirstPassDone = true;
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
final long rejectBefore = System.currentTimeMillis() - REJECT_OLDER_THAN;
// Collect all finished tasks
boolean allDone = true;
List<Cursor> cursors = new ArrayList<>();
for (RecentsTask task : mTasks.values()) {
if (task.isDone()) {
try {
final Cursor cursor = task.get();
if (cursor == null)
continue;
final FilteringCursorWrapper filtered = new FilteringCursorWrapper(cursor, mState.acceptMimes, RECENT_REJECT_MIMES, rejectBefore) {
@Override
public void close() {
// Ignored, since we manage cursor lifecycle internally
}
};
cursors.add(filtered);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
// We already logged on other side
} catch (Exception e) {
Log.e(TAG, "Failed to query Recents for authority: " + task.authority + ". Skip this authority in Recents.", e);
}
} else {
allDone = false;
}
}
if (DEBUG) {
Log.d(TAG, "Found " + cursors.size() + " of " + mTasks.size() + " recent queries done");
}
final DirectoryResult result = new DirectoryResult();
result.sortOrder = SORT_ORDER_LAST_MODIFIED;
final Cursor merged;
if (cursors.size() > 0) {
merged = new MergeCursor(cursors.toArray(new Cursor[cursors.size()]));
} else {
// Return something when nobody is ready
merged = new MatrixCursor(new String[0]);
}
// Tell the UI if this is an in-progress result. When loading is complete, another update is
// sent with EXTRA_LOADING set to false.
Bundle extras = new Bundle();
extras.putBoolean(DocumentsContract.EXTRA_LOADING, !allDone);
merged.setExtras(extras);
result.cursor = merged;
return result;
}
use of android.database.MergeCursor in project android_frameworks_base by crdroidandroid.
the class RecentsLoader method loadInBackgroundLocked.
private DirectoryResult loadInBackgroundLocked() {
if (mFirstPassLatch == null) {
// First time through we kick off all the recent tasks, and wait
// around to see if everyone finishes quickly.
final Collection<RootInfo> roots = mRoots.getMatchingRootsBlocking(mState);
for (RootInfo root : roots) {
if (root.supportsRecents()) {
mTasks.put(root, new RecentsTask(root.authority, root.rootId));
}
}
mFirstPassLatch = new CountDownLatch(mTasks.size());
for (RecentsTask task : mTasks.values()) {
ProviderExecutor.forAuthority(task.authority).execute(task);
}
try {
mFirstPassLatch.await(MAX_FIRST_PASS_WAIT_MILLIS, TimeUnit.MILLISECONDS);
mFirstPassDone = true;
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
final long rejectBefore = System.currentTimeMillis() - REJECT_OLDER_THAN;
// Collect all finished tasks
boolean allDone = true;
List<Cursor> cursors = new ArrayList<>();
for (RecentsTask task : mTasks.values()) {
if (task.isDone()) {
try {
final Cursor cursor = task.get();
if (cursor == null)
continue;
final FilteringCursorWrapper filtered = new FilteringCursorWrapper(cursor, mState.acceptMimes, RECENT_REJECT_MIMES, rejectBefore) {
@Override
public void close() {
// Ignored, since we manage cursor lifecycle internally
}
};
cursors.add(filtered);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
// We already logged on other side
} catch (Exception e) {
Log.e(TAG, "Failed to query Recents for authority: " + task.authority + ". Skip this authority in Recents.", e);
}
} else {
allDone = false;
}
}
if (DEBUG) {
Log.d(TAG, "Found " + cursors.size() + " of " + mTasks.size() + " recent queries done");
}
final DirectoryResult result = new DirectoryResult();
result.sortOrder = SORT_ORDER_LAST_MODIFIED;
final Cursor merged;
if (cursors.size() > 0) {
merged = new MergeCursor(cursors.toArray(new Cursor[cursors.size()]));
} else {
// Return something when nobody is ready
merged = new MatrixCursor(new String[0]);
}
// Tell the UI if this is an in-progress result. When loading is complete, another update is
// sent with EXTRA_LOADING set to false.
Bundle extras = new Bundle();
extras.putBoolean(DocumentsContract.EXTRA_LOADING, !allDone);
merged.setExtras(extras);
result.cursor = merged;
return result;
}
use of android.database.MergeCursor in project android_frameworks_base by crdroidandroid.
the class Model method updateModelData.
/**
* Scan over the incoming cursor data, generate Model IDs for each row, and sort the IDs
* according to the current sort order.
*/
private void updateModelData() {
int[] positions = new int[mCursorCount];
mIds = new String[mCursorCount];
boolean[] isDirs = new boolean[mCursorCount];
String[] displayNames = null;
long[] longValues = null;
switch(mSortOrder) {
case SORT_ORDER_DISPLAY_NAME:
displayNames = new String[mCursorCount];
break;
case SORT_ORDER_LAST_MODIFIED:
case SORT_ORDER_SIZE:
longValues = new long[mCursorCount];
break;
}
String mimeType;
mCursor.moveToPosition(-1);
for (int pos = 0; pos < mCursorCount; ++pos) {
if (!mCursor.moveToNext()) {
Log.e(TAG, "Fail to move cursor to next pos: " + pos);
return;
}
positions[pos] = pos;
// with the authority to avoid collisions.
if (mCursor instanceof MergeCursor) {
mIds[pos] = getCursorString(mCursor, RootCursorWrapper.COLUMN_AUTHORITY) + "|" + getCursorString(mCursor, Document.COLUMN_DOCUMENT_ID);
} else {
mIds[pos] = getCursorString(mCursor, Document.COLUMN_DOCUMENT_ID);
}
mimeType = getCursorString(mCursor, Document.COLUMN_MIME_TYPE);
isDirs[pos] = Document.MIME_TYPE_DIR.equals(mimeType);
switch(mSortOrder) {
case SORT_ORDER_DISPLAY_NAME:
final String displayName = getCursorString(mCursor, Document.COLUMN_DISPLAY_NAME);
displayNames[pos] = displayName;
break;
case SORT_ORDER_LAST_MODIFIED:
longValues[pos] = getLastModified(mCursor);
break;
case SORT_ORDER_SIZE:
longValues[pos] = getCursorLong(mCursor, Document.COLUMN_SIZE);
break;
}
}
switch(mSortOrder) {
case SORT_ORDER_DISPLAY_NAME:
binarySort(displayNames, isDirs, positions, mIds);
break;
case SORT_ORDER_LAST_MODIFIED:
case SORT_ORDER_SIZE:
binarySort(longValues, isDirs, positions, mIds);
break;
}
// Populate the positions.
mPositions.clear();
for (int i = 0; i < mCursorCount; ++i) {
mPositions.put(mIds[i], positions[i]);
}
}
Aggregations