Browse Source

添加节拍器加减速度按钮与进度逻辑

Pq 2 years ago
parent
commit
ad2fedf5ff

+ 10 - 19
metronome/src/main/java/com/cooleshow/metronome/MetronomeActivity.java

@@ -316,8 +316,7 @@ public class MetronomeActivity extends BaseActivity<ActivityMetronomeLayoutBindi
         if (id == R.id.iv_reduce) {
             //减速
             if (currentBeatRate != MetronomeConfig.MIN_PLAY_RATE) {
-                currentBeatRate -= 1;
-                updateSpeedText();
+                updateAnim(-1);
             }
             return;
         }
@@ -325,8 +324,7 @@ public class MetronomeActivity extends BaseActivity<ActivityMetronomeLayoutBindi
         if (id == R.id.iv_add) {
             //加速
             if (currentBeatRate != MetronomeConfig.MAX_PLAY_RATE) {
-                currentBeatRate += 1;
-                updateSpeedText();
+                updateAnim(1);
             }
             return;
         }
@@ -334,20 +332,13 @@ public class MetronomeActivity extends BaseActivity<ActivityMetronomeLayoutBindi
 
     private void updateAnim(int value) {
         int progress = viewBinding.cirSeekbar.getProgress();
-        if (value > 0) {
-            progress += (value * MetronomeConfig.PLAY_RATE_UNIT);
-            Log.i("pq", "progress:" + progress);
-            progress = progress % MetronomeConfig.MAX_RATE_PROGRESS;
-            Log.i("pq", "progress:" + progress);
-            viewBinding.cirSeekbar.setProgress(progress);
-        } else {
-            progress += (value * MetronomeConfig.PLAY_RATE_UNIT);
-            if (progress < 0) {
-                viewBinding.cirSeekbar.setProgress(MetronomeConfig.MAX_RATE_PROGRESS + progress);
-            } else {
-                Log.i("pq", "progress:" + progress);
-                viewBinding.cirSeekbar.setProgress(progress);
-            }
-        }
+        progress += value;
+//        if (progress > MetronomeConfig.MAX_RATE_PROGRESS) {
+//            progress = MetronomeConfig.MAX_RATE_PROGRESS;
+//        }
+//        if (progress < 0) {
+//            progress = 0;
+//        }
+        viewBinding.cirSeekbar.setProgress(progress);
     }
 }

+ 17 - 2
metronome/src/main/java/com/cooleshow/metronome/widget/CircularSeekBar.java

@@ -342,6 +342,13 @@ public class CircularSeekBar extends View {
         Log.i("pq","progressMark width:"+size1);
         float x = markPointX - (adjust / 2);
         Log.i("pq","result:"+x);
+        if(angle!=0){
+            float radian = (float) Math.toRadians(angle);
+            Log.i("pq", "radian:" + radian);
+            markPointX = (float) (cx + Math.sin(radian) * outerRadius);
+        }else{
+            markPointX = startPointX;
+        }
         return markPointX;
     }
 
@@ -359,6 +366,13 @@ public class CircularSeekBar extends View {
         Log.i("pq","progressMark height:"+size1);
         float y = markPointY - (adjust / 2);
         Log.i("pq","result:"+y);
+        if(angle!=0){
+            float radian = (float) Math.toRadians(angle);
+            Log.i("pq", "radian:" + radian);
+            markPointY = (float) (cy - Math.cos(radian) * outerRadius);
+        }else{
+            markPointY =startPointY;
+        }
         return markPointY;
     }
 
@@ -490,6 +504,7 @@ public class CircularSeekBar extends View {
                 int newAngle = (newPercent * 360) / 100 ;
                 this.setAngle(newAngle);
                 this.setProgressPercent(newPercent);
+                invalidate();
             }
             mListener.onProgressChange(this, this.getProgress());
             CALLED_FROM_ANGLE = false;
@@ -587,8 +602,8 @@ public class CircularSeekBar extends View {
         if (distance < outerRadius + adjustmentFactor && distance > innerRadius - adjustmentFactor && !up) {
             IS_PRESSED = true;
 
-            markPointX = (float) (cx + outerRadius * Math.cos(Math.atan2(x - cx, cy - y) - (Math.PI /2)));
-            markPointY = (float) (cy + outerRadius * Math.sin(Math.atan2(x - cx, cy - y) - (Math.PI /2)));
+//            markPointX = (float) (cx + outerRadius * Math.cos(Math.atx - cx, cy - y) - (Math.PI /2)));
+//            markPointY = (float) (cy + outerRadius * Math.sin(Math.atan2(x - cx, cy - y) - (Math.PI /2)));
 
             float degrees = (float) ((float) ((Math.toDegrees(Math.atan2(x - cx, cy - y)) + 360.0)) % 360.0);
             // and to make it count 0-360