com.bumptech.glide.load.resource.drawable.DrawableResource Java Examples

The following examples show how to use com.bumptech.glide.load.resource.drawable.DrawableResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ByteBufferAnimationDecoder.java    From APNG4Android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Resource<Drawable> decode(@NonNull final ByteBuffer source, int width, int height, @NonNull Options options) throws IOException {
    Loader loader = new ByteBufferLoader() {
        @Override
        public ByteBuffer getByteBuffer() {
            source.position(0);
            return source;
        }
    };
    FrameAnimationDrawable drawable;
    if (WebPParser.isAWebP(new ByteBufferReader(source))) {
        drawable = new WebPDrawable(loader);
    } else if (APNGParser.isAPNG(new ByteBufferReader(source))) {
        drawable = new APNGDrawable(loader);
    } else if (GifParser.isGif(new ByteBufferReader(source))) {
        drawable = new GifDrawable(loader);
    } else {
        return null;
    }
    return new DrawableResource<Drawable>(drawable) {
        @NonNull
        @Override
        public Class<Drawable> getResourceClass() {
            return Drawable.class;
        }

        @Override
        public int getSize() {
            return source.limit();
        }

        @Override
        public void recycle() {
            ((FrameAnimationDrawable) drawable).stop();
        }
    };
}
 
Example #2
Source File: ApplicationIconDecoder.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public Resource<Drawable> decode(ApplicationInfo source, int width, int height) throws IOException {
	Drawable icon = context.getPackageManager().getApplicationIcon(source);
	return new DrawableResource<Drawable>(icon) {
		@Override public int getSize() { // best effort
			if (drawable instanceof BitmapDrawable) {
				return Util.getBitmapByteSize(((BitmapDrawable)drawable).getBitmap());
			} else {
				return 1;
			}
		}
		@Override public void recycle() { /* not from our pool */ }
	};
}
 
Example #3
Source File: DrawableResourceDecoder.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public Resource<Drawable> decode(Drawable source, int width, int height) throws IOException {
	return new DrawableResource<Drawable>(source) {
		@Override public int getSize() {
			return 1;
		}
		@Override public void recycle() {
		}
	};
}