Search in sources :

Example 31 with RowBuilder

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

the class TestDocumentsProvider method includeFile.

private static void includeFile(MatrixCursor result, String docId, int flags) {
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);
    row.add(Document.COLUMN_DISPLAY_NAME, docId);
    row.add(Document.COLUMN_LAST_MODIFIED, System.currentTimeMillis());
    row.add(Document.COLUMN_FLAGS, flags);
    if (MY_DOC_ID.equals(docId)) {
        row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
        row.add(Document.COLUMN_FLAGS, Document.FLAG_DIR_SUPPORTS_CREATE);
    } else if (MY_DOC_NULL.equals(docId)) {
    // No MIME type
    } else {
        row.add(Document.COLUMN_MIME_TYPE, "application/octet-stream");
    }
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder)

Example 32 with RowBuilder

use of android.database.MatrixCursor.RowBuilder in project android_frameworks_base by AOSPA.

the class MtpDatabase method queryRoots.

/**
     * Queries roots information.
     * @param columnNames Column names defined in {@link android.provider.DocumentsContract.Root}.
     * @return Database cursor.
     */
Cursor queryRoots(Resources resources, String[] columnNames) {
    final String selection = COLUMN_ROW_STATE + " IN (?, ?) AND " + COLUMN_DOCUMENT_TYPE + " = ?";
    final Cursor deviceCursor = mDatabase.query(TABLE_DOCUMENTS, strings(COLUMN_DEVICE_ID), selection, strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_DEVICE), COLUMN_DEVICE_ID, null, null, null);
    try {
        final SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
        builder.setTables(JOIN_ROOTS);
        builder.setProjectionMap(COLUMN_MAP_ROOTS);
        final MatrixCursor result = new MatrixCursor(columnNames);
        final ContentValues values = new ContentValues();
        while (deviceCursor.moveToNext()) {
            final int deviceId = deviceCursor.getInt(0);
            final Cursor storageCursor = builder.query(mDatabase, columnNames, selection + " AND " + COLUMN_DEVICE_ID + " = ?", strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_STORAGE, deviceId), null, null, null);
            try {
                values.clear();
                try (final Cursor deviceRoot = builder.query(mDatabase, columnNames, selection + " AND " + COLUMN_DEVICE_ID + " = ?", strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_DEVICE, deviceId), null, null, null)) {
                    deviceRoot.moveToNext();
                    DatabaseUtils.cursorRowToContentValues(deviceRoot, values);
                }
                if (storageCursor.getCount() != 0) {
                    long capacityBytes = 0;
                    long availableBytes = 0;
                    final int capacityIndex = storageCursor.getColumnIndex(Root.COLUMN_CAPACITY_BYTES);
                    final int availableIndex = storageCursor.getColumnIndex(Root.COLUMN_AVAILABLE_BYTES);
                    while (storageCursor.moveToNext()) {
                        // don't calculate corresponding values.
                        if (capacityIndex != -1) {
                            capacityBytes += storageCursor.getLong(capacityIndex);
                        }
                        if (availableIndex != -1) {
                            availableBytes += storageCursor.getLong(availableIndex);
                        }
                    }
                    values.put(Root.COLUMN_CAPACITY_BYTES, capacityBytes);
                    values.put(Root.COLUMN_AVAILABLE_BYTES, availableBytes);
                } else {
                    values.putNull(Root.COLUMN_CAPACITY_BYTES);
                    values.putNull(Root.COLUMN_AVAILABLE_BYTES);
                }
                if (storageCursor.getCount() == 1 && values.containsKey(Root.COLUMN_TITLE)) {
                    storageCursor.moveToFirst();
                    // Add storage name to device name if we have only 1 storage.
                    values.put(Root.COLUMN_TITLE, resources.getString(R.string.root_name, values.getAsString(Root.COLUMN_TITLE), storageCursor.getString(storageCursor.getColumnIndex(Root.COLUMN_TITLE))));
                }
            } finally {
                storageCursor.close();
            }
            final RowBuilder row = result.newRow();
            for (final String key : values.keySet()) {
                row.add(key, values.get(key));
            }
        }
        return result;
    } finally {
        deviceCursor.close();
    }
}
Also used : ContentValues(android.content.ContentValues) RowBuilder(android.database.MatrixCursor.RowBuilder) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder) MatrixCursor(android.database.MatrixCursor)

Example 33 with RowBuilder

use of android.database.MatrixCursor.RowBuilder in project android_frameworks_base by AOSPA.

the class StressProvider method includeDocument.

private void includeDocument(MatrixCursor result, StubDocument document) {
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, document.id);
    row.add(Document.COLUMN_DISPLAY_NAME, document.id);
    row.add(Document.COLUMN_SIZE, document.size);
    row.add(Document.COLUMN_MIME_TYPE, document.mimeType);
    row.add(Document.COLUMN_FLAGS, document.thumbnail != -1 ? Document.FLAG_SUPPORTS_THUMBNAIL : 0);
    row.add(Document.COLUMN_LAST_MODIFIED, document.lastModified);
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder)

Example 34 with RowBuilder

use of android.database.MatrixCursor.RowBuilder in project android_frameworks_base by AOSPA.

the class StressProvider method includeRoot.

private void includeRoot(MatrixCursor result, StubRoot root) {
    final RowBuilder row = result.newRow();
    row.add(Root.COLUMN_ROOT_ID, root.id);
    row.add(Root.COLUMN_FLAGS, 0);
    row.add(Root.COLUMN_TITLE, root.id);
    row.add(Root.COLUMN_DOCUMENT_ID, root.documentId);
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder)

Example 35 with RowBuilder

use of android.database.MatrixCursor.RowBuilder in project android_frameworks_base by DirtyUnicorns.

the class BugreportStorageProvider method addFileRow.

private void addFileRow(MatrixCursor result, File file) {
    String mimeType = getTypeForName(file.getName());
    int flags = Document.FLAG_SUPPORTS_DELETE;
    if (mArchiveHelper.isSupportedArchiveType(mimeType)) {
        flags |= Document.FLAG_ARCHIVE;
    }
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForFile(file));
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    row.add(Document.COLUMN_DISPLAY_NAME, file.getName());
    row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified());
    row.add(Document.COLUMN_FLAGS, flags);
    row.add(Document.COLUMN_SIZE, file.length());
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder)

Aggregations

RowBuilder (android.database.MatrixCursor.RowBuilder)60 MatrixCursor (android.database.MatrixCursor)30 ContentValues (android.content.ContentValues)5 Cursor (android.database.Cursor)5 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)5 Point (android.graphics.Point)5 Uri (android.net.Uri)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5