FileDocCategorySizeDatePackage
Recolor.javaAPI DocAndroid 5.1 API3914Thu Mar 12 22:22:10 GMT 2015android.transition

Recolor

public class Recolor extends Transition
This transition tracks changes during scene changes to the {@link View#setBackground(android.graphics.drawable.Drawable) background} property of its target views (when the background is a {@link ColorDrawable}, as well as the {@link TextView#setTextColor(android.content.res.ColorStateList) color} of the text for target TextViews. If the color changes between scenes, the color change is animated.
hide

Fields Summary
private static final String
PROPNAME_BACKGROUND
private static final String
PROPNAME_TEXT_COLOR
Constructors Summary
public Recolor()


      
public Recolor(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
    
Methods Summary
public voidcaptureEndValues(TransitionValues transitionValues)

        captureValues(transitionValues);
    
public voidcaptureStartValues(TransitionValues transitionValues)

        captureValues(transitionValues);
    
private voidcaptureValues(TransitionValues transitionValues)

        transitionValues.values.put(PROPNAME_BACKGROUND, transitionValues.view.getBackground());
        if (transitionValues.view instanceof TextView) {
            transitionValues.values.put(PROPNAME_TEXT_COLOR,
                    ((TextView)transitionValues.view).getCurrentTextColor());
        }
    
public android.animation.AnimatorcreateAnimator(android.view.ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues)

        if (startValues == null || endValues == null) {
            return null;
        }
        final View view = endValues.view;
        Drawable startBackground = (Drawable) startValues.values.get(PROPNAME_BACKGROUND);
        Drawable endBackground = (Drawable) endValues.values.get(PROPNAME_BACKGROUND);
        boolean changed = false;
        if (startBackground instanceof ColorDrawable && endBackground instanceof ColorDrawable) {
            ColorDrawable startColor = (ColorDrawable) startBackground;
            ColorDrawable endColor = (ColorDrawable) endBackground;
            if (startColor.getColor() != endColor.getColor()) {
                endColor.setColor(startColor.getColor());
                changed = true;
                return ObjectAnimator.ofArgb(endBackground, "color", startColor.getColor(),
                        endColor.getColor());
            }
        }
        if (view instanceof TextView) {
            TextView textView = (TextView) view;
            int start = (Integer) startValues.values.get(PROPNAME_TEXT_COLOR);
            int end = (Integer) endValues.values.get(PROPNAME_TEXT_COLOR);
            if (start != end) {
                textView.setTextColor(end);
                changed = true;
                return ObjectAnimator.ofArgb(textView, "textColor", start, end);
            }
        }
        return null;