android.database.AbstractCursor Java Examples
The following examples show how to use
android.database.AbstractCursor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FontProvider.java From FontProvider with MIT License | 6 votes |
@SuppressLint("NewApi") @Nullable @Override public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) { String path = uri.getEncodedPath(); if (!path.startsWith("/font/") || selectionArgs == null || selectionArgs[0] == null) { return null; } String name = path.substring("/font/".length()); String[] w = selectionArgs[0].split(","); int[] weight = new int[w.length]; for (int i = 0; i < w.length; i++) { weight[i] = Integer.parseInt(w[i]); } FontFamily[] families = FontManager.getFontFamily(getContext(), name, weight); Bundle bundle = new Bundle(); bundle.putParcelableArray("data", families); AbstractCursor cursor = new SimpleCursor(); cursor.setExtras(bundle); return cursor; }
Example #2
Source File: DocumentArchiveHelper.java From FireFiles with Apache License 2.0 | 4 votes |
private Loader getInstanceUncheckedLocked(String documentId) throws FileNotFoundException { try { final ParsedDocumentId id = ParsedDocumentId.fromDocumentId(documentId, mIdDelimiter); if (mArchives.get(id.mArchiveId) != null) { return mArchives.get(id.mArchiveId); } final Cursor cursor = mProvider.queryDocument(id.mArchiveId, new String[] { Document.COLUMN_MIME_TYPE, COLUMN_LOCAL_FILE_PATH }); cursor.moveToFirst(); final String mimeType = cursor.getString(cursor.getColumnIndex( Document.COLUMN_MIME_TYPE)); Preconditions.checkArgument(isSupportedArchiveType(mimeType), "Unsupported archive type."); final int columnIndex = cursor.getColumnIndex(COLUMN_LOCAL_FILE_PATH); final String localFilePath = columnIndex != -1 ? cursor.getString(columnIndex) : null; final File localFile = localFilePath != null ? new File(localFilePath) : null; final Uri notificationUri = ((AbstractCursor)cursor).getNotificationUri(); final Loader loader = new Loader(mProvider, localFile, id, mIdDelimiter, notificationUri); // Remove the instance from mArchives collection once the archive file changes. if (notificationUri != null) { final LruCache<String, Loader> finalArchives = mArchives; mProvider.getContext().getContentResolver().registerContentObserver(notificationUri, false, new ContentObserver(null) { @Override public void onChange(boolean selfChange, Uri uri) { synchronized (mArchives) { final Loader currentLoader = mArchives.get(id.mArchiveId); if (currentLoader == loader) { mArchives.remove(id.mArchiveId); } } } }); } mArchives.put(id.mArchiveId, loader); return loader; } catch (IOException e) { // DocumentsProvider doesn't use IOException. For consistency convert it to // IllegalStateException. throw new IllegalStateException(e); } }
Example #3
Source File: DocumentArchiveHelper.java From FireFiles with Apache License 2.0 | 4 votes |
private Loader getInstanceUncheckedLocked(String documentId) throws FileNotFoundException { try { final ParsedDocumentId id = ParsedDocumentId.fromDocumentId(documentId, mIdDelimiter); if (mArchives.get(id.mArchiveId) != null) { return mArchives.get(id.mArchiveId); } final Cursor cursor = mProvider.queryDocument(id.mArchiveId, new String[] { Document.COLUMN_MIME_TYPE, COLUMN_LOCAL_FILE_PATH }); cursor.moveToFirst(); final String mimeType = cursor.getString(cursor.getColumnIndex( Document.COLUMN_MIME_TYPE)); Preconditions.checkArgument(isSupportedArchiveType(mimeType), "Unsupported archive type."); final int columnIndex = cursor.getColumnIndex(COLUMN_LOCAL_FILE_PATH); final String localFilePath = columnIndex != -1 ? cursor.getString(columnIndex) : null; final File localFile = localFilePath != null ? new File(localFilePath) : null; final Uri notificationUri = ((AbstractCursor)cursor).getNotificationUri(); final Loader loader = new Loader(mProvider, localFile, id, mIdDelimiter, notificationUri); // Remove the instance from mArchives collection once the archive file changes. if (notificationUri != null) { final LruCache<String, Loader> finalArchives = mArchives; mProvider.getContext().getContentResolver().registerContentObserver(notificationUri, false, new ContentObserver(null) { @Override public void onChange(boolean selfChange, Uri uri) { synchronized (mArchives) { final Loader currentLoader = mArchives.get(id.mArchiveId); if (currentLoader == loader) { mArchives.remove(id.mArchiveId); } } } }); } mArchives.put(id.mArchiveId, loader); return loader; } catch (IOException e) { // DocumentsProvider doesn't use IOException. For consistency convert it to // IllegalStateException. throw new IllegalStateException(e); } }
Example #4
Source File: DocumentArchiveHelper.java From FireFiles with Apache License 2.0 | 4 votes |
private Loader getInstanceUncheckedLocked(String documentId) throws FileNotFoundException { try { final ParsedDocumentId id = ParsedDocumentId.fromDocumentId(documentId, mIdDelimiter); if (mArchives.get(id.mArchiveId) != null) { return mArchives.get(id.mArchiveId); } final Cursor cursor = mProvider.queryDocument(id.mArchiveId, new String[] { Document.COLUMN_MIME_TYPE, COLUMN_LOCAL_FILE_PATH }); cursor.moveToFirst(); final String mimeType = cursor.getString(cursor.getColumnIndex( Document.COLUMN_MIME_TYPE)); Preconditions.checkArgument(isSupportedArchiveType(mimeType), "Unsupported archive type."); final int columnIndex = cursor.getColumnIndex(COLUMN_LOCAL_FILE_PATH); final String localFilePath = columnIndex != -1 ? cursor.getString(columnIndex) : null; final File localFile = localFilePath != null ? new File(localFilePath) : null; final Uri notificationUri = ((AbstractCursor)cursor).getNotificationUri(); final Loader loader = new Loader(mProvider, localFile, id, mIdDelimiter, notificationUri); // Remove the instance from mArchives collection once the archive file changes. if (notificationUri != null) { final LruCache<String, Loader> finalArchives = mArchives; mProvider.getContext().getContentResolver().registerContentObserver(notificationUri, false, new ContentObserver(null) { @Override public void onChange(boolean selfChange, Uri uri) { synchronized (mArchives) { final Loader currentLoader = mArchives.get(id.mArchiveId); if (currentLoader == loader) { mArchives.remove(id.mArchiveId); } } } }); } mArchives.put(id.mArchiveId, loader); return loader; } catch (IOException e) { // DocumentsProvider doesn't use IOException. For consistency convert it to // IllegalStateException. throw new IllegalStateException(e); } }
Example #5
Source File: SettingsProvider.java From Study_Android_Demo with Apache License 2.0 | 4 votes |
private Cursor queryForUser(Uri url, String[] select, String where, String[] whereArgs, String sort, int forUser) { if (LOCAL_LOGV) Slog.v(TAG, "query(" + url + ") for user " + forUser); SqlArguments args = new SqlArguments(url, where, whereArgs); DatabaseHelper dbH; dbH = getOrEstablishDatabase( TABLE_GLOBAL.equals(args.table) ? UserHandle.USER_OWNER : forUser); SQLiteDatabase db = dbH.getReadableDatabase(); // The favorites table was moved from this provider to a provider inside Home // Home still need to query this table to upgrade from pre-cupcake builds // However, a cupcake+ build with no data does not contain this table which will // cause an exception in the SQL stack. The following line is a special case to // let the caller of the query have a chance to recover and avoid the exception if (TABLE_FAVORITES.equals(args.table)) { return null; } else if (TABLE_OLD_FAVORITES.equals(args.table)) { args.table = TABLE_FAVORITES; Cursor cursor = db.rawQuery("PRAGMA table_info(favorites);", null); if (cursor != null) { boolean exists = cursor.getCount() > 0; cursor.close(); if (!exists) return null; } else { return null; } } SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(args.table); Cursor ret = qb.query(db, select, args.where, args.args, null, null, sort); // the default Cursor interface does not support per-user observation try { AbstractCursor c = (AbstractCursor) ret; c.setNotificationUri(getContext().getContentResolver(), url, forUser); } catch (ClassCastException e) { // details of the concrete Cursor implementation have changed and this code has // not been updated to match -- complain and fail hard. Log.wtf(TAG, "Incompatible cursor derivation!"); throw e; } return ret; }
Example #6
Source File: AbstractCursor_Assert.java From assertj-android with Apache License 2.0 | 4 votes |
public AbstractCursor_Assert(AbstractCursor actual) { super(actual, AbstractCursor_Assert.class); }