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 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 load_withApplicationIconResourceNameUri_asBitmap_withTransform_nonNullBitmap() throws ExecutionException, InterruptedException, NameNotFoundException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Context toUse = context.createPackageContext(packageName, /*flags=*/ 0); Resources resources = toUse.getResources(); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .appendPath(resources.getResourceTypeName(iconResourceId)) .appendPath(resources.getResourceEntryName(iconResourceId)) .build(); Bitmap bitmap = Glide.with(context) .asBitmap() .apply(centerCropTransform()) .load(uri) .submit() .get(); assertThat(bitmap).isNotNull(); } }
@Test public void loadVideoResourceUri_fromName_withFrame_decodesFrame() { Resources resources = context.getResources(); int resourceId = ResourceIds.raw.video; Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(resources.getResourcePackageName(resourceId)) .appendPath(resources.getResourceTypeName(resourceId)) .appendPath(resources.getResourceEntryName(resourceId)) .build(); Bitmap frame = concurrency.get( GlideApp.with(context) .asBitmap() .load(uri) .frame(TimeUnit.SECONDS.toMicros(1)) .submit()); assertThat(frame).isNotNull(); }
Uri uri = new Uri.Builder() .scheme("http") .authority("foo.com") .path("someservlet") .appendQueryParameter("param1", foo) .appendQueryParameter("param2", bar) .build();
@Test public void load_withApplicationIconResourceNameUri_asBitmap_producesNonNullBitmap() throws ExecutionException, InterruptedException, NameNotFoundException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Context toUse = context.createPackageContext(packageName, /*flags=*/ 0); Resources resources = toUse.getResources(); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .appendPath(resources.getResourceTypeName(iconResourceId)) .appendPath(resources.getResourceEntryName(iconResourceId)) .build(); Bitmap bitmap = Glide.with(context) .asBitmap() .load(uri) .submit() .get(); assertThat(bitmap).isNotNull(); } }
@Test public void loadVideoResourceUriString_fromName_withFrame_decodesFrame() { Resources resources = context.getResources(); int resourceId = ResourceIds.raw.video; Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(resources.getResourcePackageName(resourceId)) .appendPath(resources.getResourceTypeName(resourceId)) .appendPath(resources.getResourceEntryName(resourceId)) .build(); Bitmap frame = concurrency.get( GlideApp.with(context) .asBitmap() .load(uri.toString()) .frame(TimeUnit.SECONDS.toMicros(1)) .submit()); assertThat(frame).isNotNull(); } }
@Test public void load_withApplicationIconResourceNameUri_asDrawable_withTransform_nonNullDrawable() throws ExecutionException, InterruptedException, NameNotFoundException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Context toUse = context.createPackageContext(packageName, /*flags=*/ 0); Resources resources = toUse.getResources(); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .appendPath(resources.getResourceTypeName(iconResourceId)) .appendPath(resources.getResourceEntryName(iconResourceId)) .build(); Drawable drawable = Glide.with(context) .load(uri) .apply(centerCropTransform()) .submit() .get(); assertThat(drawable).isNotNull(); } }
@Test public void load_withApplicationIconResourceNameUri_asDrawable_producesNonNullDrawable() throws ExecutionException, InterruptedException, NameNotFoundException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Context toUse = context.createPackageContext(packageName, /*flags=*/ 0); Resources resources = toUse.getResources(); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .appendPath(resources.getResourceTypeName(iconResourceId)) .appendPath(resources.getResourceEntryName(iconResourceId)) .build(); Drawable drawable = Glide.with(context) .load(uri) .submit() .get(); assertThat(drawable).isNotNull(); } }
@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 loadVideoResourceUriString_fromName_decodesFrame() { Resources resources = context.getResources(); int resourceId = ResourceIds.raw.video; Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(resources.getResourcePackageName(resourceId)) .appendPath(resources.getResourceTypeName(resourceId)) .appendPath(resources.getResourceEntryName(resourceId)) .build(); Bitmap frame = concurrency.get( GlideApp.with(context) .asBitmap() .load(uri.toString()) .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_fromName_decodesFrame() { Resources resources = context.getResources(); int resourceId = ResourceIds.raw.video; Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(resources.getResourcePackageName(resourceId)) .appendPath(resources.getResourceTypeName(resourceId)) .appendPath(resources.getResourceEntryName(resourceId)) .build(); Bitmap frame = concurrency.get( GlideApp.with(context) .asBitmap() .load(uri) .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_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 loadVideoResourceUri_fromName_decodesFrame() { Resources resources = context.getResources(); int resourceId = ResourceIds.raw.video; Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(resources.getResourcePackageName(resourceId)) .appendPath(resources.getResourceTypeName(resourceId)) .appendPath(resources.getResourceEntryName(resourceId)) .build(); Drawable frame = concurrency.get( GlideApp.with(context) .load(uri) .submit()); assertThat(frame).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(); }
@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(); }
@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(); }