@Nullable public static UniFile getDownloadLocation() { UniFile dir = null; try { Uri.Builder builder = new Uri.Builder(); builder.scheme(getString(KEY_DOWNLOAD_SAVE_SCHEME, null)); builder.encodedAuthority(getString(KEY_DOWNLOAD_SAVE_AUTHORITY, null)); builder.encodedPath(getString(KEY_DOWNLOAD_SAVE_PATH, null)); builder.encodedQuery(getString(KEY_DOWNLOAD_SAVE_QUERY, null)); builder.encodedFragment(getString(KEY_DOWNLOAD_SAVE_FRAGMENT, null)); dir = UniFile.fromUri(sContext, builder.build()); } catch (Throwable e) { ExceptionUtils.throwIfFatal(e); // Ignore } return dir != null ? dir : UniFile.fromFile(AppConfig.getDefaultDownloadDir()); }
/** * Adds a business contact type encoded fragment to the URL. Used to ensure photo URLS * from Nearby Places can be identified as business photo URLs rather than URLs for personal * contact photos. * * @param photoUrl The photo URL to modify. * @return URL with the contact type parameter added and set to TYPE_BUSINESS. */ public static String appendBusinessContactType(String photoUrl) { Uri uri = Uri.parse(photoUrl); Builder builder = uri.buildUpon(); builder.encodedFragment(String.valueOf(TYPE_BUSINESS)); return builder.build().toString(); }
/** * Creates a JSON-encoded lookup uri for a unknown number without an associated contact * * @param number - Unknown phone number * @return JSON-encoded URI that can be used to perform a lookup when clicking on the quick * contact card. */ private static Uri createTemporaryContactUri(String number) { try { final JSONObject contactRows = new JSONObject().put(Phone.CONTENT_ITEM_TYPE, new JSONObject().put(Phone.NUMBER, number).put(Phone.TYPE, Phone.TYPE_CUSTOM)); final String jsonString = new JSONObject().put(Contacts.DISPLAY_NAME, number) .put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.PHONE) .put(Contacts.CONTENT_ITEM_TYPE, contactRows).toString(); return Contacts.CONTENT_LOOKUP_URI .buildUpon() .appendPath(Constants.LOOKUP_URI_ENCODED) .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Long.MAX_VALUE)) .encodedFragment(jsonString) .build(); } catch (JSONException e) { return null; } }
@Override protected Uri getContactUri(int partitionIndex, Cursor cursor, int contactIdColumn, int lookUpKeyColumn) { final DirectoryPartition directory = (DirectoryPartition) getPartition(partitionIndex); final long directoryId = directory.getDirectoryId(); if (!isExtendedDirectory(directoryId)) { return super.getContactUri(partitionIndex, cursor, contactIdColumn, lookUpKeyColumn); } return Contacts.CONTENT_LOOKUP_URI.buildUpon() .appendPath(Constants.LOOKUP_URI_ENCODED) .appendQueryParameter(Directory.DISPLAY_NAME, directory.getLabel()) .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId)) .encodedFragment(cursor.getString(lookUpKeyColumn)) .build(); }
/** * 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. */ 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; }