Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ abstract class AbstractSlider extends FrameLayout {
protected int color = Color.WHITE;
protected ImageView selector;
protected String preferenceName;
protected boolean selectorPositionInitialized = false;

public AbstractSlider(Context context) {
super(context);
Expand Down Expand Up @@ -206,6 +207,7 @@ public void setSelectorPosition(@FloatRange(from = 0.0, to = 1.0) float selector
float x = (getWidth() * selectorPosition) - getSelectorSize() - getBorderHalfSize();
selectedX = (int) getBoundaryX(x);
selector.setX(selectedX);
selectorPositionInitialized = true;
}

public void setSelectorByHalfSelectorPosition(
Expand All @@ -214,6 +216,7 @@ public void setSelectorByHalfSelectorPosition(
float x = (getWidth() * selectorPosition) - (getSelectorSize() * 0.5f) - getBorderHalfSize();
selectedX = (int) getBoundaryX(x);
selector.setX(selectedX);
selectorPositionInitialized = true;
}

private float getBoundaryX(float x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ public void updatePaint(Paint colorPaint) {

@Override
public void onInflateFinished() {
// Skip default positioning if the selector position was already set
// (e.g., via setInitialColor before layout completed)
if (selectorPositionInitialized) {
return;
}

int defaultPosition = getWidth() - selector.getWidth();
if (getPreferenceName() != null) {
updateSelectorX(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ protected void updatePaint(Paint colorPaint) {
public void onInflateFinished() {
selector.post(
() -> {
// Skip default positioning if the selector position was already set
// (e.g., via setInitialColor before layout completed)
if (selectorPositionInitialized) {
return;
}

int defaultPosition = getWidth() - selector.getWidth();

if (getPreferenceName() != null) {
Expand Down