Search in sources :

Example 66 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project PageIndicatorView by romandanylyk.

the class SwapAnimation method with.

@NonNull
public SwapAnimation with(int startValue, int endValue) {
    if (animator != null && hasChanges(startValue, endValue)) {
        xStartCoordinate = startValue;
        xEndCoordinate = endValue;
        PropertyValuesHolder holder = createColorPropertyHolder();
        animator.setValues(holder);
    }
    return this;
}
Also used : PropertyValuesHolder(android.animation.PropertyValuesHolder) NonNull(android.support.annotation.NonNull)

Example 67 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project android-different-loading-animations by raweng.

the class AllAnimation method waveAnimation.

public void waveAnimation() {
    PropertyValuesHolder tvOne_Y = PropertyValuesHolder.ofFloat(hangoutTvOne.TRANSLATION_Y, -40.0f);
    PropertyValuesHolder tvOne_X = PropertyValuesHolder.ofFloat(hangoutTvOne.TRANSLATION_X, 0);
    waveOneAnimator = ObjectAnimator.ofPropertyValuesHolder(hangoutTvOne, tvOne_X, tvOne_Y);
    waveOneAnimator.setRepeatCount(-1);
    waveOneAnimator.setRepeatMode(ValueAnimator.REVERSE);
    waveOneAnimator.setDuration(300);
    waveOneAnimator.start();
    PropertyValuesHolder tvTwo_Y = PropertyValuesHolder.ofFloat(hangoutTvTwo.TRANSLATION_Y, -40.0f);
    PropertyValuesHolder tvTwo_X = PropertyValuesHolder.ofFloat(hangoutTvTwo.TRANSLATION_X, 0);
    waveTwoAnimator = ObjectAnimator.ofPropertyValuesHolder(hangoutTvTwo, tvTwo_X, tvTwo_Y);
    waveTwoAnimator.setRepeatCount(-1);
    waveTwoAnimator.setRepeatMode(ValueAnimator.REVERSE);
    waveTwoAnimator.setDuration(300);
    waveTwoAnimator.setStartDelay(100);
    waveTwoAnimator.start();
    PropertyValuesHolder tvThree_Y = PropertyValuesHolder.ofFloat(hangoutTvThree.TRANSLATION_Y, -40.0f);
    PropertyValuesHolder tvThree_X = PropertyValuesHolder.ofFloat(hangoutTvThree.TRANSLATION_X, 0);
    waveThreeAnimator = ObjectAnimator.ofPropertyValuesHolder(hangoutTvThree, tvThree_X, tvThree_Y);
    waveThreeAnimator.setRepeatCount(-1);
    waveThreeAnimator.setRepeatMode(ValueAnimator.REVERSE);
    waveThreeAnimator.setDuration(300);
    waveThreeAnimator.setStartDelay(200);
    waveThreeAnimator.start();
}
Also used : PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 68 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project android_frameworks_base by crdroidandroid.

the class ChangeBounds method createAnimator.

