Open d4rken opened 5 years ago
This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
:man_shrugging:
This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
Why are you wrapping it in an AnimatableDrawable? Also why are you mutating the drawable before you set the tint, but not referencing the returned Drawable? mutate() often returns a copy of the original Drawable, specifically so you can apply thins like tints to some copies of the image but not others while still storing only one copy of the image bytes in memory.
Otherwise you can compare the difference between your custom Target and DrawableImageViewTarget. The only one I can think of off the top of my head that might be relevant is that DrawableImageViewTarget will start animated drawables if they implement Animatable. Maybe the animated drawable ignores your tint
Why are you wrapping it in an AnimatableDrawable?
That code was simplified, the actual code loops through multiple Android packages, gets their icons, creates an animation with one icon per frame and tints each frame.
Also why are you mutating the drawable before you set the tint, but not referencing the returned Drawable? mutate() often returns a copy of the original Drawable, specifically so you can apply thins like tints to some copies of the image but not others while still storing only one copy of the image bytes in memory.
Documentation leads me to believe that .mutate()
affects the drawable itself, with mutate()
returning itself as code sugar.
Otherwise you can compare the difference between your custom Target and DrawableImageViewTarget. The only one I can think of off the top of my head that might be relevant is that DrawableImageViewTarget will start animated drawables if they implement Animatable. Maybe the animated drawable ignores your tint
Tried it but it also doesn't work with just this:
Drawable drawable = ContextCompat.getDrawable(context, R.drawable.ic_ghost_white_24dp);
drawable = DrawableCompat.wrap(drawable);
drawable = drawable.mutate();
DrawableCompat.setTint(drawable, ContextCompat.getColor(context, R.color.state_m3));
return new SimpleResource<>(drawable);
Here is a minimal example project:
https://github.com/d4rken/android-kotlin-starter/compare/pr-glidedemo
It works with the DrawableImageViewTarget
.
So it seems related to
public ViewTarget<ImageView, TranscodeType> into(@NonNull ImageView view)
This is causing it, no idea why though, but if I overwrite the requestOptions
via debugger with dontTransform()
then it works. Hm, thoughts @sjudd ?
RequestOptions requestOptions = this.requestOptions;
if (!requestOptions.isTransformationSet()
&& requestOptions.isTransformationAllowed()
&& view.getScaleType() != null) {
// Clone in this method so that if we use this RequestBuilder to load into a View and then
// into a different target, we don't retain the transformation applied based on the previous
// View's scale type.
switch (view.getScaleType()) {
case CENTER_CROP:
requestOptions = requestOptions.clone().optionalCenterCrop();
break;
case CENTER_INSIDE:
requestOptions = requestOptions.clone().optionalCenterInside();
break;
case FIT_CENTER:
case FIT_START:
case FIT_END:
requestOptions = requestOptions.clone().optionalFitCenter();
break;
case FIT_XY:
requestOptions = requestOptions.clone().optionalCenterInside();
break;
case CENTER:
case MATRIX:
default:
// Do nothing.
}
}
Glide Version: 4.8.0
Device/Android Version: Pixel2@Android 9
Issue details / Repro steps / Use case background: Trying to tint a drawable within my custom decoder.
Decoder snippet
Glide call:
This doesn't work, no tint is applied.
Now I created a custom target which currently does NOTHING:
and use
.into(new TintTarget(ownerIcon));
and now it works, without any other changes.When I look at
DrawableImageViewTarget
which gets automatically created by Glide when just usinginto(ImageView)
, then it doesn't work, even though myTintTarget
is same thing?What am I missing here?