Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7225747 authored by Chet Haase's avatar Chet Haase Committed by Android (Google) Code Review
Browse files

Merge "Fix minor transition bugs and add capabilities"

parents 70d3dd4f c81a8493
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -28856,6 +28856,7 @@ package android.view.transition {
    method public void setFadeBehavior(int);
    method public void setResizeBehavior(int);
    field public static final int FADE_BEHAVIOR_CROSSFADE = 0; // 0x0
    field public static final int FADE_BEHAVIOR_OUT_IN = 2; // 0x2
    field public static final int FADE_BEHAVIOR_REVEAL = 1; // 0x1
    field public static final int RESIZE_BEHAVIOR_NONE = 0; // 0x0
    field public static final int RESIZE_BEHAVIOR_SCALE = 1; // 0x1
@@ -28903,6 +28904,11 @@ package android.view.transition {
  public class TextChange extends android.view.transition.Transition {
    ctor public TextChange();
    method protected void captureValues(android.view.transition.TransitionValues, boolean);
    method public void setChangeBehavior(int);
    field public static final int CHANGE_BEHAVIOR_IN = 2; // 0x2
    field public static final int CHANGE_BEHAVIOR_KEEP = 0; // 0x0
    field public static final int CHANGE_BEHAVIOR_OUT = 1; // 0x1
    field public static final int CHANGE_BEHAVIOR_OUT_IN = 3; // 0x3
  }
  public abstract class Transition implements java.lang.Cloneable {
+28 −8
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.animation.RectEvaluator;
import android.animation.ValueAnimator;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -79,6 +80,15 @@ public class Crossfade extends Transition {
     * @see #setFadeBehavior(int)
     */
    public static final int FADE_BEHAVIOR_REVEAL = 1;
    /**
     * Flag specifying that the fading animation should first fade
     * out the original representation completely and then fade in the
     * new one. This effect may be more suitable than the other
     * fade behaviors for views with.
     *
     * @see #setFadeBehavior(int)
     */
    public static final int FADE_BEHAVIOR_OUT_IN = 2;

    /**
     * Flag specifying that the transition should not animate any
@@ -112,7 +122,7 @@ public class Crossfade extends Transition {
     * transition is run.
     */
    public void setFadeBehavior(int fadeBehavior) {
        if (fadeBehavior >= FADE_BEHAVIOR_CROSSFADE && fadeBehavior <= FADE_BEHAVIOR_REVEAL) {
        if (fadeBehavior >= FADE_BEHAVIOR_CROSSFADE && fadeBehavior <= FADE_BEHAVIOR_OUT_IN) {
            mFadeBehavior = fadeBehavior;
        }
    }
@@ -145,6 +155,7 @@ public class Crossfade extends Transition {
        if (startValues == null || endValues == null) {
            return null;
        }
        final boolean useParentOverlay = mFadeBehavior != FADE_BEHAVIOR_REVEAL;
        final View view = endValues.view;
        Map<String, Object> startVals = startValues.values;
        Map<String, Object> endVals = endValues.values;
@@ -159,8 +170,8 @@ public class Crossfade extends Transition {
                    " for start, end: " + startBitmap + ", " + endBitmap);
        }
        if (startDrawable != null && endDrawable != null && !startBitmap.sameAs(endBitmap)) {
            ViewOverlay overlay = (mFadeBehavior == FADE_BEHAVIOR_REVEAL) ?
                    view.getOverlay() : ((ViewGroup) view.getParent()).getOverlay();
            ViewOverlay overlay = useParentOverlay ?
                    ((ViewGroup) view.getParent()).getOverlay() : view.getOverlay();
            if (mFadeBehavior == FADE_BEHAVIOR_REVEAL) {
                overlay.add(endDrawable);
            }
@@ -169,7 +180,13 @@ public class Crossfade extends Transition {
            // gradually fading out the start drawable. So it's not really a cross-fade, but rather
            // a reveal of the end scene over time. Also, animate the bounds of both drawables
            // to mimic the change in the size of the view itself between scenes.
            ObjectAnimator anim = ObjectAnimator.ofInt(startDrawable, "alpha", 0);
            ObjectAnimator anim;
            if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
                // Fade out completely halfway through the transition
                anim = ObjectAnimator.ofInt(startDrawable, "alpha", 255, 0, 0);
            } else {
                anim = ObjectAnimator.ofInt(startDrawable, "alpha", 0);
            }
            anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
@@ -178,7 +195,10 @@ public class Crossfade extends Transition {
                }
            });
            ObjectAnimator anim1 = null;
            if (mFadeBehavior == FADE_BEHAVIOR_CROSSFADE) {
            if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
                // start fading in halfway through the transition
                anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 0, 1);
            } else if (mFadeBehavior == FADE_BEHAVIOR_CROSSFADE) {
                anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1);
            }
            if (Transition.DBG) {
@@ -188,8 +208,8 @@ public class Crossfade extends Transition {
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    ViewOverlay overlay = (mFadeBehavior == FADE_BEHAVIOR_REVEAL) ?
                            view.getOverlay() : ((ViewGroup) view.getParent()).getOverlay();
                    ViewOverlay overlay = useParentOverlay ?
                            ((ViewGroup) view.getParent()).getOverlay() : view.getOverlay();
                    overlay.remove(startDrawable);
                    if (mFadeBehavior == FADE_BEHAVIOR_REVEAL) {
                        overlay.remove(endDrawable);
@@ -227,7 +247,7 @@ public class Crossfade extends Transition {
    protected void captureValues(TransitionValues values, boolean start) {
        View view = values.view;
        Rect bounds = new Rect(0, 0, view.getWidth(), view.getHeight());
        if (mFadeBehavior == FADE_BEHAVIOR_CROSSFADE) {
        if (mFadeBehavior != FADE_BEHAVIOR_REVEAL) {
            bounds.offset(view.getLeft(), view.getTop());
        }
        values.values.put(PROPNAME_BOUNDS, bounds);
+111 −8
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@ package android.view.transition;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.graphics.Color;
import android.util.ArrayMap;
import android.view.ViewGroup;
import android.widget.TextView;
@@ -34,15 +36,69 @@ import java.util.Map;
 */
public class TextChange extends Transition {
    private static final String PROPNAME_TEXT = "android:textchange:text";
    private static final String PROPNAME_TEXT_COLOR = "android:textchange:textColor";

    // TODO: think about other options we could have here, like cross-fading the text, or fading
    // it out/in. These could be parameters to supply to the constructors (and xml attributes).
    private int mChangeBehavior = CHANGE_BEHAVIOR_KEEP;

    /**
     * Flag specifying that the text in affected/changing TextView targets will keep
     * their original text during the transition, setting it to the final text when
     * the transition ends. This is the default behavior.
     *
     * @see #setChangeBehavior(int)
     */
    public static final int CHANGE_BEHAVIOR_KEEP = 0;
    /**
     * Flag specifying that the text changing animation should first fade
     * out the original text completely. The new text is set on the target
     * view at the end of the fade-out animation. This transition is typically
     * used with a later {@link #CHANGE_BEHAVIOR_IN} transition, allowing more
     * flexibility than the {@link #CHANGE_BEHAVIOR_OUT_IN} by allowing other
     * transitions to be run sequentially or in parallel with these fades.
     *
     * @see #setChangeBehavior(int)
     */
    public static final int CHANGE_BEHAVIOR_OUT = 1;
    /**
     * Flag specifying that the text changing animation should fade in the
     * end text into the affected target view(s). This transition is typically
     * used in conjunction with an earlier {@link #CHANGE_BEHAVIOR_OUT}
     * transition, possibly with other transitions running as well, such as
     * a sequence to fade out, then resize the view, then fade in.
     *
     * @see #setChangeBehavior(int)
     */
    public static final int CHANGE_BEHAVIOR_IN = 2;
    /**
     * Flag specifying that the text changing animation should first fade
     * out the original text completely and then fade in the
     * new text.
     *
     * @see #setChangeBehavior(int)
     */
    public static final int CHANGE_BEHAVIOR_OUT_IN = 3;

    /**
     * Sets the type of changing animation that will be run, one of
     * {@link #CHANGE_BEHAVIOR_KEEP} and {@link #CHANGE_BEHAVIOR_OUT_IN}.
     *
     * @param changeBehavior The type of fading animation to use when this
     * transition is run.
     */
    public void setChangeBehavior(int changeBehavior) {
        if (changeBehavior >= CHANGE_BEHAVIOR_KEEP && changeBehavior <= CHANGE_BEHAVIOR_OUT_IN) {
            mChangeBehavior = changeBehavior;
        }
    }

    @Override
    protected void captureValues(TransitionValues values, boolean start) {
        if (values.view instanceof TextView) {
            TextView textview = (TextView) values.view;
            values.values.put(PROPNAME_TEXT, textview.getText());
            if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
                values.values.put(PROPNAME_TEXT_COLOR, textview.getCurrentTextColor());
            }
        }
    }

@@ -59,13 +115,60 @@ public class TextChange extends Transition {
        final String endText = (String) endVals.get(PROPNAME_TEXT);
        if (!startText.equals(endText)) {
            view.setText(startText);
            ValueAnimator anim = ValueAnimator.ofFloat(0, 1);
            Animator anim;
            if (mChangeBehavior == CHANGE_BEHAVIOR_KEEP) {
                anim = ValueAnimator.ofFloat(0, 1);
                anim.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        view.setText(endText);
                    }
                });
            } else {
                // Fade out start text
                final int startColor = (Integer) startVals.get(PROPNAME_TEXT_COLOR);
                final int endColor = (Integer) endVals.get(PROPNAME_TEXT_COLOR);
                ValueAnimator outAnim = null, inAnim = null;
                if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN ||
                        mChangeBehavior == CHANGE_BEHAVIOR_OUT) {
                    outAnim = ValueAnimator.ofInt(255, 0);
                    outAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            int currAlpha = (Integer) animation.getAnimatedValue();
                            view.setTextColor(currAlpha << 24 | Color.red(startColor) << 16 |
                                    Color.green(startColor) << 8 | Color.red(startColor));
                        }
                    });
                    outAnim.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            view.setText(endText);
                        }
                    });
                }
                if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN ||
                        mChangeBehavior == CHANGE_BEHAVIOR_IN) {
                    inAnim = ValueAnimator.ofInt(0, 255);
                    inAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            int currAlpha = (Integer) animation.getAnimatedValue();
                            view.setTextColor(currAlpha << 24 | Color.red(endColor) << 16 |
                                    Color.green(endColor) << 8 | Color.red(endColor));
                        }
                    });
                }
                if (outAnim != null && inAnim != null) {
                    anim = new AnimatorSet();
                    ((AnimatorSet) anim).playSequentially(outAnim, inAnim);
                } else if (outAnim != null) {
                    anim = outAnim;
                } else {
                    // Must be an in-only animation
                    anim = inAnim;
                }
            }
            return anim;
        }
        return null;