@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    Map<String, Object> startParentVals = startValues.values;
    Map<String, Object> endParentVals = endValues.values;
    ViewGroup startParent = (ViewGroup) startParentVals.get(PROPNAME_PARENT);
    ViewGroup endParent = (ViewGroup) endParentVals.get(PROPNAME_PARENT);
    if (startParent == null || endParent == null) {
        return null;
    }
    final View view = endValues.view;
    if (parentMatches(startParent, endParent)) {
        Rect startBounds = (Rect) startValues.values.get(PROPNAME_BOUNDS);
        Rect endBounds = (Rect) endValues.values.get(PROPNAME_BOUNDS);
        final int startLeft = startBounds.left;
        final int endLeft = endBounds.left;
        final int startTop = startBounds.top;
        final int endTop = endBounds.top;
        final int startRight = startBounds.right;
        final int endRight = endBounds.right;
        final int startBottom = startBounds.bottom;
        final int endBottom = endBounds.bottom;
        final int startWidth = startRight - startLeft;
        final int startHeight = startBottom - startTop;
        final int endWidth = endRight - endLeft;
        final int endHeight = endBottom - endTop;
        Rect startClip = (Rect) startValues.values.get(PROPNAME_CLIP);
        Rect endClip = (Rect) endValues.values.get(PROPNAME_CLIP);
        int numChanges = 0;
        if ((startWidth != 0 && startHeight != 0) || (endWidth != 0 && endHeight != 0)) {
            if (startLeft != endLeft || startTop != endTop)
                ++numChanges;
            if (startRight != endRight || startBottom != endBottom)
                ++numChanges;
        }
        if ((startClip != null && !startClip.equals(endClip)) || (startClip == null && endClip != null)) {
            ++numChanges;
        }
        if (numChanges > 0) {
            Animator anim;
            if (!mResizeClip) {
                view.setLeftTopRightBottom(startLeft, startTop, startRight, startBottom);
                if (numChanges == 2) {
                    if (startWidth == endWidth && startHeight == endHeight) {
                        Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                        anim = ObjectAnimator.ofObject(view, POSITION_PROPERTY, null, topLeftPath);
                    } else {
                        final ViewBounds viewBounds = new ViewBounds(view);
                        Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                        ObjectAnimator topLeftAnimator = ObjectAnimator.ofObject(viewBounds, TOP_LEFT_PROPERTY, null, topLeftPath);
                        Path bottomRightPath = getPathMotion().getPath(startRight, startBottom, endRight, endBottom);
                        ObjectAnimator bottomRightAnimator = ObjectAnimator.ofObject(viewBounds, BOTTOM_RIGHT_PROPERTY, null, bottomRightPath);
                        AnimatorSet set = new AnimatorSet();
                        set.playTogether(topLeftAnimator, bottomRightAnimator);
                        anim = set;
                        set.addListener(new AnimatorListenerAdapter() {

                            // We need a strong reference to viewBounds until the
                            // animator ends.
                            private ViewBounds mViewBounds = viewBounds;
                        });
                    }
                } else if (startLeft != endLeft || startTop != endTop) {
                    Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                    anim = ObjectAnimator.ofObject(view, TOP_LEFT_ONLY_PROPERTY, null, topLeftPath);
                } else {
                    Path bottomRight = getPathMotion().getPath(startRight, startBottom, endRight, endBottom);
                    anim = ObjectAnimator.ofObject(view, BOTTOM_RIGHT_ONLY_PROPERTY, null, bottomRight);
                }
            } else {
                int maxWidth = Math.max(startWidth, endWidth);
                int maxHeight = Math.max(startHeight, endHeight);
                view.setLeftTopRightBottom(startLeft, startTop, startLeft + maxWidth, startTop + maxHeight);
                ObjectAnimator positionAnimator = null;
                if (startLeft != endLeft || startTop != endTop) {
                    Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                    positionAnimator = ObjectAnimator.ofObject(view, POSITION_PROPERTY, null, topLeftPath);
                }
                final Rect finalClip = endClip;
                if (startClip == null) {
                    startClip = new Rect(0, 0, startWidth, startHeight);
                }
                if (endClip == null) {
                    endClip = new Rect(0, 0, endWidth, endHeight);
                }
                ObjectAnimator clipAnimator = null;
                if (!startClip.equals(endClip)) {
                    view.setClipBounds(startClip);
                    clipAnimator = ObjectAnimator.ofObject(view, "clipBounds", sRectEvaluator, startClip, endClip);
                    clipAnimator.addListener(new AnimatorListenerAdapter() {

                        private boolean mIsCanceled;

                        @Override
                        public void onAnimationCancel(Animator animation) {
                            mIsCanceled = true;
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (!mIsCanceled) {
                                view.setClipBounds(finalClip);
                                view.setLeftTopRightBottom(endLeft, endTop, endRight, endBottom);
                            }
                        }
                    });
                }
                anim = TransitionUtils.mergeAnimators(positionAnimator, clipAnimator);
            }
            if (view.getParent() instanceof ViewGroup) {
                final ViewGroup parent = (ViewGroup) view.getParent();
                parent.suppressLayout(true);
                TransitionListener transitionListener = new TransitionListenerAdapter() {

                    boolean mCanceled = false;

                    @Override
                    public void onTransitionCancel(Transition transition) {
                        parent.suppressLayout(false);
                        mCanceled = true;
                    }

                    @Override
                    public void onTransitionEnd(Transition transition) {
                        if (!mCanceled) {
                            parent.suppressLayout(false);
                        }
                    }

                    @Override
                    public void onTransitionPause(Transition transition) {
                        parent.suppressLayout(false);
                    }

                    @Override
                    public void onTransitionResume(Transition transition) {
                        parent.suppressLayout(true);
                    }
                };
                addListener(transitionListener);
            }
            return anim;
        }
    } else {
        sceneRoot.getLocationInWindow(tempLocation);
        int startX = (Integer) startValues.values.get(PROPNAME_WINDOW_X) - tempLocation[0];
        int startY = (Integer) startValues.values.get(PROPNAME_WINDOW_Y) - tempLocation[1];
        int endX = (Integer) endValues.values.get(PROPNAME_WINDOW_X) - tempLocation[0];
        int endY = (Integer) endValues.values.get(PROPNAME_WINDOW_Y) - tempLocation[1];
        // TODO: also handle size changes: check bounds and animate size changes
        if (startX != endX || startY != endY) {
            final int width = view.getWidth();
            final int height = view.getHeight();
            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            view.draw(canvas);
            final BitmapDrawable drawable = new BitmapDrawable(bitmap);
            drawable.setBounds(startX, startY, startX + width, startY + height);
            final float transitionAlpha = view.getTransitionAlpha();
            view.setTransitionAlpha(0);
            sceneRoot.getOverlay().add(drawable);
            Path topLeftPath = getPathMotion().getPath(startX, startY, endX, endY);
            PropertyValuesHolder origin = PropertyValuesHolder.ofObject(DRAWABLE_ORIGIN_PROPERTY, null, topLeftPath);
            ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(drawable, origin);
            anim.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    sceneRoot.getOverlay().remove(drawable);
                    view.setTransitionAlpha(transitionAlpha);
                }
            });
            return anim;
        }
    }
    return null;
}
Also used : Path(android.graphics.Path) Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) ObjectAnimator(android.animation.ObjectAnimator) Canvas(android.graphics.Canvas) AnimatorSet(android.animation.AnimatorSet) BitmapDrawable(android.graphics.drawable.BitmapDrawable) View(android.view.View) Bitmap(android.graphics.Bitmap) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 69 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project android_frameworks_base by crdroidandroid.

