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

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

Merge "Use transition-only alpha property for fading transitions" into klp-dev

parents 3490228e c46181a9
Loading
Loading
Loading
Loading
+36 −64
Original line number Original line Diff line number Diff line
@@ -41,7 +41,6 @@ public class Fade extends Visibility {
    private static boolean DBG = Transition.DBG && false;
    private static boolean DBG = Transition.DBG && false;


    private static final String LOG_TAG = "Fade";
    private static final String LOG_TAG = "Fade";
    private static final String PROPNAME_ALPHA = "android:fade:alpha";
    private static final String PROPNAME_SCREEN_X = "android:fade:screenX";
    private static final String PROPNAME_SCREEN_X = "android:fade:screenX";
    private static final String PROPNAME_SCREEN_Y = "android:fade:screenY";
    private static final String PROPNAME_SCREEN_Y = "android:fade:screenY";


@@ -90,7 +89,8 @@ public class Fade extends Visibility {
            }
            }
            return null;
            return null;
        }
        }
        final ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", startAlpha, endAlpha);
        final ObjectAnimator anim = ObjectAnimator.ofFloat(view, "transitionAlpha", startAlpha,
                endAlpha);
        if (DBG) {
        if (DBG) {
            Log.d(LOG_TAG, "Created animator " + anim);
            Log.d(LOG_TAG, "Created animator " + anim);
        }
        }
@@ -102,8 +102,6 @@ public class Fade extends Visibility {
    }
    }


    private void captureValues(TransitionValues transitionValues) {
    private void captureValues(TransitionValues transitionValues) {
        float alpha = transitionValues.view.getAlpha();
        transitionValues.values.put(PROPNAME_ALPHA, alpha);
        int[] loc = new int[2];
        int[] loc = new int[2];
        transitionValues.view.getLocationOnScreen(loc);
        transitionValues.view.getLocationOnScreen(loc);
        transitionValues.values.put(PROPNAME_SCREEN_X, loc[0]);
        transitionValues.values.put(PROPNAME_SCREEN_X, loc[0]);
@@ -116,29 +114,6 @@ public class Fade extends Visibility {
        captureValues(transitionValues);
        captureValues(transitionValues);
    }
    }



    @Override
    public void captureEndValues(TransitionValues transitionValues) {
        super.captureEndValues(transitionValues);
    }

    @Override
    public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
            TransitionValues endValues) {
        Animator animator = super.createAnimator(sceneRoot, startValues, endValues);
        if (animator == null && startValues != null && endValues != null) {
            boolean endVisible = isVisible(endValues);
            final View endView = endValues.view;
            float endAlpha = endView.getAlpha();
            float startAlpha = (Float) startValues.values.get(PROPNAME_ALPHA);
            if ((endVisible && startAlpha < endAlpha && (mFadingMode & Fade.IN) != 0) ||
                    (!endVisible && startAlpha > endAlpha && (mFadingMode & Fade.OUT) != 0)) {
                animator = createAnimation(endView, startAlpha, endAlpha, null);
            }
        }
        return animator;
    }

    @Override
    @Override
    public Animator onAppear(ViewGroup sceneRoot,
    public Animator onAppear(ViewGroup sceneRoot,
            TransitionValues startValues, int startVisibility,
            TransitionValues startValues, int startVisibility,
@@ -152,40 +127,37 @@ public class Fade extends Visibility {
            Log.d(LOG_TAG, "Fade.onAppear: startView, startVis, endView, endVis = " +
            Log.d(LOG_TAG, "Fade.onAppear: startView, startVis, endView, endVis = " +
                    startView + ", " + startVisibility + ", " + endView + ", " + endVisibility);
                    startView + ", " + startVisibility + ", " + endView + ", " + endVisibility);
        }
        }
        // if alpha < 1, just fade it in from the current value
        endView.setTransitionAlpha(0);
        if (endView.getAlpha() == 1.0f) {
            endView.setAlpha(0);
        TransitionListener transitionListener = new TransitionListenerAdapter() {
        TransitionListener transitionListener = new TransitionListenerAdapter() {
            boolean mCanceled = false;
            boolean mCanceled = false;
            float mPausedAlpha;
            float mPausedAlpha;


            @Override
            @Override
            public void onTransitionCancel(Transition transition) {
            public void onTransitionCancel(Transition transition) {
                    endView.setAlpha(1);
                endView.setTransitionAlpha(1);
                mCanceled = true;
                mCanceled = true;
            }
            }


            @Override
            @Override
            public void onTransitionEnd(Transition transition) {
            public void onTransitionEnd(Transition transition) {
                if (!mCanceled) {
                if (!mCanceled) {
                        endView.setAlpha(1);
                    endView.setTransitionAlpha(1);
                }
                }
            }
            }


            @Override
            @Override
            public void onTransitionPause(Transition transition) {
            public void onTransitionPause(Transition transition) {
                    mPausedAlpha = endView.getAlpha();
                mPausedAlpha = endView.getTransitionAlpha();
                    endView.setAlpha(1);
                endView.setTransitionAlpha(1);
            }
            }


            @Override
            @Override
            public void onTransitionResume(Transition transition) {
            public void onTransitionResume(Transition transition) {
                    endView.setAlpha(mPausedAlpha);
                endView.setTransitionAlpha(mPausedAlpha);
            }
            }
        };
        };
        addListener(transitionListener);
        addListener(transitionListener);
        }
        return createAnimation(endView, 0, 1, null);
        return createAnimation(endView, endView.getAlpha(), 1, null);
    }
    }


    @Override
    @Override
