I got screen orientation
fun checkRotation(context: Context, onChangeRotation: (rotation : Int) -> Unit) {
val mOrientationEventListener = object : OrientationEventListener(context) {
override fun onOrientationChanged(orientation: Int) {
val rotation: Int
if (orientation >= 45 && orientation < 135) {
rotation = android.view.Surface.ROTATION_270
} else if (orientation >= 135 && orientation < 225) {
rotation = android.view.Surface.ROTATION_180
} else if (orientation >= 225 && orientation < 315) {
rotation = android.view.Surface.ROTATION_90
} else {
rotation = android.view.Surface.ROTATION_0
}
onChangeRotation(rotation)
}
}
mOrientationEventListener.enable()
}
When app is in portrait i have values of 0 and in landscape 1 and 3.
Ok when i use camera i set orientation :
private fun getImageAnalysis(): ImageAnalysis {
var resolutionSelector = cameraInfoService.getResolutionSelector(
orientationScreen,
cameraInfoService.getISCamera4k(cameraInfo, cameraId)
)
imageAnalysis = ImageAnalysis.Builder()
. setTargetRotation(rotationTarget) .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_RGBA_8888)
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST).also {
Camera2Interop.Extender(it)
.setSessionCaptureCallback(object : CameraCaptureSession.CaptureCallback() {
override fun onCaptureCompleted(
session: CameraCaptureSession,
request: CaptureRequest,
result: TotalCaptureResult
) {
super.onCaptureCompleted(session, request, result)
mCapturedIso = result.get(CaptureResult.SENSOR_SENSITIVITY) ?: -1
}
})
}
.build().also {
it.setAnalyzer(
ContextCompat.getMainExecutor(cameraInfoService.getContext()),
rgbaAnalyzer
)
}
return imageAnalysis
}
but when i log imageAnalysis.resolutionInfo.rotationDegrees i find 90 for portrait and i's wiorng
when (resolutionInfo?.rotationDegrees) {
90, 270 -> {
isPortrait = false
width = resolutionInfo.resolution.height
height = resolutionInfo.resolution.width
}
0, 180 -> {
isPortrait = true
width = resolutionInfo.resolution.width
height = resolutionInfo.resolution.height
}
}