Search in sources :

Example 96 with MatrixCursor

use of android.database.MatrixCursor in project routerkeygenAndroid by routerkeygen.

the class LocalStorageProvider method includeFile.

private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException {
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath());
    row.add(Document.COLUMN_DISPLAY_NAME, file.getName());
    String mimeType = getDocumentType(file.getAbsolutePath());
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE : 0;
    // this flag set
    if (mimeType.startsWith("image/"))
        flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
    row.add(Document.COLUMN_FLAGS, flags);
    // COLUMN_SIZE is required, but can be null
    row.add(Document.COLUMN_SIZE, file.length());
    // These columns are optional
    row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified());
// Document.COLUMN_ICON can be a resource id identifying a custom icon.
// The system provides default icons
// based on mime type
// Document.COLUMN_SUMMARY is optional additional information about the
// file
}
Also used : MatrixCursor(android.database.MatrixCursor) Point(android.graphics.Point)

Example 97 with MatrixCursor

use of android.database.MatrixCursor in project muzei by romannurik.

the class MuzeiDocumentsProvider method queryDocument.

@Override
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
    ContentResolver contentResolver = getContext() != null ? getContext().getContentResolver() : null;
    if (contentResolver == null) {
        return result;
    }
    if (ROOT_DOCUMENT_ID.equals(documentId)) {
        final MatrixCursor.RowBuilder row = result.newRow();
        row.add(DocumentsContract.Document.COLUMN_DOCUMENT_ID, ROOT_DOCUMENT_ID);
        row.add(DocumentsContract.Document.COLUMN_DISPLAY_NAME, getContext().getString(R.string.app_name));
        row.add(DocumentsContract.Document.COLUMN_MIME_TYPE, DocumentsContract.Document.MIME_TYPE_DIR);
        row.add(DocumentsContract.Document.COLUMN_FLAGS, 0);
        row.add(DocumentsContract.Document.COLUMN_SIZE, null);
    } else if (BY_DATE_DOCUMENT_ID.equals(documentId)) {
        includeByDateRow(result.newRow());
    } else if (BY_SOURCE_DOCUMENT_ID.equals(documentId)) {
        includeBySourceRow(result.newRow());
    } else if (documentId != null && documentId.startsWith(ARTWORK_DOCUMENT_ID_PREFIX)) {
        long artworkId = Long.parseLong(documentId.replace(ARTWORK_DOCUMENT_ID_PREFIX, ""));
        includeAllArtwork(result, contentResolver.query(ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, artworkId), ARTWORK_PROJECTION, null, null, null));
    } else if (documentId != null && documentId.startsWith(SOURCE_DOCUMENT_ID_PREFIX)) {
        long sourceId = Long.parseLong(documentId.replace(SOURCE_DOCUMENT_ID_PREFIX, ""));
        includeAllSources(result, contentResolver.query(ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI, sourceId), SOURCE_PROJECTION, null, null, null));
    }
    return result;
}
Also used : MatrixCursor(android.database.MatrixCursor) ContentResolver(android.content.ContentResolver)

Example 98 with MatrixCursor

use of android.database.MatrixCursor in project muzei by romannurik.

the class MuzeiDocumentsProvider method querySearchDocuments.

@Override
public Cursor querySearchDocuments(final String rootId, final String query, final String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
    ContentResolver contentResolver = getContext() != null ? getContext().getContentResolver() : null;
    if (contentResolver == null) {
        return result;
    }
    String selection = MuzeiContract.Artwork.COLUMN_NAME_TITLE + " LIKE ? OR " + MuzeiContract.Artwork.COLUMN_NAME_BYLINE + " LIKE ? OR " + MuzeiContract.Artwork.COLUMN_NAME_ATTRIBUTION + " LIKE ?";
    String likeAnyPositionQuery = "%" + query + "%";
    includeAllArtwork(result, contentResolver.query(MuzeiContract.Artwork.CONTENT_URI, ARTWORK_PROJECTION, selection, new String[] { likeAnyPositionQuery, likeAnyPositionQuery, likeAnyPositionQuery }, MuzeiContract.Artwork.DEFAULT_SORT_ORDER));
    return result;
}
Also used : MatrixCursor(android.database.MatrixCursor) ContentResolver(android.content.ContentResolver)

Example 99 with MatrixCursor

use of android.database.MatrixCursor in project android_frameworks_base by crdroidandroid.

the class StubProvider method queryDocument.

@Override
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
    final StubDocument file = mStorage.get(documentId);
    if (file == null) {
        throw new FileNotFoundException();
    }
    includeDocument(result, file);
    return result;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) MatrixCursor(android.database.MatrixCursor)

Example 100 with MatrixCursor

use of android.database.MatrixCursor in project android_frameworks_base by crdroidandroid.

the class StubProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION);
    for (Map.Entry<String, RootInfo> entry : mRoots.entrySet()) {
        final String id = entry.getKey();
        final RootInfo info = entry.getValue();
        final RowBuilder row = result.newRow();
        row.add(Root.COLUMN_ROOT_ID, id);
        row.add(Root.COLUMN_FLAGS, info.flags);
        row.add(Root.COLUMN_TITLE, id);
        row.add(Root.COLUMN_DOCUMENT_ID, info.document.documentId);
        row.add(Root.COLUMN_AVAILABLE_BYTES, info.getRemainingCapacity());
    }
    return result;
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder) HashMap(java.util.HashMap) Map(java.util.Map) 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