Search in sources :

Example 36 with Interpolator

use of android.view.animation.Interpolator in project UltimateAndroid by cymcsg.

the class RayLayout method bindChildAnimation.

private void bindChildAnimation(final View child, final int index, final long duration) {
    final boolean expanded = mExpanded;
    final int childCount = getChildCount();
    Rect frame = computeChildFrame(!expanded, mLeftHolderWidth, index, mChildGap, mChildSize);
    final int toXDelta = frame.left - child.getLeft();
    final int toYDelta = frame.top - child.getTop();
    Interpolator interpolator = mExpanded ? new AccelerateInterpolator() : new OvershootInterpolator(1.5f);
    final long startOffset = computeStartOffset(childCount, mExpanded, index, 0.1f, duration, interpolator);
    Animation animation = mExpanded ? createShrinkAnimation(0, toXDelta, 0, toYDelta, startOffset, duration, interpolator) : createExpandAnimation(0, toXDelta, 0, toYDelta, startOffset, duration, interpolator);
    final boolean isLast = getTransformedIndex(expanded, childCount, index) == childCount - 1;
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (isLast) {
                postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        onAllAnimationsEnd();
                    }
                }, 0);
            }
        }
    });
    child.setAnimation(animation);
}
Also used : Rect(android.graphics.Rect) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) OvershootInterpolator(android.view.animation.OvershootInterpolator) RotateAnimation(android.view.animation.RotateAnimation) Animation(android.view.animation.Animation) Interpolator(android.view.animation.Interpolator) LinearInterpolator(android.view.animation.LinearInterpolator) OvershootInterpolator(android.view.animation.OvershootInterpolator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) AnimationListener(android.view.animation.Animation.AnimationListener)

Example 37 with Interpolator

use of android.view.animation.Interpolator in project android_frameworks_base by DirtyUnicorns.

the class AnimatorInflater method loadAnimator.

/**
     * Creates a new animation whose parameters come from the specified context
     * and attributes set.
     *
     * @param res The resources
     * @param attrs The set of attributes holding the animation parameters
     * @param anim Null if this is a ValueAnimator, otherwise this is an
     *            ObjectAnimator
     */
private static ValueAnimator loadAnimator(Resources res, Theme theme, AttributeSet attrs, ValueAnimator anim, float pathErrorScale) throws NotFoundException {
    TypedArray arrayAnimator = null;
    TypedArray arrayObjectAnimator = null;
    if (theme != null) {
        arrayAnimator = theme.obtainStyledAttributes(attrs, R.styleable.Animator, 0, 0);
    } else {
        arrayAnimator = res.obtainAttributes(attrs, R.styleable.Animator);
    }
    // If anim is not null, then it is an object animator.
    if (anim != null) {
        if (theme != null) {
            arrayObjectAnimator = theme.obtainStyledAttributes(attrs, R.styleable.PropertyAnimator, 0, 0);
        } else {
            arrayObjectAnimator = res.obtainAttributes(attrs, R.styleable.PropertyAnimator);
        }
        anim.appendChangingConfigurations(arrayObjectAnimator.getChangingConfigurations());
    }
    if (anim == null) {
        anim = new ValueAnimator();
    }
    anim.appendChangingConfigurations(arrayAnimator.getChangingConfigurations());
    parseAnimatorFromTypeArray(anim, arrayAnimator, arrayObjectAnimator, pathErrorScale);
    final int resID = arrayAnimator.getResourceId(R.styleable.Animator_interpolator, 0);
    if (resID > 0) {
        final Interpolator interpolator = AnimationUtils.loadInterpolator(res, theme, resID);
        if (interpolator instanceof BaseInterpolator) {
            anim.appendChangingConfigurations(((BaseInterpolator) interpolator).getChangingConfiguration());
        }
        anim.setInterpolator(interpolator);
    }
    arrayAnimator.recycle();
    if (arrayObjectAnimator != null) {
        arrayObjectAnimator.recycle();
    }
    return anim;
}
Also used : TypedArray(android.content.res.TypedArray) BaseInterpolator(android.view.animation.BaseInterpolator) Interpolator(android.view.animation.Interpolator) BaseInterpolator(android.view.animation.BaseInterpolator)

Example 38 with Interpolator

use of android.view.animation.Interpolator in project android_frameworks_base by DirtyUnicorns.

the class AnimatorInflater method loadKeyframe.

private static Keyframe loadKeyframe(Resources res, Theme theme, AttributeSet attrs, int valueType) throws XmlPullParserException, IOException {
    TypedArray a;
    if (theme != null) {
        a = theme.obtainStyledAttributes(attrs, R.styleable.Keyframe, 0, 0);
    } else {
        a = res.obtainAttributes(attrs, R.styleable.Keyframe);
    }
    Keyframe keyframe = null;
    float fraction = a.getFloat(R.styleable.Keyframe_fraction, -1);
    TypedValue keyframeValue = a.peekValue(R.styleable.Keyframe_value);
    boolean hasValue = (keyframeValue != null);
    if (valueType == VALUE_TYPE_UNDEFINED) {
        // If not, fall back to default value type (i.e. float type).
        if (hasValue && isColorType(keyframeValue.type)) {
            valueType = VALUE_TYPE_COLOR;
        } else {
            valueType = VALUE_TYPE_FLOAT;
        }
    }
    if (hasValue) {
        switch(valueType) {
            case VALUE_TYPE_FLOAT:
                float value = a.getFloat(R.styleable.Keyframe_value, 0);
                keyframe = Keyframe.ofFloat(fraction, value);
                break;
            case VALUE_TYPE_COLOR:
            case VALUE_TYPE_INT:
                int intValue = a.getInt(R.styleable.Keyframe_value, 0);
                keyframe = Keyframe.ofInt(fraction, intValue);
                break;
        }
    } else {
        keyframe = (valueType == VALUE_TYPE_FLOAT) ? Keyframe.ofFloat(fraction) : Keyframe.ofInt(fraction);
    }
    final int resID = a.getResourceId(R.styleable.Keyframe_interpolator, 0);
    if (resID > 0) {
        final Interpolator interpolator = AnimationUtils.loadInterpolator(res, theme, resID);
        keyframe.setInterpolator(interpolator);
    }
    a.recycle();
    return keyframe;
}
Also used : TypedArray(android.content.res.TypedArray) Interpolator(android.view.animation.Interpolator) BaseInterpolator(android.view.animation.BaseInterpolator) TypedValue(android.util.TypedValue)

Example 39 with Interpolator

use of android.view.animation.Interpolator in project android_frameworks_base by DirtyUnicorns.

the class KeyguardAffordanceView method setCircleRadius.

