Skip to content

Commit

Permalink
Fixed: AlphaSeekBar progress out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
rtugeek committed Oct 13, 2021
1 parent 60a0776 commit 8d58f18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Expand Up @@ -50,6 +50,7 @@ class AlphaSeekBarFragment : Fragment() {
),
50, 50
)
alphaSeekBar.alphaValue = 200
alphaSeekBar.borderColor = Color.BLACK
alphaSeekBar.setOnAlphaChangeListener { progress, alpha ->
Log.i("AlphaSeekBarFragment", "===progress:$progress-alpha:$alpha===")
Expand Down Expand Up @@ -116,7 +117,6 @@ class AlphaSeekBarFragment : Fragment() {
tv_radius.text =
String.format("Bar Radius: %dpx", progress)
}

override fun onStartTrackingTouch(seekBar: SeekBar) {}
override fun onStopTrackingTouch(seekBar: SeekBar) {}
})
Expand Down
Expand Up @@ -184,10 +184,10 @@ protected void onDraw(Canvas canvas) {
}

@Override
protected void onBarTouch(int progress) {
setProgress(progress);
protected void onBarTouch(int newProgress) {
setProgress(newProgress);
if (listener != null) {
listener.onAlphaChangeListener(progress, getAlphaValue());
listener.onAlphaChangeListener(this.progress, getAlphaValue());
}
}

Expand All @@ -206,7 +206,17 @@ public int getAlphaValue() {
}

public void setAlphaValue(@IntRange(from = 0, to = 255) int alpha) {
setProgress((int) (alpha / 255f * maxProgress));
float percent = alpha / 255f;
if (isVertical()) {
if (direction == Direction.BOTTOM_TO_TOP) {
percent = 1 - percent;
}
} else {
if (direction == Direction.RIGHT_TO_LEFT) {
percent = 1 - percent;
}
}
setProgress((int) (percent * maxProgress));
if (listener != null) {
listener.onAlphaChangeListener(progress, getAlphaValue());
}
Expand Down

0 comments on commit 8d58f18

Please sign in to comment.