|
@@ -1,5 +1,6 @@
|
|
|
package com.cooleshow.musictuner.widget;
|
|
|
|
|
|
+import android.animation.ValueAnimator;
|
|
|
import android.content.Context;
|
|
|
import android.content.res.Resources;
|
|
|
import android.graphics.Canvas;
|
|
@@ -19,7 +20,9 @@ import android.util.Log;
|
|
|
import android.util.TypedValue;
|
|
|
import android.view.View;
|
|
|
|
|
|
+import com.cooleshow.base.utils.LOG;
|
|
|
import com.cooleshow.base.utils.SizeUtils;
|
|
|
+import com.cooleshow.musictuner.constants.MusicTunerConstants;
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
@@ -52,12 +55,14 @@ public class DashBoardView extends View {
|
|
|
private float pointerHeight = 0;
|
|
|
private double innerGradientRadiusPercent = 0.75;
|
|
|
private int pointerAngle = 0;
|
|
|
- private int currentProgress = 0;
|
|
|
+ private float currentProgress = 0;
|
|
|
private RectF whiteAreaRectF;
|
|
|
private Paint mWhiteAreaPaint;
|
|
|
private int whiteAreaStartColor;
|
|
|
private int whiteAreaEndColor;
|
|
|
|
|
|
+ private ValueAnimator mAnimator;
|
|
|
+
|
|
|
public DashBoardView(Context context) {
|
|
|
this(context, null);
|
|
|
}
|
|
@@ -168,6 +173,15 @@ public class DashBoardView extends View {
|
|
|
|
|
|
canvas.drawArc(whiteAreaRectF, -108, 36, true, mWhiteAreaPaint);
|
|
|
canvas.drawArc(mGradientLineRectF, -180, 180, false, mOuterGradientPaint);
|
|
|
+
|
|
|
+ LOG.i("onDraw:" + currentProgress);
|
|
|
+ currentProgress += offsetValue;
|
|
|
+ if (currentProgress >= maxMusicHzOffset) {
|
|
|
+ currentProgress = maxMusicHzOffset;
|
|
|
+ }
|
|
|
+ if (currentProgress < minMusicHzOffset) {
|
|
|
+ currentProgress = minMusicHzOffset;
|
|
|
+ }
|
|
|
float[] floats = countPointerPosition(currentProgress);
|
|
|
canvas.drawLine(cx, cy, floats[0], floats[1], mPointerPaint);
|
|
|
|
|
@@ -299,8 +313,49 @@ public class DashBoardView extends View {
|
|
|
|
|
|
public void setProgress(int progress) {
|
|
|
if (progress != -100) {
|
|
|
- this.currentProgress = progress;
|
|
|
+
|
|
|
+ LOG.i("setProgress:" + progress);
|
|
|
+ if (progress >= maxMusicHzOffset) {
|
|
|
+ progress = maxMusicHzOffset;
|
|
|
+ }
|
|
|
+ if (progress <= minMusicHzOffset) {
|
|
|
+ progress = minMusicHzOffset;
|
|
|
+ }
|
|
|
+ offsetValue = 0;
|
|
|
+ currentOffsetValue = 0;
|
|
|
+ startAnimation(progress - currentProgress);
|
|
|
invalidate();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private float lastAnimProgress = 0f;
|
|
|
+ private float offsetValue = 0;
|
|
|
+ private float currentOffsetValue = 0;
|
|
|
+
|
|
|
+ private void startAnimation(float progress) {
|
|
|
+ LOG.i("startAnimation:" + progress);
|
|
|
+ this.currentOffsetValue = progress;
|
|
|
+ if (mAnimator == null) {
|
|
|
+ mAnimator = ValueAnimator.ofFloat(0f, 1f);
|
|
|
+
|
|
|
+ mAnimator.setDuration(MusicTunerConstants.TUNER_POINTER_ANIMATION);
|
|
|
+ mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
|
+ @Override
|
|
|
+ public void onAnimationUpdate(ValueAnimator animation) {
|
|
|
+ float value = (float) animation.getAnimatedValue();
|
|
|
+ LOG.i("onAnimationUpdate:" + value + "--当前偏移总量:" + currentOffsetValue);
|
|
|
+ float d = currentOffsetValue * value;
|
|
|
+ LOG.i("d:" + d);
|
|
|
+ offsetValue = (value-lastAnimProgress)*currentOffsetValue;
|
|
|
+ lastAnimProgress =value;
|
|
|
+ LOG.i("offsetValue:" + offsetValue);
|
|
|
+ invalidate();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (mAnimator.isRunning()) {
|
|
|
+ mAnimator.cancel();
|
|
|
+ }
|
|
|
+ mAnimator.start();
|
|
|
+ }
|
|
|
}
|