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;
}
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());
}
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));
}
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();
}
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();
}
Aggregations