Search in sources :

Example 76 with MatrixCursor

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

the class MusicProvider method getRootItemCursor.

public MatrixCursor getRootItemCursor(int type) {
    if (type == BrowserService.NOW_PLAYING) {
        MatrixCursor matrixCursor = new MatrixCursor(BrowserService.MEDIA_CONTAINER_PROJECTION);
        try {
            // Just return all of the tracks for now
            List<MusicTrack> musicTracks = retreiveMedia();
            for (MusicTrack musicTrack : musicTracks) {
                Uri.Builder builder = new Uri.Builder();
                builder.authority(BrowserService.AUTHORITY);
                builder.appendPath(BrowserService.NOW_PLAYING_PATH);
                builder.appendPath(musicTrack.getTitle());
                matrixCursor.addRow(new Object[] { builder.build(), musicTrack.getTitle(), musicTrack.getArtist(), musicTrack.getImage(), PlaybackState.ACTION_PLAY });
                Log.d(TAG, "Uri " + builder.build());
            }
        } catch (JSONException e) {
            Log.e(TAG, "::getRootItemCursor:", e);
        }
        Log.d(TAG, "cursor: " + matrixCursor.getCount());
        return matrixCursor;
    } else if (type == BrowserService.PIANO) {
        MatrixCursor matrixCursor = new MatrixCursor(BrowserService.MEDIA_CONTAINER_PROJECTION);
        try {
            List<MusicTrack> musicTracks = retreiveMedia();
            for (MusicTrack musicTrack : musicTracks) {
                Uri.Builder builder = new Uri.Builder();
                builder.authority(BrowserService.AUTHORITY);
                builder.appendPath(BrowserService.PIANO_BASE_PATH);
                builder.appendPath(musicTrack.getTitle());
                matrixCursor.addRow(new Object[] { builder.build(), musicTrack.getTitle(), musicTrack.getArtist(), musicTrack.getImage(), PlaybackState.ACTION_PLAY });
                Log.d(TAG, "Uri " + builder.build());
            }
        } catch (JSONException e) {
            Log.e(TAG, "::getRootItemCursor:", e);
        }
        Log.d(TAG, "cursor: " + matrixCursor.getCount());
        return matrixCursor;
    } else if (type == BrowserService.VOICE) {
        MatrixCursor matrixCursor = new MatrixCursor(BrowserService.MEDIA_CONTAINER_PROJECTION);
        try {
            List<MusicTrack> musicTracks = retreiveMedia();
            for (MusicTrack musicTrack : musicTracks) {
                Uri.Builder builder = new Uri.Builder();
                builder.authority(BrowserService.AUTHORITY);
                builder.appendPath(BrowserService.VOICE_BASE_PATH);
                builder.appendPath(musicTrack.getTitle());
                matrixCursor.addRow(new Object[] { builder.build(), musicTrack.getTitle(), musicTrack.getArtist(), musicTrack.getImage(), PlaybackState.ACTION_PLAY });
                Log.d(TAG, "Uri " + builder.build());
            }
        } catch (JSONException e) {
            Log.e(TAG, "::getRootItemCursor:", e);
        }
        Log.d(TAG, "cursor: " + matrixCursor.getCount());
        return matrixCursor;
    }
    return null;
}
Also used : JSONException(org.json.JSONException) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) Uri(android.net.Uri) MatrixCursor(android.database.MatrixCursor)

Example 77 with MatrixCursor

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

the class TestDocumentsProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    Log.d(TAG, "Someone asked for our roots!");
    if (LAG)
        lagUntilCanceled(null);
    if (ROOTS_WEDGE)
        wedgeUntilCanceled(null);
    if (ROOTS_CRASH)
        System.exit(12);
    if (ROOTS_REFRESH) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                SystemClock.sleep(3000);
                Log.d(TAG, "Notifying that something changed!!");
                final Uri uri = DocumentsContract.buildRootsUri(mAuthority);
                getContext().getContentResolver().notifyChange(uri, null, false);
                return null;
            }
        }.execute();
    }
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    final RowBuilder row = result.newRow();
    row.add(Root.COLUMN_ROOT_ID, MY_ROOT_ID);
    row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_RECENTS | Root.FLAG_SUPPORTS_CREATE);
    row.add(Root.COLUMN_TITLE, "_Test title which is really long");
    row.add(Root.COLUMN_SUMMARY, SystemClock.elapsedRealtime() + " summary which is also super long text");
    row.add(Root.COLUMN_DOCUMENT_ID, MY_DOC_ID);
    row.add(Root.COLUMN_AVAILABLE_BYTES, 1024);
    return result;
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder) Uri(android.net.Uri) MatrixCursor(android.database.MatrixCursor)

Example 78 with MatrixCursor

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

the class ExternalStorageProvider method querySearchDocuments.

@Override
public Cursor querySearchDocuments(String rootId, String query, String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    query = query.toLowerCase();
    final File parent;
    synchronized (mRootsLock) {
        parent = mRoots.get(rootId).path;
    }
    final LinkedList<File> pending = new LinkedList<File>();
    pending.add(parent);
    while (!pending.isEmpty() && result.getCount() < 24) {
        final File file = pending.removeFirst();
        if (file.isDirectory()) {
            for (File child : file.listFiles()) {
                pending.add(child);
            }
        }
        if (file.getName().toLowerCase().contains(query)) {
            includeFile(result, null, file);
        }
    }
    return result;
}
Also used : File(java.io.File) MatrixCursor(android.database.MatrixCursor) LinkedList(java.util.LinkedList)

Example 79 with MatrixCursor

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

the class ContentProviderOperationTest method getCursor.

/**
     * Build a {@link Cursor} with a single row that contains all values
     * provided through the given {@link ContentValues}.
     */
private Cursor getCursor(ContentValues contentValues, int numRows) {
    final Set<Entry<String, Object>> valueSet = contentValues.valueSet();
    final String[] keys = new String[valueSet.size()];
    final Object[] values = new Object[valueSet.size()];
    int i = 0;
    for (Entry<String, Object> entry : valueSet) {
        keys[i] = entry.getKey();
        values[i] = entry.getValue();
        i++;
    }
    final MatrixCursor cursor = new MatrixCursor(keys);
    for (i = 0; i < numRows; i++) {
        cursor.addRow(values);
    }
    return cursor;
}
Also used : Entry(java.util.Map.Entry) MatrixCursor(android.database.MatrixCursor)

Example 80 with MatrixCursor

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

the class SettingsProvider method getAllSecureSettings.

private Cursor getAllSecureSettings(int userId, String[] projection) {
    if (DEBUG) {
        Slog.v(LOG_TAG, "getAllSecureSettings(" + userId + ")");
    }
    // Resolve the userId on whose behalf the call is made.
    final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId);
    synchronized (mLock) {
        List<String> names = mSettingsRegistry.getSettingsNamesLocked(SETTINGS_TYPE_SECURE, callingUserId);
        final int nameCount = names.size();
        String[] normalizedProjection = normalizeProjection(projection);
        MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount);
        for (int i = 0; i < nameCount; i++) {
            String name = names.get(i);
            // Determine the owning user as some profile settings are cloned from the parent.
            final int owningUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, name);
            // Special case for location (sigh).
            if (isLocationProvidersAllowedRestricted(name, callingUserId, owningUserId)) {
                continue;
            }
            Setting setting = mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SECURE, owningUserId, 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