package com.basic.security.widget;
|
|
import android.animation.ValueAnimator;
|
import android.content.Context;
|
import android.graphics.Canvas;
|
import android.graphics.Color;
|
import android.graphics.Paint;
|
import android.util.AttributeSet;
|
import android.view.View;
|
import android.view.animation.LinearInterpolator;
|
|
import com.basic.security.R;
|
import com.basic.security.base.BaseApplication;
|
|
public class PlusView extends View {
|
|
public float value;
|
private Paint mPaint;
|
private ValueAnimator anim;
|
|
public PlusView(Context context) {
|
super(context);
|
init();
|
}
|
|
public PlusView(Context context, AttributeSet attrs) {
|
super(context, attrs);
|
init();
|
}
|
|
public PlusView(Context context, AttributeSet attrs, int defStyle) {
|
super(context, attrs, defStyle);
|
init();
|
}
|
|
private void init() {
|
setLayerType(LAYER_TYPE_SOFTWARE, null);
|
mPaint = new Paint();
|
mPaint.setColor(Color.parseColor("#74F8F5"));
|
mPaint.setStrokeWidth(BaseApplication.getApplication().activity.getResources().getDimension(R.dimen.h3));
|
|
startAnimation();
|
// mPaint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.SOLID));
|
}
|
|
@Override
|
protected void onDraw(Canvas canvas) {
|
super.onDraw(canvas);
|
int width = this.getWidth();
|
// int height = this.getHeight();
|
|
// int lineLong = (int) BaseApplication.getApplication().activity.getResources().getDimension(R.dimen.h70);
|
|
// // 横
|
// canvas.drawLine(width / 2 - lineLong / 2, height / 2, width / 2 + lineLong / 2, height / 2, mPaint);
|
//
|
// // 竖
|
// canvas.drawLine(width / 2, height / 2 - lineLong / 2, width / 2, height / 2 + lineLong / 2, mPaint);
|
|
|
canvas.drawLine(0, value, width, value + 1, mPaint);
|
|
}
|
|
|
public void startAnimation() {
|
anim = ValueAnimator.ofFloat(0, (int) BaseApplication.getApplication().activity.getResources().getDimension(R.dimen.h310));
|
anim.setRepeatCount(ValueAnimator.INFINITE);
|
// anim.setRepeatMode(ValueAnimator.REVERSE);
|
anim.setDuration(2000);
|
anim.setInterpolator(new LinearInterpolator());
|
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
@Override
|
public void onAnimationUpdate(ValueAnimator animation) {
|
value = (Float) animation.getAnimatedValue();
|
postInvalidate();
|
}
|
});
|
anim.start();
|
}
|
|
}
|