Created
November 4, 2015 16:24
-
-
Save bherbst/c42c8d2af6aa493b3d4c to your computer and use it in GitHub Desktop.
Transform that copies the drawable from a starting ImageView to an ending ImageView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Similar to {@link ChangeImageTransform}, but prior to capturing the end values for the transition | |
* it will copy the drawable from the starting image to the ending image. | |
* | |
* This allows the image transform to work when the end ImageView doesn't immediately have content, | |
* such as when the image will be loaded via Picasso. | |
* | |
* @author bherbst | |
*/ | |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
public class CopyDrawableImageTransform extends ChangeImageTransform { | |
private Drawable drawable; | |
@Override | |
public void captureStartValues(TransitionValues transitionValues) { | |
if (transitionValues.view instanceof ImageView) { | |
drawable = ((ImageView) transitionValues.view).getDrawable(); | |
} | |
super.captureStartValues(transitionValues); | |
} | |
@Override | |
public void captureEndValues(TransitionValues transitionValues) { | |
if (transitionValues.view instanceof ImageView) { | |
ImageView imageView = (ImageView) transitionValues.view; | |
if (imageView.getDrawable() == null) { | |
imageView.setImageDrawable(drawable); | |
} | |
} | |
super.captureEndValues(transitionValues); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment