Skip to content

Commit

Permalink
fix over scroll glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
abd3lraouf committed Dec 23, 2019
1 parent 1b48f45 commit 9c49107
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,22 @@ class ScrollingValuePicker : LinearLayout {
}

when (defaultPosition) {
DefaultPosition.BEGINNING -> scrollTo(step.toFloat())
DefaultPosition.MIDDLE -> scrollTo(((rulerMaxValue - rulerMinValue) / 2F + 1) * step)
DefaultPosition.END -> scrollTo(rulerMaxValue * step.toFloat())
DefaultPosition.BEGINNING -> scrollTo(startPosition())
DefaultPosition.MIDDLE -> scrollTo(middlePosition())
DefaultPosition.END -> scrollTo(endPosition())
}
// Create the left and right spacers, don't worry about their dimensions, yet.

container.addView(mLeftSpacer, 0)
container.addView(mRightSpacer)
}

private fun startPosition() = step.toFloat()

private fun middlePosition() = ((rulerMaxValue - rulerMinValue) / 2F + 1) * step

private fun endPosition() = (rulerMaxValue - rulerMinValue + 1) * startPosition()

private fun getPointer(): View {
val pointer = ImageView(context)
val shape = getDrawable(context, R.drawable.pointer_line) as Drawable
Expand Down Expand Up @@ -278,10 +284,11 @@ class ScrollingValuePicker : LinearLayout {

val correctedX = finalizeValue(value)

if (value < rulerMinValue)
scrollTo(step.toFloat())
else
scrollTo(correctedX.toFloat())
when {
underScrolled(value) -> scrollTo(startPosition())
overScrolled(value) -> scrollTo(endPosition())
else -> scrollTo(correctedX.toFloat())
}

if (valueChanged(value) && firstLaunchSkipped) {
playTickSound(value)
Expand All @@ -293,6 +300,11 @@ class ScrollingValuePicker : LinearLayout {
return value
}


private fun overScrolled(value: Int) = value > rulerMaxValue

private fun underScrolled(value: Int) = value < rulerMinValue

private fun playTickSound(value: Int) {
val soundPlayTimes = 8
val diff = oldValue - value
Expand Down

0 comments on commit 9c49107

Please sign in to comment.