All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bumptech.glide.request.target.SimpleTarget Maven / Gradle / Ivy

Go to download

A fast and efficient image loading library for Android focused on smooth scrolling.

There is a newer version: 5.0.0-rc01
Show newest version
package com.bumptech.glide.request.target;

import com.bumptech.glide.util.Util;

/**
 * A simple {@link com.bumptech.glide.request.target.Target} base class with default (usually noop)
 * implementations of non essential methods that allows the caller to specify an exact width/height.
 * Typically use cases look something like this:
 * 
 * 
 * Glide.load("http://somefakeurl.com/fakeImage.jpeg")
 *      .asBitmap()
 *      .withFitCenter()
 *      .into(new SimpleTarget(250, 250) {
 *
 *          {@literal @Override}
 *          public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
 *              // Do something with bitmap here.
 *          }
 *
 *      });
 * }
 * 
 * 
* * @param The type of resource that this target will receive. */ public abstract class SimpleTarget extends BaseTarget { private final int width; private final int height; /** * Constructor for the target that uses {@link Target#SIZE_ORIGINAL} as the target width and * height. */ public SimpleTarget() { this(SIZE_ORIGINAL, SIZE_ORIGINAL); } /** * Constructor for the target that takes the desired dimensions of the decoded and/or transformed * resource. * * @param width The width in pixels of the desired resource. * @param height The height in pixels of the desired resource. */ public SimpleTarget(int width, int height) { this.width = width; this.height = height; } /** * Immediately calls the given callback with the sizes given in the constructor. * * @param cb {@inheritDoc} */ @Override public final void getSize(SizeReadyCallback cb) { if (!Util.isValidDimensions(width, height)) { throw new IllegalArgumentException( "Width and height must both be > 0 or Target#SIZE_ORIGINAL, but given" + " width: " + width + " and height: " + height + ", either provide dimensions in the constructor" + " or call override()"); } cb.onSizeReady(width, height); } @Override public void removeCallback(SizeReadyCallback cb) { // Do nothing, we never retain a reference to the callback. } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy