Search in sources :

Example 16 with Animator

use of android.animation.Animator 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 17 with Animator

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

the class CircularAnimUtil method show.

/**
     * 向四周伸张,直到完成显示。
     */
@SuppressLint("NewApi")
public static void show(View myView, float startRadius, long durationMills) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        myView.setVisibility(View.VISIBLE);
        return;
    }
    int cx = (myView.getLeft() + myView.getRight()) / 2;
    int cy = (myView.getTop() + myView.getBottom()) / 2;
    int w = myView.getWidth();
    int h = myView.getHeight();
    // 勾股定理 & 进一法
    int finalRadius = (int) Math.sqrt(w * w + h * h) + 1;
    Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, startRadius, finalRadius);
    myView.setVisibility(View.VISIBLE);
    anim.setDuration(durationMills);
    anim.start();
}
Also used : Animator(android.animation.Animator) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 18 with Animator

use of android.animation.Animator 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 19 with Animator

use of android.animation.Animator 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 20 with Animator

use of android.animation.Animator 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)

Aggregations

Animator (android.animation.Animator)1384 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)848 ObjectAnimator (android.animation.ObjectAnimator)712 ValueAnimator (android.animation.ValueAnimator)627 AnimatorSet (android.animation.AnimatorSet)278 View (android.view.View)227 ViewGroup (android.view.ViewGroup)110 ArrayList (java.util.ArrayList)101 PropertyValuesHolder (android.animation.PropertyValuesHolder)94 Paint (android.graphics.Paint)78 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)75 ImageView (android.widget.ImageView)68 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)66 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)65 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)61 TextView (android.widget.TextView)60 RenderNodeAnimator (android.view.RenderNodeAnimator)51 ViewPropertyAnimator (android.view.ViewPropertyAnimator)50 Rect (android.graphics.Rect)49 Interpolator (android.view.animation.Interpolator)49