private void setCircleRadius(float circleRadius, boolean slowAnimation, boolean noAnimation) {
    // Check if we need a new animation
    boolean radiusHidden = (mCircleAnimator != null && mCircleWillBeHidden) || (mCircleAnimator == null && mCircleRadius == 0.0f);
    boolean nowHidden = circleRadius == 0.0f;
    boolean radiusNeedsAnimation = (radiusHidden != nowHidden) && !noAnimation;
    if (!radiusNeedsAnimation) {
        if (mCircleAnimator == null) {
            mCircleRadius = circleRadius;
            updateIconColor();
            invalidate();
            if (nowHidden) {
                if (mPreviewView != null) {
                    mPreviewView.setVisibility(View.INVISIBLE);
                }
            }
        } else if (!mCircleWillBeHidden) {
            // We just update the end value
            float diff = circleRadius - mMinBackgroundRadius;
            PropertyValuesHolder[] values = mCircleAnimator.getValues();
            values[0].setFloatValues(mCircleStartValue + diff, circleRadius);
            mCircleAnimator.setCurrentPlayTime(mCircleAnimator.getCurrentPlayTime());
        }
    } else {
        cancelAnimator(mCircleAnimator);
        cancelAnimator(mPreviewClipper);
        ValueAnimator animator = getAnimatorToRadius(circleRadius);
        Interpolator interpolator = circleRadius == 0.0f ? Interpolators.FAST_OUT_LINEAR_IN : Interpolators.LINEAR_OUT_SLOW_IN;
        animator.setInterpolator(interpolator);
        long duration = 250;
        if (!slowAnimation) {
            float durationFactor = Math.abs(mCircleRadius - circleRadius) / (float) mMinBackgroundRadius;
            duration = (long) (CIRCLE_APPEAR_DURATION * durationFactor);
            duration = Math.min(duration, CIRCLE_DISAPPEAR_MAX_DURATION);
        }
        animator.setDuration(duration);
        animator.start();
        if (mPreviewView != null && mPreviewView.getVisibility() == View.VISIBLE) {
            mPreviewView.setVisibility(View.VISIBLE);
            mPreviewClipper = ViewAnimationUtils.createCircularReveal(mPreviewView, getLeft() + mCenterX, getTop() + mCenterY, mCircleRadius, circleRadius);
            mPreviewClipper.setInterpolator(interpolator);
            mPreviewClipper.setDuration(duration);
            mPreviewClipper.addListener(mClipEndListener);
            mPreviewClipper.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    mPreviewView.setVisibility(View.INVISIBLE);
                }
            });
            mPreviewClipper.start();
        }
    }
}
Also used : Animator(android.animation.Animator) RenderNodeAnimator(android.view.RenderNodeAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Interpolator(android.view.animation.Interpolator) ValueAnimator(android.animation.ValueAnimator)

Example 40 with Interpolator

use of android.view.animation.Interpolator in project android_frameworks_base by DirtyUnicorns.

the class NotificationStackScrollLayout method startBottomAnimation.

private void startBottomAnimation() {
    int previousStartValue = mStartAnimationRect.bottom;
    int previousEndValue = mEndAnimationRect.bottom;
    int newEndValue = mBackgroundBounds.bottom;
    ObjectAnimator previousAnimator = mBottomAnimator;
    if (previousAnimator != null && previousEndValue == newEndValue) {
        return;
    }
    if (!mAnimateNextBackgroundBottom) {
        // 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();
            values[0].setIntValues(previousStartValue, newEndValue);
            mStartAnimationRect.bottom = previousStartValue;
            mEndAnimationRect.bottom = newEndValue;
            previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
            return;
        } else {
            // no new animation needed, let's just apply the value
            setBackgroundBottom(newEndValue);
            return;
        }
    }
    if (previousAnimator != null) {
        previousAnimator.cancel();
    }
    ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundBottom", mCurrentBounds.bottom, 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.bottom = -1;
            mEndAnimationRect.bottom = -1;
            mBottomAnimator = null;
        }
    });
    animator.start();
    mStartAnimationRect.bottom = mCurrentBounds.bottom;
    mEndAnimationRect.bottom = newEndValue;
    mBottomAnimator = 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)

Aggregations

Interpolator (android.view.animation.Interpolator)229 Animator (android.animation.Animator)60 ValueAnimator (android.animation.ValueAnimator)49 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)46 ObjectAnimator (android.animation.ObjectAnimator)39 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)25 PathInterpolator (android.view.animation.PathInterpolator)25 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)23 LinearInterpolator (android.view.animation.LinearInterpolator)18 Paint (android.graphics.Paint)17 View (android.view.View)17 PropertyValuesHolder (android.animation.PropertyValuesHolder)16 FloatKeyframe (com.actionbarsherlock.internal.nineoldandroids.animation.Keyframe.FloatKeyframe)16 IntKeyframe (com.actionbarsherlock.internal.nineoldandroids.animation.Keyframe.IntKeyframe)16 TimeAnimator (android.animation.TimeAnimator)15 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)14 TypedArray (android.content.res.TypedArray)14 Animation (android.view.animation.Animation)13 AnimatorSet (android.animation.AnimatorSet)12 TimeInterpolator (android.animation.TimeInterpolator)11