Created
April 16, 2020 04:41
-
-
Save husaynhakeem/d80fd43e42d75625d36778bf31cfaa2a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Implementation details omitted. Check out full sample | |
class DrawingCanvas: View(context) { | |
// When the user pinches the view, zoom in, when they reverse pinch the view, zoom out | |
private val scaleGestureDetector = ScaleGestureDetector(context, object : | |
ScaleGestureDetector.SimpleOnScaleGestureListener() { | |
override fun onScale(detector: ScaleGestureDetector?): Boolean { | |
detector?.let { | |
scaleX *= detector.scaleFactor | |
scaleY *= detector.scaleFactor | |
} | |
return true | |
} | |
}) | |
override fun onTouchEvent(event: MotionEvent?): Boolean { | |
// Handle the different types of actions | |
when (event?.actionMasked) { | |
// ... | |
} | |
// Let the scale gesture detector analyze the event. If a scale gesture is detected, `onScale()` is invoked | |
scaleGestureDetector.onTouchEvent(event) | |
invalidate() | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment