camera-samples icon indicating copy to clipboard operation
camera-samples copied to clipboard

CameraXBasic: Update sample with latest stable WindowManager

Open zeusalmighty717 opened this issue 3 years ago • 2 comments

When reporting the issue latest WindowManager available is androidx.window:window:1.0.0

zeusalmighty717 avatar Apr 12 '22 07:04 zeusalmighty717

I updated the latest WindowManager but I get: CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/fragments/CameraFragment.kt: (49, 24): Unresolved reference: WindowManager CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/fragments/CameraFragment.kt: (102, 41): Unresolved reference: WindowManager CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/fragments/CameraFragment.kt: (205, 25): Unresolved reference: WindowManager

mpicci avatar Apr 12 '22 23:04 mpicci

class androidx.window.WindowManager might have been removed to avoid confusion with interface android.view.WindowManager.

The suggested fix would be to obtain the aspect ratio with the WindowMetricsCalculator:

// Get screen metrics used to setup camera for full screen resolution
val windowMetrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(requireActivity())
Log.d(TAG, "Screen metrics: ${windowMetrics.bounds.width()} x ${windowMetrics.bounds.height()}")
    
val screenAspectRatio = aspectRatio(windowMetrics.bounds.width(), windowMetrics.bounds.height())
Log.d(TAG, "Preview aspect ratio: $screenAspectRatio")

See this blog post: Unbundling the WindowManager.

syslogic avatar Jun 02 '22 12:06 syslogic