Skip to content

Commit

Permalink
Fixed: Setting color that doesn't contained in the seek bar will rese…
Browse files Browse the repository at this point in the history
…t progress into 0
  • Loading branch information
rtugeek committed Oct 9, 2021
1 parent 1f787a9 commit 88eed6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
Expand Up @@ -28,7 +28,6 @@ public class AlphaSeekBar extends BaseSeekBar {
private final int GRID_GREY = 0xFFEDEDED;

private OnAlphaChangeListener listener;
private boolean movingBar;

private boolean mShowGrid = true;
private final Path mClipPath = new Path();
Expand Down Expand Up @@ -193,5 +192,4 @@ public void setOnAlphaChangeListener(OnAlphaChangeListener listener) {
this.listener = listener;
}


}
Expand Up @@ -214,21 +214,6 @@ protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}


private float calculateTouchPercent(float x) {
if (isVertical()) {
return (x - thumbDragRect.top) / thumbDragRect.height() * maxProgress;
} else {
return (x - thumbDragRect.left) / thumbDragRect.width() * maxProgress;
}
}

@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
}


/**
* @param position
* @return color
Expand Down Expand Up @@ -314,7 +299,7 @@ public int getProgressByColor(int color) {


public List<Integer> getColors() {
if (cachedColors.isEmpty()) {
if (cachedColors.isEmpty() && mCachedBitmap != null) {
for (int i = 0; i < maxProgress; i++) {
cachedColors.add(pickColor(i));
}
Expand All @@ -339,10 +324,12 @@ public void setColor(int color) {
}
int withoutAlphaColor = Color.rgb(Color.red(color), Color.green(color), Color.blue(color));
List<Integer> colors = getColors();
int position = colors.indexOf(withoutAlphaColor);
setProgress(position);
if (mOnColorChangeLister != null) {
mOnColorChangeLister.onColorChangeListener(progress, getColor());
int progress = colors.indexOf(withoutAlphaColor);
if (progress != -1) {
setProgress(progress);
if (mOnColorChangeLister != null) {
mOnColorChangeLister.onColorChangeListener(progress, getColor());
}
}
}

Expand Down

0 comments on commit 88eed6d

Please sign in to comment.