Skip to content

Instantly share code, notes, and snippets.

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 e4basil/e590b67da247884bf110cb7092b206d4 to your computer and use it in GitHub Desktop.
Save e4basil/e590b67da247884bf110cb7092b206d4 to your computer and use it in GitHub Desktop.
// Create a listener with a callback invoked when a gesture event has occurred
val listener = object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
override fun onScale(detector: ScaleGestureDetector): Boolean {
// Get the current camera zoom ratio
val currentZoomRatio: Float = cameraInfo.zoomRatio.value ?: 1F
// Get by how much the scale has changed due to the user's pinch gesture
val delta = detector.scaleFactor
// Update the camera's zoom ratio
cameraControl.setZoomRatio(currentZoomRatio * delta)
return true
}
}
// Attach PreviewView's touch events listener to the scale gesture listener
val scaleGestureDetector = ScaleGestureDetector(context, listener)
// Pass touch events from PreviewView to the scale gesture listener
previewView.setOnTouchListener { _, event ->
scaleGestureDetector.onTouchEvent(event)
return@setOnTouchListener true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment