當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。