Search in sources :

Example 71 with MatrixCursor

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());
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) MatrixCursor(android.database.MatrixCursor)

Example 72 with MatrixCursor

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);
    }
}
Also used : MatrixCursor(android.database.MatrixCursor)

Example 73 with MatrixCursor

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;
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) MergeCursor(android.database.MergeCursor) CountDownLatch(java.util.concurrent.CountDownLatch) Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) MatrixCursor(android.database.MatrixCursor) RootInfo(com.android.documentsui.model.RootInfo) ExecutionException(java.util.concurrent.ExecutionException)

Example 74 with MatrixCursor

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;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) MatrixCursor(android.database.MatrixCursor)

Example 75 with MatrixCursor

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;
}
Also used : Uri(android.net.Uri) MatrixCursor(android.database.MatrixCursor)

Aggregations

MatrixCursor (android.database.MatrixCursor)259 Cursor (android.database.Cursor)37 DirectoryResult (com.android.documentsui.DirectoryResult)35 RowBuilder (android.database.MatrixCursor.RowBuilder)30 File (java.io.File)30 MergeCursor (android.database.MergeCursor)18 Uri (android.net.Uri)18 Test (org.junit.Test)17 Setting (com.android.providers.settings.SettingsState.Setting)15 FileNotFoundException (java.io.FileNotFoundException)15 ArrayList (java.util.ArrayList)13 Bundle (android.os.Bundle)10 BitSet (java.util.BitSet)10 Random (java.util.Random)10 IOException (java.io.IOException)7 LinkedList (java.util.LinkedList)7 ContentValues (android.content.ContentValues)6 HashSet (java.util.HashSet)6 Map (java.util.Map)6 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)5