Search in sources :

Example 66 with Interpolator

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

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 67 with Interpolator

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

the class FlingAnimationUtils method getDismissingProperties.

private AnimatorProperties getDismissingProperties(float currValue, float endValue, float velocity, float maxDistance) {
    float maxLengthSeconds = (float) (mMaxLengthSeconds * Math.pow(Math.abs(endValue - currValue) / maxDistance, 0.5f));
    float diff = Math.abs(endValue - currValue);
    float velAbs = Math.abs(velocity);
    float y2 = calculateLinearOutFasterInY2(velAbs);
    float startGradient = y2 / LINEAR_OUT_FASTER_IN_X2;
    Interpolator mLinearOutFasterIn = new PathInterpolator(0, 0, LINEAR_OUT_FASTER_IN_X2, y2);
    float durationSeconds = startGradient * diff / velAbs;
    if (durationSeconds <= maxLengthSeconds) {
        mAnimatorProperties.interpolator = mLinearOutFasterIn;
    } else if (velAbs >= mMinVelocityPxPerSecond) {
        // Cross fade between linear-out-faster-in and linear interpolator with current
        // velocity.
        durationSeconds = maxLengthSeconds;
        VelocityInterpolator velocityInterpolator = new VelocityInterpolator(durationSeconds, velAbs, diff);
        InterpolatorInterpolator superInterpolator = new InterpolatorInterpolator(velocityInterpolator, mLinearOutFasterIn, mLinearOutSlowIn);
        mAnimatorProperties.interpolator = superInterpolator;
    } else {
        // Just use a normal interpolator which doesn't take the velocity into account.
        durationSeconds = maxLengthSeconds;
        mAnimatorProperties.interpolator = Interpolators.FAST_OUT_LINEAR_IN;
    }
    mAnimatorProperties.duration = (long) (durationSeconds * 1000);
    return mAnimatorProperties;
}
Also used : PathInterpolator(android.view.animation.PathInterpolator) Interpolator(android.view.animation.Interpolator) PathInterpolator(android.view.animation.PathInterpolator)

Example 68 with Interpolator

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

the class AssistInteractionSession method playAssistAnimation.

private void playAssistAnimation() {
    Interpolator linearOutSlowIn = AnimationUtils.loadInterpolator(mBackground.getContext(), android.R.interpolator.linear_out_slow_in);
    Interpolator fastOutSlowIn = AnimationUtils.loadInterpolator(mBackground.getContext(), android.R.interpolator.fast_out_slow_in);
    mScrim.setAlpha(0f);
    mScrim.animate().alpha(1f).setStartDelay(100).setDuration(500);
    mBackground.setTranslationY(50 * mDensity);
    mBackground.animate().translationY(0).setDuration(300).setInterpolator(linearOutSlowIn);
    int centerX = mBackground.getWidth() / 2;
    int centerY = (int) (mBackground.getHeight() / 5 * 3.8f);
    int radius = (int) Math.sqrt(centerX * centerX + centerY * centerY) + 1;
    Animator animator = ViewAnimationUtils.createCircularReveal(mBackground, centerX, centerY, 0, radius);
    animator.setDuration(300);
    animator.setInterpolator(fastOutSlowIn);
    animator.start();
    ValueAnimator colorAnim = ValueAnimator.ofArgb(Color.WHITE, 0xffe0e0e0);
    colorAnim.setDuration(300);
    colorAnim.setInterpolator(fastOutSlowIn);
    colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mBackground.setBackgroundColor((Integer) animation.getAnimatedValue());
        }
    });
    colorAnim.start();
    mCard1.setY(mBackground.getHeight());
    mCard2.setTranslationY(mCard1.getTranslationY());
    mCard1.animate().translationY(0).setDuration(500).setInterpolator(linearOutSlowIn).setStartDelay(100);
    mCard2.animate().translationY(0).setInterpolator(linearOutSlowIn).setStartDelay(150).setDuration(500);
    mNavbarScrim.setAlpha(0f);
    mNavbarScrim.animate().alpha(1f).setDuration(500).setStartDelay(100);
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) Interpolator(android.view.animation.Interpolator) ValueAnimator(android.animation.ValueAnimator)

Example 69 with Interpolator

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

the class TaskStackAnimationHelper method startScrollToFocusedTaskAnimation.

/**
     * Starts the animation to focus the next {@link TaskView} when paging through recents.
     *
     * @return whether or not this will trigger a scroll in the stack
     */
