Search in sources :

Example 11 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project GeekNews by codeestX.

the class CircularAnimUtil method hide.

/**
     * 由满向中间收缩,直到隐藏。
     */
@SuppressLint("NewApi")
public static void hide(final View myView, float endRadius, long durationMills) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        myView.setVisibility(View.INVISIBLE);
        return;
    }
    int cx = (myView.getLeft() + myView.getRight()) / 2;
    int cy = (myView.getTop() + myView.getBottom()) / 2;
    int w = myView.getWidth();
    int h = myView.getHeight();
    // 勾股定理 & 进一法
    int initialRadius = (int) Math.sqrt(w * w + h * h) + 1;
    Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, endRadius);
    anim.setDuration(durationMills);
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            myView.setVisibility(View.INVISIBLE);
        }
    });
    anim.start();
}
Also used : Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 12 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project GeekNews by codeestX.

the class CircularAnimUtil method startActivityForResult.

/**
     * 从指定View开始向四周伸张(伸张颜色或图片为colorOrImageRes), 然后进入另一个Activity,
     * 返回至 @thisActivity 后显示收缩动画。
     */
@SuppressLint("NewApi")
public static void startActivityForResult(final Activity thisActivity, final Intent intent, final Integer requestCode, final Bundle bundle, final View triggerView, int colorOrImageRes, long durationMills) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        thisActivity.startActivity(intent);
        return;
    }
    int[] location = new int[2];
    triggerView.getLocationInWindow(location);
    final int cx = location[0] + triggerView.getWidth() / 2;
    final int cy = location[1] + triggerView.getHeight() / 2;
    final ImageView view = new ImageView(thisActivity);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageResource(colorOrImageRes);
    final ViewGroup decorView = (ViewGroup) thisActivity.getWindow().getDecorView();
    int w = decorView.getWidth();
    int h = decorView.getHeight();
    decorView.addView(view, w, h);
    // 计算中心点至view边界的最大距离
    int maxW = Math.max(cx, w - cx);
    int maxH = Math.max(cy, h - cy);
    final int finalRadius = (int) Math.sqrt(maxW * maxW + maxH * maxH) + 1;
    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
    int maxRadius = (int) Math.sqrt(w * w + h * h) + 1;
    // 若使用默认时长,则需要根据水波扩散的距离来计算实际时间
    if (durationMills == PERFECT_MILLS) {
        // 算出实际边距与最大边距的比率
        double rate = 1d * finalRadius / maxRadius;
        // 水波扩散的距离与扩散时间成正比
        durationMills = (long) (PERFECT_MILLS * rate);
    }
    final long finalDuration = durationMills;
    anim.setDuration(finalDuration);
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (requestCode == null)
                thisActivity.startActivity(intent);
            else if (bundle == null)
                thisActivity.startActivityForResult(intent, requestCode);
            else
                thisActivity.startActivityForResult(intent, requestCode, bundle);
            // 默认渐隐过渡动画.
            thisActivity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            // 默认显示返回至当前Activity的动画.
            triggerView.postDelayed(new Runnable() {

                @Override
                public void run() {
                    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, finalRadius, 0);
                    anim.setDuration(finalDuration);
                    anim.addListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            try {
                                decorView.removeView(view);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    anim.start();
                }
            }, 1000);
        }
    });
    anim.start();
}
Also used : Animator(android.animation.Animator) ViewGroup(android.view.ViewGroup) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ImageView(android.widget.ImageView) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 13 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project ENViews by codeestX.

the class ENDownloadView method downloadAnim.

private void downloadAnim() {
    ValueAnimator downloadAnim = ValueAnimator.ofFloat(1.f, 100.f);
    downloadAnim.setDuration(mDownloadTime);
    downloadAnim.setInterpolator(new LinearInterpolator());
    downloadAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mFraction = valueAnimator.getAnimatedFraction();
            if (mUnit != DownloadUnit.NONE && mTotalSize > 0)
                mCurrentSize = mFraction * mTotalSize;
            invalidate();
        }
    });
    downloadAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentState = STATE_END;
            endAnim();
        }
    });
    downloadAnim.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) LinearInterpolator(android.view.animation.LinearInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Example 14 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project ENViews by codeestX.

the class ENDownloadView method endAnim.

private void endAnim() {
    ValueAnimator endAnim = ValueAnimator.ofFloat(1.f, 100.f);
    endAnim.setDuration(700);
    endAnim.setInterpolator(new OvershootInterpolator());
    endAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mFraction = valueAnimator.getAnimatedFraction();
            invalidate();
        }
    });
    endAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mFraction = 0;
            mCurrentState = STATE_RESET;
            if (onDownloadStateListener != null) {
                onDownloadStateListener.onDownloadFinish();
            }
        }
    });
    endAnim.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) OvershootInterpolator(android.view.animation.OvershootInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Example 15 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project ENViews by codeestX.

the class ENSearchView method start.

public void start() {
    if (mCurrentState == STATE_SEARCHING) {
        return;
    }
    mCurrentState = STATE_SEARCHING;
    ValueAnimator valueAnim = ValueAnimator.ofFloat(1.f, 100.f);
    valueAnim.setDuration(mDuration);
    valueAnim.setInterpolator(new LinearInterpolator());
    valueAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mFraction = valueAnimator.getAnimatedFraction();
            invalidate();
        }
    });
    valueAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentState = STATE_WAIT;
        }
    });
    valueAnim.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) LinearInterpolator(android.view.animation.LinearInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Aggregations

Animator (android.animation.Animator)848 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)848 ValueAnimator (android.animation.ValueAnimator)458 ObjectAnimator (android.animation.ObjectAnimator)456 AnimatorSet (android.animation.AnimatorSet)139 View (android.view.View)130 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 Rect (android.graphics.Rect)39 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)39 RenderNodeAnimator (android.view.RenderNodeAnimator)36 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)36 TimeAnimator (android.animation.TimeAnimator)30 ArrayList (java.util.ArrayList)26