提交 ba414a3e 编写于 作者: S Sam Judd

Generify Target.

上级 407cdc3d
......@@ -223,7 +223,7 @@ public class GlideTest {
Glide.with(getContext()).load(file).into(target);
verify(target).onImageReady(any(Bitmap.class));
verify(target).onResourceReady(any(Resource.class));
verify(target).setRequest((Request) notNull());
}
......@@ -233,7 +233,7 @@ public class GlideTest {
Glide.with(getContext()).loadFromImage(url).into(target);
verify(target).onImageReady(any(Bitmap.class));
verify(target).onResourceReady(any(Resource.class));
verify(target).setRequest((Request) notNull());
}
......@@ -260,7 +260,7 @@ public class GlideTest {
Glide.with(getContext()).load(uri).into(target);
verify(target).onImageReady(any(Bitmap.class));
verify(target).onResourceReady(any(Resource.class));
verify(target).setRequest((Request) notNull());
}
......@@ -318,7 +318,7 @@ public class GlideTest {
private void runTestStringDefaultLoader(String string) {
Glide.with(getContext()).load(string).into(target);
verify(target).onImageReady(any(Bitmap.class));
verify(target).onResourceReady(any(Resource.class));
verify(target).setRequest((Request) notNull());
}
......@@ -345,7 +345,7 @@ public class GlideTest {
Glide.with(getContext()).load(integer).into(target);
verify(target).onImageReady(any(Bitmap.class));
verify(target).onResourceReady(any(Resource.class));
verify(target).setRequest((Request) notNull());
}
......@@ -354,7 +354,7 @@ public class GlideTest {
byte[] bytes = new byte[10];
Glide.with(getContext()).loadFromImage(bytes).into(target);
verify(target).onImageReady(any(Bitmap.class));
verify(target).onResourceReady(any(Resource.class));
verify(target).setRequest((Request) notNull());
}
......@@ -364,7 +364,7 @@ public class GlideTest {
String id = "test";
Glide.with(getContext()).loadFromImage(bytes, id).into(target);
verify(target).onImageReady(any(Bitmap.class));
verify(target).onResourceReady(any(Resource.class));
verify(target).setRequest((Request) notNull());
}
......
......@@ -93,7 +93,6 @@ public class BitmapRequestTest {
@Test
public void testResourceIsNotCompleteWhenAskingCoordinatorIfCanSetImage() {
RequestCoordinator requestCoordinator = mock(RequestCoordinator.class);
requestCoordinator = mock(RequestCoordinator.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
......@@ -274,11 +273,11 @@ public class BitmapRequestTest {
return context;
}
private static class MockTarget implements Target {
private static class MockTarget implements Target<Object> {
private Drawable currentPlaceholder;
@Override
public void onImageReady(Bitmap bitmap) {
public void onResourceReady(Resource<Object> resource) {
currentPlaceholder = null;
}
......
......@@ -23,7 +23,7 @@ import com.bumptech.glide.request.RequestCoordinator;
import com.bumptech.glide.request.ThumbnailRequestCoordinator;
import com.bumptech.glide.request.bitmap.BitmapRequest;
import com.bumptech.glide.request.bitmap.RequestListener;
import com.bumptech.glide.request.target.ImageViewTarget;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.bumptech.glide.request.target.Target;
import java.util.ArrayList;
......@@ -333,7 +333,7 @@ public class GenericRequestBuilder<ModelType, ImageResourceType, VideoResourceTy
* @param target The target to load te image for
* @return The given target.
*/
public <Y extends Target> Y into(Y target) {
public <Y extends Target<Bitmap>> Y into(Y target) {
Request previous = target.getRequest();
if (previous != null) {
previous.clear();
......@@ -354,13 +354,13 @@ public class GenericRequestBuilder<ModelType, ImageResourceType, VideoResourceTy
* @see Glide#clear(View)
*
* @param view The view to cancel previous loads for and load the new image into.
* @return The {@link ImageViewTarget} used to wrap the given {@link ImageView}.
* @return The {@link BitmapImageViewTarget} used to wrap the given {@link ImageView}.
*/
public ImageViewTarget into(ImageView view) {
return into(new ImageViewTarget(view));
public BitmapImageViewTarget into(ImageView view) {
return into(new BitmapImageViewTarget(view));
}
private <Y extends Target> Request buildRequest(Y target) {
private Request buildRequest(Target<Bitmap> target) {
final Request result;
if (priority == null) {
......@@ -417,7 +417,7 @@ public class GenericRequestBuilder<ModelType, ImageResourceType, VideoResourceTy
return result;
}
private <Y extends Target> Request buildBitmapRequest(Y target, float sizeMultiplier, Priority priority,
private Request buildBitmapRequest(Target<Bitmap> target, float sizeMultiplier, Priority priority,
RequestCoordinator requestCoordinator) {
if (model == null) {
return buildBitmapRequestForType(target, imageLoadProvider, sizeMultiplier, priority, null);
......@@ -437,7 +437,7 @@ public class GenericRequestBuilder<ModelType, ImageResourceType, VideoResourceTy
}
}
private <Y extends Target, Z> Request buildBitmapRequestForType(Y target,
private <Z> Request buildBitmapRequestForType(Target<Bitmap> target,
LoadProvider<ModelType, Z, Bitmap> loadProvider, float sizeMultiplier, Priority priority,
RequestCoordinator requestCoordinator) {
return new BitmapRequest<ModelType, Z>(loadProvider, model, context, priority, target, sizeMultiplier,
......
......@@ -674,13 +674,13 @@ public class Glide {
}
}
private static class ClearTarget extends ViewTarget<View> {
private static class ClearTarget extends ViewTarget<View, Object> {
public ClearTarget(View view) {
super(view);
}
@Override
public void onImageReady(Bitmap bitmap) { }
public void onResourceReady(Resource<Object> resource) { }
@Override
public void setPlaceholder(Drawable placeholder) { }
......
package com.bumptech.glide;
import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.os.Build;
import android.widget.AbsListView;
import com.bumptech.glide.request.target.BaseTarget;
......@@ -170,7 +169,8 @@ public abstract class ListPreloader<T> implements AbsListView.OnScrollListener {
private int photoWidth;
@Override
public void onImageReady(Bitmap bitmap) { }
public void onResourceReady(Resource resource) {
}
@Override
public void getSize(SizeReadyCallback cb) {
......
......@@ -25,23 +25,23 @@ import java.io.InputStream;
/**
* A {@link Request} that loads an {@link Bitmap} into a given {@link Target}.
*
* @param <T> The type of the model that the {@link Bitmap} will be loaded from.
* @param <Z> The type of the resource that the {@link Bitmap} will be loaded from.
* @param <A> The type of the model that the {@link Bitmap} will be loaded from.
* @param <T> The type of the resource that the {@link Bitmap} will be loaded from.
*/
public class BitmapRequest<T, Z> implements Request, Target.SizeReadyCallback, ResourceCallback<Bitmap> {
public class BitmapRequest<A, T> implements Request, Target.SizeReadyCallback, ResourceCallback<Bitmap> {
private static final String TAG = "BitmapRequest";
private final int placeholderResourceId;
private final int errorResourceId;
private final Context context;
private final Transformation<Bitmap> transformation;
private final LoadProvider<T, Z, Bitmap> loadProvider;
private final LoadProvider<A, T, Bitmap> loadProvider;
private final int animationId;
private final RequestCoordinator requestCoordinator;
private final T model;
private final A model;
private Priority priority;
private final Target target;
private final RequestListener<T> requestListener;
private final Target<Bitmap> target;
private final RequestListener<A> requestListener;
private final float sizeMultiplier;
private final Engine engine;
private Animation animation;
......@@ -53,10 +53,11 @@ public class BitmapRequest<T, Z> implements Request, Target.SizeReadyCallback, R
private Resource<Bitmap> resource;
private Engine.LoadStatus loadStatus;
public BitmapRequest(LoadProvider<T, Z, Bitmap> loadProvider, T model, Context context, Priority priority,
Target target, float sizeMultiplier, Drawable placeholderDrawable, int placeholderResourceId,
Drawable errorDrawable, int errorResourceId, RequestListener<T> requestListener, int animationId,
Animation animation, RequestCoordinator requestCoordinator, Engine engine, Transformation<Bitmap> transformation) {
public BitmapRequest(LoadProvider<A, T, Bitmap> loadProvider, A model, Context context, Priority priority,
Target<Bitmap> target, float sizeMultiplier, Drawable placeholderDrawable, int placeholderResourceId,
Drawable errorDrawable, int errorResourceId, RequestListener<A> requestListener, int animationId,
Animation animation, RequestCoordinator requestCoordinator, Engine engine,
Transformation<Bitmap> transformation) {
this.loadProvider = loadProvider;
this.model = model;
this.context = context;
......@@ -148,12 +149,12 @@ public class BitmapRequest<T, Z> implements Request, Target.SizeReadyCallback, R
width = Math.round(sizeMultiplier * width);
height = Math.round(sizeMultiplier * height);
ResourceDecoder<InputStream, Bitmap> cacheDecoder = loadProvider.getCacheDecoder();
ResourceDecoder<Z, Bitmap> decoder = loadProvider.getSourceDecoder();
ResourceDecoder<T, Bitmap> decoder = loadProvider.getSourceDecoder();
ResourceEncoder <Bitmap> encoder = loadProvider.getEncoder();
ModelLoader<T, Z> modelLoader = loadProvider.getModelLoader();
ModelLoader<A, T> modelLoader = loadProvider.getModelLoader();
final String id = modelLoader.getId(model);
final ResourceFetcher<Z> resourceFetcher = modelLoader.getResourceFetcher(model, width, height);
final ResourceFetcher<T> resourceFetcher = modelLoader.getResourceFetcher(model, width, height);
loadedFromMemoryCache = true;
loadStatus = engine.load(id, width, height, cacheDecoder, resourceFetcher, decoder, transformation,
......@@ -179,8 +180,7 @@ public class BitmapRequest<T, Z> implements Request, Target.SizeReadyCallback, R
resource.release();
return;
}
Bitmap loaded = resource.get();
target.onImageReady(loaded);
target.onResourceReady(resource);
if (!loadedFromMemoryCache && !isAnyImageSet()) {
if (animation == null && animationId > 0) {
animation = AnimationUtils.loadAnimation(context, animationId);
......
......@@ -3,21 +3,22 @@ package com.bumptech.glide.request.target;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import com.bumptech.glide.Resource;
/**
* A target wrapping an ImageView. Obtains the runtime dimensions of the ImageView.
*/
public class ImageViewTarget extends ViewTarget<ImageView> {
public class BitmapImageViewTarget extends ViewTarget<ImageView, Bitmap> {
private final ImageView view;
public ImageViewTarget(ImageView view) {
public BitmapImageViewTarget(ImageView view) {
super(view);
this.view = view;
}
@Override
public void onImageReady(Bitmap bitmap) {
view.setImageBitmap(bitmap);
public void onResourceReady(Resource<Bitmap> resource) {
view.setImageBitmap(resource.get());
}
@Override
......
package com.bumptech.glide.request.target;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.animation.Animation;
import com.bumptech.glide.Resource;
import com.bumptech.glide.request.Request;
/**
* An interface that Glide can load an image into
*
* @param <Z> The type of resource the target can display.
*/
public interface Target {
public interface Target<Z> {
/**
* A callback that must be called when the target has determined its size. For fixed size targets it can
......@@ -20,9 +22,9 @@ public interface Target {
/**
* The method that will be called when the image load has finished
* @param bitmap The loaded image
* @param resource the loaded resource.
*/
public void onImageReady(Bitmap bitmap);
public void onResourceReady(Resource<Z> resource);
/**
* A method that can optionally be implemented to set any placeholder that might have been passed to Glide to
......
......@@ -34,7 +34,7 @@ import java.util.Set;
*
* @param <T> The specific subclass of view wrapped by this target.
*/
public abstract class ViewTarget<T extends View> implements Target {
public abstract class ViewTarget<T extends View, Z> implements Target<Z> {
private static final String TAG = "ViewTarget";
private final T view;
private final SizeDeterminer sizeDeterminer;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册