• 自定义view属性动画



    import android.animation.AnimatorSet;
    import android.animation.TimeInterpolator;
    import android.animation.TypeEvaluator;
    import android.animation.ValueAnimator;
    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.graphics.Canvas;
    import android.graphics.Paint;
    import android.graphics.Point;
    import android.os.Build;
    import android.os.Handler;
    import android.os.HandlerThread;
    import android.os.Message;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.View;

    import java.util.Timer;
    import java.util.TimerTask;

    /**
    * Created by Administrator on 2018/5/2.
    */

    public class MyView extends View {

    private Paint mPaint;
    private Point mPoint;
    private int mColor;
    private ValueAnimator animator1;
    private ValueAnimator animator;
    private Context context;
    private Timer timer;
    private int i = 1;

    public MyView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initPaint();
    }

    public MyView(Context context) {
    super(context);
    initPaint();
    }

    private void initPaint() {
    mPaint = new Paint();
    mPaint.setColor(0xFFF00000);
    mPaint.setAntiAlias(true); // 鎶楅敮榻?
    }

    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawCircle(mPoint.x, mPoint.y, 60, mPaint);
    Log.d("jljs-----x",""+mPoint.x);
    Log.d("jljs",""+mPoint.y);
    }

    public void start(final Context context) {
    this.context = context;
    animator = ValueAnimator.ofObject(new PointEvaluator(),
    new Point(60, 60), new Point(990, 1680));
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
    mPoint = (Point) animation.getAnimatedValue();
    invalidate();
    }
    });
    if (Build.VERSION.SDK_INT < 21){
    animator1 = ValueAnimator.ofObject(new TextArgbEvaluator(), 0xFFF000ff, 0xFF00FF00);
    }else {
    animator1 = ValueAnimator.ofArgb(0xFFFff000, 0xFF000000);
    }
    animator1.setRepeatCount(ValueAnimator.INFINITE);
    animator1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
    mColor = (int) animation.getAnimatedValue();
    mPaint.setColor(mColor);
    }
    });

    AnimatorSet animationSet = new AnimatorSet();
    animationSet.setDuration(10000);
    animationSet.setInterpolator(new LgDecelerateInterpolator());
    animationSet.play(animator).with(animator1);
    animationSet.start();

    @SuppressLint("HandlerLeak") final Handler mHandler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
    super.handleMessage(msg);
    int obj = (int) msg.obj;
    if (obj == 5){
    Intent intent = new Intent(context, Main2Activity.class);
    context.startActivity(intent);
    timer.cancel();
    MainActivity mainActivity = (MainActivity) context;
    mainActivity.finish();
    }
    }
    };
    timer = new Timer();
    TimerTask task = new TimerTask() {
    @Override
    public void run() {
    i++;
    Message message = new Message();
    message.obj = i;
    mHandler.sendMessage(message);

    }
    };
    timer.schedule(task,0,1000);

    }

    class PointEvaluator implements TypeEvaluator {

    @Override
    public Object evaluate(float fraction, Object startValue, Object endValue) {
    Point startPoint = (Point) startValue;
    Point endPoint = (Point) endValue;

    int x = (int) (startPoint.x + fraction * (endPoint.x - startPoint.x));
    int y = (int) (startPoint.y + fraction * (endPoint.y - startPoint.y));

    return new Point(x, y);
    }
    }

    class LgDecelerateInterpolator implements TimeInterpolator {

    private float background;

    public LgDecelerateInterpolator() {
    background = 10;
    }

    @Override
    public float getInterpolation(float input) {
    return (1 - (float) Math.pow(background, -input));
    }
    }
    private class TextArgbEvaluator implements TypeEvaluator {
    //杩欐�浠g爜鏄�粠婧愮爜涓�姞鍑烘潵鐨?
    public Object evaluate(float fraction, Object startValue, Object endValue) {
    int startInt = (Integer) startValue;
    int startA = (startInt >> 24) & 0xff;
    int startR = (startInt >> 16) & 0xff;
    int startG = (startInt >> 8) & 0xff;
    int startB = startInt & 0xff;

    int endInt = (Integer) endValue;
    int endA = (endInt >> 24) & 0xff;
    int endR = (endInt >> 16) & 0xff;
    int endG = (endInt >> 8) & 0xff;
    int endB = endInt & 0xff;

    return (int) ((startA + (int) (fraction * (endA - startA))) << 24) |
    (int) ((startR + (int) (fraction * (endR - startR))) << 16) |
    (int) ((startG + (int) (fraction * (endG - startG))) << 8) |
    (int) ((startB + (int) (fraction * (endB - startB))));
    }
    }
    public class FloatEvaluator implements TypeEvaluator<Number> {
    public Float evaluate(float fraction, Number startValue, Number endValue) {
    float startFloat = startValue.floatValue();
    return startFloat + fraction * (endValue.floatValue() - startFloat);
    }
    }
    }

  • 相关阅读:
    wsl中的git问题
    接口测试框架实战(三)| JSON 请求与响应断言
    接口测试框架实战(二)| 接口请求断言
    面试大厂测试开发之前,你需要做好哪些准备?
    接口测试框架实战(一) | Requests 与接口请求构造
    实战 | UI 自动化测试框架设计与 PageObject 改造
    用 Pytest+Allure 生成漂亮的 HTML 图形化测试报告
    外包测试的职业发展利弊分析与建议
    做软件测试,到底能不能去外包?
    移动自动化测试入门,你必须了解的背景知识和工具特性
  • 原文地址:https://www.cnblogs.com/Nigeria/p/8979305.html
Copyright © 2020-2023  润新知