diff --git a/app/src/main/java/opencraft/com/verticalseekbar/MainActivity.kt b/app/src/main/java/opencraft/com/verticalseekbar/MainActivity.kt index 3358d55..035cdf7 100644 --- a/app/src/main/java/opencraft/com/verticalseekbar/MainActivity.kt +++ b/app/src/main/java/opencraft/com/verticalseekbar/MainActivity.kt @@ -34,7 +34,7 @@ class MainActivity : AppCompatActivity() { }) - seekbar.post { seekbar.applyInitialAnimation(2500) } + seekbar.post { seekbar.applyInitialValue(1075, false) } } } diff --git a/verticalseekbarlib/src/main/java/opencraft/com/verticalseekbarlib/VerticalSeekBar.java b/verticalseekbarlib/src/main/java/opencraft/com/verticalseekbarlib/VerticalSeekBar.java index 7f17e4c..be39086 100644 --- a/verticalseekbarlib/src/main/java/opencraft/com/verticalseekbarlib/VerticalSeekBar.java +++ b/verticalseekbarlib/src/main/java/opencraft/com/verticalseekbarlib/VerticalSeekBar.java @@ -131,13 +131,26 @@ private int calculatePixelToInteraction() { return getHeight() / interations; } - public void applyInitialAnimation(int wantedValue) { + public void applyInitialValue(int wantedValue, boolean withAnimation) { int pixelNumberToInteractionWithoutMargin = calculatePixelToInteraction(); int interationsToGetWantedValue = wantedValue / step; float wantedValueY = interationsToGetWantedValue * pixelNumberToInteractionWithoutMargin; - AnimatorSet animSetViews = new AnimatorSet(); + if (withAnimation) { + applyAnimation(pixelNumberToInteractionWithoutMargin, wantedValueY); + } else { + calculateValueFromYPosition((int) wantedValueY, pixelNumberToInteractionWithoutMargin); + verticalSeekBarThumb.setY(wantedValueY + thumbMarginTop); + verticalSeekBarBackground.setY(wantedValueY); + addMarginToBackground(wantedValueY); + callOnValueChanged(calculatedValue); + listener.onYPositionChanged(wantedValueY + thumbMarginTop, wantedValueY); + } + } + + private void applyAnimation(int pixelNumberToInteractionWithoutMargin, float wantedValueY) { + AnimatorSet animSetViews = new AnimatorSet(); for (int i = (int) verticalSeekBarBackground.getY(); i <= wantedValueY; i++) { final int finalYPosition = i; calculateValueFromYPosition(i, pixelNumberToInteractionWithoutMargin);