Browse Source

prevented jumping in SeekBar (more of a DragBar now but eh)

main
James Fenn 3 years ago
parent
commit
b6f347ce45
1 changed files with 9 additions and 1 deletions
  1. +9
    -1
      app/src/main/java/james/metronome/views/SeekBar.java

+ 9
- 1
app/src/main/java/james/metronome/views/SeekBar.java View File

@@ -23,6 +23,7 @@ public class SeekBar extends View implements View.OnTouchListener {
private OnProgressChangeListener listener;
private int progress;
private int maxProgress = 100;
private float touchDiff;

private Disposable textColorPrimarySubscription;
private Disposable textColorSecondarySubscription;
@@ -116,8 +117,15 @@ public class SeekBar extends View implements View.OnTouchListener {
float x = event.getX();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touchDiff = x - (((float) progress / maxProgress) * view.getMeasuredWidth());
case MotionEvent.ACTION_MOVE:
setProgress((int) (maxProgress * (x / view.getMeasuredWidth())));
int progress = (int) (maxProgress * ((x - touchDiff) / view.getMeasuredWidth()));
if (progress < 0)
progress = 0;
else if (progress > maxProgress)
progress = maxProgress;

setProgress(progress);
}
return false;
}


Loading…
Cancel
Save