@Override public void setRequest(Request request) { target.setRequest(request); }
@Override public void setRequest(Request request) { this.request = request; if (target != null) target.setRequest(request); }
synchronized boolean untrack(@NonNull Target<?> target) { Request request = target.getRequest(); // If the Target doesn't have a request, it's already been cleared. if (request == null) { return true; } if (requestTracker.clearRemoveAndRecycle(request)) { targetTracker.untrack(target); target.setRequest(null); return true; } else { return false; } }
private void runTestFileDefaultLoader() { File file = new File("fake"); mockUri(Uri.fromFile(file)); requestManager.load(file).into(target); requestManager.load(file).into(imageView); verify(target).onResourceReady(isA(BitmapDrawable.class), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
private void runTestIntegerDefaultLoader() { int integer = android.R.drawable.star_on; mockUri("android.resource://" + "android" + "/drawable/star_on"); requestManager.load(integer).into(target); requestManager.load(integer).into(imageView); verify(target).onResourceReady(isA(BitmapDrawable.class), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
@Test public void testByteArrayDefaultLoader() { byte[] bytes = new byte[10]; requestManager.load(bytes).into(target); requestManager.load(bytes).into(imageView); verify(target).onResourceReady(isA(BitmapDrawable.class), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
@SuppressWarnings("deprecation") @Test public void testUrlDefaultLoader() throws MalformedURLException { URL url = new URL("http://www.google.com"); requestManager.load(url).into(target); requestManager.load(url).into(imageView); verify(target).onResourceReady(isA(BitmapDrawable.class), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
private void runTestUriDefaultLoader() { Uri uri = Uri.parse("content://test/something"); mockUri(uri); requestManager.load(uri).into(target); requestManager.load(uri).into(imageView); verify(target).onResourceReady(notNull(), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
private void untrackOrDelegate(@NonNull Target<?> target) { boolean isOwnedByUs = untrack(target); // We'll end up here if the Target was cleared after the RequestManager that started the request // is destroyed. That can happen for at least two reasons: // 1. We call clear() on a background thread using something other than Application Context // RequestManager. // 2. The caller retains a reference to the RequestManager after the corresponding Activity or // Fragment is destroyed, starts a load with it, and then clears that load with a different // RequestManager. Callers seem especially likely to do this in retained Fragments (#2262). // // #1 is always an error. At best the caller is leaking memory briefly in something like an // AsyncTask. At worst the caller is leaking an Activity or Fragment for a sustained period of // time if they do something like reference the Activity RequestManager in a long lived // background thread or task. // // #2 is always an error. Callers shouldn't be starting new loads using RequestManagers after // the corresponding Activity or Fragment is destroyed because retaining any reference to the // RequestManager leaks memory. It's possible that there's some brief period of time during or // immediately after onDestroy where this is reasonable, but I can't think of why. if (!isOwnedByUs && !glide.removeFromManagers(target) && target.getRequest() != null) { Request request = target.getRequest(); target.setRequest(null); request.clear(); } }
target.setRequest(request); requestManager.track(target, request);
private void runTestStringDefaultLoader(String string) { requestManager.load(string).listener(new RequestListener<Drawable>() { @Override public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { throw new RuntimeException("Load failed"); } @Override public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { return false; } }).into(target); requestManager.load(string).into(imageView); verify(target).onResourceReady(isA(BitmapDrawable.class), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
@Override public void setRequest(Request request) { target.setRequest(request); }
/** * Cancel any pending loads Glide may have for the target and free any resources (such as {@link Bitmap}s) that may * have been loaded for the target so they may be reused. * * @param target The Target to cancel loads for. */ public static void clear(Target<?> target) { Util.assertMainThread(); Request request = target.getRequest(); if (request != null) { request.clear(); target.setRequest(null); } }
/** * Set the target the resource will be loaded into. * * @see Glide#clear(Target) * * @param target The target to load the resource into. * @return The given target. */ public <Y extends Target<TranscodeType>> Y into(Y target) { Util.assertMainThread(); if (target == null) { throw new IllegalArgumentException("You must pass in a non null Target"); } if (!isModelSet) { throw new IllegalArgumentException("You must first set a model (try #load())"); } Request previous = target.getRequest(); if (previous != null) { previous.clear(); requestTracker.removeRequest(previous); previous.recycle(); } Request request = buildRequest(target); target.setRequest(request); lifecycle.addListener(target); requestTracker.runRequest(request); return target; }
@Override public void setRequest(Request request) { this.request = request; if (target != null) target.setRequest(request); }
@Override public void setRequest(Request request) { target.setRequest(request); }
boolean untrack(Target<?> target) { Request request = target.getRequest(); // If the Target doesn't have a request, it's already been cleared. if (request == null) { return true; } if (requestTracker.clearRemoveAndRecycle(request)) { targetTracker.untrack(target); target.setRequest(null); return true; } else { return false; } }
private <Y extends Target<TranscodeType>> Y into(@NonNull Y target, RequestOptions options) { Util.assertMainThread(); Preconditions.checkNotNull(target); if (!isModelSet) { throw new IllegalArgumentException("You must call #load() before calling #into()"); } options = options.autoClone(); Request request = buildRequest(target, options); Request previous = target.getRequest(); if (request.isEquivalentTo(previous)) { request.recycle(); // If the request is completed, beginning again will ensure the result is re-delivered, // triggering RequestListeners and Targets. If the request is failed, beginning again will // restart the request, giving it another chance to complete. If the request is already // running, we can let it continue running without interruption. if (!Preconditions.checkNotNull(previous).isRunning()) { previous.begin(); } return target; } requestManager.clear(target); target.setRequest(request); requestManager.track(target, request); return target; }