Search in sources :

Example 61 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project gdk-compass-sample by googleglass.

the class CompassView method setupAnimator.

/**
     * Sets up a {@link ValueAnimator} that will be used to animate the compass
     * when the distance between two sensor events is large.
     */
private void setupAnimator() {
    mAnimator.setInterpolator(new LinearInterpolator());
    mAnimator.setDuration(250);
    // Notifies us at each frame of the animation so we can redraw the view.
    mAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            mAnimatedHeading = MathUtils.mod((Float) mAnimator.getAnimatedValue(), 360.0f);
            invalidate();
        }
    });
    // Notifies us when the animation is over. During an animation, the user's head may have
    // continued to move to a different orientation than the original destination angle of the
    // animation. Since we can't easily change the animation goal while it is running, we call
    // animateTo() again, which will either redraw at the new orientation (if the difference is
    // small enough), or start another animation to the new heading. This seems to produce
    // fluid results.
    mAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animator) {
            animateTo(mHeading);
        }
    });
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) LinearInterpolator(android.view.animation.LinearInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 62 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project ListenerMusicPlayer by hefuyicoder.

the class LyricView method doFlingAnimator.

/**
     * 滑行动画
     * @param velocity  滑动速度
     * */
private void doFlingAnimator(float velocity) {
    //注:     Math.abs(velocity)  < =  16000
    // 计算就已当前的滑动速度理论上的滑行距离是多少
    float distance = (velocity / Math.abs(velocity) * Math.min((Math.abs(velocity) * 0.050f), 640));
    // 综合考虑边界问题后得出的实际滑行距离
    float to = Math.min(Math.max(0, (mScrollY - distance)), (mLineCount - 1) * mLineHeight);
    mFlingAnimator = ValueAnimator.ofFloat(mScrollY, to);
    mFlingAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mScrollY = (float) animation.getAnimatedValue();
            measureCurrentLine();
            invalidateView();
        }
    });
    mFlingAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mVelocity = mMinStartUpSpeed - 1;
            mSliding = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mSliding = false;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
        }
    });
    mFlingAnimator.setDuration(420);
    mFlingAnimator.setInterpolator(new DecelerateInterpolator());
    mFlingAnimator.start();
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Example 63 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project ListenerMusicPlayer by hefuyicoder.

the class PlayPauseDrawable method getPausePlayAnimator.

public Animator getPausePlayAnimator() {
    final Animator anim = ObjectAnimator.ofFloat(this, PROGRESS, mIsPlay ? 1 : 0, mIsPlay ? 0 : 1);
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mIsPlay = !mIsPlay;
        }
    });
    return anim;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 64 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project material-components-android by material-components.

the class FloatingActionButtonIcs method show.

@Override
void show(@Nullable final InternalVisibilityChangedListener listener, final boolean fromUser) {
    if (isOrWillBeShown()) {
        // We either are or will soon be visible, skip the call
        return;
    }
    mView.animate().cancel();
    if (shouldAnimateVisibilityChange()) {
        mAnimState = ANIM_STATE_SHOWING;
        if (mView.getVisibility() != View.VISIBLE) {
            // If the view isn't visible currently, we'll animate it from a single pixel
            mView.setAlpha(0f);
            mView.setScaleY(0f);
            mView.setScaleX(0f);
        }
        mView.animate().scaleX(1f).scaleY(1f).alpha(1f).setDuration(SHOW_HIDE_ANIM_DURATION).setInterpolator(AnimationUtils.LINEAR_OUT_SLOW_IN_INTERPOLATOR).setListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationStart(Animator animation) {
                mView.internalSetVisibility(View.VISIBLE, fromUser);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mAnimState = ANIM_STATE_NONE;
                if (listener != null) {
                    listener.onShown();
                }
            }
        });
    } else {
        mView.internalSetVisibility(View.VISIBLE, fromUser);
        mView.setAlpha(1f);
        mView.setScaleY(1f);
        mView.setScaleX(1f);
        if (listener != null) {
            listener.onShown();
        }
    }
}
Also used : Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 65 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project material-components-android by material-components.

the class FloatingActionButtonIcs method hide.

@Override
void hide(@Nullable final InternalVisibilityChangedListener listener, final boolean fromUser) {
    if (isOrWillBeHidden()) {
        // We either are or will soon be hidden, skip the call
        return;
    }
    mView.animate().cancel();
    if (shouldAnimateVisibilityChange()) {
        mAnimState = ANIM_STATE_HIDING;
        mView.animate().scaleX(0f).scaleY(0f).alpha(0f).setDuration(SHOW_HIDE_ANIM_DURATION).setInterpolator(AnimationUtils.FAST_OUT_LINEAR_IN_INTERPOLATOR).setListener(new AnimatorListenerAdapter() {

            private boolean mCancelled;

            @Override
            public void onAnimationStart(Animator animation) {
                mView.internalSetVisibility(View.VISIBLE, fromUser);
                mCancelled = false;
            }

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

            @Override
            public void onAnimationEnd(Animator animation) {
                mAnimState = ANIM_STATE_NONE;
                if (!mCancelled) {
                    mView.internalSetVisibility(fromUser ? View.GONE : View.INVISIBLE, fromUser);
                    if (listener != null) {
                        listener.onHidden();
                    }
                }
            }
        });
    } else {
        // If the view isn't laid out, or we're in the editor, don't run the animation
        mView.internalSetVisibility(fromUser ? View.GONE : View.INVISIBLE, fromUser);
        if (listener != null) {
            listener.onHidden();
        }
    }
}
Also used : Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Aggregations

Animator (android.animation.Animator)868 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)868 ObjectAnimator (android.animation.ObjectAnimator)464 ValueAnimator (android.animation.ValueAnimator)459 AnimatorSet (android.animation.AnimatorSet)144 View (android.view.View)131 ViewGroup (android.view.ViewGroup)92 PropertyValuesHolder (android.animation.PropertyValuesHolder)70 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)70 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)62 ImageView (android.widget.ImageView)45 TextView (android.widget.TextView)43 Interpolator (android.view.animation.Interpolator)42 Paint (android.graphics.Paint)41 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)41 Rect (android.graphics.Rect)40 RenderNodeAnimator (android.view.RenderNodeAnimator)36 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)36 TimeAnimator (android.animation.TimeAnimator)30 TargetApi (android.annotation.TargetApi)30