android.content.UriMatcher Java Examples

The following examples show how to use android.content.UriMatcher. 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: AcronymProvider.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to match each URI to the ACRONYM integers
 * constant defined above.
 * 
 * @return UriMatcher
 */
private static UriMatcher buildUriMatcher() {
    // All paths added to the UriMatcher have a corresponding code
    // to return when a match is found.  The code passed into the
    // constructor represents the code to return for the rootURI.
    // It's common to use NO_MATCH as the code for this case.
    final UriMatcher matcher = 
        new UriMatcher(UriMatcher.NO_MATCH);

    // For each type of URI that is added, a corresponding code is
    // created.
    matcher.addURI(AcronymContract.CONTENT_AUTHORITY,
                   AcronymContract.PATH_ACRONYM,
                   ACRONYMS);
    matcher.addURI(AcronymContract.CONTENT_AUTHORITY,
                   AcronymContract.PATH_ACRONYM 
                   + "/#",
                   ACRONYM);
    return matcher;
}
 
Example #2
Source File: ClipboardHelper.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
protected void onCreate() {
    mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    mTypes.clear();
    final int count = getAdapterCount();
    if (count <= 0)
        return;
    for (int i = 0; i < count; i++) {
        final Adapter adapter = getAdapter(i);
        if (adapter == null)
            continue;
        final String type = adapter.getType();
        final String subType = adapter.getSubType();
        mTypes.put(i, type);
        mMatcher.addURI(getAuthority(), getPath() + "/" + subType, i);
    }
}
 
Example #3
Source File: AbstractRecipesDBContentProvider.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
@Override
  protected UriMatcher createUriMatcher() {
      final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
      final String authority = RecipesDBContract.CONTENT_AUTHORITY;

matcher.addURI(authority, "recipes", RECIPES);
matcher.addURI(authority, "recipes/#", RECIPES_ID);
matcher.addURI(authority, "ingredients", INGREDIENTS);
matcher.addURI(authority, "ingredients/#", INGREDIENTS_ID);
matcher.addURI(authority, "categories", CATEGORIES);
matcher.addURI(authority, "categories/#", CATEGORIES_ID);
matcher.addURI(authority, "search", SEARCH);
matcher.addURI(authority, "search/#", SEARCH_ID);
matcher.addURI(authority, "search_with_recipe", SEARCH_WITH_RECIPE);
matcher.addURI(authority, "search_with_recipe/#", SEARCH_WITH_RECIPE_ID);

// User Actions
      return matcher;
  }
 
Example #4
Source File: TestTaskContentProvider.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This function tests that the UriMatcher returns the correct integer value for
 * each of the Uri types that the ContentProvider can handle. Uncomment this when you are
 * ready to test your UriMatcher.
 */
@Test
public void testUriMatcher() {

    /* Create a URI matcher that the TaskContentProvider uses */
    UriMatcher testMatcher = TaskContentProvider.buildUriMatcher();

    /* Test that the code returned from our matcher matches the expected TASKS int */
    String tasksUriDoesNotMatch = "Error: The TASKS URI was matched incorrectly.";
    int actualTasksMatchCode = testMatcher.match(TEST_TASKS);
    int expectedTasksMatchCode = TaskContentProvider.TASKS;
    assertEquals(tasksUriDoesNotMatch,
            actualTasksMatchCode,
            expectedTasksMatchCode);

    /* Test that the code returned from our matcher matches the expected TASK_WITH_ID */
    String taskWithIdDoesNotMatch =
            "Error: The TASK_WITH_ID URI was matched incorrectly.";
    int actualTaskWithIdCode = testMatcher.match(TEST_TASK_WITH_ID);
    int expectedTaskWithIdCode = TaskContentProvider.TASK_WITH_ID;
    assertEquals(taskWithIdDoesNotMatch,
            actualTaskWithIdCode,
            expectedTaskWithIdCode);
}
 
Example #5
Source File: AvailableDataContentProvider.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreate() {
    try {
        Context appContext = getContext().getApplicationContext();
        ApplicationInfo appInfo = appContext.getApplicationInfo();
        String packageName = appInfo.packageName;


        AUTHORITY = packageName + ".provider.availabledata";//NON-NLS
        BASE_CONTENT_URI = Uri.parse("content://" + AUTHORITY);//NON-NLS

        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        uriMatcher.addURI(AUTHORITY, SPATIALITE, SPATIALITE_ID);
        uriMatcher.addURI(AUTHORITY, BASEMAPS, BASEMAPS_ID);
        uriMatcher.addURI(AUTHORITY, TAGS, TAGS_ID);

    } catch (Exception e) {
        GPLog.error(this, null, e);
        return false;
    }
    return true;
}
 