public boolean startScrollToFocusedTaskAnimation(Task newFocusedTask, boolean requestViewFocus) {
    TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
    TaskStackViewScroller stackScroller = mStackView.getScroller();
    TaskStack stack = mStackView.getStack();
    final float curScroll = stackScroller.getStackScroll();
    final float newScroll = stackScroller.getBoundedStackScroll(stackLayout.getStackScrollForTask(newFocusedTask));
    boolean willScrollToFront = newScroll > curScroll;
    boolean willScroll = Float.compare(newScroll, curScroll) != 0;
    // Get the current set of task transforms
    int taskViewCount = mStackView.getTaskViews().size();
    ArrayList<Task> stackTasks = stack.getStackTasks();
    mStackView.getCurrentTaskTransforms(stackTasks, mTmpCurrentTaskTransforms);
    // Pick up the newly visible views after the scroll
    mStackView.bindVisibleTaskViews(newScroll);
    // Update the internal state
    stackLayout.setFocusState(TaskStackLayoutAlgorithm.STATE_FOCUSED);
    stackScroller.setStackScroll(newScroll, null);
    mStackView.cancelDeferredTaskViewLayoutAnimation();
    // Get the final set of task transforms
    mStackView.getLayoutTaskTransforms(newScroll, stackLayout.getFocusState(), stackTasks, true, /* ignoreTaskOverrides */
    mTmpFinalTaskTransforms);
    // Focus the task view
    TaskView newFocusedTaskView = mStackView.getChildViewForTask(newFocusedTask);
    if (newFocusedTaskView == null) {
        // Log the error if we have no task view, and skip the animation
        Log.e("TaskStackAnimationHelper", "b/27389156 null-task-view prebind:" + taskViewCount + " postbind:" + mStackView.getTaskViews().size() + " prescroll:" + curScroll + " postscroll: " + newScroll);
        return false;
    }
    newFocusedTaskView.setFocusedState(true, requestViewFocus);
    // Setup the end listener to return all the hidden views to the view pool after the
    // focus animation
    ReferenceCountedTrigger postAnimTrigger = new ReferenceCountedTrigger();
    postAnimTrigger.addLastDecrementRunnable(new Runnable() {

        @Override
        public void run() {
            mStackView.bindVisibleTaskViews(newScroll);
        }
    });
    List<TaskView> taskViews = mStackView.getTaskViews();
    taskViewCount = taskViews.size();
    int newFocusTaskViewIndex = taskViews.indexOf(newFocusedTaskView);
    for (int i = 0; i < taskViewCount; i++) {
        TaskView tv = taskViews.get(i);
        Task task = tv.getTask();
        if (mStackView.isIgnoredTask(task)) {
            continue;
        }
        int taskIndex = stackTasks.indexOf(task);
        TaskViewTransform fromTransform = mTmpCurrentTaskTransforms.get(taskIndex);
        TaskViewTransform toTransform = mTmpFinalTaskTransforms.get(taskIndex);
        // Update the task to the initial state (for the newly picked up tasks)
        mStackView.updateTaskViewToTransform(tv, fromTransform, AnimationProps.IMMEDIATE);
        int duration;
        Interpolator interpolator;
        if (willScrollToFront) {
            duration = calculateStaggeredAnimDuration(i);
            interpolator = FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR;
        } else {
            if (i < newFocusTaskViewIndex) {
                duration = 150 + ((newFocusTaskViewIndex - i - 1) * 50);
                interpolator = FOCUS_BEHIND_NEXT_TASK_INTERPOLATOR;
            } else if (i > newFocusTaskViewIndex) {
                duration = Math.max(100, 150 - ((i - newFocusTaskViewIndex - 1) * 50));
                interpolator = FOCUS_IN_FRONT_NEXT_TASK_INTERPOLATOR;
            } else {
                duration = 200;
                interpolator = FOCUS_NEXT_TASK_INTERPOLATOR;
            }
        }
        AnimationProps anim = new AnimationProps().setDuration(AnimationProps.BOUNDS, duration).setInterpolator(AnimationProps.BOUNDS, interpolator).setListener(postAnimTrigger.decrementOnAnimationEnd());
        postAnimTrigger.increment();
        mStackView.updateTaskViewToTransform(tv, toTransform, anim);
    }
    return willScroll;
}
Also used : Task(com.android.systemui.recents.model.Task) TaskStack(com.android.systemui.recents.model.TaskStack) ReferenceCountedTrigger(com.android.systemui.recents.misc.ReferenceCountedTrigger) TimeInterpolator(android.animation.TimeInterpolator) PathInterpolator(android.view.animation.PathInterpolator) Interpolator(android.view.animation.Interpolator)

Example 70 with Interpolator

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

the class StackScrollerDecorView method animateText.

/**
     * Animate the text to a new visibility.
     *
     * @param nowVisible should it now be visible
     * @param onFinishedRunnable A runnable which should be run when the animation is
     *        finished.
     */
private void animateText(boolean nowVisible, final Runnable onFinishedRunnable) {
    if (nowVisible != mIsVisible) {
        // Animate text
        float endValue = nowVisible ? 1.0f : 0.0f;
        Interpolator interpolator;
        if (nowVisible) {
            interpolator = Interpolators.ALPHA_IN;
        } else {
            interpolator = Interpolators.ALPHA_OUT;
        }
        mAnimating = true;
        mContent.animate().alpha(endValue).setInterpolator(interpolator).setDuration(260).withEndAction(new Runnable() {

            @Override
            public void run() {
                mAnimating = false;
                if (onFinishedRunnable != null) {
                    onFinishedRunnable.run();
                }
            }
        });
        mIsVisible = nowVisible;
    } else {
        if (onFinishedRunnable != null) {
            onFinishedRunnable.run();
        }
    }
}
Also used : Interpolator(android.view.animation.Interpolator)

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