package com.test.BTClient;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.webkit.WebHistoryItem;
import org.jetbrains.annotations.Nullable;
import static com.test.BTClient.util.dpToPixel;
import static com.test.BTClient.util.setColor;
/**
* Created by T_baby on 19/06/11.
*/
public class ProcessView2 extends View {
//刻度宽度
final float sWith = dpToPixel(3);
//刻度总个数
final int mCount = 50;
//定义进度
float progress = 60;
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
//定义属性动画
ObjectAnimator animator = ObjectAnimator.ofFloat(this, "progress", 0, progress);
public ProcessView2(Context context) {
super(context);
}
public ProcessView2(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public ProcessView2(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
{
animator.setDuration(2000);
animator.setInterpolator(new FastOutSlowInInterpolator());
}
public float getProgress() {
return progress;
}
public void setProgress(float progress) {
this.progress = progress;
invalidate();
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
animator.start();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
animator.end();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float centerX = getWidth() / 2;
float centerY = getHeight() / 2;
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeCap(Paint.Cap.BUTT);
paint.setStrokeWidth(dpToPixel(30));
//刻度
canvas.save();
int a=0;
int b=0;
for (int i = 0; i <mCount; i++) {
//渐变色 刻度盘划过部
paint.setColor(setColor(i, mCount));
if (i >= (int) (progress / 2)) {
//刻度盘 未划过部分
paint.setColor(Color.GRAY);
a=a+1;
}else{
b=b+1;
}
canvas.drawLine(0, centerY, sWith, centerY, paint);
canvas.translate(30,0);
}
Log.e(a+"",b+"");
canvas.restore();
}
}