Example #6
Source File: UriMatcherTest.java    From Popular-Movies-App with Apache License 2.0 6 votes vote down vote up
@Test
public void testUriMatcher() {
    UriMatcher uriMatcher = MoviesProvider.buildUriMatcher();

    assertEquals("Error: The BASE CONTENT URI was matched incorrectly.",
            UriMatcher.NO_MATCH, uriMatcher.match(TEST_BASE_URI));
    assertEquals("Error: The MOVIES URI was matched incorrectly.",
            MoviesProvider.MOVIES, uriMatcher.match(TEST_MOVIES_URI));
    assertEquals("Error: The MOVIE BY ID URI was matched incorrectly.",
            MoviesProvider.MOVIE_BY_ID, uriMatcher.match(TEST_MOVIE_BY_ID_URI));

    assertEquals("Error: The MOST POPULAR MOVIES URI was matched incorrectly.",
            MoviesProvider.MOST_POPULAR_MOVIES, uriMatcher.match(TEST_MOST_POPULAR_MOVIES_URI));
    assertEquals("Error: The HIGHEST RATED MOVIES URI was matched incorrectly.",
            MoviesProvider.HIGHEST_RATED_MOVIES, uriMatcher.match(TEST_HIGHEST_RATED_MOVIES_URI));
    assertEquals("Error: The MOST RATED MOVIES URI was matched incorrectly.",
            MoviesProvider.MOST_RATED_MOVIES, uriMatcher.match(TEST_MOST_RATED_MOVIES_URI));

    assertEquals("Error: The FAVORITES URI was matched incorrectly.",
            MoviesProvider.FAVORITES, uriMatcher.match(TEST_FAVORITES_URI));
}
 
Example #7
Source File: MoviesProvider.java    From Popular-Movies-App with Apache License 2.0 6 votes vote down vote up
static UriMatcher buildUriMatcher() {
    final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    final String authority = MoviesContract.CONTENT_AUTHORITY;

    uriMatcher.addURI(authority, MoviesContract.PATH_MOVIES, MOVIES);
    uriMatcher.addURI(authority, MoviesContract.PATH_MOVIES + "/#", MOVIE_BY_ID);

    uriMatcher.addURI(authority, MoviesContract.PATH_MOVIES + "/" +
            MoviesContract.PATH_MOST_POPULAR, MOST_POPULAR_MOVIES);
    uriMatcher.addURI(authority, MoviesContract.PATH_MOVIES + "/" +
            MoviesContract.PATH_HIGHEST_RATED, HIGHEST_RATED_MOVIES);
    uriMatcher.addURI(authority, MoviesContract.PATH_MOVIES + "/" +
            MoviesContract.PATH_MOST_RATED, MOST_RATED_MOVIES);

    uriMatcher.addURI(authority, MoviesContract.PATH_MOVIES + "/" +
            MoviesContract.PATH_FAVORITES, FAVORITES);

    return uriMatcher;
}
 
Example #8
Source File: MultiprocessSharedPreferences.java    From MultiprocessSharedPreferences with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreate() {
	if (checkInitAuthority(getContext())) {
		mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_ALL, GET_ALL);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_STRING, GET_STRING);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_INT, GET_INT);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_LONG, GET_LONG);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_FLOAT, GET_FLOAT);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_BOOLEAN, GET_BOOLEAN);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_CONTAINS, CONTAINS);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_APPLY, APPLY);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_COMMIT, COMMIT);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_REGISTER_ON_SHARED_PREFERENCE_CHANGE_LISTENER, REGISTER_ON_SHARED_PREFERENCE_CHANGE_LISTENER);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_UNREGISTER_ON_SHARED_PREFERENCE_CHANGE_LISTENER, UNREGISTER_ON_SHARED_PREFERENCE_CHANGE_LISTENER);
		mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_STRING_SET, GET_STRING_SET);
		return true;
	} else {
		return false;
	}
}
 
Example #9
Source File: TestTaskContentProvider.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This function tests that the UriMatcher returns the correct integer value for
 * each of the Uri types that the ContentProvider can handle. Uncomment this when you are
 * ready to test your UriMatcher.
 */
@Test
public void testUriMatcher() {

    /* Create a URI matcher that the TaskContentProvider uses */
    UriMatcher testMatcher = TaskContentProvider.buildUriMatcher();

    /* Test that the code returned from our matcher matches the expected TASKS int */
    String tasksUriDoesNotMatch = "Error: The TASKS URI was matched incorrectly.";
    int actualTasksMatchCode = testMatcher.match(TEST_TASKS);
    int expectedTasksMatchCode = TaskContentProvider.TASKS;
    assertEquals(tasksUriDoesNotMatch,
            actualTasksMatchCode,
            expectedTasksMatchCode);

    /* Test that the code returned from our matcher matches the expected TASK_WITH_ID */
    String taskWithIdDoesNotMatch =
            "Error: The TASK_WITH_ID URI was matched incorrectly.";
    int actualTaskWithIdCode = testMatcher.match(TEST_TASK_WITH_ID);
    int expectedTaskWithIdCode = TaskContentProvider.TASK_WITH_ID;
    assertEquals(taskWithIdDoesNotMatch,
            actualTaskWithIdCode,
            expectedTaskWithIdCode);
}
 
Example #10
Source File: TaskContentProvider.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 Initialize a new matcher object without any matches,
 then use .addURI(String authority, String path, int match) to add matches
 */
public static UriMatcher buildUriMatcher() {

    // Initialize a UriMatcher with no matches by passing in NO_MATCH to the constructor
    UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);

    /*
      All paths added to the UriMatcher have a corresponding int.
      For each kind of uri you may want to access, add the corresponding match with addURI.
      The two calls below add matches for the task directory and a single item by ID.
     */
    uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS, TASKS);
    uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS + "/#", TASK_WITH_ID);

    return uriMatcher;
}
 
Example #11
Source File: WeatherProvider.java    From android-weather with MIT License 6 votes vote down vote up
static UriMatcher buildUriMatcher() {
    // I know what you're thinking.  Why create a UriMatcher when you can use regular
    // expressions instead?  Because you're not crazy, that's why.

    // All paths added to the UriMatcher have a corresponding code to return when a match is
    // found.  The code passed into the constructor represents the code to return for the root
    // URI.  It's common to use NO_MATCH as the code for this case.
    final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
    final String authority = WeatherContract.CONTENT_AUTHORITY;

    // For each type of URI you want to add, create a corresponding code.
    matcher.addURI(authority, WeatherContract.PATH_WEATHER, WEATHER);
    matcher.addURI(authority, WeatherContract.PATH_WEATHER + "/*", WEATHER_WITH_LOCATION);
    matcher.addURI(authority, WeatherContract.PATH_WEATHER + "/*/#", WEATHER_WITH_LOCATION_AND_DATE);

    matcher.addURI(authority, WeatherContract.PATH_LOCATION, LOCATION);
    return matcher;
}
 
Example #12
Source File: WeatherProvider.java    From Krishi-Seva with MIT License 6 votes vote down vote up
static UriMatcher buildUriMatcher() {
    // I know what you're thinking.  Why create a UriMatcher when you can use regular
    // expressions instead?  Because you're not crazy, that's why.

    // All paths added to the UriMatcher have a corresponding code to return when a match is
    // found.  The code passed into the constructor represents the code to return for the root
    // URI.  It's common to use NO_MATCH as the code for this case.
    final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
    final String authority = WeatherContract.CONTENT_AUTHORITY;

    // For each type of URI you want to add, create a corresponding code.
    matcher.addURI(authority, WeatherContract.PATH_WEATHER, WEATHER);
    matcher.addURI(authority, WeatherContract.PATH_WEATHER + "/*", WEATHER_WITH_LOCATION);
    matcher.addURI(authority, WeatherContract.PATH_WEATHER + "/*/#", WEATHER_WITH_LOCATION_AND_DATE);

    matcher.addURI(authority, WeatherContract.PATH_LOCATION, LOCATION);
    return matcher;
}
 
Example #13
Source File: BaseModelProvider.java    From hr with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    int count = 0;
    setModel(uri);
    setMatcher(uri);
    int match = matcher.match(uri);
    switch (match) {
        case COLLECTION:
            SQLiteDatabase db = mModel.getWritableDatabase();
            count = db.delete(mModel.getTableName(), selection, selectionArgs);
            break;
        case SINGLE_ROW:
            db = mModel.getWritableDatabase();
            String row_id = uri.getLastPathSegment();
            count = db.delete(mModel.getTableName(), OColumn.ROW_ID + "  = ?", new String[]{row_id});
            break;
        case UriMatcher.NO_MATCH:
            break;
        default:
            throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    notifyDataChange(uri);
    return count;
}
 
Example #14
Source File: TestTaskContentProvider.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * This function tests that the UriMatcher returns the correct integer value for
 * each of the Uri types that the ContentProvider can handle. Uncomment this when you are
 * ready to test your UriMatcher.
 */
@Test
public void testUriMatcher() {

    /* Create a URI matcher that the TaskContentProvider uses */
    UriMatcher testMatcher = TaskContentProvider.buildUriMatcher();

    /* Test that the code returned from our matcher matches the expected TASKS int */
    String tasksUriDoesNotMatch = "Error: The TASKS URI was matched incorrectly.";
    int actualTasksMatchCode = testMatcher.match(TEST_TASKS);
    int expectedTasksMatchCode = TaskContentProvider.TASKS;
    assertEquals(tasksUriDoesNotMatch,
            actualTasksMatchCode,
            expectedTasksMatchCode);

    /* Test that the code returned from our matcher matches the expected TASK_WITH_ID */
    String taskWithIdDoesNotMatch =
            "Error: The TASK_WITH_ID URI was matched incorrectly.";
    int actualTaskWithIdCode = testMatcher.match(TEST_TASK_WITH_ID);
    int expectedTaskWithIdCode = TaskContentProvider.TASK_WITH_ID;
    assertEquals(taskWithIdDoesNotMatch,
            actualTaskWithIdCode,
            expectedTaskWithIdCode);
}
 
Example #15
Source File: MonsterInfoDescriptor.java    From PADListener with GNU General Public License v2.0 5 votes vote down vote up
private static UriMatcher buildUriMatcher() {
	final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);

	matcher.addURI(AUTHORITY, Paths.ALL_INFO.path, Paths.ALL_INFO.id);
	matcher.addURI(AUTHORITY, Paths.INFO_BY_ID.path, Paths.INFO_BY_ID.id);
	matcher.addURI(AUTHORITY, Paths.IMAGE_BY_ID.path, Paths.IMAGE_BY_ID.id);

	return matcher;
}
 
Example #16
Source File: LoaderThrottleSupport.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
/**
 * Global provider initialization.
 */
public SimpleProvider() {
    // Create and initialize URI matcher.
    mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    mUriMatcher.addURI(AUTHORITY, MainTable.TABLE_NAME, MAIN);
    mUriMatcher.addURI(AUTHORITY, MainTable.TABLE_NAME + "/#", MAIN_ID);

    // Create and initialize projection map for all columns.  This is
    // simply an identity mapping.
    mNotesProjectionMap = new HashMap<String, String>();
    mNotesProjectionMap.put(MainTable._ID, MainTable._ID);
    mNotesProjectionMap.put(MainTable.COLUMN_NAME_DATA, MainTable.COLUMN_NAME_DATA);
}
 
Example #17
Source File: WeatherProvider.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
/**
 * Build the UriMatcher for this Content Provider.
 */
public static UriMatcher buildUriMatcher() {
    // Add default 'no match' result to matcher.
    final UriMatcher matcher =
        new UriMatcher(UriMatcher.NO_MATCH);

    // Initialize the matcher with the URIs used to access each
    // table.
    matcher.addURI(WeatherContract.AUTHORITY,
                   WeatherContract.WeatherValuesEntry.WEATHER_VALUES_TABLE_NAME,
                   WEATHER_VALUES_ITEMS);
    matcher.addURI(WeatherContract.AUTHORITY,
                   WeatherContract.WeatherValuesEntry.WEATHER_VALUES_TABLE_NAME 
                   + "/#",
                   WEATHER_VALUES_ITEM);

    matcher.addURI(WeatherContract.AUTHORITY,
                   WeatherContract.WeatherConditionsEntry.WEATHER_CONDITIONS_TABLE_NAME,
                   WEATHER_CONDITIONS_ITEMS);

    matcher.addURI(WeatherContract.AUTHORITY,
                   WeatherContract.WeatherConditionsEntry.WEATHER_CONDITIONS_TABLE_NAME
                   + "/#",
                   WEATHER_CONDITIONS_ITEM);

    matcher.addURI(WeatherContract.AUTHORITY,
                   WeatherContract.ACCESS_ALL_DATA_FOR_LOCATION_PATH,
                   ACCESS_ALL_DATA_FOR_LOCATION_ITEM);

    return matcher;
}
 
Example #18
Source File: ContentProvider.java    From mobile-android-survey-app with MIT License 5 votes vote down vote up
private Class<? extends Model> getModelType(Uri uri) {
	final int code = URI_MATCHER.match(uri);
	if (code != UriMatcher.NO_MATCH) {
		return TYPE_CODES.get(code);
	}

	return null;
}
 
Example #19
Source File: HNewsProvider.java    From yahnac with Apache License 2.0 5 votes vote down vote up
private static UriMatcher buildUriMatcher() {
    final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
    final String authority = HNewsContract.CONTENT_AUTHORITY;

    matcher.addURI(authority, HNewsContract.PATH_ITEM, STORY);
    matcher.addURI(authority, HNewsContract.PATH_ITEM + "/*", STORY_ITEM);
    matcher.addURI(authority, HNewsContract.PATH_COMMENT, COMMENT);
    matcher.addURI(authority, HNewsContract.PATH_BOOKMARKS, BOOKMARK);

    return matcher;
}
 
Example #20
Source File: SearchProviderBase.java    From iview-android-tv with MIT License 5 votes vote down vote up
private UriMatcher getUriMatcher() {
    UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
    // to get suggestions...
    Log.d(TAG, "suggest_uri_path_query: " + SearchManager.SUGGEST_URI_PATH_QUERY);
    matcher.addURI(getAuthority(), SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
    matcher.addURI(getAuthority(), SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);
    return matcher;
}
 
Example #21
Source File: LoaderThrottle.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Global provider initialization.
 */
public SimpleProvider() {
    // Create and initialize URI matcher.
    mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    mUriMatcher.addURI(AUTHORITY, MainTable.TABLE_NAME, MAIN);
    mUriMatcher.addURI(AUTHORITY, MainTable.TABLE_NAME + "/#", MAIN_ID);

    // Create and initialize projection map for all columns.  This is
    // simply an identity mapping.
    mNotesProjectionMap = new HashMap<String, String>();
    mNotesProjectionMap.put(MainTable._ID, MainTable._ID);
    mNotesProjectionMap.put(MainTable.COLUMN_NAME_DATA, MainTable.COLUMN_NAME_DATA);
}
 
Example #22
Source File: BaseModelProvider.java    From hr with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Uri insert(Uri uri, ContentValues all_values) {
    setModel(uri);
    setMatcher(uri);
    ContentValues[] values = generateValues(all_values);
    ContentValues value_to_insert = values[0];
    value_to_insert.put("_write_date", ODateUtils.getUTCDate());
    if (!value_to_insert.containsKey("_is_active"))
        value_to_insert.put("_is_active", "true");
    if (!value_to_insert.containsKey("_is_dirty"))
        value_to_insert.put("_is_dirty", "false");
    int match = matcher.match(uri);
    switch (match) {
        case COLLECTION:
            SQLiteDatabase db = mModel.getWritableDatabase();
            long new_id = 0;
            new_id = db.insert(mModel.getTableName(), null, value_to_insert);
            // Updating relation columns for record
            if (values[1].size() > 0) {
                storeUpdateRelationRecords(values[1], OColumn.ROW_ID + "  = ?", new String[]{new_id + ""});
            }

            return uri.withAppendedPath(uri, new_id + "");
        case SINGLE_ROW:
            throw new UnsupportedOperationException(
                    "Insert not supported on URI: " + uri);
        case UriMatcher.NO_MATCH:
            break;
        default:
            throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    notifyDataChange(uri);
    return null;
}
 
Example #23
Source File: PoiProvider.java    From Mobike with Apache License 2.0 5 votes vote down vote up
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
	int code = matcher.match(uri);
	int result = 0;
	switch (code) {
	case UriMatcher.NO_MATCH:
		break;
	case 1:
		// 删除所有
		result = db.delete(DBHelper.USERTABLE, null, null);
		Log.d("qf", "删除所有数据!");
		break;
	case 2:
		// content://com.lenve.cphost.mycontentprovider/user/10
		// 按条件删除,id
		result = db.delete(DBHelper.USERTABLE, "_id=?", new String[] { ContentUris.parseId(uri) + "" });
		Log.d("qf", "根据删除一条数据");
		break;
	case 3:
		// content://com.lenve.cphost.mycontentprovider/user/zhangsan
		// uri.getPathSegments()拿到一个List<String>,里边的值分别是0-->user、1-->zhangsan
		result = db.delete(DBHelper.USERTABLE, "USERNAME=?", new String[] { uri.getPathSegments().get(1) });
		break;
	default:
		break;
	}
	return result;
}
 
Example #24
Source File: DataProvider.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
private static UriMatcher buildUriMatcher() {
    final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
    final String authority = Contract.AUTHORITY;

    // Add a pattern that routes URIs terminated with "entries" to an ENTRIES operation
    // that is performed on the whole table
    matcher.addURI(authority, "entries", ENTRIES);

    // Add a pattern that routes URIs terminated with a number to an ENTRIES operation
    // that is aimed at a specific entry where the path ends with its uuid
    matcher.addURI(authority, "entries/*", ENTRIES_ID);

    return matcher;
}
 
Example #25
Source File: DespicableContentProvider.java    From WonderAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreate() {
  uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
  minions = new SparseArray<MinionContentProvider>();

  return false;
}
 
Example #26
Source File: MyTracksProvider.java    From mytracks with Apache License 2.0 5 votes vote down vote up
public MyTracksProvider() {
  uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
  uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TrackPointsColumns.TABLE_NAME,
      UrlType.TRACKPOINTS.ordinal());
  uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TrackPointsColumns.TABLE_NAME + "/#",
      UrlType.TRACKPOINTS_ID.ordinal());
  uriMatcher.addURI(
      MyTracksProviderUtils.AUTHORITY, TracksColumns.TABLE_NAME, UrlType.TRACKS.ordinal());
  uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TracksColumns.TABLE_NAME + "/#",
      UrlType.TRACKS_ID.ordinal());
  uriMatcher.addURI(
      MyTracksProviderUtils.AUTHORITY, WaypointsColumns.TABLE_NAME, UrlType.WAYPOINTS.ordinal());
  uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, WaypointsColumns.TABLE_NAME + "/#",
      UrlType.WAYPOINTS_ID.ordinal());
}
 
Example #27
Source File: PredatorProvider.java    From Capstone-Project with MIT License 5 votes vote down vote up
private static UriMatcher buildUriMatcher() {
    UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.PostsEntry.PATH_POSTS_ADD, POSTS_ADD);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.PostsEntry.PATH_POSTS_DELETE_ALL, POSTS_DELETE);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.PostsEntry.PATH_POSTS, POSTS_GET);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.PostsEntry.PATH_POSTS + "/#", POSTS_GET_BY_ID);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.PostsEntry.PATH_POSTS_UPDATE, POSTS_UPDATE);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.UsersEntry.PATH_USERS_ADD, USERS_ADD);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.UsersEntry.PATH_USERS_DELETE_ALL, USERS_DELETE);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.UsersEntry.PATH_USERS, USERS_GET);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.UsersEntry.PATH_USERS + "/#", USERS_GET_BY_ID);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CommentsEntry.PATH_COMMENTS_ADD, COMMENTS_ADD);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CommentsEntry.PATH_COMMENTS_DELETE_ALL, COMMENTS_DELETE);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CommentsEntry.PATH_COMMENTS, COMMENTS_GET);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CommentsEntry.PATH_COMMENTS + "/#", COMMENTS_GET_BY_ID);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.InstallLinksEntry.PATH_INSTALL_LINKS_ADD, INSTALL_LINKS_ADD);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.InstallLinksEntry.PATH_INSTALL_LINKS_DELETE_ALL, INSTALL_LINKS_DELETE);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.InstallLinksEntry.PATH_INSTALL_LINKS, INSTALL_LINKS_GET);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.InstallLinksEntry.PATH_INSTALL_LINKS + "/#", INSTALL_LINKS_GET_BY_ID);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.MediaEntry.PATH_MEDIA_ADD, MEDIA_ADD);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.MediaEntry.PATH_MEDIA_DELETE_ALL, MEDIA_DELETE);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.MediaEntry.PATH_MEDIA, MEDIA_GET);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.MediaEntry.PATH_MEDIA + "/#", MEDIA_GET_BY_ID);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CollectionsEntry.PATH_COLLECTIONS_ADD, COLLECTIONS_ADD);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CollectionsEntry.PATH_COLLECTIONS_DELETE_ALL, COLLECTIONS_DELETE);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CollectionsEntry.PATH_COLLECTIONS, COLLECTIONS_GET);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CollectionsEntry.PATH_COLLECTIONS + "/#", COLLECTIONS_GET_BY_ID);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CategoryEntry.PATH_CATEGORY_ADD, CATEGORY_ADD);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CategoryEntry.PATH_CATEGORY_DELETE_ALL, CATEGORY_DELETE);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CategoryEntry.PATH_CATEGORY, CATEGORY_GET);
    uriMatcher.addURI(PredatorDbHelper.CONTENT_AUTHORITY, PredatorContract.CategoryEntry.PATH_CATEGORY + "/#", CATEGORY_GET_BY_ID);
    return uriMatcher;
}
 
Example #28
Source File: DocumentsProvider.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void registerAuthority(String authority) {
    mAuthority = authority;

    mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    mMatcher.addURI(mAuthority, "root", MATCH_ROOTS);
    mMatcher.addURI(mAuthority, "root/*", MATCH_ROOT);
    mMatcher.addURI(mAuthority, "root/*/recent", MATCH_RECENT);
    mMatcher.addURI(mAuthority, "root/*/search", MATCH_SEARCH);
    mMatcher.addURI(mAuthority, "document/*", MATCH_DOCUMENT);
    mMatcher.addURI(mAuthority, "document/*/children", MATCH_CHILDREN);
    mMatcher.addURI(mAuthority, "tree/*/document/*", MATCH_DOCUMENT_TREE);
    mMatcher.addURI(mAuthority, "tree/*/document/*/children", MATCH_CHILDREN_TREE);
}
 
Example #29
Source File: GithubDataProvider.java    From gito-github-client with Apache License 2.0 5 votes vote down vote up
private static UriMatcher buildUriMatcher() {
    final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
    final String authority = RepositoryContract.CONTENT_AUTHORITY;
    matcher.addURI(authority, RepositoryContract.PATH_REPOSITORY, REPOSITORIES);
    matcher.addURI(authority, ReferrerContract.PATH_REFERRERS, REFERRERS);
    matcher.addURI(authority, ViewsContract.PATH_VIEWS, VIEWS);
    matcher.addURI(authority, ClonesContract.PATH_CLONES, CLONES);
    matcher.addURI(authority, TrendingContract.PATH_TRENDING, TRENDING);
    matcher.addURI(authority, StargazersContract.PATH_STARGAZERS, STARGAZERS);
    matcher.addURI(authority, RepositoryContract.PATH_REPOSITORY_STARGAZERS, REPOSITORIES_STARGAZERS);
    matcher.addURI(authority, UserContract.PATH_USERS, USERS);
    return matcher;
}
 
Example #30
Source File: ToolboxContentProvider.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@Override public boolean onCreate() {
  securityManager = new ToolboxSecurityManager(getContext().getPackageManager());
  uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
  uriMatcher.addURI(BuildConfig.CONTENT_AUTHORITY, "token", TOKEN);
  uriMatcher.addURI(BuildConfig.CONTENT_AUTHORITY, "refreshToken", REFRESH_TOKEN);
  uriMatcher.addURI(BuildConfig.CONTENT_AUTHORITY, "repo", REPO);
  uriMatcher.addURI(BuildConfig.CONTENT_AUTHORITY, "loginType", LOGIN_TYPE);
  uriMatcher.addURI(BuildConfig.CONTENT_AUTHORITY, "passHash", PASSHASH);
  uriMatcher.addURI(BuildConfig.CONTENT_AUTHORITY, "loginName", LOGIN_NAME);
  uriMatcher.addURI(BuildConfig.CONTENT_AUTHORITY, "changePreference", CHANGE_PREFERENCE);
  ((AptoideApplication) getContext().getApplicationContext()).getApplicationComponent()
      .inject(this);
  return true;
}