public static Uri getProfilePictureUri( String userId, int width, int height) { Validate.notNullOrEmpty(userId, "userId"); width = Math.max(width, UNSPECIFIED_DIMENSION); height = Math.max(height, UNSPECIFIED_DIMENSION); if (width == UNSPECIFIED_DIMENSION && height == UNSPECIFIED_DIMENSION) { throw new IllegalArgumentException("Either width or height must be greater than 0"); } Uri.Builder builder = Uri.parse(ServerProtocol.getGraphUrlBase()) .buildUpon() .path(String.format( Locale.US, PATH, FacebookSdk.getGraphApiVersion(), userId)); if (height != UNSPECIFIED_DIMENSION) { builder.appendQueryParameter(HEIGHT_PARAM, String.valueOf(height)); } if (width != UNSPECIFIED_DIMENSION) { builder.appendQueryParameter(WIDTH_PARAM, String.valueOf(width)); } builder.appendQueryParameter(MIGRATION_PARAM, MIGRATION_VALUE); return builder.build(); }
void handleUrlAndFinish(final String url) { final File urlOpenerProgramFile = new File(URL_OPENER_PROGRAM); if (!urlOpenerProgramFile.isFile()) { showErrorDialogAndQuit("The following file does not exist:\n$HOME/bin/termux-url-opener\n\n" + "Create this file as a script or a symlink - it will be called with the shared URL as only argument."); return; } // Do this for the user if necessary: //noinspection ResultOfMethodCallIgnored urlOpenerProgramFile.setExecutable(true); final Uri urlOpenerProgramUri = new Uri.Builder().scheme("file").path(URL_OPENER_PROGRAM).build(); Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE, urlOpenerProgramUri); executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class); executeIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, new String[]{url}); startService(executeIntent); finish(); }
@Test @Config(manifest = Config.NONE) public void parse() { assertThat(Uri.parse(basePath).buildUpon().path(resourcePath).build()).isEqualTo(expectedUri); }
final Uri scriptUri = new Uri.Builder().scheme("file").path(EDITOR_PROGRAM).build();
/** * This method is called when the Open Location in Map button is clicked. It will open the * a map to the location represented by the variable addressString using implicit Intents. * * @param v Button that was clicked. */ public void onClickOpenAddressButton(View v) { // COMPLETED (5) Store an address in a String String addressString = "1600 Amphitheatre Parkway, CA"; // COMPLETED (6) Use Uri.Builder with the appropriate scheme and query to form the Uri for the address Uri.Builder builder = new Uri.Builder(); builder.scheme("geo") .path("0,0") .appendQueryParameter("q", addressString); Uri addressUri = builder.build(); // COMPLETED (7) Replace the Toast with a call to showMap, passing in the Uri from the previous step showMap(addressUri); }
/** * This method is called when the Open Location in Map button is clicked. It will open the * a map to the location represented by the variable addressString using implicit Intents. * * @param v Button that was clicked. */ public void onClickOpenAddressButton(View v) { String addressString = "1600 Amphitheatre Parkway, CA"; Uri.Builder builder = new Uri.Builder(); builder.scheme("geo") .path("0,0") .appendQueryParameter("q", addressString); Uri addressUri = builder.build(); showMap(addressUri); }
public static Uri buildUri(String authority, String path, Bundle parameters) { Uri.Builder builder = new Uri.Builder(); builder.scheme(URL_SCHEME); builder.authority(authority); builder.path(path); if (parameters != null) { for (String key : parameters.keySet()) { Object parameter = parameters.get(key); if (parameter instanceof String) { builder.appendQueryParameter(key, (String) parameter); } } } return builder.build(); }
public static Uri createUserUri(@NonNull String userId) { return new Uri.Builder() .scheme(BuildConfig.APPLICATION_ID) .authority(HOST_USER) .path(userId) .build(); }
public static Uri createItemUri(@NonNull String itemId) { return new Uri.Builder() .scheme(BuildConfig.APPLICATION_ID) .authority(HOST_ITEM) .path(itemId) .build(); }
public Uri getContentUri() { return new Uri.Builder() .scheme("file") .path("/android_asset") .appendPath(filename) .build(); }
@Test public void load_withApplicationIconResourceIdUri_asBitmap_producesNonNullBitmap() throws NameNotFoundException, ExecutionException, InterruptedException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .path(String.valueOf(iconResourceId)) .build(); Bitmap bitmap = Glide.with(context) .asBitmap() .load(uri) .submit() .get(); assertThat(bitmap).isNotNull(); } }
@Test public void load_withApplicationIconResourceIdUri_asDrawable_withTransformation_nonNullDrawable() throws NameNotFoundException, ExecutionException, InterruptedException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .path(String.valueOf(iconResourceId)) .build(); Drawable drawable = Glide.with(context) .load(uri) .apply(centerCropTransform()) .submit() .get(); assertThat(drawable).isNotNull(); } }
@Test public void load_withApplicationIconResourceIdUri_asDrawable_producesNonNullDrawable() throws NameNotFoundException, ExecutionException, InterruptedException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .path(String.valueOf(iconResourceId)) .build(); Drawable drawable = Glide.with(context) .load(uri) .submit() .get(); assertThat(drawable).isNotNull(); } }
@Test public void loadVideoResourceUriString_fromId_withFrame_decodesFrame() { Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(context.getPackageName()) .path(String.valueOf(ResourceIds.raw.video)) .build(); Bitmap frame = concurrency.get( GlideApp.with(context) .asBitmap() .load(uri.toString()) .frame(TimeUnit.SECONDS.toMicros(1)) .submit()); assertThat(frame).isNotNull(); }
@Test public void loadVideoResourceUri_fromId_withFrame_decodesFrame() { Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(context.getPackageName()) .path(String.valueOf(ResourceIds.raw.video)) .build(); Bitmap frame = concurrency.get( GlideApp.with(context) .asBitmap() .load(uri) .frame(TimeUnit.SECONDS.toMicros(1)) .submit()); assertThat(frame).isNotNull(); }
@Test public void load_withApplicationIconResourceIdUri_asBitmap_withTransformation_nonNullBitmap() throws ExecutionException, InterruptedException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .path(String.valueOf(iconResourceId)) .build(); Bitmap bitmap = Glide.with(context) .asBitmap() .apply(centerCropTransform()) .load(uri) .submit() .get(); assertThat(bitmap).isNotNull(); } }
@Test public void loadVideoResourceUri_asBitmap_fromId_decodesFrame() { Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(context.getPackageName()) .path(String.valueOf(ResourceIds.raw.video)) .build(); Bitmap frame = concurrency.get( GlideApp.with(context) .asBitmap() .load(uri) .submit()); assertThat(frame).isNotNull(); }
public static Uri buildUri(String filePath, boolean pipeMode) { Uri.Builder builder = new Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority(AUTHORITY) .path(filePath); if (pipeMode) { builder.appendQueryParameter(TestContentProvider.PARAM_PIPE_MODE, "1"); } return builder.build(); }
@Test public void loadVideoResourceUri_fromId_decodesFrame() { Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(context.getPackageName()) .path(String.valueOf(ResourceIds.raw.video)) .build(); Drawable frame = concurrency.get( GlideApp.with(context) .load(uri) .submit()); assertThat(frame).isNotNull(); }
@Test public void loadVideoResourceUriString_fromId_decodesFrame() { Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(context.getPackageName()) .path(String.valueOf(ResourceIds.raw.video)) .build(); Bitmap frame = concurrency.get( GlideApp.with(context) .asBitmap() .load(uri.toString()) .submit()); assertThat(frame).isNotNull(); }