use of android.database.MatrixCursor in project android_frameworks_base by DirtyUnicorns.
the class SectionBreakDocumentsAdapterWrapperTest method testItemCount_mixed.
// Tests that the item count is correct for a directory containing files and subdirs.
public void testItemCount_mixed() {
MatrixCursor c = new MatrixCursor(TestModel.COLUMNS);
for (int i = 0; i < 5; ++i) {
MatrixCursor.RowBuilder row = c.newRow();
row.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY);
row.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i));
row.add(Document.COLUMN_SIZE, i);
String mimeType = (i < 2) ? Document.MIME_TYPE_DIR : "text/*";
row.add(Document.COLUMN_MIME_TYPE, mimeType);
}
DirectoryResult r = new DirectoryResult();
r.cursor = c;
r.sortOrder = State.SORT_ORDER_SIZE;
mModel.update(r);
assertEquals(mModel.getItemCount() + 1, mAdapter.getItemCount());
}
use of android.database.MatrixCursor in project android_frameworks_base by DirtyUnicorns.
the class SuggestionProvider method query.
@Override
public Cursor query(Uri url, String[] projectionIn, String selection, String[] selectionArgs, String sort) {
int match = sURLMatcher.match(url);
switch(match) {
case SEARCH_SUGGESTIONS:
String query = url.getLastPathSegment();
MatrixCursor cursor = new MatrixCursor(COLUMNS);
String[] suffixes = { "", "a", " foo", "XXXXXXXXXXXXXXXXX" };
for (String suffix : suffixes) {
addRow(cursor, query + suffix);
}
return cursor;
default:
throw new IllegalArgumentException("Unknown URL: " + url);
}
}
use of android.database.MatrixCursor in project android_frameworks_base by DirtyUnicorns.
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.MatrixCursor in project android_frameworks_base by DirtyUnicorns.
the class StubProvider method querySearchDocuments.
@Override
public Cursor querySearchDocuments(String rootId, String query, String[] projection) throws FileNotFoundException {
StubDocument parentDocument = mRoots.get(rootId).document;
if (parentDocument == null || parentDocument.file.isFile()) {
throw new FileNotFoundException();
}
final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
for (File file : parentDocument.file.listFiles()) {
if (file.getName().toLowerCase().contains(query)) {
StubDocument document = mStorage.get(getDocumentIdForFile(file));
if (document != null) {
includeDocument(result, document);
}
}
}
return result;
}
use of android.database.MatrixCursor in project android_frameworks_base by DirtyUnicorns.
the class MusicProvider method getRootContainerCurser.
public MatrixCursor getRootContainerCurser() {
MatrixCursor matrixCursor = new MatrixCursor(BrowserService.MEDIA_CONTAINER_PROJECTION);
Uri.Builder pianoBuilder = new Uri.Builder();
pianoBuilder.authority(BrowserService.AUTHORITY);
pianoBuilder.appendPath(BrowserService.PIANO_BASE_PATH);
matrixCursor.addRow(new Object[] { pianoBuilder.build(), BrowserService.PIANO_BASE_PATH, "subtitle", null, 0 });
Uri.Builder voiceBuilder = new Uri.Builder();
voiceBuilder.authority(BrowserService.AUTHORITY);
voiceBuilder.appendPath(BrowserService.VOICE_BASE_PATH);
matrixCursor.addRow(new Object[] { voiceBuilder.build(), BrowserService.VOICE_BASE_PATH, "subtitle", null, 0 });
return matrixCursor;
}
Aggregations