Search in sources :

Example 51 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project UltimateAndroid by cymcsg.

the class AnimationUtils method leftRightShake.

/**
     * Shake the view from left to right
     *
     * @param view
     * @return
     */
public static ObjectAnimator leftRightShake(View view) {
    // int delta = view.getResources().getDimensionPixelOffset(R.dimen.spacing_medium);
    int delta = 40;
    PropertyValuesHolder pvhTranslateX = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_X, Keyframe.ofFloat(0f, 0), Keyframe.ofFloat(.10f, -delta), Keyframe.ofFloat(.26f, delta), Keyframe.ofFloat(.42f, -delta), Keyframe.ofFloat(.58f, delta), Keyframe.ofFloat(.74f, -delta), Keyframe.ofFloat(.90f, delta), Keyframe.ofFloat(1f, 0f));
    return ObjectAnimator.ofPropertyValuesHolder(view, pvhTranslateX).setDuration(500);
}
Also used : PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 52 with PropertyValuesHolder

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

the class StackView method handlePointerUp.

private void handlePointerUp(MotionEvent ev) {
    int pointerIndex = ev.findPointerIndex(mActivePointerId);
    float newY = ev.getY(pointerIndex);
    int deltaY = (int) (newY - mInitialY);
    mLastInteractionTime = System.currentTimeMillis();
    if (mVelocityTracker != null) {
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
        mYVelocity = (int) mVelocityTracker.getYVelocity(mActivePointerId);
    }
    if (mVelocityTracker != null) {
        mVelocityTracker.recycle();
        mVelocityTracker = null;
    }
    if (deltaY > mSwipeThreshold && mSwipeGestureType == GESTURE_SLIDE_DOWN && mStackSlider.mMode == StackSlider.NORMAL_MODE) {
        // We reset the gesture variable, because otherwise we will ignore showPrevious() /
        // showNext();
        mSwipeGestureType = GESTURE_NONE;
        // Swipe threshold exceeded, swipe down
        if (mStackMode == ITEMS_SLIDE_UP) {
            showPrevious();
        } else {
            showNext();
        }
        mHighlight.bringToFront();
    } else if (deltaY < -mSwipeThreshold && mSwipeGestureType == GESTURE_SLIDE_UP && mStackSlider.mMode == StackSlider.NORMAL_MODE) {
        // We reset the gesture variable, because otherwise we will ignore showPrevious() /
        // showNext();
        mSwipeGestureType = GESTURE_NONE;
        // Swipe threshold exceeded, swipe up
        if (mStackMode == ITEMS_SLIDE_UP) {
            showNext();
        } else {
            showPrevious();
        }
        mHighlight.bringToFront();
    } else if (mSwipeGestureType == GESTURE_SLIDE_UP) {
        // Didn't swipe up far enough, snap back down
        int duration;
        float finalYProgress = (mStackMode == ITEMS_SLIDE_DOWN) ? 1 : 0;
        if (mStackMode == ITEMS_SLIDE_UP || mStackSlider.mMode != StackSlider.NORMAL_MODE) {
            duration = Math.round(mStackSlider.getDurationForNeutralPosition());
        } else {
            duration = Math.round(mStackSlider.getDurationForOffscreenPosition());
        }
        StackSlider animationSlider = new StackSlider(mStackSlider);
        PropertyValuesHolder snapBackY = PropertyValuesHolder.ofFloat("YProgress", finalYProgress);
        PropertyValuesHolder snapBackX = PropertyValuesHolder.ofFloat("XProgress", 0.0f);
        ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, snapBackX, snapBackY);
        pa.setDuration(duration);
        pa.setInterpolator(new LinearInterpolator());
        pa.start();
    } else if (mSwipeGestureType == GESTURE_SLIDE_DOWN) {
        // Didn't swipe down far enough, snap back up
        float finalYProgress = (mStackMode == ITEMS_SLIDE_DOWN) ? 0 : 1;
        int duration;
        if (mStackMode == ITEMS_SLIDE_DOWN || mStackSlider.mMode != StackSlider.NORMAL_MODE) {
            duration = Math.round(mStackSlider.getDurationForNeutralPosition());
        } else {
            duration = Math.round(mStackSlider.getDurationForOffscreenPosition());
        }
        StackSlider animationSlider = new StackSlider(mStackSlider);
        PropertyValuesHolder snapBackY = PropertyValuesHolder.ofFloat("YProgress", finalYProgress);
        PropertyValuesHolder snapBackX = PropertyValuesHolder.ofFloat("XProgress", 0.0f);
        ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, snapBackX, snapBackY);
        pa.setDuration(duration);
        pa.start();
    }
    mActivePointerId = INVALID_POINTER;
    mSwipeGestureType = GESTURE_NONE;
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder) Paint(android.graphics.Paint)

