CameraXObjectDetection icon indicating copy to clipboard operation
CameraXObjectDetection copied to clipboard

Why transform the ViewFinder on the update of different physical display?

Open eneim opened this issue 5 years ago • 2 comments

Thanks for the amazing sample code (simple yet fully work + :heart: the auto resize preview)

I'm not super familiar with Display API but I notice that in this line you will update/transform the ViewFinder on the update event of different Display than that of the ViewFinder. What is the reason behind this?

eneim avatar May 13 '19 00:05 eneim

this code based on https://github.com/android/camera/blob/master/CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/utils/AutoFitPreviewBuilder.kt#L61

It aims to support 180 degree device orientation changes. I tried some orientation changes with Pixel 3, but I couldn't find the situation that this callback be called. 😵

yanzm avatar May 14 '19 14:05 yanzm

@yanzm I see, just have time to the official sample and I see the code.

Just try to debug and I think the reason the callback is not called is that this line will result in a call to this line so on first update of the Preview, your DisplayListener is already unregistered 😕, and it is never re-registered again. My work around is instead of registering the listener here, I would do it here when the viewFinder is attached again. Will try to ask in official repo about this.

Even though, doing this will have the callback is called correctly, but the display Id is always the same. I guess you need to attach the phone to another display via the cable or dock (my environment doesn't have a spare display :(, please try).

Still want to hear the answer about different displayId so I will try to ask in android/camera repo. My guess is when any other display is updated, the camera preview need to be adjusted for whatever reason ...

eneim avatar May 15 '19 01:05 eneim