Skip to content

Instantly share code, notes, and snippets.

@o4oren
Created May 2, 2020 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save o4oren/b9b39d9eae4446942b0aa3ac05d9cb93 to your computer and use it in GitHub Desktop.
Save o4oren/b9b39d9eae4446942b0aa3ac05d9cb93 to your computer and use it in GitHub Desktop.
onScroll
override fun onScroll(e1: MotionEvent, e2: MotionEvent, distanceX: Float, distanceY: Float)
: Boolean {
val rotationDegrees = calculateAngle(e2.x, e2.y)
// use only -150 to 150 range (knob min/max points
if (rotationDegrees >= -150 && rotationDegrees <= 150) {
setKnobPosition(rotationDegrees)
// Calculate rotary value
// The range is the 300 degrees between -150 and 150, so we'll add 150 to adjust the
// range to 0 - 300
val valueRangeDegrees = rotationDegrees + 150
value = ((valueRangeDegrees / divider) + minValue).toInt()
if (listener != null) listener!!.onRotate(value)
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment