Search in sources :

Example 1 with SizeReadyCallback

use of com.bumptech.glide.request.target.SizeReadyCallback in project GestureViews by alexvasilkov.

the class GlideHelper method loadResource.

public static void loadResource(@DrawableRes int drawableId, @NonNull ImageView image) {
    DisplayMetrics metrics = image.getResources().getDisplayMetrics();
    final int displayWidth = metrics.widthPixels;
    final int displayHeight = metrics.heightPixels;
    Glide.with(image.getContext()).load(drawableId).asBitmap().dontAnimate().diskCacheStrategy(DiskCacheStrategy.NONE).into(new BitmapImageViewTarget(image) {

        @Override
        public void getSize(final SizeReadyCallback cb) {
            // We don't want to load very big images on devices with small screens.
            // This will help Glide correctly choose images scale when reading them.
            super.getSize(new SizeReadyCallback() {

                @Override
                public void onSizeReady(int width, int height) {
                    cb.onSizeReady(displayWidth / 2, displayHeight / 2);
                }
            });
        }
    });
}
Also used : BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) SizeReadyCallback(com.bumptech.glide.request.target.SizeReadyCallback) DisplayMetrics(android.util.DisplayMetrics)

Example 2 with SizeReadyCallback

use of com.bumptech.glide.request.target.SizeReadyCallback in project glide by bumptech.

the class ListPreloaderTest method getTargetsSizes.

private <R> List<Integer> getTargetsSizes(RequestBuilder<R> requestBuilder, VerificationMode mode) {
    ArgumentCaptor<Integer> integerArgumentCaptor = ArgumentCaptor.forClass(Integer.class);
    ArgumentCaptor<Target<R>> targetArgumentCaptor = cast(ArgumentCaptor.forClass(Target.class));
    SizeReadyCallback cb = mock(SizeReadyCallback.class);
    verify(requestBuilder, mode).into(targetArgumentCaptor.capture());
    for (Target<R> target : targetArgumentCaptor.getAllValues()) {
        target.getSize(cb);
    }
    verify(cb, mode).onSizeReady(integerArgumentCaptor.capture(), integerArgumentCaptor.capture());
    return integerArgumentCaptor.getAllValues();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Target(com.bumptech.glide.request.target.Target) SizeReadyCallback(com.bumptech.glide.request.target.SizeReadyCallback)

Example 3 with SizeReadyCallback

use of com.bumptech.glide.request.target.SizeReadyCallback in project glide by bumptech.

the class RequestFutureTargetTest method testCallsSizeReadyCallbackOnGetSize.

@Test
public void testCallsSizeReadyCallbackOnGetSize() {
    SizeReadyCallback cb = mock(SizeReadyCallback.class);
    future.getSize(cb);
    verify(cb).onSizeReady(eq(width), eq(height));
}
Also used : SizeReadyCallback(com.bumptech.glide.request.target.SizeReadyCallback) Test(org.junit.Test)

Aggregations

SizeReadyCallback (com.bumptech.glide.request.target.SizeReadyCallback)3 DisplayMetrics (android.util.DisplayMetrics)1 BitmapImageViewTarget (com.bumptech.glide.request.target.BitmapImageViewTarget)1 Target (com.bumptech.glide.request.target.Target)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1