Hi,
Thanks for your quick response, I didn't know about the `RotationProvider` API, I gave it a try, but unfortunately I encountered the same results I've been finding when using either a `DisplayManager.DisplayListener` or a `OrientationEventListener` to update the ImageAnalysis usecase.
For
OrientationEventListener I've done:
private val orientationEventListener by lazy {
object : OrientationEventListener(context) {
override fun onOrientationChanged(orientation: Int) {
if (orientation == ORIENTATION_UNKNOWN) {
return
}
val rotation = when (orientation) {
in 45 until 135 -> Surface.ROTATION_270
in 135 until 225 -> Surface.ROTATION_180
in 225 until 315 -> Surface.ROTATION_90
else -> Surface.ROTATION_0
}
imageAnalysisUseCase?.targetRotation = rotation
}
}
}Continuously updating the imageAnalysisUseCase results in an upside down image despite updating the targetRotation as described in the logs, you can see how it goes from one landscape to another, even identifying the transition to portrait, the API you suggested resembles a lot to this one described in the
best practices :
// Using OrientationEventListener
OrientationEventListener changed: ROTATION_90
OrientationEventListener changed: ROTATION_180
OrientationEventListener changed: ROTATION_270For
RotationProvider.Listener I tried as you suggested:
private val rotationProviderListener = object: RotationProvider.Listener {
override fun onRotationChanged(rotation: Int) {
// Dynamically update the target rotation of the ImageAnalysis use case
imageAnalysisUseCase?.targetRotation = rotation
}
}
Aside from the less frequent updates, I got exactly the same reported orientation and applied it to the imageAnalysisUseCase, this also results in an upside-down image despite the last targetRotation being 270 as shown in the logs:
// Using RotationProvider.Listener
RotationProvider.Listener changed: ROTATION_90
RotationProvider.Listener changed: ROTATION_180
RotationProvider.Listener changed: ROTATION_270
For DisplayManager.DisplayListener while, the results were the same, this only identified the change from landscape to landscape, it doesn't use the sensors I guess and can't determine that there was a transition to portrait, hence I only saw a single orientation change to 270, despite all that, the three suggested methods detect the orientation change and update the imageAnalysisUseCase target rotation, but they still produce an upside-down image.
// Using DisplayListener
DisplayManager.DisplayListener changed: ROTATION_270
Are these rotation events the expected result for the RotationProvider.Listener you've mentioned? should I see a different result? is there anything else that could explain why the ImageAnalysisUsecase does not "pickup" the new targetRotation and seems to be unaware that there must be a change?