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;
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations