for (String column : columns) { if (column.equals(FlashCardsContract.Model._ID)) { rb.add(modelId); } else if (column.equals(FlashCardsContract.Model.NAME)) { rb.add(jsonObject.getString("name")); } else if (column.equals(FlashCardsContract.Model.FIELD_NAMES)) { JSONArray flds = jsonObject.getJSONArray("flds"); rb.add(Utils.joinFields(allFlds)); } else if (column.equals(FlashCardsContract.Model.NUM_CARDS)) { rb.add(jsonObject.getJSONArray("tmpls").length()); } else if (column.equals(FlashCardsContract.Model.CSS)) { rb.add(jsonObject.getString("css")); } else if (column.equals(FlashCardsContract.Model.DECK_ID)) { rb.add(jsonObject.getLong("did")); } else if (column.equals(FlashCardsContract.Model.SORT_FIELD_INDEX)) { rb.add(jsonObject.getLong("sortf")); } else if (column.equals(FlashCardsContract.Model.TYPE)) { rb.add(jsonObject.getLong("type")); } else if (column.equals(FlashCardsContract.Model.LATEX_POST)) { rb.add(jsonObject.getString("latexPost")); } else if (column.equals(FlashCardsContract.Model.LATEX_PRE)) { rb.add(jsonObject.getString("latexPre")); } else if (column.equals(FlashCardsContract.Model.NOTE_COUNT)) { rb.add(models.useCount(jsonObject)); } else { throw new UnsupportedOperationException("Column \"" + column + "\" is unknown");
row.add(Document.COLUMN_DOCUMENT_ID, docId); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SIZE, file.length()); row.add(Document.COLUMN_MIME_TYPE, mimeType); row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); row.add(Document.COLUMN_FLAGS, flags); row.add(Document.COLUMN_ICON, R.drawable.ic_launcher);
Parcel parcel = Parcel.obtain(); hook.writeToParcel(parcel, XHook.FLAG_WITH_LUA); result.newRow().add(parcel.marshall()).add(cursor.getString(colUsed)); parcel.recycle(); } else result.newRow().add(hook.toJSON()).add(cursor.getString(colUsed)); } else if (BuildConfig.DEBUG) Log.w(TAG, "Hook " + hookid + " not found");
row.add(Root.COLUMN_ROOT_ID, ROOT); row.add(Root.COLUMN_SUMMARY, getContext().getString(R.string.root_summary)); row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_RECENTS | Root.FLAG_SUPPORTS_SEARCH); row.add(Root.COLUMN_TITLE, getContext().getString(R.string.app_name)); row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(mBaseDir)); row.add(Root.COLUMN_MIME_TYPES, getChildMimeTypes(mBaseDir)); row.add(Root.COLUMN_AVAILABLE_BYTES, mBaseDir.getFreeSpace()); row.add(Root.COLUMN_ICON, R.drawable.ic_launcher);
switch (source.getType(i)) { case Cursor.FIELD_TYPE_INTEGER: row.add(source.getInt(i)); break; case Cursor.FIELD_TYPE_FLOAT: row.add(source.getFloat(i)); break; case Cursor.FIELD_TYPE_STRING: row.add(source.getString(i)); break; case Cursor.FIELD_TYPE_BLOB: row.add(source.getBlob(i)); break; case Cursor.FIELD_TYPE_NULL: default: row.add(null); break;
MatrixCursor.RowBuilder row = cursor.newRow(); for (int i = 0; i < columnNames.length; i++) { row.add(source.getString(i));
@SuppressLint("WrongConstant") private static Cursor getHooks(Context context, String[] selection, boolean marshall) throws Throwable { boolean all = (selection != null && selection.length == 1 && "all".equals(selection[0])); List<String> collection = getCollection(context, Util.getUserId(Binder.getCallingUid())); List<XHook> hv = new ArrayList(); synchronized (lock) { for (XHook hook : hooks.values()) if (all || hook.isAvailable(null, collection)) hv.add(hook); } Collections.sort(hv, new Comparator<XHook>() { @Override public int compare(XHook h1, XHook h2) { return h1.getId().compareTo(h2.getId()); } }); MatrixCursor result = new MatrixCursor(new String[]{marshall ? "blob" : "json"}); for (XHook hook : hv) if (marshall) { Parcel parcel = Parcel.obtain(); hook.writeToParcel(parcel, XHook.FLAG_WITH_LUA); result.newRow().add(parcel.marshall()); parcel.recycle(); } else result.addRow(new Object[]{hook.toJSON()}); return result; }
private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath()); row.add(Document.COLUMN_DISPLAY_NAME, file.getName()); String mimeType = getDocumentType(file.getAbsolutePath()); row.add(Document.COLUMN_MIME_TYPE, mimeType); int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE : 0; // We only show thumbnails for image files - expect a call to // openDocumentThumbnail for each file that has // this flag set if (mimeType.startsWith("image/")) flags |= Document.FLAG_SUPPORTS_THUMBNAIL; row.add(Document.COLUMN_FLAGS, flags); // COLUMN_SIZE is required, but can be null row.add(Document.COLUMN_SIZE, file.length()); // These columns are optional row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); // Document.COLUMN_ICON can be a resource id identifying a custom icon. // The system provides default icons // based on mime type // Document.COLUMN_SUMMARY is optional additional information about the // file }
private void includeFile(final MatrixCursor result, final File file) throws FileNotFoundException { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath()); row.add(Document.COLUMN_DISPLAY_NAME, file.getName()); String mimeType = getDocumentType(file.getAbsolutePath()); row.add(Document.COLUMN_MIME_TYPE, mimeType); int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE : 0; // We only show thumbnails for image files - expect a call to // openDocumentThumbnail for each file that has // this flag set if (mimeType.startsWith("image/")) flags |= Document.FLAG_SUPPORTS_THUMBNAIL; row.add(Document.COLUMN_FLAGS, flags); // COLUMN_SIZE is required, but can be null row.add(Document.COLUMN_SIZE, file.length()); // These columns are optional row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified()); // Document.COLUMN_ICON can be a resource id identifying a custom icon. // The system provides default icons // based on mime type // Document.COLUMN_SUMMARY is optional additional information about the // file }
@Override public Cursor queryRoots(final String[] projection) throws FileNotFoundException { // Create a cursor with either the requested fields, or the default // projection if "projection" is null. final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION); // Add Home directory File homeDir = Environment.getExternalStorageDirectory(); final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath()); row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath()); row.add(Root.COLUMN_TITLE, getContext().getString(R.string.internal_storage)); row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE); row.add(Root.COLUMN_ICON, R.drawable.ic_provider); // These columns are optional row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace()); // Root.COLUMN_MIME_TYPE is another optional column and useful if you // have multiple roots with different // types of mime types (roots that don't match the requested mime type // are automatically hidden) return result; }
@Override public Cursor queryRoots(final String[] projection) throws FileNotFoundException { // Create a cursor with either the requested fields, or the default // projection if "projection" is null. final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION); // Add Home directory File homeDir = Environment.getExternalStorageDirectory(); final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath()); row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath()); row.add(Root.COLUMN_TITLE, "internal storage"); row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE); //row.add(Root.COLUMN_ICON, R.drawable.ic_provider); // These columns are optional row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace()); // Root.COLUMN_MIME_TYPE is another optional column and useful if you // have multiple roots with different // types of mime types (roots that don't match the requested mime type // are automatically hidden) return result; }
public Cursor query(@NonNull Uri paramUri, String[] paramArrayOfString1, String paramString1, String[] paramArrayOfString2, String paramString2) { MatrixCursor cursor = new MatrixCursor(new String[]{"string"}); try { if (getContext() == null) return cursor; final String path = paramUri.getPath().substring(1); final String[] items = getContext().getAssets().list(path); for (String s : items) { cursor.newRow().add(s); cursor.moveToNext(); } cursor.moveToFirst(); } catch (Exception e) { cursor.close(); throw new RuntimeException(e); } return cursor; }
public Cursor query(@NonNull Uri paramUri, String[] paramArrayOfString1, String paramString1, String[] paramArrayOfString2, String paramString2) { MatrixCursor cursor = new MatrixCursor(new String[]{"string"}); try { if (getContext() == null) return cursor; final String path = paramUri.getPath().substring(1); final String[] items = getContext().getAssets().list(path); for (String s : items) { cursor.newRow().add(s); cursor.moveToNext(); } cursor.moveToFirst(); } catch (Exception e) { cursor.close(); throw new RuntimeException(e); } return cursor; }
private void searchTracks(String query, MatrixCursor cursor) { TracksPager tracksPager = SpotifyTvApplication.getInstance().getSpotifyService().searchTracks(query, getSearchOptions()); if (tracksPager != null && tracksPager.tracks != null) { for (Track track : tracksPager.tracks.items) { MatrixCursor.RowBuilder row = cursor.newRow(); row.add(SearchManager.SUGGEST_COLUMN_TEXT_1, track.name); row.add(SearchManager.SUGGEST_COLUMN_CONTENT_TYPE, track.type); row.add(SearchManager.SUGGEST_COLUMN_DURATION, track.duration_ms); row.add(SearchManager.SUGGEST_COLUMN_INTENT_DATA, track.uri); if (track.artists != null && track.artists.size() > 0) { row.add(SearchManager.SUGGEST_COLUMN_TEXT_2, track.artists.get(0).name); } if (track.album != null && track.album.images != null && track.album.images.size() > 0) { row.add(SearchManager.SUGGEST_COLUMN_RESULT_CARD_IMAGE, track.album.images.get(0).url); } } } }
public Cursor query(@NonNull Uri paramUri, String[] paramArrayOfString1, String paramString1, String[] paramArrayOfString2, String paramString2) { MatrixCursor cursor = new MatrixCursor(new String[]{"string"}); try { if (getContext() == null) return cursor; final String path = paramUri.getPath().substring(1); final String[] items = getContext().getAssets().list(path); for (String s : items) { cursor.newRow().add(s); cursor.moveToNext(); } cursor.moveToFirst(); } catch (Exception e) { cursor.close(); throw new RuntimeException(e); } return cursor; }
@Override public Cursor queryRoots(String[] projection) { final MatrixCursor result = new MatrixCursor(projection == null ? DEFAULT_ROOT_PROJECTION : projection); final MatrixCursor.RowBuilder row = result.newRow(); row.add(DocumentsContract.Root.COLUMN_ROOT_ID, DUMMY_ROOT); row.add(DocumentsContract.Root.COLUMN_DOCUMENT_ID, DUMMY_ROOT); row.add(DocumentsContract.Root.COLUMN_ICON, R.mipmap.ic_launcher_egg); row.add(DocumentsContract.Root.COLUMN_TITLE, Utility.isProfileOwner(getContext()) ? getContext().getString(R.string.fragment_profile_main) : getContext().getString(R.string.fragment_profile_work)); row.add(DocumentsContract.Root.COLUMN_FLAGS, DocumentsContract.Root.FLAG_SUPPORTS_CREATE | DocumentsContract.Root.FLAG_LOCAL_ONLY | DocumentsContract.Root.FLAG_SUPPORTS_IS_CHILD); // SUPPORTS_IS_CHILD is required for OPEN_DOCUMENT_TREE return result; }
private void searchAlbums(String query, MatrixCursor cursor) { AlbumsPager albumsPager = SpotifyTvApplication.getInstance().getSpotifyService().searchAlbums(query, getSearchOptions()); if (albumsPager != null && albumsPager.albums != null) { for (AlbumSimple album : albumsPager.albums.items) { MatrixCursor.RowBuilder row = cursor.newRow(); row.add(SearchManager.SUGGEST_COLUMN_TEXT_1, album.name); row.add(SearchManager.SUGGEST_COLUMN_CONTENT_TYPE, album.type); row.add(SearchManager.SUGGEST_COLUMN_INTENT_DATA, album.uri); row.add(SearchManager.SUGGEST_COLUMN_TEXT_2, getContext().getString(R.string.albums)); if (album.images != null && album.images.size() > 0) { row.add(SearchManager.SUGGEST_COLUMN_RESULT_CARD_IMAGE, album.images.get(0).url); } } } }
private void searchArtists(String query, MatrixCursor cursor) { ArtistsPager artistsPager = SpotifyTvApplication.getInstance().getSpotifyService().searchArtists(query, getSearchOptions()); if (artistsPager != null && artistsPager.artists != null) { for (Artist artist : artistsPager.artists.items) { MatrixCursor.RowBuilder row = cursor.newRow(); row.add(SearchManager.SUGGEST_COLUMN_TEXT_1, artist.name); row.add(SearchManager.SUGGEST_COLUMN_CONTENT_TYPE, artist.type); row.add(SearchManager.SUGGEST_COLUMN_INTENT_DATA, artist.uri); row.add(SearchManager.SUGGEST_COLUMN_TEXT_2, getContext().getString(R.string.artists)); if (artist.images != null && artist.images.size() > 0) { row.add(SearchManager.SUGGEST_COLUMN_RESULT_CARD_IMAGE, artist.images.get(0).url); } } } }
private void searchPlaylists(String query, MatrixCursor cursor) { PlaylistsPager playlistsPager = SpotifyTvApplication.getInstance().getSpotifyService().searchPlaylists(query, getSearchOptions()); if (playlistsPager != null && playlistsPager.playlists != null) { for (PlaylistSimple playlist : playlistsPager.playlists.items) { MatrixCursor.RowBuilder row = cursor.newRow(); row.add(SearchManager.SUGGEST_COLUMN_TEXT_1, playlist.name); row.add(SearchManager.SUGGEST_COLUMN_CONTENT_TYPE, playlist.type); row.add(SearchManager.SUGGEST_COLUMN_INTENT_DATA, playlist.uri); row.add(SearchManager.SUGGEST_COLUMN_TEXT_2, getContext().getString(R.string.playlists)); if (playlist.images != null && playlist.images.size() > 0) { row.add(SearchManager.SUGGEST_COLUMN_RESULT_CARD_IMAGE, playlist.images.get(0).url); } } } }