List of usage examples for android.content UriMatcher NO_MATCH
int NO_MATCH
To view the source code for android.content UriMatcher NO_MATCH.
Click Source Link
From source file:org.voidsink.anewjkuapp.fragment.LvaDetailFragment.java
@Override public void onStart() { super.onStart(); UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); uriMatcher.addURI(KusssContentContract.AUTHORITY, KusssContentContract.Course.PATH_CONTENT_CHANGED, 0); uriMatcher.addURI(KusssContentContract.AUTHORITY, KusssContentContract.Assessment.PATH_CONTENT_CHANGED, 1); mLvaObserver = new BaseContentObserver(uriMatcher, this); getActivity().getContentResolver().registerContentObserver(KusssContentContract.Course.CONTENT_CHANGED_URI, false, mLvaObserver);//from w w w . j av a2 s . co m getActivity().getContentResolver() .registerContentObserver(KusssContentContract.Assessment.CONTENT_CHANGED_URI, false, mLvaObserver); PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); }
From source file:pl.selvin.android.syncframework.content.BaseContentProvider.java
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { final int code = contentHelper.matchUri(uri); if (code != UriMatcher.NO_MATCH) { if (code == ContentHelper.uriClearCode) { if (DEBUG) { Log.d("delete", "uriClearCode"); }/*from w ww . j av a2 s . c o m*/ mDB.onUpgrade(getWritableDatabase(), 1, contentHelper.DATABASE_VERSION); return 0; } if (code == ContentHelper.uriSyncCode) { throw new IllegalArgumentException("Can not delete with Sync Uri."); } boolean syncToNetwork = checkSyncToNetwork(uri); final TableInfo tab = contentHelper.getTableFromCode(code & ContentHelper.uriCode); if (tab.readonly) { throw new IllegalArgumentException("Table " + tab.name + " is readonly."); } if (isItemCode(code)) { if (isItemRowIDCode(code)) { selection = "isDeleted=0 AND ROWID=" + uri.getPathSegments().get(2) + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } else { selection = "isDeleted=0" + tab.getSelection() + (!TextUtils.isEmpty(selection) ? "(" + selection + ") AND " : ""); int i = 0; final String[] old = selectionArgs; final int len = (old == null) ? 0 : old.length; selectionArgs = new String[len + tab.primaryKey.length]; for (; i < tab.primaryKey.length; i++) { selectionArgs[i] = uri.getPathSegments().get(i); } if (len > 0) { for (; i < old.length; i++) { selectionArgs[i] = old[i - tab.primaryKey.length]; } } } } else { selection = "isDeleted=0" + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } int ret = 0; int cascaderet = 0; if (tab.cascadeDelete != null) { for (CascadeInfo info : tab.cascadeDelete) { final Cursor c = query(contentHelper.getDirUri(tab.name), info.pk, selection, selectionArgs, null); if (c.moveToFirst()) { do { final String[] args = new String[info.pk.length]; final StringBuilder sb = new StringBuilder(); for (int i = 0; i < info.pk.length; i++) { if (i > 0) sb.append("AND "); sb.append(info.fk[i]); sb.append("=? "); args[i] = c.getString(i); } cascaderet += delete(contentHelper.getDirUri(info.table, syncToNetwork), sb.toString(), args); } while (c.moveToNext()); } c.close(); } } ContentValues values = new ContentValues(2); values.put("isDirty", 1); values.put("isDeleted", 1); ret = getWritableDatabase().update(tab.name, values, "tempId IS NULL AND " + selection, selectionArgs); ret += getWritableDatabase().delete(tab.name, "tempId IS NOT NULL AND " + selection, selectionArgs); if (ret > 0) { final ContentResolver cr = getContext().getContentResolver(); cr.notifyChange(uri, null, syncToNetwork); for (String n : tab.notifyUris) { cr.notifyChange(Uri.parse(n), null, syncToNetwork); } } return ret + cascaderet; } throw new IllegalArgumentException("Unknown Uri " + uri); }
From source file:org.cdmckay.android.provider.MediaWikiProvider.java
private UriMatcher buildUriMatcher() { UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH); matcher.addURI(MediaWikiMetaData.AUTHORITY, "*/search/*", SEARCH); matcher.addURI(MediaWikiMetaData.AUTHORITY, "*/page/title/*", PAGE_BY_TITLE); matcher.addURI(MediaWikiMetaData.AUTHORITY, "*/page/id/#", PAGE_BY_ID); matcher.addURI(MediaWikiMetaData.AUTHORITY, "*/page/title/*/sections", SECTIONS_BY_TITLE); matcher.addURI(MediaWikiMetaData.AUTHORITY, "*/page/title/*/section/#", SECTION_BY_TITLE); return matcher; }
From source file:org.voidsink.anewjkuapp.fragment.CalendarFragment.java
@Override public void onStart() { super.onStart(); UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); uriMatcher.addURI(CalendarContractWrapper.AUTHORITY(), CalendarContractWrapper.Events.CONTENT_URI().buildUpon().appendPath("#").build().toString(), 0); mDataObserver = new BaseContentObserver(uriMatcher, this); // listen to all changes getActivity().getContentResolver().registerContentObserver( CalendarContractWrapper.Events.CONTENT_URI().buildUpon().appendPath("#").build(), false, mDataObserver);// ww w . ja v a2s . com }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
/** * Creates and initializes the URI matcher * * @return the URI Matcher//from w ww. ja va 2 s.com */ private static UriMatcher buildUriMatcher() { final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH); matcher.addURI(MuzeiContract.AUTHORITY, MuzeiContract.Artwork.TABLE_NAME, MuzeiProvider.ARTWORK); matcher.addURI(MuzeiContract.AUTHORITY, MuzeiContract.Artwork.TABLE_NAME + "/#", MuzeiProvider.ARTWORK_ID); matcher.addURI(MuzeiContract.AUTHORITY, MuzeiContract.Sources.TABLE_NAME, MuzeiProvider.SOURCES); matcher.addURI(MuzeiContract.AUTHORITY, MuzeiContract.Sources.TABLE_NAME + "/#", MuzeiProvider.SOURCE_ID); return matcher; }
From source file:pl.selvin.android.syncframework.content.BaseContentProvider.java
@Override public String getType(Uri uri) { final int code = contentHelper.matchUri(uri); if (code != UriMatcher.NO_MATCH) { if (code == ContentHelper.uriSyncCode) { throw new IllegalArgumentException("There is no type for SYNC Uri: " + uri); }/*from w w w .j a v a2s . c om*/ final TableInfo tab = contentHelper.getTableFromCode(code & ContentHelper.uriCode); return (isItemCode(code)) ? tab.ItemMime : tab.DirMime; } throw new IllegalArgumentException("Unknown Uri " + uri); }
From source file:pl.selvin.android.syncframework.content.BaseContentProvider.java
@Override public Uri insert(Uri uri, ContentValues values) { final int code = contentHelper.matchUri(uri); if (code != UriMatcher.NO_MATCH) { if (code == ContentHelper.uriSyncCode) { throw new IllegalArgumentException("Can not insert with Sync Uri."); }// ww w. ja v a2s. c om final TableInfo tab = contentHelper.getTableFromCode(code & ContentHelper.uriCode); if (tab.readonly) { throw new IllegalArgumentException("Table " + tab.name + " is readonly."); } if (isItemCode(code)) { throw new IllegalArgumentException("Can not delete with Item type Uri."); } /*-String tempId = UUID.randomUUID().toString(); if (tab.primaryKey.length == 1 && tab.primaryKey[0].type == ColumnType.guid) { tempId = values.getAsString(tab.primaryKey[0].name); }*/ boolean syncToNetwork = checkSyncToNetwork(uri); values.put("tempId", UUID.randomUUID().toString()); values.put("isDirty", 1); values.put("isDeleted", 0); long rowId = getWritableDatabase().insert(tab.name, null, values); if (rowId > 0) { Uri ret_uri = contentHelper.getItemUri(tab.name, syncToNetwork, rowId); final ContentResolver cr = getContext().getContentResolver(); cr.notifyChange(ret_uri, null, syncToNetwork); for (String n : tab.notifyUris) { cr.notifyChange(Uri.parse(n), null, syncToNetwork); } return ret_uri; } } throw new SQLException("Failed to insert row into " + uri); }
From source file:pl.selvin.android.syncframework.content.BaseContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final int code = contentHelper.matchUri(uri); if (code != UriMatcher.NO_MATCH) { if (code == ContentHelper.uriSyncCode) { return null; }//from w w w.ja va 2s. co m SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); final TableInfo tab = contentHelper.getTableFromCode(code & ContentHelper.uriCode); builder.setTables(tab.name); if (isItemCode(code)) { if (isItemRowIDCode(code)) { selection = "isDeleted=0 AND ROWID=" + uri.getPathSegments().get(2) + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } else { selection = "isDeleted=0" + tab.getSelection() + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ")" : ""); int i = 0; final String[] old = selectionArgs; final int len = (old == null) ? 0 : old.length; selectionArgs = new String[len + tab.primaryKey.length]; for (; i < tab.primaryKey.length; i++) { selectionArgs[i] = uri.getPathSegments().get(i + 1); } if (len > 0) { for (; i < old.length; i++) { selectionArgs[i] = old[i - tab.primaryKey.length]; } } } } else { selection = "isDeleted=0" + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } builder.setProjectionMap(tab.map); Cursor cursor = builder.query(getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder); if (DEBUG) { Log.d("Query", builder.buildQuery(projection, selection, selectionArgs, null, null, sortOrder, null)); } cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; } throw new IllegalArgumentException("Unknown Uri " + uri); }
From source file:pl.selvin.android.syncframework.content.BaseContentProvider.java
@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { final int code = contentHelper.matchUri(uri); if (code != UriMatcher.NO_MATCH) { if (code == ContentHelper.uriSyncCode) { if (DEBUG) { Log.d(TAG, "CP-update-sync: " + uri.toString()); }//from w w w .ja v a 2s.c om return (Sync(uri.getPathSegments().get(1), uri.getPathSegments().get(2), selection) ? 1 : 0); } final TableInfo tab = contentHelper.getTableFromCode(code & ContentHelper.uriCode); if (tab.readonly) { throw new IllegalArgumentException("Table " + tab.name + " is readonly."); } if (isItemCode(code)) { if (isItemRowIDCode(code)) { selection = "isDeleted=0 AND ROWID=" + uri.getPathSegments().get(2) + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } else { selection = "isDeleted=0" + tab.getSelection() + (!TextUtils.isEmpty(selection) ? "(" + selection + ") AND " : ""); int i = 0; final String[] old = selectionArgs; final int len = (old == null) ? 0 : old.length; selectionArgs = new String[len + tab.primaryKey.length]; for (; i < tab.primaryKey.length; i++) { selectionArgs[i] = uri.getPathSegments().get(i); } if (len > 0) { for (; i < old.length; i++) { selectionArgs[i] = old[i - tab.primaryKey.length]; } } } } else { selection = "isDeleted=0" + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } boolean syncToNetwork = checkSyncToNetwork(uri); values.put("isDirty", 1); int ret = getWritableDatabase().update(tab.name, values, selection, selectionArgs); if (ret > 0) { final ContentResolver cr = getContext().getContentResolver(); cr.notifyChange(uri, null, syncToNetwork); for (String n : tab.notifyUris) { cr.notifyChange(Uri.parse(n), null, syncToNetwork); } } return ret; } throw new IllegalArgumentException("Unknown Uri " + uri); }
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; }//www .j a v a 2 s. co m 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; } }