19fc12334a7d14347cd6951d0653264b2597bd3a0Sam Juddpackage com.bumptech.glide.request.target; 233943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd 333943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd/** 45f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * A simple {@link com.bumptech.glide.request.target.Target} base class with default (usually noop) implementations 55f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * of non essential methods that allows the caller to specify an exact width/height. Typicaly use cases look something 65f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * like this: 75f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * <pre> 8b5419dc08eb0a0f82821d774435720e5a31bc936Sam Judd * <code> 95f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * Glide.load("http://somefakeurl.com/fakeImage.jpeg") 105f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * .asBitmap() 11b5419dc08eb0a0f82821d774435720e5a31bc936Sam Judd * .fitCenter() 125f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * .into(new SimpleTarget<Bitmap>(250, 250) { 135f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * 14b5419dc08eb0a0f82821d774435720e5a31bc936Sam Judd * {@literal @Override} 155f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * public void onResourceReady(Bitmap resource, GlideAnimation<Bitmap> glideAnimation) { 165f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * // Do something with bitmap here. 175f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * } 185f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * 195f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * }); 205f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * } 21b5419dc08eb0a0f82821d774435720e5a31bc936Sam Judd * </code> 225f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * </pre> 23b5419dc08eb0a0f82821d774435720e5a31bc936Sam Judd * 24b5419dc08eb0a0f82821d774435720e5a31bc936Sam Judd * @param <Z> The type of resource that this target will receive. 2533943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd */ 26b38d03ba0aa2b9dc036bb987a13cb5fcc6ec661dSam Juddpublic abstract class SimpleTarget<Z> extends BaseTarget<Z> { 27b44604067356bb73cae3c910ac0e0044d26974a5Sam Judd private final int width; 28b44604067356bb73cae3c910ac0e0044d26974a5Sam Judd private final int height; 2933943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd 305f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd /** 3129438d5d293744613485914005d2717e03cae485Sam Judd * Constructor for the target that assumes you will have called 3229438d5d293744613485914005d2717e03cae485Sam Judd * {@link com.bumptech.glide.GenericRequestBuilder#override(int, int)} on the request builder this target is given 3329438d5d293744613485914005d2717e03cae485Sam Judd * to. 3429438d5d293744613485914005d2717e03cae485Sam Judd * 3529438d5d293744613485914005d2717e03cae485Sam Judd * <p> 3629438d5d293744613485914005d2717e03cae485Sam Judd * Requests that load into this target will throw an {@link java.lang.IllegalArgumentException} if 3729438d5d293744613485914005d2717e03cae485Sam Judd * {@link com.bumptech.glide.GenericRequestBuilder#override(int, int)} was not called on the request builder. 3829438d5d293744613485914005d2717e03cae485Sam Judd * </p> 3929438d5d293744613485914005d2717e03cae485Sam Judd */ 4029438d5d293744613485914005d2717e03cae485Sam Judd public SimpleTarget() { 4129438d5d293744613485914005d2717e03cae485Sam Judd this(-1, -1); 4229438d5d293744613485914005d2717e03cae485Sam Judd } 4329438d5d293744613485914005d2717e03cae485Sam Judd 4429438d5d293744613485914005d2717e03cae485Sam Judd /** 455f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * Constructor for the target that takes the desired dimensions of the decoded and/or transformed resource. 465f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * 4764d97bb3532525879dd90f3b246ac6060f466684Sam Judd * @param width The width in pixels of the desired resource. 4864d97bb3532525879dd90f3b246ac6060f466684Sam Judd * @param height The height in pixels of the desired resource. 495f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd */ 50b44604067356bb73cae3c910ac0e0044d26974a5Sam Judd public SimpleTarget(int width, int height) { 51b44604067356bb73cae3c910ac0e0044d26974a5Sam Judd this.width = width; 52b44604067356bb73cae3c910ac0e0044d26974a5Sam Judd this.height = height; 53b44604067356bb73cae3c910ac0e0044d26974a5Sam Judd } 5433943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd 555f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd /** 565f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * Immediately calls the given callback with the sizes given in the constructor. 575f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * 585f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd * @param cb {@inheritDoc} 595f4610b54d517be58105bcf73ce3291ba79f9f40Sam Judd */ 6033943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd @Override 61b44604067356bb73cae3c910ac0e0044d26974a5Sam Judd public final void getSize(SizeReadyCallback cb) { 6229438d5d293744613485914005d2717e03cae485Sam Judd if (width <= 0 || height <= 0) { 6329438d5d293744613485914005d2717e03cae485Sam Judd throw new IllegalArgumentException("Width and height must both be > 0, but given width: " + width + " and" 6429438d5d293744613485914005d2717e03cae485Sam Judd + " height: " + height + ", either provide dimensions in the constructor or call override()"); 6529438d5d293744613485914005d2717e03cae485Sam Judd } 66b44604067356bb73cae3c910ac0e0044d26974a5Sam Judd cb.onSizeReady(width, height); 6733943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd } 6833943be3ddf092ffb670ac0b51c884f9f39ee0b0Sam Judd} 69