Last active
July 19, 2022 16:46
-
-
Save husaynhakeem/d7ee8b0ec5011e11a1339e279c55fd65 to your computer and use it in GitHub Desktop.
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
// Listen to pinch gestures | |
val listener = object : ScaleGestureDetector.SimpleOnScaleGestureListener() { | |
override fun onScale(detector: ScaleGestureDetector): Boolean { | |
// Get the camera's current zoom ratio | |
val currentZoomRatio = cameraInfo.zoomState.value?.zoomRatio ?: 0F | |
// Get the pinch gesture's scaling factor | |
val delta = detector.scaleFactor | |
// Update the camera's zoom ratio. This is an asynchronous operation that returns | |
// a ListenableFuture, allowing you to listen to when the operation completes. | |
cameraControl.setZoomRatio(currentZoomRatio * delta) | |
// Return true, as the event was handled | |
return true | |
} | |
} | |
val scaleGestureDetector = ScaleGestureDetector(context, listener) | |
// Attach the pinch gesture listener to the viewfinder | |
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
i found this error, can you help me ?
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
at android.view.ScaleGestureDetector.(ScaleGestureDetector.java:237)
at android.view.ScaleGestureDetector.(ScaleGestureDetector.java:217)
at id.t_rec.app.modules.absentx.AbsentXActivity.startCamera(AbsentXActivity.kt:126)