Search in sources :

Example 6 with PropertyValuesHolder

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

the class AnimationUtils method nope.

public static ObjectAnimator nope(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 7 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project TextSurface by elevenetc.

the class Rotate3D method start.

@Override
public void start(@Nullable final IEndListener listener) {
    PropertyValuesHolder valHolder = null;
    int fromDegree;
    int toDegree;
    text.setAlpha(255);
    if (show) {
        fromDegree = 90;
        toDegree = 0;
    } else {
        fromDegree = 0;
        toDegree = -90;
    }
    if ((pivot & Pivot.BOTTOM) == Pivot.BOTTOM) {
        valHolder = PropertyValuesHolder.ofFloat("rotationX", fromDegree, toDegree);
        cameraTransXPre = -text.getWidth() / 2;
        cameraTransXPost = text.getWidth() / 2;
        cameraTransYPre = -text.getFontDescent();
        cameraTransYPost = 0;
    } else if ((pivot & Pivot.TOP) == Pivot.TOP) {
        valHolder = PropertyValuesHolder.ofFloat("rotationX", -fromDegree, toDegree);
        cameraTransXPre = -text.getWidth() / 2;
        cameraTransXPost = text.getWidth() / 2;
        cameraTransYPre = text.getHeight() - text.getFontDescent();
        cameraTransYPost = -text.getHeight();
    }
    if ((pivot & Pivot.LEFT) == Pivot.LEFT) {
        valHolder = PropertyValuesHolder.ofFloat("rotationY", fromDegree, toDegree);
        cameraTransXPre = 0;
        cameraTransXPost = 0;
        cameraTransYPre = text.getHeight() / 2 - text.getFontDescent();
        cameraTransYPost = text.getHeight() / 2 - text.getHeight();
    } else if ((pivot & Pivot.RIGHT) == Pivot.RIGHT) {
        valHolder = PropertyValuesHolder.ofFloat("rotationY", -fromDegree, toDegree);
        cameraTransXPre = -text.getWidth();
        cameraTransXPost = text.getWidth();
        cameraTransYPre = text.getHeight() / 2 - text.getFontDescent();
        cameraTransYPost = text.getHeight() / 2 - text.getHeight();
    }
    if ((pivot & Pivot.CENTER) == Pivot.CENTER) {
        valHolder = PropertyValuesHolder.ofFloat(axis == Axis.Y ? "rotationY" : "rotationX", fromDegree, toDegree);
        cameraTransXPre = -text.getWidth() / 2;
        cameraTransXPost = text.getWidth() / 2;
        cameraTransYPre = text.getHeight() / 2 - text.getFontDescent();
        cameraTransYPost = text.getHeight() / 2 - text.getHeight();
    }
    if (valHolder != null) {
        animator = ObjectAnimator.ofPropertyValuesHolder(this, valHolder);
        animator.setInterpolator(new FastOutSlowInInterpolator());
        Utils.addEndListener(this, animator, new IEndListener() {

            @Override
            public void onAnimationEnd(ISurfaceAnimation animation) {
                text.removeEffect(Rotate3D.this);
                if (!show)
                    text.setAlpha(0);
                if (listener != null)
                    listener.onAnimationEnd(Rotate3D.this);
            }
        });
        animator.setDuration(duration);
        animator.addUpdateListener(this);
        animator.start();
    } else {
        throw new RuntimeException(getClass().getSuperclass() + " was not configured properly. Pivot:" + pivot);
    }
}
Also used : ISurfaceAnimation(su.levenetc.android.textsurface.interfaces.ISurfaceAnimation) FastOutSlowInInterpolator(android.support.v4.view.animation.FastOutSlowInInterpolator) PropertyValuesHolder(android.animation.PropertyValuesHolder) IEndListener(su.levenetc.android.textsurface.interfaces.IEndListener) Paint(android.graphics.Paint)

Example 8 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project TextSurface by elevenetc.

the class ScaleSurface method start.

@Override
public void start(@Nullable IEndListener listener) {
    float pivotX;
    float pivotY;
    if (fit == -1) {
        pivotX = textPivot.getPosition().getRelativeX(pivot, textPivot, true);
        pivotY = textPivot.getPosition().getRelativeY(pivot, textPivot, true);
    } else {
        int surfaceWidth = textSurface.getWidth();
        float textWidth = textPivot.getWidth();
        toScale = surfaceWidth / textWidth;
        pivotX = textPivot.getPosition().getRelativeX(Pivot.CENTER, textPivot, true);
        pivotY = textPivot.getPosition().getRelativeY(Pivot.CENTER, textPivot, true);
    }
    PropertyValuesHolder scaleHolder = PropertyValuesHolder.ofFloat("scale", camera.getScale(), toScale);
    PropertyValuesHolder pivotXHolder = PropertyValuesHolder.ofFloat("scalePivotX", camera.getScalePivotX(), pivotX);
    PropertyValuesHolder pivotYHolder = PropertyValuesHolder.ofFloat("scalePivotY", camera.getScalePivotY(), pivotY);
    animator = ObjectAnimator.ofPropertyValuesHolder(camera, scaleHolder, pivotXHolder, pivotYHolder);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.setDuration(duration);
    animator.addUpdateListener(this);
    Utils.addEndListener(this, animator, listener);
    animator.start();
}
Also used : FastOutSlowInInterpolator(android.support.v4.view.animation.FastOutSlowInInterpolator) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 9 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 10 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)

Aggregations

PropertyValuesHolder (android.animation.PropertyValuesHolder)192 ObjectAnimator (android.animation.ObjectAnimator)141 Animator (android.animation.Animator)94 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)70 ValueAnimator (android.animation.ValueAnimator)64 Paint (android.graphics.Paint)33 AnimatorSet (android.animation.AnimatorSet)25 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 Point (android.graphics.Point)11 Keyframe (android.animation.Keyframe)10 TimeAnimator (android.animation.TimeAnimator)10 Path (android.graphics.Path)10 NonNull (android.support.annotation.NonNull)9 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)8 Rect (android.graphics.Rect)7 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)6