Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Smile, it’s CameraX! [preview and capture] | Capture - Step 2: add orientation event listener
val orientationEventListener = object : OrientationEventListener(this as Context) {
override fun onOrientationChanged(orientation: Int) {
val rotation: Int = when (orientation) {
in 45..134 -> Surface.ROTATION_270
in 135..224 -> Surface.ROTATION_180
in 225..314 -> Surface.ROTATION_90
else -> Surface.ROTATION_0
}
// default => Display.getRotation()
imageCapture.targetRotation = rotation
}
}
orientationEventListener.enable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.