Search in sources :

Example 11 with MatrixCursor

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

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)

Example 12 with MatrixCursor

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

the class StressProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(DEFAULT_DOCUMENT_PROJECTION);
    final ArrayList<StubDocument> childDocuments = mChildDocuments.get(parentDocumentId);
    if (childDocuments != null) {
        for (StubDocument document : childDocuments) {
            includeDocument(result, document);
        }
    }
    return result;
}
Also used : MatrixCursor(android.database.MatrixCursor)

Example 13 with MatrixCursor

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

the class MtpDocumentsProvider method createErrorCursor.

/**
     * Creates empty cursor with specific error message.
     *
     * @param projection Column names.
     * @param stringResId String resource ID of error message.
     * @return Empty cursor with error message.
     */
private Cursor createErrorCursor(String[] projection, int stringResId) {
    final Bundle bundle = new Bundle();
    bundle.putString(DocumentsContract.EXTRA_ERROR, mResources.getString(stringResId));
    final Cursor cursor = new MatrixCursor(projection);
    cursor.setExtras(bundle);
    return cursor;
}
Also used : Bundle(android.os.Bundle) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor) MatrixCursor(android.database.MatrixCursor)

Example 14 with MatrixCursor

use of android.database.MatrixCursor 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 15 with MatrixCursor

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

the class SettingsProvider method getAllGlobalSettings.

private Cursor getAllGlobalSettings(String[] projection) {
    if (DEBUG) {
        Slog.v(LOG_TAG, "getAllGlobalSettings()");
    }
    synchronized (mLock) {
        // Get the settings.
        SettingsState settingsState = mSettingsRegistry.getSettingsLocked(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM);
        List<String> names = settingsState.getSettingNamesLocked();
        final int nameCount = names.size();
        String[] normalizedProjection = normalizeProjection(projection);
        MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount);
        // Anyone can get the global settings, so no security checks.
        for (int i = 0; i < nameCount; i++) {
            String name = names.get(i);
            Setting setting = settingsState.getSettingLocked(name);
            appendSettingToCursor(result, setting);
        }
        return result;
    }
}
Also used : Setting(com.android.providers.settings.SettingsState.Setting) 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