@@ -236,7 +208,7 @@ public class Fade extends Visibility {
            overlayView.offsetTopAndBottom((screenY - loc[1]) - overlayView.getTop());
            overlayView.offsetTopAndBottom((screenY - loc[1]) - overlayView.getTop());
            sceneRoot.getOverlay().add(overlayView);
            sceneRoot.getOverlay().add(overlayView);
            // TODO: add automatic facility to Visibility superclass for keeping views around
            // TODO: add automatic facility to Visibility superclass for keeping views around
            final float startAlpha = view.getAlpha();
            final float startAlpha = 1;
            float endAlpha = 0;
            float endAlpha = 0;
            final View finalView = view;
            final View finalView = view;
            final View finalOverlayView = overlayView;
            final View finalOverlayView = overlayView;
@@ -245,7 +217,7 @@ public class Fade extends Visibility {
            final AnimatorListenerAdapter endListener = new AnimatorListenerAdapter() {
            final AnimatorListenerAdapter endListener = new AnimatorListenerAdapter() {
                @Override
                @Override
                public void onAnimationEnd(Animator animation) {
                public void onAnimationEnd(Animator animation) {
                    finalView.setAlpha(startAlpha);
                    finalView.setTransitionAlpha(startAlpha);
                    // TODO: restore view offset from overlay repositioning
                    // TODO: restore view offset from overlay repositioning
                    if (finalViewToKeep != null) {
                    if (finalViewToKeep != null) {
                        finalViewToKeep.setVisibility(finalVisibility);
                        finalViewToKeep.setVisibility(finalVisibility);
@@ -276,7 +248,7 @@ public class Fade extends Visibility {
            // VISIBLE for the duration of the transition
            // VISIBLE for the duration of the transition
            viewToKeep.setVisibility((View.VISIBLE));
            viewToKeep.setVisibility((View.VISIBLE));
            // TODO: add automatic facility to Visibility superclass for keeping views around
            // TODO: add automatic facility to Visibility superclass for keeping views around
            final float startAlpha = view.getAlpha();
            final float startAlpha = 1;
            float endAlpha = 0;
            float endAlpha = 0;
            final View finalView = view;
            final View finalView = view;
            final View finalOverlayView = overlayView;
            final View finalOverlayView = overlayView;
@@ -291,8 +263,8 @@ public class Fade extends Visibility {
                    if (finalViewToKeep != null && !mCanceled) {
                    if (finalViewToKeep != null && !mCanceled) {
                        finalViewToKeep.setVisibility(finalVisibility);
                        finalViewToKeep.setVisibility(finalVisibility);
                    }
                    }
                    mPausedAlpha = finalView.getAlpha();
                    mPausedAlpha = finalView.getTransitionAlpha();
                    finalView.setAlpha(startAlpha);
                    finalView.setTransitionAlpha(startAlpha);
                }
                }


                @Override
                @Override
@@ -300,21 +272,21 @@ public class Fade extends Visibility {
                    if (finalViewToKeep != null && !mCanceled) {
                    if (finalViewToKeep != null && !mCanceled) {
                        finalViewToKeep.setVisibility(View.VISIBLE);
                        finalViewToKeep.setVisibility(View.VISIBLE);
                    }
                    }
                    finalView.setAlpha(mPausedAlpha);
                    finalView.setTransitionAlpha(mPausedAlpha);
                }
                }


                @Override
                @Override
                public void onAnimationCancel(Animator animation) {
                public void onAnimationCancel(Animator animation) {
                    mCanceled = true;
                    mCanceled = true;
                    if (mPausedAlpha >= 0) {
                    if (mPausedAlpha >= 0) {
                        finalView.setAlpha(mPausedAlpha);
                        finalView.setTransitionAlpha(mPausedAlpha);
                    }
                    }
                }
                }


                @Override
                @Override
                public void onAnimationEnd(Animator animation) {
                public void onAnimationEnd(Animator animation) {
                    if (!mCanceled) {
                    if (!mCanceled) {
                        finalView.setAlpha(startAlpha);
                        finalView.setTransitionAlpha(startAlpha);
                    }
                    }
                    // TODO: restore view offset from overlay repositioning
                    // TODO: restore view offset from overlay repositioning
                    if (finalViewToKeep != null && !mCanceled) {
                    if (finalViewToKeep != null && !mCanceled) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -353,7 +353,7 @@ public abstract class Transition implements Cloneable {
                if (endValues.viewValues.get(view) != null) {
                if (endValues.viewValues.get(view) != null) {
                    end = endValues.viewValues.get(view);
                    end = endValues.viewValues.get(view);
                    endCopy.remove(view);
                    endCopy.remove(view);
                } else {
                } else if (id != View.NO_ID) {
                    end = endValues.idValues.get(id);
                    end = endValues.idValues.get(id);
                    View removeView = null;
                    View removeView = null;
                    for (View viewToRemove : endCopy.keySet()) {
                    for (View viewToRemove : endCopy.keySet()) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -354,7 +354,7 @@ public class TransitionSet extends Transition {
        clone.mTransitions = new ArrayList<Transition>();
        clone.mTransitions = new ArrayList<Transition>();
        int numTransitions = mTransitions.size();
        int numTransitions = mTransitions.size();
        for (int i = 0; i < numTransitions; ++i) {
        for (int i = 0; i < numTransitions; ++i) {
            clone.mTransitions.add((Transition) mTransitions.get(i).clone());
            clone.addTransition((Transition) mTransitions.get(i).clone());
        }
        }
        return clone;
        return clone;
    }
    }
+61 −8
Original line number Original line Diff line number Diff line
@@ -2894,6 +2894,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
         */
         */
        @ViewDebug.ExportedProperty
        @ViewDebug.ExportedProperty
        float mAlpha = 1f;
        float mAlpha = 1f;
        /**
         * The opacity of the view as manipulated by the Fade transition. This is a hidden
         * property only used by transitions, which is composited with the other alpha
         * values to calculate the final visual alpha value.
         */
        float mTransitionAlpha = 1f;
    }
    }
    TransformationInfo mTransformationInfo;
    TransformationInfo mTransformationInfo;
@@ -5335,7 +5342,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                View view = (View) current;
                View view = (View) current;
                // We have attach info so this view is attached and there is no
                // We have attach info so this view is attached and there is no
                // need to check whether we reach to ViewRootImpl on the way up.
                // need to check whether we reach to ViewRootImpl on the way up.
                if (view.getAlpha() <= 0 || view.getVisibility() != VISIBLE) {
                if (view.getAlpha() <= 0 || view.getTransitionAlpha() <= 0 ||
                        view.getVisibility() != VISIBLE) {
                    return false;
                    return false;
                }
                }
                current = view.mParent;
                current = view.mParent;
@@ -9786,7 +9794,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                mPrivateFlags &= ~PFLAG_ALPHA_SET;
                mPrivateFlags &= ~PFLAG_ALPHA_SET;
                invalidateViewProperty(true, false);
                invalidateViewProperty(true, false);
                if (mDisplayList != null) {
                if (mDisplayList != null) {
                    mDisplayList.setAlpha(alpha);
                    mDisplayList.setAlpha(getFinalAlpha());
                }
                }
            }
            }
        }
        }
@@ -9813,13 +9821,58 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            } else {
            } else {
                mPrivateFlags &= ~PFLAG_ALPHA_SET;
                mPrivateFlags &= ~PFLAG_ALPHA_SET;
                if (mDisplayList != null) {
                if (mDisplayList != null) {
                    mDisplayList.setAlpha(alpha);
                    mDisplayList.setAlpha(getFinalAlpha());
                }
                }
            }
            }
        }
        }
        return false;
        return false;
    }
    }
    /**
     * This property is hidden and intended only for use by the Fade transition, which
     * animates it to produce a visual translucency that does not side-effect (or get
     * affected by) the real alpha property. This value is composited with the other
     * alpha value (and the AlphaAnimation value, when that is present) to produce
     * a final visual translucency result, which is what is passed into the DisplayList.
     *
     * @hide
     */
    public void setTransitionAlpha(float alpha) {
        ensureTransformationInfo();
        if (mTransformationInfo.mTransitionAlpha != alpha) {
            mTransformationInfo.mTransitionAlpha = alpha;
            mPrivateFlags &= ~PFLAG_ALPHA_SET;
            invalidateViewProperty(true, false);
            if (mDisplayList != null) {
                mDisplayList.setAlpha(getFinalAlpha());
            }
        }
    }
    /**
     * Calculates the visual alpha of this view, which is a combination of the actual
     * alpha value and the transitionAlpha value (if set).
     */
    private float getFinalAlpha() {
        if (mTransformationInfo != null) {
            return mTransformationInfo.mAlpha * mTransformationInfo.mTransitionAlpha;
        }
        return 1;
    }
    /**
     * This property is hidden and intended only for use by the Fade transition, which
     * animates it to produce a visual translucency that does not side-effect (or get
     * affected by) the real alpha property. This value is composited with the other
     * alpha value (and the AlphaAnimation value, when that is present) to produce
     * a final visual translucency result, which is what is passed into the DisplayList.
     *
     * @hide
     */
    public float getTransitionAlpha() {
        return mTransformationInfo != null ? mTransformationInfo.mTransitionAlpha : 1;
    }
    /**
    /**
     * Top position of this view relative to its parent.
     * Top position of this view relative to its parent.
     *
     *
@@ -10913,7 +10966,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    @ViewDebug.ExportedProperty(category = "drawing")
    @ViewDebug.ExportedProperty(category = "drawing")
    public boolean isOpaque() {
    public boolean isOpaque() {
        return (mPrivateFlags & PFLAG_OPAQUE_MASK) == PFLAG_OPAQUE_MASK &&
        return (mPrivateFlags & PFLAG_OPAQUE_MASK) == PFLAG_OPAQUE_MASK &&
                ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1.0f) >= 1.0f);
                getFinalAlpha() >= 1.0f;
    }
    }
    /**
    /**
@@ -13868,7 +13921,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                }
                }
            }
            }
            if (mTransformationInfo != null) {
            if (mTransformationInfo != null) {
                alpha *= mTransformationInfo.mAlpha;
                alpha *= getFinalAlpha();
                if (alpha < 1) {
                if (alpha < 1) {
                    final int multipliedAlpha = (int) (255 * alpha);
                    final int multipliedAlpha = (int) (255 * alpha);
                    if (onSetAlpha(multipliedAlpha)) {
                    if (onSetAlpha(multipliedAlpha)) {
@@ -14057,7 +14110,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            }
            }
        }
        }
        float alpha = useDisplayListProperties ? 1 : getAlpha();
        float alpha = useDisplayListProperties ? 1 : (getAlpha() * getTransitionAlpha());
        if (transformToApply != null || alpha < 1 ||  !hasIdentityMatrix() ||
        if (transformToApply != null || alpha < 1 ||  !hasIdentityMatrix() ||
                (mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_ALPHA) == PFLAG3_VIEW_IS_ANIMATING_ALPHA) {
                (mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_ALPHA) == PFLAG3_VIEW_IS_ANIMATING_ALPHA) {
            if (transformToApply != null || !childHasIdentityMatrix) {
            if (transformToApply != null || !childHasIdentityMatrix) {
@@ -14115,7 +14168,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                            layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG;
                            layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG;
                        }
                        }
                        if (useDisplayListProperties) {
                        if (useDisplayListProperties) {
                            displayList.setAlpha(alpha * getAlpha());
                            displayList.setAlpha(alpha * getAlpha() * getTransitionAlpha());
                        } else  if (layerType == LAYER_TYPE_NONE) {
                        } else  if (layerType == LAYER_TYPE_NONE) {
                            final int scrollX = hasDisplayList ? 0 : sx;
                            final int scrollX = hasDisplayList ? 0 : sx;
                            final int scrollY = hasDisplayList ? 0 : sy;
                            final int scrollY = hasDisplayList ? 0 : sy;