|
@@ -4,10 +4,12 @@ import android.content.Context;
|
|
|
import android.content.res.Resources;
|
|
|
import android.graphics.Canvas;
|
|
|
import android.graphics.Color;
|
|
|
+import android.graphics.LinearGradient;
|
|
|
import android.graphics.Paint;
|
|
|
import android.graphics.Path;
|
|
|
import android.graphics.PorterDuff;
|
|
|
import android.graphics.PorterDuffXfermode;
|
|
|
+import android.graphics.RadialGradient;
|
|
|
import android.graphics.Rect;
|
|
|
import android.graphics.RectF;
|
|
|
import android.graphics.Shader;
|
|
@@ -51,6 +53,10 @@ public class DashBoardView extends View {
|
|
|
private double innerGradientRadiusPercent = 0.75;//渐变线的圆半径比例
|
|
|
private int pointerAngle = 0;
|
|
|
private int currentProgress = 0;
|
|
|
+ private RectF whiteAreaRectF;
|
|
|
+ private Paint mWhiteAreaPaint;
|
|
|
+ private int whiteAreaStartColor;
|
|
|
+ private int whiteAreaEndColor;
|
|
|
|
|
|
public DashBoardView(Context context) {
|
|
|
this(context, null);
|
|
@@ -66,6 +72,9 @@ public class DashBoardView extends View {
|
|
|
}
|
|
|
|
|
|
private void init() {
|
|
|
+
|
|
|
+ whiteAreaStartColor = Color.parseColor("#006DB7FF");
|
|
|
+ whiteAreaEndColor = Color.parseColor("#606DB7FF");
|
|
|
mLinePaint = new Paint();
|
|
|
mLinePaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
mLinePaint.setStrokeWidth(SizeUtils.dp2px(1));
|
|
@@ -90,6 +99,8 @@ public class DashBoardView extends View {
|
|
|
mPointerPaint.setColor(Color.WHITE);
|
|
|
mPointerPaint.setStyle(Paint.Style.FILL);
|
|
|
mPointerPaint.setStrokeWidth(SizeUtils.dp2px(2));
|
|
|
+
|
|
|
+// initWhiteAreaPaint();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -104,6 +115,7 @@ public class DashBoardView extends View {
|
|
|
mRadius = (int) ((width / 2) * 0.8);
|
|
|
pointerHeight = (float) (mRadius * innerGradientRadiusPercent + SizeUtils.dp2px(9));//加上渐变环线笔的宽度的一半
|
|
|
initGradientPaint();
|
|
|
+ initWhiteAreaPaint();
|
|
|
|
|
|
mGradientLineRectF = new RectF();
|
|
|
mGradientLineRectF.set(
|
|
@@ -112,6 +124,11 @@ public class DashBoardView extends View {
|
|
|
(float) (cx + mRadius * innerGradientRadiusPercent),
|
|
|
(float) (cy + (mRadius * innerGradientRadiusPercent))
|
|
|
);
|
|
|
+ whiteAreaRectF = new RectF();
|
|
|
+ whiteAreaRectF.set((float) (cx - mRadius * innerGradientRadiusPercent),
|
|
|
+ (float) (cy - (mRadius * innerGradientRadiusPercent) + SizeUtils.dp2px(9)),
|
|
|
+ (float) (cx + mRadius * innerGradientRadiusPercent),
|
|
|
+ (float) (cy + (mRadius * innerGradientRadiusPercent) - SizeUtils.dp2px(9)));
|
|
|
}
|
|
|
|
|
|
private void initGradientPaint() {
|
|
@@ -130,10 +147,26 @@ public class DashBoardView extends View {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void initWhiteAreaPaint() {
|
|
|
+ mWhiteAreaPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
+ mWhiteAreaPaint.setDither(true);
|
|
|
+ mWhiteAreaPaint.setAntiAlias(true);
|
|
|
+// Shader mShader = new LinearGradient(0,0,100,100,Color.parseColor("#6DB7FF"),Color.parseColor("#006DB7FF"), Shader.TileMode.MIRROR);
|
|
|
+// mWhiteAreaPaint.setColor(Color.parseColor("#256DB7FF"));
|
|
|
+ int r= (int) (mRadius * innerGradientRadiusPercent- SizeUtils.dp2px(9));
|
|
|
+ Shader mShader = new RadialGradient(cx,cy,r,whiteAreaStartColor,whiteAreaEndColor,Shader.TileMode.MIRROR);
|
|
|
+ mWhiteAreaPaint.setShader(mShader);
|
|
|
+ mWhiteAreaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
|
|
|
+ mWhiteAreaPaint.setStyle(Paint.Style.FILL);
|
|
|
+ mWhiteAreaPaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
+ mWhiteAreaPaint.setStrokeWidth(1);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
super.onDraw(canvas);
|
|
|
// canvas.drawLine(cx, cy, cx, 0, mCenterPointPaint);
|
|
|
+ canvas.drawArc(whiteAreaRectF, -108, 36, true, mWhiteAreaPaint);
|
|
|
canvas.drawArc(mGradientLineRectF, -180, 180, false, mOuterGradientPaint);
|
|
|
float[] floats = countPointerPosition(currentProgress);
|
|
|
canvas.drawLine(cx, cy, floats[0], floats[1], mPointerPaint);
|
|
@@ -245,7 +278,7 @@ public class DashBoardView extends View {
|
|
|
|
|
|
if (diff > 0) {
|
|
|
double angle = (diff / maxMusicHzOffset) * mSweepAngle / 2;
|
|
|
- Log.i("zxc","angle:"+angle);
|
|
|
+ Log.i("zxc", "angle:" + angle);
|
|
|
float radian = (float) Math.toRadians(angle);
|
|
|
points[0] = (float) (cx + Math.sin(radian) * pointerHeight);
|
|
|
points[1] = (float) (cy - Math.cos(radian) * pointerHeight);
|
|
@@ -254,13 +287,13 @@ public class DashBoardView extends View {
|
|
|
points[1] = (float) (cy - pointerHeight);
|
|
|
} else {
|
|
|
double angle = Math.abs((diff / minMusicHzOffset) * mSweepAngle / 2);
|
|
|
- Log.i("zxc","angle:"+angle);
|
|
|
+ Log.i("zxc", "angle:" + angle);
|
|
|
float radian = (float) Math.toRadians(angle);
|
|
|
points[0] = (float) (cx - Math.sin(radian) * pointerHeight);
|
|
|
points[1] = (float) (cy - Math.cos(radian) * pointerHeight);
|
|
|
}
|
|
|
- Log.i("zxc","points[0]:"+points[0]);
|
|
|
- Log.i("zxc","points[1]:"+points[1]);
|
|
|
+ Log.i("zxc", "points[0]:" + points[0]);
|
|
|
+ Log.i("zxc", "points[1]:" + points[1]);
|
|
|
return points;
|
|
|
}
|
|
|
|