List of usage examples for android.database Cursor setNotificationUri
void setNotificationUri(ContentResolver cr, Uri uri);
From source file:com.odoo.support.provider.OContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sort) { projection = validateProjections(projection); Cursor c = createQuery(uri, projection, selection, selectionArgs, sort); Context ctx = getContext();// w w w . ja va 2 s . c om assert ctx != null; c.setNotificationUri(ctx.getContentResolver(), uri); return c; }
From source file:org.mozilla.labs.Soup.provider.AppsProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(APPS_TABLE_NAME);//from w w w.ja v a2 s . c o m switch (sUriMatcher.match(uri)) { case APPS: qb.setProjectionMap(sAppsProjectionMap); break; case APP_ID: qb.setProjectionMap(sAppsProjectionMap); qb.appendWhere(Apps._ID + "=" + uri.getPathSegments().get(1)); break; case LIVE_FOLDER_APPS: qb.setProjectionMap(sLiveFolderProjectionMap); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } // If no sort order is specified use the default String orderBy; if (TextUtils.isEmpty(sortOrder)) { orderBy = AppsContract.Apps.DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } // Get the database and run the query SQLiteDatabase db = mOpenHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy); // Tell the cursor what uri to watch, so it knows when its source data // changes c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
From source file:com.gmail.emerssso.srbase.database.SRContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selArgs, String sortOrder) { // Using SQLiteQueryBuilder instead of query() method SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); int uriType = sURIMatcher.match(uri); String tableName = ""; String[] columns;//from w w w .ja v a 2s. co m switch (uriType) { case SRS: case SR_ID: tableName = SRTable.TABLE_NAME; columns = SRTable.COLUMNS; break; case DAILIES: case DAILY_ID: tableName = DailyTable.TABLE_NAME; columns = DailyTable.COLUMNS; break; case PARTS: case PART_ID: tableName = PartTable.TABLE_NAME; columns = PartTable.COLUMNS; break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } checkColumns(projection, columns); queryBuilder.setTables(tableName); if (isIdType(uriType)) { queryBuilder.appendWhere("_id =" + uri.getLastPathSegment()); } SQLiteDatabase db = database.getWritableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selArgs, null, null, sortOrder); // make sure that potential listeners are getting notified cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
From source file:com.luboganev.dejalist.ui.MainActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { data.setNotificationUri(getContentResolver(), DejalistContract.Categories.CONTENT_URI); mAdapter.changeCursor(data);/*from w w w . j av a 2s. c o m*/ if (mStateSelectedNavigationPosition >= 0) { mDrawerList.setItemChecked(mStateSelectedNavigationPosition, true); mStateSelectedNavigationPosition = -1; } }
From source file:com.hivewallet.androidclient.wallet.AddressBookProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String originalSelection, final String[] originalSelectionArgs, final String sortOrder) { final SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(DATABASE_TABLE);/* ww w . j a v a2 s .c o m*/ final List<String> pathSegments = uri.getPathSegments(); if (pathSegments.size() > 1) throw new IllegalArgumentException(uri.toString()); String selection = null; String[] selectionArgs = null; if (pathSegments.size() == 1) { final String address = uri.getLastPathSegment(); qb.appendWhere(KEY_ADDRESS + "="); qb.appendWhereEscapeString(address); } else if (SELECTION_IN.equals(originalSelection)) { final String[] addresses = originalSelectionArgs[0].trim().split(","); qb.appendWhere(KEY_ADDRESS + " IN ("); appendAddresses(qb, addresses); qb.appendWhere(")"); } else if (SELECTION_NOTIN.equals(originalSelection)) { final String[] addresses = originalSelectionArgs[0].trim().split(","); qb.appendWhere(KEY_ADDRESS + " NOT IN ("); appendAddresses(qb, addresses); qb.appendWhere(")"); } else if (SELECTION_QUERY.equals(originalSelection)) { final String query = '%' + originalSelectionArgs[0].trim() + '%'; selection = KEY_ADDRESS + " LIKE ? OR " + KEY_LABEL + " LIKE ?"; selectionArgs = new String[] { query, query }; } final Cursor cursor = qb.query(helper.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
From source file:redgun.bakingapp.data.RecipesProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Here's the switch statement that, given a URI, will determine what kind of request it is, // and query the database accordingly. Cursor retCursor; switch (sUriMatcher.match(uri)) { case RECIPES: { retCursor = mOpenHelper.getReadableDatabase().query(RecipesContract.RecipeEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); break;//from w w w .j av a 2 s . com } default: throw new UnsupportedOperationException("Unknown uri: " + uri); } retCursor.setNotificationUri(getContext().getContentResolver(), uri); return retCursor; }
From source file:edu.stanford.mobisocial.dungbeetle.DungBeetleContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { ContentResolver resolver = getContext().getContentResolver(); final String realAppId = getCallingActivityId(); if (realAppId == null) { Log.d(TAG, "No AppId for calling activity. Ignoring query."); return null; }/* w w w. ja va2s .com*/ if (DBG) Log.d(TAG, "Processing query: " + uri + " from appId " + realAppId); int match = sUriMatcher.match(uri); switch (match) { case UriMatcher.NO_MATCH: break; case FEEDS: Cursor c = mHelper.queryFeedList(realAppId, projection, selection, selectionArgs, sortOrder); c.setNotificationUri(resolver, Feed.feedListUri()); return c; case FEEDS_ID: List<String> segs = uri.getPathSegments(); switch (Feed.typeOf(uri)) { case APP: String queriedAppId = segs.get(1); queriedAppId = queriedAppId.substring(queriedAppId.lastIndexOf('^') + 1); int pos = queriedAppId.lastIndexOf(':'); if (pos > 0) { queriedAppId = queriedAppId.substring(0, pos); } if (!realAppId.equals(queriedAppId)) { Log.w(TAG, "Illegal data access."); return null; } String table = DbObj.TABLE; String select = DbObj.COL_APP_ID + " = ?"; String[] selectArgs = new String[] { realAppId }; String[] columns = projection; String groupBy = null; String having = null; String orderBy = null; select = DBHelper.andClauses(select, selection); selectArgs = DBHelper.andArguments(selectArgs, selectionArgs); c = mHelper.getReadableDatabase().query(table, columns, select, selectArgs, groupBy, having, orderBy); c.setNotificationUri(resolver, uri); return c; default: boolean isMe = segs.get(1).equals("me"); String feedName = isMe ? "friend" : segs.get(1); if (Feed.FEED_NAME_GLOBAL.equals(feedName)) { feedName = null; } select = isMe ? DBHelper.andClauses(selection, DbObject.CONTACT_ID + "=" + Contact.MY_ID) : selection; c = mHelper.queryFeed(realAppId, feedName, projection, select, selectionArgs, sortOrder); c.setNotificationUri(resolver, uri); return c; } case OBJS: if (!SUPER_APP_ID.equals(realAppId)) { String selection2 = DbObj.COL_APP_ID + " = ?"; String[] selectionArgs2 = new String[] { realAppId }; selection = DBHelper.andClauses(selection, selection2); selectionArgs = DBHelper.andArguments(selectionArgs, selectionArgs2); } return mHelper.getReadableDatabase().query(DbObject.TABLE, projection, selection, selectionArgs, null, null, sortOrder); case OBJS_ID: if (!SUPER_APP_ID.equals(realAppId)) { return null; } // objects by database id String objId = uri.getLastPathSegment(); selectionArgs = DBHelper.andArguments(selectionArgs, new String[] { objId }); selection = DBHelper.andClauses(selection, DbObject._ID + " = ?"); return mHelper.getReadableDatabase().query(DbObject.TABLE, projection, selection, selectionArgs, null, null, sortOrder); } /////////////////////////////////////////////////////// // TODO: Remove code from here down, add to UriMatcher List<String> segs = uri.getPathSegments(); if (match(uri, "feeds", ".+", "head")) { boolean isMe = segs.get(1).equals("me"); String feedName = isMe ? "friend" : segs.get(1); String select = isMe ? DBHelper.andClauses(selection, DbObject.CONTACT_ID + "=" + Contact.MY_ID) : selection; Cursor c = mHelper.queryFeedLatest(realAppId, feedName, projection, select, selectionArgs, sortOrder); c.setNotificationUri(resolver, Uri.parse(CONTENT_URI + "/feeds/" + feedName)); if (isMe) c.setNotificationUri(resolver, Uri.parse(CONTENT_URI + "/feeds/me")); return c; } else if (match(uri, "groups_membership", ".+")) { if (!realAppId.equals(SUPER_APP_ID)) return null; Long contactId = Long.valueOf(segs.get(1)); Cursor c = mHelper.queryGroupsMembership(contactId); c.setNotificationUri(resolver, uri); return c; } else if (match(uri, "group_contacts", ".+")) { if (!realAppId.equals(SUPER_APP_ID)) return null; Long group_id = Long.valueOf(segs.get(1)); Cursor c = mHelper.queryGroupContacts(group_id); c.setNotificationUri(resolver, uri); return c; } else if (match(uri, "local_user", ".+")) { // currently available to any local app with a feed id. String feed_name = uri.getLastPathSegment(); Cursor c = mHelper.queryLocalUser(realAppId, feed_name); c.setNotificationUri(resolver, uri); return c; } else if (match(uri, "members", ".+")) { // TODO: This is a hack so we can us SocialKit // to get the sender of a mass message. if (match(uri, "members", "friend")) { if (!realAppId.equals(SUPER_APP_ID)) return null; return mHelper.getReadableDatabase().query(Contact.TABLE, projection, selection, selectionArgs, null, null, sortOrder); } switch (Feed.typeOf(uri)) { case FRIEND: String personId = Feed.friendIdForFeed(uri); if (personId == null) { Log.w(TAG, "no person id in person feed"); return null; } selection = DBHelper.andClauses(selection, Contact.PERSON_ID + " = ?"); selectionArgs = DBHelper.andArguments(selectionArgs, new String[] { personId }); return mHelper.getReadableDatabase().query(Contact.TABLE, projection, selection, selectionArgs, null, null, sortOrder); case GROUP: case APP: String feedName = segs.get(1); if (feedName == null || Feed.FEED_NAME_GLOBAL.equals(feedName)) { if (!SUPER_APP_ID.equals(realAppId)) { return null; } } Cursor c = mHelper.queryFeedMembers(projection, selection, selectionArgs, uri, realAppId); c.setNotificationUri(resolver, uri); return c; default: return null; } } else if (match(uri, "groups")) { if (!realAppId.equals(SUPER_APP_ID)) return null; Cursor c = mHelper.queryGroups(); c.setNotificationUri(resolver, Uri.parse(CONTENT_URI + "/groups")); return c; } else if (match(uri, "contacts") || match(uri, "subscribers") || match(uri, "group_members")) { if (!realAppId.equals(SUPER_APP_ID)) return null; Cursor c = mHelper.getReadableDatabase().query(segs.get(0), projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(resolver, Uri.parse(CONTENT_URI + "/" + segs.get(0))); return c; } else if (match(uri, "users")) { if (!realAppId.equals(SUPER_APP_ID)) return null; Cursor c = mHelper.getReadableDatabase().query(Contact.TABLE, projection, selection, selectionArgs, null, null, sortOrder); return c; } else { Log.d(TAG, "Unrecognized query: " + uri); return null; } }
From source file:org.opendatakit.services.instance.provider.InstanceProvider.java
@Override public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {//from w ww.j av a2s. com possiblyWaitForContentProviderDebugger(); List<String> segments = uri.getPathSegments(); if (segments.size() < 2 || segments.size() > 3) { throw new SQLException("Unknown URI (too many segments!) " + uri); } String appName = segments.get(0); ODKFileUtils.verifyExternalStorageAvailability(); ODKFileUtils.assertDirectoryStructure(appName); String tableId = segments.get(1); DbHandle dbHandleName = OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface() .generateInternalUseDbHandle(); boolean success = false; OdkConnectionInterface db = null; try { // +1 referenceCount if db is returned (non-null) db = OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface().getConnection(appName, dbHandleName); Cursor c = db.query(tableId, projection, selection, selectionArgs, null, null, sortOrder, null); if (c == null) { return null; } // Tell the cursor what uri to watch, so it knows when its source data // changes c.setNotificationUri(getContext().getContentResolver(), uri); c.registerDataSetObserver(new InvalidateMonitor(appName, dbHandleName)); success = true; return c; } finally { if (db != null) { try { db.releaseReference(); } finally { if (!success) { // this closes the connection // if it was successful, then the InvalidateMonitor will close the connection OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface().removeConnection(appName, dbHandleName); } } } } }
From source file:org.thomnichols.android.gmarks.GmarksProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); // Log.d(TAG, "Managed query: " + uri); String groupBy = null;//from w w w. ja v a 2 s .c o m String orderBy = null; String limit = null; switch (sUriMatcher.match(uri)) { case BOOKMARKS_URI: qb.setTables(BOOKMARKS_TABLE_NAME); qb.setProjectionMap(bookmarksProjectionMap); String labelID = uri.getQueryParameter("label_id"); if (labelID != null) { qb.setTables("bookmarks join bookmark_labels on bookmarks._id = bookmark_labels.bookmark_id"); qb.appendWhere("bookmark_labels.label_id=?"); selectionArgs = (String[]) ArrayUtils.addAll(selectionArgs, new String[] { labelID }); } break; case BOOKMARK_SEARCH_URI: case BOOKMARK_SEARCH_SUGGEST_URI: String query = null; if (sUriMatcher.match(uri) == BOOKMARK_SEARCH_SUGGEST_URI) { qb.setProjectionMap(searchSuggestProjectionMap); // path looks like "search_suggest_query/[query]?limit=50 query = uri.getLastPathSegment(); limit = uri.getQueryParameter("limit"); if (sortOrder == null) sortOrder = Bookmark.Columns.SORT_MODIFIED; } else query = uri.getQueryParameter("q"); if (query != null) { qb.setTables("bookmarks join bookmarks_FTS on bookmarks._id = bookmarks_FTS.docid"); qb.appendWhere("bookmarks_FTS MATCH ?"); if (selectionArgs == null) selectionArgs = new String[] { query }; else selectionArgs = (String[]) ArrayUtils.addAll(selectionArgs, new String[] { query }); } else if (selectionArgs == null || selectionArgs.length < 1) throw new IllegalArgumentException("No search criteria given for query!"); break; case BOOKMARK_ID_URI: qb.setTables(BOOKMARKS_TABLE_NAME); qb.setProjectionMap(bookmarksProjectionMap); qb.appendWhere(Bookmark.Columns._ID + "=" + uri.getPathSegments().get(1)); break; case LABELS_URI: qb.setTables("labels join bookmark_labels on labels._id = bookmark_labels.label_id"); groupBy = "label"; if (sortOrder == null) sortOrder = Label.Columns.DEFAULT_SORT_ORDER; qb.setProjectionMap(labelsProjectionMap); break; case LIVE_FOLDER_BOOKMARKS_URI: qb.setTables(BOOKMARKS_TABLE_NAME); qb.setProjectionMap(sLiveFolderProjectionMap); String labelId = uri.getQueryParameter("label_id"); if (labelId != null) { qb.setTables("bookmarks join bookmark_labels on bookmarks._id = bookmark_labels.bookmark_id"); qb.appendWhere("bookmark_labels.label_id=?"); selectionArgs = (String[]) ArrayUtils.addAll(selectionArgs, new String[] { labelId }); } sortOrder = "modified DESC"; // for some reason this gets set to 'name ASC' break; case BOOKMARK_LISTS_URI: qb.setTables(BookmarkList.TABLE_NAME); qb.setProjectionMap(listsProjectionMap); if (sortOrder == null) sortOrder = BookmarkList.Columns.DEFAULT_SORT_ORDER; String type = uri.getQueryParameter(BookmarkList.PARAM_CATEGORY); if (BookmarkList.LISTS_PRIVATE.equals(type)) qb.appendWhere("owned=1"); else if (BookmarkList.LISTS_SHARED.equals(type)) qb.appendWhere("shared=1"); else if (BookmarkList.LISTS_PUBLIC.equals(type)) qb.appendWhere("publshed=1"); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } // If no sort order is specified use the default if (TextUtils.isEmpty(sortOrder)) { orderBy = Bookmark.Columns.DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } // Get the database and run the query SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, groupBy, null, orderBy, limit); // Tell the cursor what uri to watch, so it knows when its source data changes c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Cursor querySource(@NonNull final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { ContentResolver contentResolver = getContext() != null ? getContext().getContentResolver() : null; if (contentResolver == null) { return null; }//from ww w. j a va 2s . c o m final SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(MuzeiContract.Sources.TABLE_NAME); qb.setProjectionMap(allSourcesColumnProjectionMap); final SQLiteDatabase db = databaseHelper.getReadableDatabase(); if (MuzeiProvider.uriMatcher.match(uri) == SOURCE_ID) { // If the incoming URI is for a single source identified by its ID, appends "_ID = <sourceId>" // to the where clause, so that it selects that single source qb.appendWhere(BaseColumns._ID + "=" + uri.getLastPathSegment()); } String orderBy; if (TextUtils.isEmpty(sortOrder)) orderBy = MuzeiContract.Sources.DEFAULT_SORT_ORDER; else orderBy = sortOrder; final Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy, null); c.setNotificationUri(contentResolver, uri); return c; }