/** * Returns a {@link RequestOptions} object with {@link #override(int, int)}} set. */ @SuppressWarnings("WeakerAccess") // Public API @NonNull @CheckResult public static RequestOptions overrideOf( @IntRange(from = 0) int width, @IntRange(from = 0) int height) { return new RequestOptions().override(width, height); }
/** * Returns a {@link RequestOptions} object with the given {@link Option} set via * {@link #set(Option, Object)}. */ @NonNull @CheckResult public static <T> RequestOptions option(@NonNull Option<T> option, @NonNull T value) { return new RequestOptions().set(option, value); }
/** * Returns a {@link RequestOptions} object with {@link #diskCacheStrategy(DiskCacheStrategy)} set. */ @NonNull @CheckResult public static RequestOptions diskCacheStrategyOf(@NonNull DiskCacheStrategy diskCacheStrategy) { return new RequestOptions().diskCacheStrategy(diskCacheStrategy); }
/** * Returns a {@link RequestOptions} object with {@link BaseRequestOptions#priority(Priority)}} * set. */ @SuppressWarnings("WeakerAccess") // Public API @NonNull @CheckResult public static RequestOptions priorityOf(@NonNull Priority priority) { return new RequestOptions().priority(priority); }
/** * Returns a {@link RequestOptions} object with {@link #placeholder(Drawable)} set. */ @NonNull @CheckResult public static RequestOptions placeholderOf(@Nullable Drawable placeholder) { return new RequestOptions().placeholder(placeholder); }
/** * Returns a {@link RequestOptions} object with {@link #placeholder(int)} set. */ @NonNull @CheckResult public static RequestOptions placeholderOf(@DrawableRes int placeholderId) { return new RequestOptions().placeholder(placeholderId); }
/** * Returns a {@link RequestOptions} object with {@link #error(int)}} set. */ @NonNull @CheckResult public static RequestOptions errorOf(@DrawableRes int errorId) { return new RequestOptions().error(errorId); }
/** * Returns a {@link RequestOptions} object with {@link #frame(long)} set. */ @SuppressWarnings("WeakerAccess") // Public API @NonNull @CheckResult public static RequestOptions frameOf(@IntRange(from = 0) long frameTimeMicros) { return new RequestOptions().frame(frameTimeMicros); }
/** * Returns a {@link RequestOptions} object with {@link #timeout(int)} set. */ @NonNull @CheckResult public static RequestOptions timeoutOf(@IntRange(from = 0) int timeout) { return new RequestOptions().timeout(timeout); }
/** * Returns a {@link com.bumptech.glide.request.RequestOptions} with {@link * #encodeQuality(int)} called with the given quality. */ @SuppressWarnings("WeakerAccess") // Public API @NonNull @CheckResult public static RequestOptions encodeQualityOf(@IntRange(from = 0, to = 100) int quality) { return new RequestOptions().encodeQuality(quality); }
/** * Returns a {@link RequestOptions} object with {@link #format(DecodeFormat)} set. */ @SuppressWarnings("WeakerAccess") // Public API @NonNull @CheckResult public static RequestOptions formatOf(@NonNull DecodeFormat format) { return new RequestOptions().format(format); }
/** * Returns a {@link RequestOptions} object with {@link #sizeMultiplier(float)} set. */ @SuppressWarnings("WeakerAccess") // Public API @NonNull @CheckResult public static RequestOptions sizeMultiplierOf( @FloatRange(from = 0, to = 1) float sizeMultiplier) { return new RequestOptions().sizeMultiplier(sizeMultiplier); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); options = new RequestOptions(); app = RuntimeEnvironment.application; }
@Test public void getPlaceholder_afterApplyingOptionsWithPlaceholderDrawable_returnsNewDrawable() { Drawable expected = new ColorDrawable(Color.GREEN); RequestOptions toApply = new RequestOptions().placeholder(expected); assertThat( options .placeholder(new ColorDrawable(Color.RED)) .apply(toApply) .getPlaceholderDrawable()) .isEqualTo(expected); }
@Test public void getPlaceholderId_afterApplyingOptionsWithPlaceholderDrawable_returnsZero() { RequestOptions toApply = new RequestOptions().placeholder(new ColorDrawable(Color.RED)); assertThat( options .placeholder(android.R.drawable.star_on) .apply(toApply) .getPlaceholderId()) .isEqualTo(0); }
@Test public void getError_afterApplyingOptionsWithErrorId_returnsNull() { RequestOptions toApply = new RequestOptions().error(android.R.drawable.star_on); assertThat( options .error(new ColorDrawable(Color.RED)) .apply(toApply) .getErrorPlaceholder()) .isNull(); }
@Test public void testIsTransformationSet_afterApplyingOptionsWithTransform_isTrue() { RequestOptions other = new RequestOptions(); other.transform(Bitmap.class, transformation); options.apply(other); assertThat(options.isTransformationSet()).isTrue(); }
@Test public void testApplyingDefaultOptions_withTransform_retrainsTransform() { options.transform(transformation); options.apply(new RequestOptions()); assertThat(options.isTransformationAllowed()).isTrue(); assertThat(options.isTransformationRequired()).isTrue(); assertThat(options.getTransformations()).containsEntry(Bitmap.class, transformation); }
@Test public void getFallbackId_afterApplyingOptionsWithFallbackId_returnsNewFallbackId() { RequestOptions toApply = new RequestOptions().fallback(android.R.drawable.star_off); assertThat( options .fallback(android.R.drawable.star_on) .apply(toApply) .getFallbackId()) .isEqualTo(android.R.drawable.star_off); }
@Test public void getErrorId_afterApplyingOptionsWithErrorId_returnsNewErrorId() { RequestOptions toApply = new RequestOptions().error(android.R.drawable.star_off); assertThat( options.error(android.R.drawable.star_on) .apply(toApply) .getErrorId()) .isEqualTo(android.R.drawable.star_off); }