当前位置: 首页>>代码示例>>Java>>正文


Java UriMatcher类代码示例

本文整理汇总了Java中android.content.UriMatcher的典型用法代码示例。如果您正苦于以下问题:Java UriMatcher类的具体用法?Java UriMatcher怎么用?Java UriMatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UriMatcher类属于android.content包,在下文中一共展示了UriMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadResourceFromUri

import android.content.UriMatcher; //导入依赖的package包/类
private InputStream loadResourceFromUri(Uri uri, ContentResolver contentResolver)
    throws FileNotFoundException {
  switch (URI_MATCHER.match(uri)) {
    case ID_CONTACTS_CONTACT:
      return openContactPhotoInputStream(contentResolver, uri);
    case ID_CONTACTS_LOOKUP:
      // If it was a Lookup uri then resolve it first, then continue loading the contact uri.
      uri = ContactsContract.Contacts.lookupContact(contentResolver, uri);
      if (uri == null) {
        throw new FileNotFoundException("Contact cannot be found");
      }
      return openContactPhotoInputStream(contentResolver, uri);
    case ID_CONTACTS_THUMBNAIL:
    case ID_CONTACTS_PHOTO:
    case UriMatcher.NO_MATCH:
    default:
      return contentResolver.openInputStream(uri);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:StreamLocalUriFetcher.java

示例2: loadResourceFromUri

import android.content.UriMatcher; //导入依赖的package包/类
private InputStream loadResourceFromUri(Uri uri, ContentResolver contentResolver)
    throws FileNotFoundException {
  switch (URI_MATCHER.match(uri)) {
    case ID_CONTACTS_CONTACT:
      return openContactPhotoInputStream(contentResolver, uri);
    case ID_CONTACTS_LOOKUP:
    case ID_LOOKUP_BY_PHONE:
      // If it was a Lookup uri then resolve it first, then continue loading the contact uri.
      uri = ContactsContract.Contacts.lookupContact(contentResolver, uri);
      if (uri == null) {
        throw new FileNotFoundException("Contact cannot be found");
      }
      return openContactPhotoInputStream(contentResolver, uri);
    case ID_CONTACTS_THUMBNAIL:
    case ID_CONTACTS_PHOTO:
    case UriMatcher.NO_MATCH:
    default:
      return contentResolver.openInputStream(uri);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:StreamLocalUriFetcher.java

示例3: createFromContentProviderResults

import android.content.UriMatcher; //导入依赖的package包/类
@Nullable
public static DatabaseIdRange createFromContentProviderResults(ContentProviderResult[] results, String path){
    UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    sUriMatcher.addURI(MessengerContentProvider.AUTHORITY, path, MATCH_CODE);

    Integer f = null;
    Integer l = null;
    for(ContentProviderResult result : results){
        if(result.uri != null && !result.uri.toString().isEmpty()){
            if(sUriMatcher.match(result.uri) != MATCH_CODE){
                continue;
            }

            int dbid = Integer.parseInt(result.uri.getPathSegments().get(1));
            if(f == null || dbid < f){
                f = dbid;
            }

            if(l == null || dbid > l){
                l = dbid;
            }
        }
    }

    return nonNull(f) && nonNull(l) ? new DatabaseIdRange(f, l) : null;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:27,代码来源:DatabaseIdRange.java

示例4: testUriMatcher

import android.content.UriMatcher; //导入依赖的package包/类
/**
 * Tests that UriMatcher returns the correct integer value for each of the Uri types that
 *  our ContentProvider can handle.
 */
@Test
public void testUriMatcher() {
    UriMatcher testMatcher = FavoritesProvider.buildUriMatcher();

    assertEquals("Error: The movie was matched incorrectly.",
            testMatcher.match(TEST_MOVIES_DIR), FavoritesProvider.MOVIES);
    assertEquals("Error: The movie was matched incorrectly.",
            testMatcher.match(TEST_MOVIE_ID_DIR), FavoritesProvider.MOVIE_ID);
    assertEquals("Error: The TV Show was matched incorrectly.",
            testMatcher.match(TEST_TV_SHOW_DIR), FavoritesProvider.TV_SHOWS);
    assertEquals("Error: The TV Show was matched incorrectly.",
            testMatcher.match(TEST_TV_SHOW_ID_DIR), FavoritesProvider.TV_SHOW_ID);
    assertEquals("Error: The Person was matched incorrectly.",
            testMatcher.match(TEST_PERSON_DIR), FavoritesProvider.PERSONS);
    assertEquals("Error: The Person was matched incorrectly.",
            testMatcher.match(TEST_PERSON_ID_DIR), FavoritesProvider.PERSON_ID);
}
 
开发者ID:an-garcia,项目名称:MovieGuide,代码行数:22,代码来源:TestUriMatcher.java

示例5: buildUriMatcher

import android.content.UriMatcher; //导入依赖的package包/类
/**
 * 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(ArticleContract.AUTHORITY, ArticleContract.PATH_ARTICLES, ARTICLES);


    return uriMatcher;
}
 
开发者ID:ansh94,项目名称:DailyTech,代码行数:20,代码来源:ArticleContentProvider.java

示例6: buildUriMatcher

import android.content.UriMatcher; //导入依赖的package包/类
/**
 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(AUTHORITY, PATH_TASKS, TASKS);
    uriMatcher.addURI(AUTHORITY, PATH_TASKS + "/#", TASK_WITH_ID);

    return uriMatcher;
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:20,代码来源:TaskContentProvider.java

示例7: testUriMatcher

import android.content.UriMatcher; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:29,代码来源:TestTaskContentProvider.java

示例8: buildUriMatcher

import android.content.UriMatcher; //导入依赖的package包/类
/**
 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;
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:20,代码来源:TaskContentProvider.java

示例9: buildUriMatcher

import android.content.UriMatcher; //导入依赖的package包/类
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;
}
 
开发者ID:changja88,项目名称:Udacity_Sunshine,代码行数:19,代码来源:WeatherProvider.java

示例10: buildUriMatcher

import android.content.UriMatcher; //导入依赖的package包/类
private static UriMatcher buildUriMatcher() {
    //The code passed into the constructor represents the code to return for the root URI.
    final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
    final String authority = GalleryContract.CONTENT_AUTHORITY;

    //for the type of URI we want to add, create a corresponding code
    //for gallery
    matcher.addURI(authority, GalleryContract.PATH_IMAGE, IMAGE);
    matcher.addURI(authority, GalleryContract.PATH_IMAGE + "/#", IMAGE_ID);

    //for article
    matcher.addURI(authority, ArticleContract.PATH_ARTICLE, ARTICLE);
    matcher.addURI(authority, ArticleContract.PATH_ARTICLE + "/#", ARTICLE_ID);

    return matcher;
}
 
开发者ID:prshntpnwr,项目名称:Monolith,代码行数:17,代码来源:DataProvider.java

示例11: buildUriMatcher

import android.content.UriMatcher; //导入依赖的package包/类
/**
 * Builds up a UriMatcher for search suggestion and shortcut refresh queries.
 */
private static UriMatcher buildUriMatcher() {
    UriMatcher matcher =  new UriMatcher(UriMatcher.NO_MATCH);
    // to get definitions...
    matcher.addURI(AUTHORITY, "dictionary", SEARCH_WORDS);
    matcher.addURI(AUTHORITY, "dictionary/#", GET_WORD);
    // to get suggestions...
    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);

    /* The following are unused in this implementation, but if we include
     * {@link SearchManager#SUGGEST_COLUMN_SHORTCUT_ID} as a column in our suggestions table, we
     * could expect to receive refresh queries when a shortcutted suggestion is displayed in
     * Quick Search Box, in which case, the following Uris would be provided and we
     * would return a cursor with a single item representing the refreshed suggestion data.
     */
    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT, REFRESH_SHORTCUT);
    matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/*", REFRESH_SHORTCUT);
    return matcher;
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:23,代码来源:DictionaryProvider.java

示例12: onCreate

import android.content.UriMatcher; //导入依赖的package包/类
@Override
public boolean onCreate() {
	/*if (KillSelfHelper.DEBUG) {
		LogUtils.d(KillSelfHelper.TAG, TAG + ".onCreate = " + android.os.Process.myPid());
	}*/
	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;
	}
}
 
开发者ID:miLLlulei,项目名称:Accessibility,代码行数:25,代码来源:MultiprocessSharedPreferences.java

示例13: delete

import android.content.UriMatcher; //导入依赖的package包/类
@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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:PoiProvider.java

示例14: getModelType

import android.content.UriMatcher; //导入依赖的package包/类
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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:ContentProvider.java

示例15: setAuthority

import android.content.UriMatcher; //导入依赖的package包/类
/**
 * @see TrayContract#setAuthority(String)
 */
static void setAuthority(final String authority) {
    sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);

    sURIMatcher.addURI(authority,
            TrayContract.Preferences.BASE_PATH,
            ALL_PREFERENCE);

    // BASE/module
    sURIMatcher.addURI(authority,
            TrayContract.Preferences.BASE_PATH + "/*",
            MODULE_PREFERENCE);

    // BASE/module/key
    sURIMatcher.addURI(authority,
            TrayContract.Preferences.BASE_PATH + "/*/*",
            SINGLE_PREFERENCE);

    sURIMatcher.addURI(authority,
            TrayContract.InternalPreferences.BASE_PATH,
            INTERNAL_ALL_PREFERENCE);

    // INTERNAL_BASE/module
    sURIMatcher.addURI(authority,
            TrayContract.InternalPreferences.BASE_PATH + "/*",
            INTERNAL_MODULE_PREFERENCE);

    // INTERNAL_BASE/module/key
    sURIMatcher.addURI(authority,
            TrayContract.InternalPreferences.BASE_PATH + "/*/*",
            INTERNAL_SINGLE_PREFERENCE);
}
 
开发者ID:sfilmak,项目名称:MakiLite,代码行数:35,代码来源:TrayProvider.java


注:本文中的android.content.UriMatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。