Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save husaynhakeem/6786e81411d956814f2b78da9e400109 to your computer and use it in GitHub Desktop.
Save husaynhakeem/6786e81411d956814f2b78da9e400109 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
}
@AhmedAbdeen11
Copy link

Great work! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment