Search in sources :

Example 6 with RowBuilder

use of android.database.MatrixCursor.RowBuilder in project platform_frameworks_base by android.

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 7 with RowBuilder

use of android.database.MatrixCursor.RowBuilder in project platform_frameworks_base by android.

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 8 with RowBuilder

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

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 9 with RowBuilder

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

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 10 with RowBuilder

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

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

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