List of usage examples for android.net Uri getEncodedFragment
@Nullable public abstract String getEncodedFragment();
From source file:Main.java
public static String extractFragmentParam(Uri url, String name) { return new Uri.Builder().encodedQuery(url.getEncodedFragment()).build().getQueryParameter(name); }
From source file:com.android.contacts.common.model.ContactLoader.java
private static Contact loadEncodedContactEntity(Uri uri, Uri lookupUri) throws JSONException { final String jsonString = uri.getEncodedFragment(); final JSONObject json = new JSONObject(jsonString); final long directoryId = Long.valueOf(uri.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY)); final String displayName = json.optString(Contacts.DISPLAY_NAME); final String altDisplayName = json.optString(Contacts.DISPLAY_NAME_ALTERNATIVE, displayName); final int displayNameSource = json.getInt(Contacts.DISPLAY_NAME_SOURCE); final String photoUri = json.optString(Contacts.PHOTO_URI, null); final Contact contact = new Contact(uri, uri, lookupUri, directoryId, null /* lookupKey */, -1 /* id */, -1 /* nameRawContactId */, displayNameSource, 0 /* photoId */, photoUri, displayName, altDisplayName, null /* phoneticName */, false /* starred */, null /* presence */, false /* sendToVoicemail */, null /* customRingtone */, false /* isUserProfile */); contact.setStatuses(new ImmutableMap.Builder<Long, DataStatus>().build()); final String accountName = json.optString(RawContacts.ACCOUNT_NAME, null); final String directoryName = uri.getQueryParameter(Directory.DISPLAY_NAME); if (accountName != null) { final String accountType = json.getString(RawContacts.ACCOUNT_TYPE); contact.setDirectoryMetaData(directoryName, null, accountName, accountType, json.optInt(Directory.EXPORT_SUPPORT, Directory.EXPORT_SUPPORT_SAME_ACCOUNT_ONLY)); } else {//ww w . j av a 2 s.c o m contact.setDirectoryMetaData(directoryName, null, null, null, json.optInt(Directory.EXPORT_SUPPORT, Directory.EXPORT_SUPPORT_ANY_ACCOUNT)); } final ContentValues values = new ContentValues(); values.put(Data._ID, -1); values.put(Data.CONTACT_ID, -1); final RawContact rawContact = new RawContact(values); final JSONObject items = json.getJSONObject(Contacts.CONTENT_ITEM_TYPE); final Iterator keys = items.keys(); while (keys.hasNext()) { final String mimetype = (String) keys.next(); // Could be single object or array. final JSONObject obj = items.optJSONObject(mimetype); if (obj == null) { final JSONArray array = items.getJSONArray(mimetype); for (int i = 0; i < array.length(); i++) { final JSONObject item = array.getJSONObject(i); processOneRecord(rawContact, item, mimetype); } } else { processOneRecord(rawContact, obj, mimetype); } } contact.setRawContacts(new ImmutableList.Builder<RawContact>().add(rawContact).build()); return contact; }
From source file:com.android.contacts.common.model.ContactBuilder.java
public ContactBuilder(Uri encodedContactUri) throws JSONException { String jsonData = encodedContactUri.getEncodedFragment(); String directoryId = encodedContactUri.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY); if (!TextUtils.isEmpty(directoryId)) { try {//from ww w. j av a 2s . c o m mDirectoryId = Long.parseLong(directoryId); } catch (NumberFormatException e) { Log.e(TAG, "Error parsing directory id of uri " + encodedContactUri, e); } } try { // name JSONObject json = new JSONObject(jsonData); JSONObject contact = json.optJSONObject(Contacts.CONTENT_ITEM_TYPE); JSONObject nameObj = contact.optJSONObject(StructuredName.CONTENT_ITEM_TYPE); mName = new Name(nameObj); if (contact != null) { // numbers if (contact.has(Phone.CONTENT_ITEM_TYPE)) { String phoneData = contact.getString(Phone.CONTENT_ITEM_TYPE); Object phoneObject = new JSONTokener(phoneData).nextValue(); JSONArray phoneNumbers; if (phoneObject instanceof JSONObject) { phoneNumbers = new JSONArray(); phoneNumbers.put(phoneObject); } else { phoneNumbers = contact.getJSONArray(Phone.CONTENT_ITEM_TYPE); } for (int i = 0; i < phoneNumbers.length(); ++i) { JSONObject phoneObj = phoneNumbers.getJSONObject(i); mPhoneNumbers.add(new PhoneNumber(phoneObj)); } } // address if (contact.has(StructuredPostal.CONTENT_ITEM_TYPE)) { JSONArray addresses = contact.getJSONArray(StructuredPostal.CONTENT_ITEM_TYPE); for (int i = 0; i < addresses.length(); ++i) { JSONObject addrObj = addresses.getJSONObject(i); mAddresses.add(new Address(addrObj)); } } // websites if (contact.has(Website.CONTENT_ITEM_TYPE)) { JSONArray websites = contact.getJSONArray(Website.CONTENT_ITEM_TYPE); for (int i = 0; i < websites.length(); ++i) { JSONObject websiteObj = websites.getJSONObject(i); final WebsiteUrl websiteUrl = new WebsiteUrl(websiteObj); if (!TextUtils.isEmpty(websiteUrl.url)) { mWebsites.add(new WebsiteUrl(websiteObj)); } } } mSpamCount = contact.optInt(CallerMetaData.SPAM_COUNT, 0); mInfoProviderName = contact.optString(CallerMetaData.INFO_PROVIDER, null); mSuccinctLocation = contact.optString(CallerMetaData.SUCCINCT_LOCATION, null); mPhotoUrl = contact.optString(CallerMetaData.PHOTO_URL, null); } } catch (JSONException e) { Log.e(TAG, "Error parsing encoded fragment of uri " + encodedContactUri, e); throw e; } }
From source file:com.android.contacts.common.ContactPhotoManager.java
/** * Removes the contact type information stored in the photo URI encoded fragment. * * @param photoUri The photo URI to remove the contact type from. * @return The photo URI with contact type removed. *//*from w w w. j a va2 s . co m*/ public static Uri removeContactType(Uri photoUri) { String encodedFragment = photoUri.getEncodedFragment(); if (!TextUtils.isEmpty(encodedFragment)) { Builder builder = photoUri.buildUpon(); builder.encodedFragment(null); return builder.build(); } return photoUri; }
From source file:com.remobile.file.ContentFilesystem.java
@Override public LocalFilesystemURL toLocalUri(Uri inputURL) { if (!"content".equals(inputURL.getScheme())) { return null; }// w w w . jav a 2 s. c o m String subPath = inputURL.getEncodedPath(); if (subPath.length() > 0) { subPath = subPath.substring(1); } Uri.Builder b = new Uri.Builder().scheme(LocalFilesystemURL.FILESYSTEM_PROTOCOL).authority("localhost") .path(name).appendPath(inputURL.getAuthority()); if (subPath.length() > 0) { b.appendEncodedPath(subPath); } Uri localUri = b.encodedQuery(inputURL.getEncodedQuery()).encodedFragment(inputURL.getEncodedFragment()) .build(); return LocalFilesystemURL.parse(localUri); }
From source file:com.android.contacts.common.ContactPhotoManager.java
/** * Inspects a photo URI to determine if the photo URI represents a business. * * @param photoUri The URI to inspect./*from w ww .ja va2 s . c om*/ * @return Whether the URI represents a business photo or not. */ public static boolean isBusinessContactUri(Uri photoUri) { if (photoUri == null) { return false; } String encodedFragment = photoUri.getEncodedFragment(); return !TextUtils.isEmpty(encodedFragment) && encodedFragment.equals(String.valueOf(TYPE_BUSINESS)); }
From source file:net.openid.appauthdemo.Configuration.java
@NonNull Uri getRequiredConfigUri(String propName) throws InvalidConfigurationException { String uriStr = getRequiredConfigString(propName); Uri uri; try {// www. ja v a2s . co m uri = Uri.parse(uriStr); } catch (Throwable ex) { throw new InvalidConfigurationException(propName + " could not be parsed", ex); } if (!uri.isHierarchical() || !uri.isAbsolute()) { throw new InvalidConfigurationException(propName + " must be hierarchical and absolute"); } if (!TextUtils.isEmpty(uri.getEncodedUserInfo())) { throw new InvalidConfigurationException(propName + " must not have user info"); } if (!TextUtils.isEmpty(uri.getEncodedQuery())) { throw new InvalidConfigurationException(propName + " must not have query parameters"); } if (!TextUtils.isEmpty(uri.getEncodedFragment())) { throw new InvalidConfigurationException(propName + " must not have a fragment"); } return uri; }