|
@@ -3,6 +3,8 @@ package com.cooleshow.musictuner.widget;
|
|
|
import android.animation.ValueAnimator;
|
|
|
import android.content.Context;
|
|
|
import android.content.res.Resources;
|
|
|
+import android.graphics.Bitmap;
|
|
|
+import android.graphics.BitmapFactory;
|
|
|
import android.graphics.Canvas;
|
|
|
import android.graphics.Color;
|
|
|
import android.graphics.LinearGradient;
|
|
@@ -15,6 +17,7 @@ import android.graphics.Rect;
|
|
|
import android.graphics.RectF;
|
|
|
import android.graphics.Shader;
|
|
|
import android.graphics.SweepGradient;
|
|
|
+import android.graphics.Typeface;
|
|
|
import android.util.AttributeSet;
|
|
|
import android.util.Log;
|
|
|
import android.util.TypedValue;
|
|
@@ -22,6 +25,7 @@ import android.view.View;
|
|
|
|
|
|
import com.cooleshow.base.utils.LOG;
|
|
|
import com.cooleshow.base.utils.SizeUtils;
|
|
|
+import com.cooleshow.musictuner.R;
|
|
|
import com.cooleshow.musictuner.constants.MusicTunerConstants;
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
@@ -30,6 +34,7 @@ import androidx.annotation.Nullable;
|
|
|
* Author by pq, Date on 2022/9/26.
|
|
|
*/
|
|
|
public class DashBoardView extends View {
|
|
|
+ private static final String TAG = "DashBoardView";
|
|
|
private int cx = 0;//圆心点坐标x
|
|
|
private int cy = 0;//圆心点坐标y
|
|
|
private int width;
|
|
@@ -53,16 +58,31 @@ public class DashBoardView extends View {
|
|
|
private RectF mGradientLineRectF;
|
|
|
private Paint mPointerPaint;
|
|
|
private float pointerHeight = 0;//指针高度
|
|
|
- private double innerGradientRadiusPercent = 0.75;//渐变线的圆半径比例
|
|
|
+ private double innerGradientRadiusPercent = 0.68;//渐变线的圆半径比例
|
|
|
+ private double innerHighlightRadiusPercent = 0.83;//中心高亮
|
|
|
+ private double scaleRoundPercent = 0.95;//刻度圆环比例
|
|
|
+ private float centerRound1RadiusPercent = 0.49f;//内圆半径比例
|
|
|
+ private float centerRound2RadiusPercent = 0.36f;//最里面内圆半径比例
|
|
|
private int pointerAngle = 0;
|
|
|
private float currentProgress = 0;
|
|
|
private RectF whiteAreaRectF;
|
|
|
private Paint mWhiteAreaPaint;
|
|
|
private int whiteAreaStartColor;
|
|
|
private int whiteAreaEndColor;
|
|
|
+ private RectF mWhiteBoardBgRect;
|
|
|
+ private Paint mBgPaint;
|
|
|
+ private Paint mCenterRound1Paint;
|
|
|
+ private Paint mCenterRound2Paint;
|
|
|
+ private Bitmap triangleBitmap;
|
|
|
+ private Rect triangleRect1;
|
|
|
+ private Rect triangleShowRect;
|
|
|
|
|
|
private ValueAnimator mAnimator;
|
|
|
|
|
|
+ private Paint mCorrectPaint;
|
|
|
+
|
|
|
+ private boolean isCorrect = false;
|
|
|
+
|
|
|
public DashBoardView(Context context) {
|
|
|
this(context, null);
|
|
|
}
|
|
@@ -77,9 +97,14 @@ public class DashBoardView extends View {
|
|
|
}
|
|
|
|
|
|
private void init() {
|
|
|
+ triangleBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_music_tuner_triangle_small);
|
|
|
+ int width = triangleBitmap.getWidth();
|
|
|
+ int height = triangleBitmap.getHeight();
|
|
|
+ triangleRect1 = new Rect(0, 0, width, height);
|
|
|
+
|
|
|
|
|
|
- whiteAreaStartColor = Color.parseColor("#006DB7FF");
|
|
|
- whiteAreaEndColor = Color.parseColor("#606DB7FF");
|
|
|
+ whiteAreaStartColor = Color.parseColor("#8AD0FF");
|
|
|
+ whiteAreaEndColor = Color.parseColor("#006DBCFF");
|
|
|
mLinePaint = new Paint();
|
|
|
mLinePaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
mLinePaint.setStrokeWidth(SizeUtils.dp2px(1));
|
|
@@ -92,20 +117,20 @@ public class DashBoardView extends View {
|
|
|
mTextValuePaint = new Paint();
|
|
|
mTextValuePaint.setAntiAlias(true);
|
|
|
mTextValuePaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
- mTextValuePaint.setColor(Color.WHITE);
|
|
|
- mTextValuePaint.setTextSize(SizeUtils.sp2px(10));
|
|
|
+ mTextValuePaint.setColor(getResources().getColor(com.cooleshow.base.R.color.color_333333));
|
|
|
+ mTextValuePaint.setTextSize(SizeUtils.sp2px(14));
|
|
|
mTextValuePaint.setTextAlign(Paint.Align.LEFT);
|
|
|
mTextValuePaint.setStyle(Paint.Style.FILL);
|
|
|
- mTextValuePaint.setAlpha(160);
|
|
|
+ mTextValuePaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
|
|
|
|
|
|
mPointerPaint = new Paint();
|
|
|
mPointerPaint.setAntiAlias(true);
|
|
|
mPointerPaint.setDither(true);
|
|
|
- mPointerPaint.setColor(Color.WHITE);
|
|
|
+ mPointerPaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
+ mPointerPaint.setColor(getContext().getResources().getColor(R.color.color_0082ff));
|
|
|
mPointerPaint.setStyle(Paint.Style.FILL);
|
|
|
- mPointerPaint.setStrokeWidth(SizeUtils.dp2px(2));
|
|
|
-
|
|
|
-// initWhiteAreaPaint();
|
|
|
+ mPointerPaint.setStrokeWidth(SizeUtils.dp2px(3));
|
|
|
+ initCenterRound2Paint();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -115,12 +140,25 @@ public class DashBoardView extends View {
|
|
|
height = getHeight();// Get View Height
|
|
|
width = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
height = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
- cx = width / 2;
|
|
|
+ Log.i(TAG, "width2:" + width);
|
|
|
+ Log.i(TAG, "height2:" + height);
|
|
|
+ cx = width / 2;//坐标圆点x坐标
|
|
|
cy = height - paddingBottom;
|
|
|
+
|
|
|
mRadius = (int) ((width / 2) * 0.8);
|
|
|
- pointerHeight = (float) (mRadius * innerGradientRadiusPercent + SizeUtils.dp2px(9));//加上渐变环线笔的宽度的一半
|
|
|
- initGradientPaint();
|
|
|
- initWhiteAreaPaint();
|
|
|
+ Log.i(TAG, "mRadius:" + mRadius);
|
|
|
+ //底部多预留30度角度的高度
|
|
|
+ double sin = Math.sin(2 * Math.PI / 360 * 30);
|
|
|
+ paddingBottom = (int) (mRadius * sin);
|
|
|
+ Log.i(TAG, "paddingBottom:" + paddingBottom);
|
|
|
+
|
|
|
+ height = cx + paddingBottom;//View的实际需要高度
|
|
|
+
|
|
|
+ cy = height - paddingBottom;//坐标圆点y坐标
|
|
|
+ setMeasuredDimension(getWidth(), height);
|
|
|
+
|
|
|
+ pointerHeight = (float) (mRadius * innerGradientRadiusPercent + SizeUtils.dp2px(16));//加上渐变环线笔的宽度的一半
|
|
|
+
|
|
|
|
|
|
mGradientLineRectF = new RectF();
|
|
|
mGradientLineRectF.set(
|
|
@@ -130,10 +168,23 @@ public class DashBoardView extends View {
|
|
|
(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)));
|
|
|
+ whiteAreaRectF.set((float) (cx - mRadius * innerHighlightRadiusPercent),
|
|
|
+ (float) (cy - (mRadius * innerHighlightRadiusPercent)),
|
|
|
+ (float) (cx + mRadius * innerHighlightRadiusPercent),
|
|
|
+ (float) (cy + (mRadius * innerHighlightRadiusPercent)));
|
|
|
+
|
|
|
+ mWhiteBoardBgRect = new RectF();
|
|
|
+ double bgRadiusPercent = 1.0;
|
|
|
+ mWhiteBoardBgRect.set((float) (cx - mRadius * bgRadiusPercent),
|
|
|
+ (float) (cy - (mRadius * bgRadiusPercent)),
|
|
|
+ (float) (cx + mRadius * bgRadiusPercent),
|
|
|
+ (float) (cy + (mRadius * bgRadiusPercent)));
|
|
|
+
|
|
|
+
|
|
|
+ initGradientPaint();
|
|
|
+ initWhiteAreaPaint();
|
|
|
+ initBgPaint();
|
|
|
+ initCenterRound1Paint();
|
|
|
}
|
|
|
|
|
|
private void initGradientPaint() {
|
|
@@ -142,9 +193,17 @@ public class DashBoardView extends View {
|
|
|
mOuterGradientPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
//设置圆环渐变色渲染
|
|
|
mOuterGradientPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
|
|
|
- float position[] = {0f, 0.25f, 0.5f, 0.875f};
|
|
|
- int[] colors = new int[]{getResources().getColor(com.cooleshow.base.R.color.color_4effc2), getResources().getColor(com.cooleshow.base.R.color.color_4effc2), getResources().getColor(com.cooleshow.base.R.color.color_ff41d3), getResources().getColor(com.cooleshow.base.R.color.color_4effc2)};
|
|
|
+ float position[] = {0f, 0.25f, 0.5f, 0.75f, 1.0f};
|
|
|
+ int[] colors = new int[]{getColor(R.color.color_abeeff), Color.TRANSPARENT, getColor(R.color.color_50c0ff), getColor(R.color.color_7cd3ff), getColor(R.color.color_abeeff)};
|
|
|
Shader mShader = new SweepGradient(cx, cy, colors, position);
|
|
|
+
|
|
|
+
|
|
|
+// float outerGradientRadius = (float) (mRadius * innerHighlightRadiusPercent);
|
|
|
+// Shader mShader = new LinearGradient(cx, cy-outerGradientRadius, cx, cy+outerGradientRadius, getResources().getColor(com.cooleshow.base.R.color.color_0aa6ff),
|
|
|
+// getResources().getColor(com.cooleshow.base.R.color.color_74E4FF), Shader.TileMode.CLAMP);
|
|
|
+ mOuterGradientPaint.setShader(mShader);
|
|
|
+
|
|
|
+
|
|
|
mOuterGradientPaint.setShader(mShader);
|
|
|
mOuterGradientPaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
mOuterGradientPaint.setStyle(Paint.Style.STROKE);
|
|
@@ -153,26 +212,120 @@ public class DashBoardView extends View {
|
|
|
}
|
|
|
|
|
|
private void initWhiteAreaPaint() {
|
|
|
- mWhiteAreaPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
- mWhiteAreaPaint.setDither(true);
|
|
|
- mWhiteAreaPaint.setAntiAlias(true);
|
|
|
+ if (mWhiteAreaPaint == null) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initBgPaint() {
|
|
|
+ if (mBgPaint == null) {
|
|
|
+ mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
+ mBgPaint.setDither(true);
|
|
|
+ mBgPaint.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);
|
|
|
+// int r = (int) (mRadius * innerGradientRadiusPercent - SizeUtils.dp2px(9));
|
|
|
+// Shader mShader = new RadialGradient(cx, cy, r, whiteAreaStartColor, whiteAreaEndColor, Shader.TileMode.MIRROR);
|
|
|
+// mBgPaint.setShader(mShader);
|
|
|
+
|
|
|
+ mBgPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
|
|
|
+ float position[] = {0f, 0.075f, 0.25f, 0.425f, 0.5f, 0.525f, 0.75f, 0.975f, 1.0f};
|
|
|
+ int[] colors = new int[]{getResources().getColor(R.color.white_35),
|
|
|
+ getResources().getColor(com.cooleshow.base.R.color.transparent),
|
|
|
+ getResources().getColor(com.cooleshow.base.R.color.transparent),
|
|
|
+ getResources().getColor(com.cooleshow.base.R.color.transparent),
|
|
|
+ getResources().getColor(R.color.white_35),
|
|
|
+ getResources().getColor(R.color.white_75),
|
|
|
+ getResources().getColor(com.cooleshow.base.R.color.white),
|
|
|
+ getResources().getColor(R.color.white_75),
|
|
|
+ getResources().getColor(R.color.white_35)};
|
|
|
+ Shader mShader = new SweepGradient(cx, cy, colors, position);
|
|
|
+ mBgPaint.setShader(mShader);
|
|
|
+ mBgPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
|
|
|
+ mBgPaint.setStyle(Paint.Style.FILL);
|
|
|
+ mBgPaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
+ mBgPaint.setStrokeWidth(1);
|
|
|
+ mBgPaint.setColor(Color.WHITE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initCenterRound1Paint() {
|
|
|
+ if (mCenterRound1Paint == null) {
|
|
|
+ mCenterRound1Paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
+ mCenterRound1Paint.setDither(true);
|
|
|
+ mCenterRound1Paint.setAntiAlias(true);
|
|
|
+ float centerRoundRadius = mRadius * centerRound1RadiusPercent;
|
|
|
+ Shader mShader = new LinearGradient(cx, cy - centerRoundRadius, cx, cy + centerRoundRadius, Color.WHITE, Color.parseColor("#D8ECFE"), Shader.TileMode.CLAMP);
|
|
|
+ mCenterRound1Paint.setShader(mShader);
|
|
|
+
|
|
|
+ mCenterRound1Paint.setStyle(Paint.Style.FILL);
|
|
|
+ mCenterRound1Paint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
+ mCenterRound1Paint.setStrokeWidth(1);
|
|
|
+ mCenterRound1Paint.setColor(Color.RED);
|
|
|
+
|
|
|
+ float s = centerRoundRadius - SizeUtils.dp2px(5);
|
|
|
+ int left = cx - triangleBitmap.getWidth() / 2;
|
|
|
+ int top = (int) (cy - s);
|
|
|
+ int right = cx + triangleBitmap.getWidth() / 2;
|
|
|
+ int bottom = top + triangleBitmap.getHeight();
|
|
|
+ triangleShowRect = new Rect(left, top, right, bottom);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mCorrectPaint == null) {
|
|
|
+ mCorrectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
+ float centerRoundRadius = mRadius * 0.36f;
|
|
|
+ int startColor = getColor(R.color.color_90e9ff);
|
|
|
+ int endColor = getColor(R.color.color_11a9ff);
|
|
|
+ Shader shader = new LinearGradient(cx, cy - centerRoundRadius, cx, cy + centerRoundRadius, startColor, endColor, Shader.TileMode.CLAMP);
|
|
|
+ mCorrectPaint.setShader(shader);
|
|
|
+ mCorrectPaint.setDither(true);
|
|
|
+ mCorrectPaint.setAntiAlias(true);
|
|
|
+ mCorrectPaint.setStyle(Paint.Style.FILL);
|
|
|
+ mCorrectPaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
+ mCorrectPaint.setStrokeWidth(1);
|
|
|
+ mCorrectPaint.setColor(Color.WHITE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initCenterRound2Paint() {
|
|
|
+ if (mCenterRound2Paint == null) {
|
|
|
+ mCenterRound2Paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
+ mCenterRound2Paint.setDither(true);
|
|
|
+ mCenterRound2Paint.setAntiAlias(true);
|
|
|
+
|
|
|
+ mCenterRound2Paint.setStyle(Paint.Style.FILL);
|
|
|
+ mCenterRound2Paint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
+ mCenterRound2Paint.setStrokeWidth(1);
|
|
|
+ mCenterRound2Paint.setColor(Color.WHITE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCorrect(boolean correct) {
|
|
|
+ isCorrect = correct;
|
|
|
}
|
|
|
|
|
|
@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();
|
|
|
+ canvas.drawArc(mWhiteBoardBgRect, -210, 240, true, mBgPaint);
|
|
|
+
|
|
|
+ //渐变色环形条
|
|
|
canvas.drawArc(mGradientLineRectF, -180, 180, false, mOuterGradientPaint);
|
|
|
+ //指针中心光亮区域
|
|
|
+ canvas.drawArc(whiteAreaRectF, -108, 36, true, mWhiteAreaPaint);
|
|
|
|
|
|
LOG.i("onDraw:" + currentProgress);
|
|
|
currentProgress += offsetValue;
|
|
@@ -183,58 +336,39 @@ public class DashBoardView extends View {
|
|
|
currentProgress = minMusicHzOffset;
|
|
|
}
|
|
|
float[] floats = countPointerPosition(currentProgress);
|
|
|
+ float angle = floats[2];
|
|
|
canvas.drawLine(cx, cy, floats[0], floats[1], mPointerPaint);
|
|
|
|
|
|
+ //中心圆背景1
|
|
|
+ canvas.drawCircle(cx, cy, mRadius * centerRound1RadiusPercent, mCenterRound1Paint);
|
|
|
|
|
|
- //绘制长刻度
|
|
|
- mLinePaint.setAlpha(255);
|
|
|
- float x0 = cx;
|
|
|
- float y0 = height - mRadius;
|
|
|
- float x1 = cx;
|
|
|
- float y1 = y0 + longScaleLineHeight;
|
|
|
- // 逆时针到开始处
|
|
|
- canvas.save();
|
|
|
- // 逆时针到开始处
|
|
|
- canvas.save();
|
|
|
- canvas.drawLine(x0, y0, x1, y1, mLinePaint);
|
|
|
- float degree = mSweepAngle / mSection;
|
|
|
- for (int i = 0; i < mSection / 2; i++) {
|
|
|
- canvas.rotate(-degree, cx, cy);
|
|
|
- canvas.drawLine(x0, y0, x1, y1, mLinePaint);
|
|
|
- }
|
|
|
- canvas.restore();
|
|
|
- // 顺时针到结尾处
|
|
|
- canvas.save();
|
|
|
- for (int i = 0; i < mSection / 2; i++) {
|
|
|
- canvas.rotate(degree, cx, cy);
|
|
|
- canvas.drawLine(x0, y0, x1, y1, mLinePaint);
|
|
|
- }
|
|
|
- canvas.restore();
|
|
|
+ //中心圆背景2
|
|
|
+ mCenterRound2Paint.setStyle(Paint.Style.FILL);
|
|
|
+ mCenterRound2Paint.setColor(Color.WHITE);
|
|
|
+ LOG.i("isCorrect:" + isCorrect);
|
|
|
+ canvas.drawCircle(cx, cy, mRadius * centerRound2RadiusPercent, isCorrect ? mCorrectPaint : mCenterRound2Paint);
|
|
|
+ mCenterRound2Paint.setStyle(Paint.Style.STROKE);
|
|
|
+ mCenterRound2Paint.setStrokeWidth(2);
|
|
|
+ mCenterRound2Paint.setColor(getResources().getColor(R.color.color_e8f4ff));
|
|
|
+ canvas.drawCircle(cx, cy, mRadius * 0.36f, mCenterRound2Paint);
|
|
|
|
|
|
- /**
|
|
|
- * 画短刻度
|
|
|
- * 同样采用canvas的旋转原理
|
|
|
- */
|
|
|
- mLinePaint.setAlpha(90);
|
|
|
|
|
|
- float x2 = cx;
|
|
|
- float y2 = y0 + shortScaleLineHeight;
|
|
|
- // 逆时针到开始处
|
|
|
canvas.save();
|
|
|
- canvas.drawLine(x0, y0, x2, y2, mLinePaint);
|
|
|
- degree = mSweepAngle / (mSection * mPortion);
|
|
|
- for (int i = 0; i < (mSection * mPortion) / 2; i++) {
|
|
|
- canvas.rotate(-degree, cx, cy);
|
|
|
- canvas.drawLine(x0, y0, x2, y2, mLinePaint);
|
|
|
- }
|
|
|
- canvas.restore();
|
|
|
- // 顺时针到结尾处
|
|
|
- canvas.save();
|
|
|
- for (int i = 0; i < (mSection * mPortion) / 2; i++) {
|
|
|
- canvas.rotate(degree, cx, cy);
|
|
|
- canvas.drawLine(x0, y0, x2, y2, mLinePaint);
|
|
|
- }
|
|
|
+ canvas.rotate(angle, cx, cy);
|
|
|
+ canvas.drawBitmap(triangleBitmap, triangleRect1, triangleShowRect, mPointerPaint);
|
|
|
canvas.restore();
|
|
|
+// canvas.save();
|
|
|
+
|
|
|
+
|
|
|
+ float x0 = cx;
|
|
|
+ float y0 = cx - (float) (mRadius * scaleRoundPercent);
|
|
|
+
|
|
|
+ //绘制短刻度
|
|
|
+ drawShortScale(canvas, x0, y0);
|
|
|
+
|
|
|
+ //绘制长刻度
|
|
|
+ drawLongScale(canvas, x0, y0);
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 画长刻度读数
|
|
@@ -278,11 +412,83 @@ public class DashBoardView extends View {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void drawShortScale(Canvas canvas, float x0, float y0) {
|
|
|
+ // mLinePaint.setAlpha(90);
|
|
|
+ mLinePaint.setColor(getColor(R.color.color_d6dfe4));
|
|
|
+ float degree = mSweepAngle / (mSection * mPortion);
|
|
|
+
|
|
|
+ float x2 = cx;
|
|
|
+ float y2 = y0 + shortScaleLineHeight;
|
|
|
+ // 逆时针到开始处
|
|
|
+ canvas.save();
|
|
|
+ canvas.drawLine(x0, y0, x2, y2, mLinePaint);
|
|
|
+ for (int i = 0; i < (mSection * mPortion) / 2; i++) {
|
|
|
+ if (i < 10) {
|
|
|
+ mLinePaint.setColor(getColor(R.color.color_198cfe));
|
|
|
+ } else {
|
|
|
+ mLinePaint.setColor(getColor(R.color.color_d6dfe4));
|
|
|
+ }
|
|
|
+ canvas.rotate(-degree, cx, cy);
|
|
|
+ canvas.drawLine(x0, y0, x2, y2, mLinePaint);
|
|
|
+ }
|
|
|
+ canvas.restore();
|
|
|
+ // 顺时针到结尾处
|
|
|
+ canvas.save();
|
|
|
+ for (int i = 0; i < (mSection * mPortion) / 2; i++) {
|
|
|
+ if (i < 10) {
|
|
|
+ mLinePaint.setColor(getColor(R.color.color_198cfe));
|
|
|
+ } else {
|
|
|
+ mLinePaint.setColor(getColor(R.color.color_d6dfe4));
|
|
|
+ }
|
|
|
+ canvas.rotate(degree, cx, cy);
|
|
|
+ canvas.drawLine(x0, y0, x2, y2, mLinePaint);
|
|
|
+ }
|
|
|
+ canvas.restore();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void drawLongScale(Canvas canvas, float x0, float y0) {
|
|
|
+ float degree = mSweepAngle / mSection;
|
|
|
+ float x1 = cx;
|
|
|
+ float y1 = y0 + longScaleLineHeight;
|
|
|
+ mLinePaint.setColor(getColor(R.color.color_198cfe));
|
|
|
+ // 逆时针到开始处
|
|
|
+ canvas.save();
|
|
|
+ canvas.drawLine(x0, y0, x1, y1, mLinePaint);
|
|
|
+ int max = mSection / 2;
|
|
|
+ for (int i = 0; i < max; i++) {
|
|
|
+ if (i == 0) {
|
|
|
+ mLinePaint.setColor(getColor(R.color.color_198cfe));
|
|
|
+ } else {
|
|
|
+ mLinePaint.setColor(getColor(com.cooleshow.base.R.color.color_999999));
|
|
|
+ }
|
|
|
+ canvas.rotate(-degree, cx, cy);
|
|
|
+ canvas.drawLine(x0, y0, x1, y1, mLinePaint);
|
|
|
+ }
|
|
|
+ mLinePaint.setColor(getColor(com.cooleshow.base.R.color.color_999999));
|
|
|
+ canvas.restore();
|
|
|
+ // 顺时针到结尾处
|
|
|
+ canvas.save();
|
|
|
+ for (int i = 0; i < mSection / 2; i++) {
|
|
|
+ if (i == 0) {
|
|
|
+ mLinePaint.setColor(getColor(R.color.color_198cfe));
|
|
|
+ } else {
|
|
|
+ mLinePaint.setColor(getColor(com.cooleshow.base.R.color.color_999999));
|
|
|
+ }
|
|
|
+ canvas.rotate(degree, cx, cy);
|
|
|
+ canvas.drawLine(x0, y0, x1, y1, mLinePaint);
|
|
|
+ }
|
|
|
+ canvas.restore();
|
|
|
+ }
|
|
|
+
|
|
|
+ private int getColor(int colorRes) {
|
|
|
+ return getResources().getColor(colorRes);
|
|
|
+ }
|
|
|
+
|
|
|
private int maxMusicHzOffset = 50;
|
|
|
private int minMusicHzOffset = -50;
|
|
|
|
|
|
private float[] countPointerPosition(float diff) {
|
|
|
- float[] points = new float[2];
|
|
|
+ float[] points = new float[3];
|
|
|
if (diff > maxMusicHzOffset) {
|
|
|
diff = maxMusicHzOffset;
|
|
|
}
|
|
@@ -292,25 +498,49 @@ public class DashBoardView extends View {
|
|
|
|
|
|
if (diff > 0) {
|
|
|
double angle = (diff / maxMusicHzOffset) * mSweepAngle / 2;
|
|
|
- Log.i("zxc", "angle:" + angle);
|
|
|
+ Log.i("zxc", "angle1:" + angle);
|
|
|
float radian = (float) Math.toRadians(angle);
|
|
|
points[0] = (float) (cx + Math.sin(radian) * pointerHeight);
|
|
|
points[1] = (float) (cy - Math.cos(radian) * pointerHeight);
|
|
|
+ points[2] = (float) angle;
|
|
|
} else if (diff == 0) {
|
|
|
+ Log.i("zxc", "angle1:" + 0);
|
|
|
points[0] = cx;
|
|
|
points[1] = (float) (cy - pointerHeight);
|
|
|
+ points[2] = 0;
|
|
|
} else {
|
|
|
double angle = Math.abs((diff / minMusicHzOffset) * mSweepAngle / 2);
|
|
|
- Log.i("zxc", "angle:" + angle);
|
|
|
+ Log.i("zxc", "angle1:" + angle);
|
|
|
float radian = (float) Math.toRadians(angle);
|
|
|
points[0] = (float) (cx - Math.sin(radian) * pointerHeight);
|
|
|
points[1] = (float) (cy - Math.cos(radian) * pointerHeight);
|
|
|
+ points[2] = (float) -angle;
|
|
|
}
|
|
|
- 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;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private double getAngle(float diff) {
|
|
|
+ if (diff > maxMusicHzOffset) {
|
|
|
+ diff = maxMusicHzOffset;
|
|
|
+ }
|
|
|
+ if (diff < minMusicHzOffset) {
|
|
|
+ diff = minMusicHzOffset;
|
|
|
+ }
|
|
|
+ double angle = 0;
|
|
|
+ if (diff > 0) {
|
|
|
+ angle = (diff / maxMusicHzOffset) * mSweepAngle / 2;
|
|
|
+ } else if (diff == 0) {
|
|
|
+ angle = 0;
|
|
|
+ } else {
|
|
|
+ angle = Math.abs((diff / minMusicHzOffset) * mSweepAngle / 2);
|
|
|
+ }
|
|
|
+ Log.i("zxc", "angle:" + angle);
|
|
|
+ return angle;
|
|
|
+ }
|
|
|
+
|
|
|
public void setProgress(int progress) {
|
|
|
if (progress != -100) {
|
|
|
// this.currentProgress = progress;
|
|
@@ -321,7 +551,7 @@ public class DashBoardView extends View {
|
|
|
if (progress <= minMusicHzOffset) {
|
|
|
progress = minMusicHzOffset;
|
|
|
}
|
|
|
- lastAnimProgress=0;
|
|
|
+ lastAnimProgress = 0f;
|
|
|
offsetValue = 0;
|
|
|
currentOffsetValue = 0;
|
|
|
startAnimation(progress - currentProgress);
|
|
@@ -347,8 +577,8 @@ public class DashBoardView extends View {
|
|
|
LOG.i("onAnimationUpdate:" + value + "--当前偏移总量:" + currentOffsetValue);
|
|
|
float d = currentOffsetValue * value;
|
|
|
LOG.i("d:" + d);
|
|
|
- offsetValue = (value-lastAnimProgress)*currentOffsetValue;
|
|
|
- lastAnimProgress =value;
|
|
|
+ offsetValue = (value - lastAnimProgress) * currentOffsetValue;
|
|
|
+ lastAnimProgress = value;
|
|
|
LOG.i("offsetValue:" + offsetValue);
|
|
|
invalidate();
|
|
|
}
|