Search in sources :

Example 36 with PropertyValuesHolder

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

the class StackStateAnimator method startAlphaAnimation.

private void startAlphaAnimation(final View child, final ViewState viewState, long duration, long delay) {
    Float previousStartValue = getChildTag(child, TAG_START_ALPHA);
    Float previousEndValue = getChildTag(child, TAG_END_ALPHA);
    final float newEndValue = viewState.alpha;
    if (previousEndValue != null && previousEndValue == newEndValue) {
        return;
    }
    ObjectAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_ALPHA);
    if (!mAnimationFilter.animateAlpha) {
        // just a local update was performed
        if (previousAnimator != null) {
            // we need to increase all animation keyframes of the previous animator by the
            // relative change to the end value
            PropertyValuesHolder[] values = previousAnimator.getValues();
            float relativeDiff = newEndValue - previousEndValue;
            float newStartValue = previousStartValue + relativeDiff;
            values[0].setFloatValues(newStartValue, newEndValue);
            child.setTag(TAG_START_ALPHA, newStartValue);
            child.setTag(TAG_END_ALPHA, newEndValue);
            previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
            return;
        } else {
            // no new animation needed, let's just apply the value
            child.setAlpha(newEndValue);
            if (newEndValue == 0) {
                child.setVisibility(View.INVISIBLE);
            }
        }
    }
    ObjectAnimator animator = ObjectAnimator.ofFloat(child, View.ALPHA, child.getAlpha(), newEndValue);
    animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
    // Handle layer type
    child.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    animator.addListener(new AnimatorListenerAdapter() {

        public boolean mWasCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            child.setLayerType(View.LAYER_TYPE_NONE, null);
            if (newEndValue == 0 && !mWasCancelled) {
                child.setVisibility(View.INVISIBLE);
            }
            // remove the tag when the animation is finished
            child.setTag(TAG_ANIMATOR_ALPHA, null);
            child.setTag(TAG_START_ALPHA, null);
            child.setTag(TAG_END_ALPHA, null);
        }

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

        @Override
        public void onAnimationStart(Animator animation) {
            mWasCancelled = false;
        }
    });
    long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator);
    animator.setDuration(newDuration);
    if (delay > 0 && (previousAnimator == null || previousAnimator.getAnimatedFraction() == 0)) {
        animator.setStartDelay(delay);
    }
    animator.addListener(getGlobalAnimationFinishedListener());
    startAnimator(animator);
    child.setTag(TAG_ANIMATOR_ALPHA, animator);
    child.setTag(TAG_START_ALPHA, child.getAlpha());
    child.setTag(TAG_END_ALPHA, newEndValue);
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 37 with PropertyValuesHolder

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

the class NotificationStackScrollLayout method startTopAnimation.

private void startTopAnimation() {
    int previousEndValue = mEndAnimationRect.top;
    int newEndValue = mBackgroundBounds.top;
    ObjectAnimator previousAnimator = mTopAnimator;
    if (previousAnimator != null && previousEndValue == newEndValue) {
        return;
    }
    if (!mAnimateNextBackgroundTop) {
        // just a local update was performed
        if (previousAnimator != null) {
            // we need to increase all animation keyframes of the previous animator by the
            // relative change to the end value
            int previousStartValue = mStartAnimationRect.top;
            PropertyValuesHolder[] values = previousAnimator.getValues();
            values[0].setIntValues(previousStartValue, newEndValue);
            mStartAnimationRect.top = previousStartValue;
            mEndAnimationRect.top = newEndValue;
            previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
            return;
        } else {
            // no new animation needed, let's just apply the value
            setBackgroundTop(newEndValue);
            return;
        }
    }
    if (previousAnimator != null) {
        previousAnimator.cancel();
    }
    ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundTop", mCurrentBounds.top, newEndValue);
    Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN;
    animator.setInterpolator(interpolator);
    animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
    // remove the tag when the animation is finished
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mStartAnimationRect.top = -1;
            mEndAnimationRect.top = -1;
            mTopAnimator = null;
        }
    });
    animator.start();
    mStartAnimationRect.top = mCurrentBounds.top;
    mEndAnimationRect.top = newEndValue;
    mTopAnimator = animator;
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) TimeAnimator(android.animation.TimeAnimator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder) Interpolator(android.view.animation.Interpolator) Paint(android.graphics.Paint)

Example 38 with PropertyValuesHolder

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

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 39 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project MaterialProgressBar by DreaminginCodeZH.

the class ObjectAnimatorCompatBase method ofFloat.

public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> yProperty, Path path) {
    float[] xValues = new float[NUM_POINTS];
    float[] yValues = new float[NUM_POINTS];
    calculateXYValues(path, xValues, yValues);
    PropertyValuesHolder xPvh = PropertyValuesHolder.ofFloat(xProperty, xValues);
    PropertyValuesHolder yPvh = PropertyValuesHolder.ofFloat(yProperty, yValues);
    return ObjectAnimator.ofPropertyValuesHolder(target, xPvh, yPvh);
}
Also used : PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 40 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project android_packages_apps_Launcher2 by CyanogenMod.

the class LauncherTransitionable method growAndFadeOutFolderIcon.

private void growAndFadeOutFolderIcon(FolderIcon fi) {
    if (fi == null)
        return;
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
    FolderInfo info = (FolderInfo) fi.getTag();
    if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        CellLayout cl = (CellLayout) fi.getParent().getParent();
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
        cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
    }
    // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
    copyFolderIconToImage(fi);
    fi.setVisibility(View.INVISIBLE);
    ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, scaleX, scaleY);
    oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
    oa.start();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) 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