the class ChangeTransform method createTransformAnimator.

private ObjectAnimator createTransformAnimator(TransitionValues startValues, TransitionValues endValues, final boolean handleParentChange) {
    Matrix startMatrix = (Matrix) startValues.values.get(PROPNAME_MATRIX);
    Matrix endMatrix = (Matrix) endValues.values.get(PROPNAME_MATRIX);
    if (startMatrix == null) {
        startMatrix = Matrix.IDENTITY_MATRIX;
    }
    if (endMatrix == null) {
        endMatrix = Matrix.IDENTITY_MATRIX;
    }
    if (startMatrix.equals(endMatrix)) {
        return null;
    }
    final Transforms transforms = (Transforms) endValues.values.get(PROPNAME_TRANSFORMS);
    // clear the transform properties so that we can use the animation matrix instead
    final View view = endValues.view;
    setIdentityTransforms(view);
    final float[] startMatrixValues = new float[9];
    startMatrix.getValues(startMatrixValues);
    final float[] endMatrixValues = new float[9];
    endMatrix.getValues(endMatrixValues);
    final PathAnimatorMatrix pathAnimatorMatrix = new PathAnimatorMatrix(view, startMatrixValues);
    PropertyValuesHolder valuesProperty = PropertyValuesHolder.ofObject(NON_TRANSLATIONS_PROPERTY, new FloatArrayEvaluator(new float[9]), startMatrixValues, endMatrixValues);
    Path path = getPathMotion().getPath(startMatrixValues[Matrix.MTRANS_X], startMatrixValues[Matrix.MTRANS_Y], endMatrixValues[Matrix.MTRANS_X], endMatrixValues[Matrix.MTRANS_Y]);
    PropertyValuesHolder translationProperty = PropertyValuesHolder.ofObject(TRANSLATIONS_PROPERTY, null, path);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(pathAnimatorMatrix, valuesProperty, translationProperty);
    final Matrix finalEndMatrix = endMatrix;
    AnimatorListenerAdapter listener = new AnimatorListenerAdapter() {

        private boolean mIsCanceled;

        private Matrix mTempMatrix = new Matrix();

        @Override
        public void onAnimationCancel(Animator animation) {
            mIsCanceled = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (!mIsCanceled) {
                if (handleParentChange && mUseOverlay) {
                    setCurrentMatrix(finalEndMatrix);
                } else {
                    view.setTagInternal(R.id.transitionTransform, null);
                    view.setTagInternal(R.id.parentMatrix, null);
                }
            }
            view.setAnimationMatrix(null);
            transforms.restore(view);
        }

        @Override
        public void onAnimationPause(Animator animation) {
            Matrix currentMatrix = pathAnimatorMatrix.getMatrix();
            setCurrentMatrix(currentMatrix);
        }

        @Override
        public void onAnimationResume(Animator animation) {
            setIdentityTransforms(view);
        }

        private void setCurrentMatrix(Matrix currentMatrix) {
            mTempMatrix.set(currentMatrix);
            view.setTagInternal(R.id.transitionTransform, mTempMatrix);
            transforms.restore(view);
        }
    };
    animator.addListener(listener);
    animator.addPauseListener(listener);
    return animator;
}
Also used : Path(android.graphics.Path) FloatArrayEvaluator(android.animation.FloatArrayEvaluator) Matrix(android.graphics.Matrix) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder) GhostView(android.view.GhostView) View(android.view.View)

Example 70 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project android_frameworks_base by crdroidandroid.

the class ActionMenuPresenter method runItemAnimations.

/**
     * This method is called once both the pre-layout and post-layout steps have
     * happened. It figures out which views are new (didn't exist prior to layout),
     * gone (existed pre-layout, but are now gone), or changed (exist in both,
     * but in a different location) and runs appropriate animations on those views.
     * Items are tracked by ids, since the underlying views that represent items
     * pre- and post-layout may be different.
     */
private void runItemAnimations() {
    for (int i = 0; i < mPreLayoutItems.size(); ++i) {
        int id = mPreLayoutItems.keyAt(i);
        final MenuItemLayoutInfo menuItemLayoutInfoPre = mPreLayoutItems.get(id);
        final int postLayoutIndex = mPostLayoutItems.indexOfKey(id);
        if (postLayoutIndex >= 0) {
            // item exists pre and post: see if it's changed
            final MenuItemLayoutInfo menuItemLayoutInfoPost = mPostLayoutItems.valueAt(postLayoutIndex);
            PropertyValuesHolder pvhX = null;
            PropertyValuesHolder pvhY = null;
            if (menuItemLayoutInfoPre.left != menuItemLayoutInfoPost.left) {
                pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, (menuItemLayoutInfoPre.left - menuItemLayoutInfoPost.left), 0);
            }
            if (menuItemLayoutInfoPre.top != menuItemLayoutInfoPost.top) {
                pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, menuItemLayoutInfoPre.top - menuItemLayoutInfoPost.top, 0);
            }
            if (pvhX != null || pvhY != null) {
                for (int j = 0; j < mRunningItemAnimations.size(); ++j) {
                    ItemAnimationInfo oldInfo = mRunningItemAnimations.get(j);
                    if (oldInfo.id == id && oldInfo.animType == ItemAnimationInfo.MOVE) {
                        oldInfo.animator.cancel();
                    }
                }
                ObjectAnimator anim;
                if (pvhX != null) {
                    if (pvhY != null) {
                        anim = ObjectAnimator.ofPropertyValuesHolder(menuItemLayoutInfoPost.view, pvhX, pvhY);
                    } else {
                        anim = ObjectAnimator.ofPropertyValuesHolder(menuItemLayoutInfoPost.view, pvhX);
                    }
                } else {
                    anim = ObjectAnimator.ofPropertyValuesHolder(menuItemLayoutInfoPost.view, pvhY);
                }
                anim.setDuration(ITEM_ANIMATION_DURATION);
                anim.start();
                ItemAnimationInfo info = new ItemAnimationInfo(id, menuItemLayoutInfoPost, anim, ItemAnimationInfo.MOVE);
                mRunningItemAnimations.add(info);
                anim.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        for (int j = 0; j < mRunningItemAnimations.size(); ++j) {
                            if (mRunningItemAnimations.get(j).animator == animation) {
                                mRunningItemAnimations.remove(j);
                                break;
                            }
                        }
                    }
                });
            }
            mPostLayoutItems.remove(id);
        } else {
            // item used to be there, is now gone
            float oldAlpha = 1;
            for (int j = 0; j < mRunningItemAnimations.size(); ++j) {
                ItemAnimationInfo oldInfo = mRunningItemAnimations.get(j);
                if (oldInfo.id == id && oldInfo.animType == ItemAnimationInfo.FADE_IN) {
                    oldAlpha = oldInfo.menuItemLayoutInfo.view.getAlpha();
                    oldInfo.animator.cancel();
                }
            }
            ObjectAnimator anim = ObjectAnimator.ofFloat(menuItemLayoutInfoPre.view, View.ALPHA, oldAlpha, 0);
            // Re-using the view from pre-layout assumes no view recycling
            ((ViewGroup) mMenuView).getOverlay().add(menuItemLayoutInfoPre.view);
            anim.setDuration(ITEM_ANIMATION_DURATION);
            anim.start();
            ItemAnimationInfo info = new ItemAnimationInfo(id, menuItemLayoutInfoPre, anim, ItemAnimationInfo.FADE_OUT);
            mRunningItemAnimations.add(info);
            anim.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    for (int j = 0; j < mRunningItemAnimations.size(); ++j) {
                        if (mRunningItemAnimations.get(j).animator == animation) {
                            mRunningItemAnimations.remove(j);
                            break;
                        }
                    }
                    ((ViewGroup) mMenuView).getOverlay().remove(menuItemLayoutInfoPre.view);
                }
            });
        }
    }
    for (int i = 0; i < mPostLayoutItems.size(); ++i) {
        int id = mPostLayoutItems.keyAt(i);
        final int postLayoutIndex = mPostLayoutItems.indexOfKey(id);
        if (postLayoutIndex >= 0) {
            // item is new
            final MenuItemLayoutInfo menuItemLayoutInfo = mPostLayoutItems.valueAt(postLayoutIndex);
            float oldAlpha = 0;
            for (int j = 0; j < mRunningItemAnimations.size(); ++j) {
                ItemAnimationInfo oldInfo = mRunningItemAnimations.get(j);
                if (oldInfo.id == id && oldInfo.animType == ItemAnimationInfo.FADE_OUT) {
                    oldAlpha = oldInfo.menuItemLayoutInfo.view.getAlpha();
                    oldInfo.animator.cancel();
                }
            }
            ObjectAnimator anim = ObjectAnimator.ofFloat(menuItemLayoutInfo.view, View.ALPHA, oldAlpha, 1);
            anim.start();
            anim.setDuration(ITEM_ANIMATION_DURATION);
            ItemAnimationInfo info = new ItemAnimationInfo(id, menuItemLayoutInfo, anim, ItemAnimationInfo.FADE_IN);
            mRunningItemAnimations.add(info);
            anim.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    for (int j = 0; j < mRunningItemAnimations.size(); ++j) {
                        if (mRunningItemAnimations.get(j).animator == animation) {
                            mRunningItemAnimations.remove(j);
                            break;
                        }
                    }
                }
            });
        }
    }
    mPreLayoutItems.clear();
    mPostLayoutItems.clear();
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ViewGroup(android.view.ViewGroup) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Aggregations

PropertyValuesHolder (android.animation.PropertyValuesHolder)210 ObjectAnimator (android.animation.ObjectAnimator)144 Animator (android.animation.Animator)96 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)70 ValueAnimator (android.animation.ValueAnimator)64 Paint (android.graphics.Paint)33 AnimatorSet (android.animation.AnimatorSet)25 NonNull (android.support.annotation.NonNull)18 LinearInterpolator (android.view.animation.LinearInterpolator)18 Interpolator (android.view.animation.Interpolator)16 ArrayList (java.util.ArrayList)16 ViewGroup (android.view.ViewGroup)14 View (android.view.View)12 IntEvaluator (android.animation.IntEvaluator)11 Point (android.graphics.Point)11 Keyframe (android.animation.Keyframe)10 TimeAnimator (android.animation.TimeAnimator)10 Path (android.graphics.Path)10 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)8 Rect (android.graphics.Rect)7