1 package com.bumptech.glide.request.target; 2 3 import android.graphics.Bitmap; 4 import android.graphics.drawable.Drawable; 5 import android.widget.ImageView; 6 7 import com.bumptech.glide.load.resource.drawable.GlideDrawable; 8 9 /** 10 * A factory responsible for producing the correct type of {@link com.bumptech.glide.request.target.Target} for a given 11 * {@link android.view.View} subclass. 12 */ 13 public class ImageViewTargetFactory { 14 15 @SuppressWarnings("unchecked") 16 public <Z> Target<Z> buildTarget(ImageView view, Class<Z> clazz) { 17 if (GlideDrawable.class.isAssignableFrom(clazz)) { 18 return (Target<Z>) new GlideDrawableImageViewTarget(view); 19 } else if (Bitmap.class.equals(clazz)) { 20 return (Target<Z>) new BitmapImageViewTarget(view); 21 } else if (Drawable.class.isAssignableFrom(clazz)) { 22 return (Target<Z>) new DrawableImageViewTarget(view); 23 } else { 24 throw new IllegalArgumentException("Unhandled class: " + clazz 25 + ", try .as*(Class).transcode(ResourceTranscoder)"); 26 } 27 } 28 } 29