Search in sources :

Example 1 with Request

use of com.bumptech.glide.request.Request in project glide by bumptech.

the class ViewTarget method getRequest.

/**
   * Returns any stored request using {@link android.view.View#getTag()}.
   *
   * <p> For Glide to function correctly, Glide must be the only thing that calls {@link
   * View#setTag(Object)}. If the tag is cleared or put to another object type, Glide will not be
   * able to retrieve and cancel previous loads which will not only prevent Glide from reusing
   * resource, but will also result in incorrect images being loaded and lots of flashing of images
   * in lists. As a result, this will throw an {@link java.lang.IllegalArgumentException} if {@link
   * android.view.View#getTag()}} returns a non null object that is not an {@link
   * com.bumptech.glide.request.Request}. </p>
   */
@Override
@Nullable
public Request getRequest() {
    Object tag = getTag();
    Request request = null;
    if (tag != null) {
        if (tag instanceof Request) {
            request = (Request) tag;
        } else {
            throw new IllegalArgumentException("You must not call setTag() on a view Glide is targeting");
        }
    }
    return request;
}
Also used : Request(com.bumptech.glide.request.Request) Nullable(android.support.annotation.Nullable)

Example 2 with Request

use of com.bumptech.glide.request.Request in project glide by bumptech.

the class ViewTargetTest method testRetrievesRequestFromPreviousTargetForView.

@Test
public void testRetrievesRequestFromPreviousTargetForView() {
    Request request = mock(Request.class);
    target.setRequest(request);
    ViewTarget<View, Object> second = new TestViewTarget(view);
    assertEquals(request, second.getRequest());
}
Also used : Request(com.bumptech.glide.request.Request) View(android.view.View) ShadowView(org.robolectric.shadows.ShadowView) Test(org.junit.Test)

Example 3 with Request

use of com.bumptech.glide.request.Request in project glide by bumptech.

the class GifFrameLoaderTest method testOnFrameReadyClearsPreviousFrame.

@Test
public void testOnFrameReadyClearsPreviousFrame() {
    // Force the loader to create a real Handler.
    loader = createGifFrameLoader(null);
    DelayTarget previous = mock(DelayTarget.class);
    Request previousRequest = mock(Request.class);
    when(previous.getRequest()).thenReturn(previousRequest);
    when(previous.getResource()).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888));
    DelayTarget current = mock(DelayTarget.class);
    when(current.getResource()).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565));
    loader.onFrameReady(previous);
    loader.onFrameReady(current);
    verify(requestManager).clear(eq(previous));
}
Also used : Request(com.bumptech.glide.request.Request) DelayTarget(com.bumptech.glide.load.resource.gif.GifFrameLoader.DelayTarget) Test(org.junit.Test)

Example 4 with Request

use of com.bumptech.glide.request.Request in project glide by bumptech.

the class RequestTrackerTest method testAvoidsConcurrentModificationWhenPausing.

@Test
public void testAvoidsConcurrentModificationWhenPausing() {
    Request first = mock(Request.class);
    Request second = mock(Request.class);
    when(first.isRunning()).thenReturn(true);
    doAnswer(new ClearAndRemoveRequest(second)).when(first).pause();
    tracker.addRequest(mock(Request.class));
    tracker.addRequest(first);
    tracker.addRequest(second);
    tracker.pauseRequests();
}
Also used : Request(com.bumptech.glide.request.Request) Test(org.junit.Test)

Example 5 with Request

use of com.bumptech.glide.request.Request in project glide by bumptech.

the class RequestTrackerTest method testAvoidsConcurrentModificationWhenRestarting.

@Test
public void testAvoidsConcurrentModificationWhenRestarting() {
    Request first = mock(Request.class);
    Request second = mock(Request.class);
    doAnswer(new ClearAndRemoveRequest(second)).when(first).pause();
    tracker.addRequest(mock(Request.class));
    tracker.addRequest(first);
    tracker.addRequest(second);
    tracker.restartRequests();
}
Also used : Request(com.bumptech.glide.request.Request) Test(org.junit.Test)

Aggregations

Request (com.bumptech.glide.request.Request)39 Test (org.junit.Test)33 DelayTarget (com.bumptech.glide.load.resource.gif.GifFrameLoader.DelayTarget)3 SingleRequest (com.bumptech.glide.request.SingleRequest)2 Nullable (android.support.annotation.Nullable)1 View (android.view.View)1 BaseRequestOptions (com.bumptech.glide.request.BaseRequestOptions)1 ThumbnailRequestCoordinator (com.bumptech.glide.request.ThumbnailRequestCoordinator)1 ShadowView (org.robolectric.shadows.ShadowView)1