-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change format for specific loads and still get transition drawable #840
Comments
You're essentially asking to do Remember that you can always do your own animation with Update: here's the v4 version I was talking about: .transition(new GenericTransitionOptions<PaletteBitmap>().transition(CROSS_FADE_FACTORY))
private static final TransitionFactory<PaletteBitmap> CROSS_FADE_FACTORY = new TransitionFactory<PaletteBitmap>() {
private final TransitionFactory<Drawable> realFactory = new DrawableCrossFadeFactory();
@Override public Transition<PaletteBitmap> build(DataSource dataSource, boolean isFirstResource) {
final Transition<Drawable> transition = realFactory.build(dataSource, isFirstResource);
return new Transition<PaletteBitmap>() {
@Override
public boolean transition(PaletteBitmap current, ViewAdapter adapter) {
Resources resources = adapter.getView().getResources();
Drawable currentBitmap = new BitmapDrawable(resources, current.bitmap);
return transition.transition(currentBitmap, adapter);
}
};
}
}; I made it for |
This response is outdated, since 3.8.0 it's possible to do The heart of all is a custom factory: private static final GlideAnimationFactory<Bitmap> CROSS_FADE_FACTORY = new GlideAnimationFactory<Bitmap>() {
private final GlideAnimationFactory<Drawable> realFactory = new DrawableCrossFadeFactory<>();
@Override public GlideAnimation<Bitmap> build(boolean isFromMemoryCache, boolean isFirstResource) {
final GlideAnimation<Drawable> transition = realFactory.build(isFromMemoryCache, isFirstResource);
return new GlideAnimation<Bitmap>() {
@Override public boolean animate(Bitmap current, ViewAdapter adapter) {
Resources resources = adapter.getView().getResources();
Drawable currentBitmap = new BitmapDrawable(resources, current);
return transition.animate(currentBitmap, adapter);
}
};
}
}; This can be exploded into several classes and Assuming you have something like this (you'll see later why I extracted the local variable): BitmapRequestBuilder<String, Bitmap> request = Glide
.with(context)
.load(fullUrl)
.asBitmap()
.format(DecodeFormat.PREFER_ARGB_8888)
.thumbnail(Glide
.with(context)
.load(thumbUrl)
.asBitmap()
)
; you have two options, both of them are weird because The proper... yet ugly: I don't like listeners to do stuff, though they were designed that way. request
.dontAnimate() // turn off defaults since we're handling it
.listener(new BitmapCrossfadeListener<>())
.into(imageView)
; public class BitmapCrossfadeListener<ModelType> implements RequestListener<ModelType, Bitmap> {
// CROSS_FADE_FACTORY here
@Override public boolean onException(Exception e, ModelType model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}
@Override public boolean onResourceReady(Bitmap resource, ModelType model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
return CROSS_FADE_FACTORY
.build(isFromMemoryCache, isFirstResource)
.animate(resource, (ViewAdapter)target)
;
}
} The hackybut would-be nicer: equivalent to calling GlideRequestBuilderAccessor.animate(request, CROSS_FADE_FACTORY);
request.into(imageView); package com.bumptech.glide;
public class GlideRequestBuilderAccessor {
public static <T> void animate(GenericRequestBuilder<?, ?, ?, T> request, GlideAnimationFactory<T> factory) {
request.animate(factory);
}
} or, depending on your preferred style, an alternative: GlideRequestBuilderAccessor.animate(request, CROSS_FADE_FACTORY).into(imageView);
public static <ModelType, DataType, ResourceType, TranscodeType>
GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeType> animate(
GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeType> request,
GlideAnimationFactory<TranscodeType> factory
) {
return request.animate(factory);
} |
Just noticed that #605 is the same and has a simpler solution, which is essentially the total inlining of the core of |
Thanks for the reply. |
Agree, pull requests welcome :) |
… to .asBitmap().transition(withCrossFade()) Fixes bumptech#840 Also introduce some missing convenience methods and fix some JavaDoc typos.
Is it possible to change the load format between ARGB and RGB_565 for specific loads and still load a drawable to get the transition effect between thumbnail and actual image?
The text was updated successfully, but these errors were encountered: