Created
May 2, 2020 12:48
-
-
Save o4oren/b9b39d9eae4446942b0aa3ac05d9cb93 to your computer and use it in GitHub Desktop.
onScroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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