+9 −7
Original line number Diff line number Diff line
@@ -509,6 +509,15 @@ public abstract class Transition implements Cloneable {
     * false otherwise
     */
    void captureValues(ViewGroup sceneRoot, boolean start) {
        if (start) {
            mStartValues.viewValues.clear();
            mStartValues.idValues.clear();
            mStartValues.itemIdValues.clear();
        } else {
            mEndValues.viewValues.clear();
            mEndValues.idValues.clear();
            mEndValues.itemIdValues.clear();
        }
        if (mTargetIds != null && mTargetIds.length > 0 ||
                mTargets != null && mTargets.length > 0) {
            if (mTargetIds != null) {
@@ -774,13 +783,6 @@ public abstract class Transition implements Cloneable {
                    v.setHasTransientState(false);
                }
            }
            mStartValues.viewValues.clear();
            mStartValues.idValues.clear();
            mStartValues.itemIdValues.clear();
            mEndValues.viewValues.clear();
            mEndValues.idValues.clear();
            mEndValues.itemIdValues.clear();
            mCurrentAnimators.clear();
        }
    }

+5 −4
Original line number Diff line number Diff line
@@ -182,16 +182,17 @@ public class TransitionManager {

    private static void sceneChangeSetup(ViewGroup sceneRoot, Transition transition) {

        // Capture current values
        Transition runningTransition = sRunningTransitions.get(sceneRoot);
        if (runningTransition != null) {
            runningTransition.cancelTransition();
        }

        // Capture current values
        if (transition != null) {
            transition.captureValues(sceneRoot, true);
        }

        if (runningTransition != null) {
            runningTransition.cancelTransition();
        }

        // Notify previous scene that it is being exited
        Scene previousScene = sceneRoot.getCurrentScene();
        if (previousScene != null) {
Loading