Example 53 with PropertyValuesHolder

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

the class StackView method transformViewAtIndex.

private void transformViewAtIndex(int index, final View view, boolean animate) {
    final float maxPerspectiveShiftY = mPerspectiveShiftY;
    final float maxPerspectiveShiftX = mPerspectiveShiftX;
    if (mStackMode == ITEMS_SLIDE_DOWN) {
        index = mMaxNumActiveViews - index - 1;
        if (index == mMaxNumActiveViews - 1)
            index--;
    } else {
        index--;
        if (index < 0)
            index++;
    }
    float r = (index * 1.0f) / (mMaxNumActiveViews - 2);
    final float scale = 1 - PERSPECTIVE_SCALE_FACTOR * (1 - r);
    float perspectiveTranslationY = r * maxPerspectiveShiftY;
    float scaleShiftCorrectionY = (scale - 1) * (getMeasuredHeight() * (1 - PERSPECTIVE_SHIFT_FACTOR_Y) / 2.0f);
    final float transY = perspectiveTranslationY + scaleShiftCorrectionY;
    float perspectiveTranslationX = (1 - r) * maxPerspectiveShiftX;
    float scaleShiftCorrectionX = (1 - scale) * (getMeasuredWidth() * (1 - PERSPECTIVE_SHIFT_FACTOR_X) / 2.0f);
    final float transX = perspectiveTranslationX + scaleShiftCorrectionX;
    // this animation so as not to interfere with the new transformation.
    if (view instanceof StackFrame) {
        ((StackFrame) view).cancelTransformAnimator();
    }
    if (animate) {
        PropertyValuesHolder translationX = PropertyValuesHolder.ofFloat("translationX", transX);
        PropertyValuesHolder translationY = PropertyValuesHolder.ofFloat("translationY", transY);
        PropertyValuesHolder scalePropX = PropertyValuesHolder.ofFloat("scaleX", scale);
        PropertyValuesHolder scalePropY = PropertyValuesHolder.ofFloat("scaleY", scale);
        ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(view, scalePropX, scalePropY, translationY, translationX);
        oa.setDuration(STACK_RELAYOUT_DURATION);
        if (view instanceof StackFrame) {
            ((StackFrame) view).setTransformAnimator(oa);
        }
        oa.start();
    } else {
        view.setTranslationX(transX);
        view.setTranslationY(transY);
        view.setScaleX(scale);
        view.setScaleY(scale);
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 54 with PropertyValuesHolder

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

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)

Example 55 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project MaterialDateTimePicker by wdullaer.

the class RadialTextsView method renderAnimations.

/**
     * Render the animations for appearing and disappearing.
     */
private void renderAnimations() {
    Keyframe kf0, kf1, kf2, kf3;
    float midwayPoint = 0.2f;
    int duration = 500;
    // Set up animator for disappearing.
    kf0 = Keyframe.ofFloat(0f, 1);
    kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier);
    PropertyValuesHolder radiusDisappear = PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2);
    kf0 = Keyframe.ofFloat(0f, 1f);
    kf1 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1);
    mDisappearAnimator = ObjectAnimator.ofPropertyValuesHolder(this, radiusDisappear, fadeOut).setDuration(duration);
    mDisappearAnimator.addUpdateListener(mInvalidateUpdateListener);
    // Set up animator for reappearing.
    float delayMultiplier = 0.25f;
    float transitionDurationMultiplier = 1f;
    float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
    int totalDuration = (int) (duration * totalDurationMultiplier);
    float delayPoint = (delayMultiplier * duration) / totalDuration;
    midwayPoint = 1 - (midwayPoint * (1 - delayPoint));
    kf0 = Keyframe.ofFloat(0f, mTransitionEndRadiusMultiplier);
    kf1 = Keyframe.ofFloat(delayPoint, mTransitionEndRadiusMultiplier);
    kf2 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf3 = Keyframe.ofFloat(1f, 1);
    PropertyValuesHolder radiusReappear = PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2, kf3);
    kf0 = Keyframe.ofFloat(0f, 0f);
    kf1 = Keyframe.ofFloat(delayPoint, 0f);
    kf2 = Keyframe.ofFloat(1f, 1f);
    PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1, kf2);
    mReappearAnimator = ObjectAnimator.ofPropertyValuesHolder(this, radiusReappear, fadeIn).setDuration(totalDuration);
    mReappearAnimator.addUpdateListener(mInvalidateUpdateListener);
}
Also used : Keyframe(android.animation.Keyframe) PropertyValuesHolder(android.animation.PropertyValuesHolder) Paint(android.graphics.Paint)

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