@capgo/camera-preview 7.4.0-alpha.25 → 7.4.0-alpha.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
package com.ahm.capacitor.camera.preview;
|
|
2
2
|
|
|
3
|
+
import static androidx.core.content.ContextCompat.getSystemService;
|
|
4
|
+
|
|
3
5
|
import android.content.Context;
|
|
4
6
|
import android.content.res.Configuration;
|
|
5
7
|
import android.graphics.Bitmap;
|
|
@@ -21,10 +23,13 @@ import android.util.Size;
|
|
|
21
23
|
import android.view.MotionEvent;
|
|
22
24
|
import android.view.View;
|
|
23
25
|
import android.view.ViewGroup;
|
|
26
|
+
import android.view.WindowManager;
|
|
27
|
+
import android.view.WindowMetrics;
|
|
24
28
|
import android.webkit.WebView;
|
|
25
29
|
import android.widget.FrameLayout;
|
|
26
30
|
import androidx.annotation.NonNull;
|
|
27
31
|
import androidx.annotation.OptIn;
|
|
32
|
+
import androidx.annotation.RequiresApi;
|
|
28
33
|
import androidx.camera.camera2.interop.Camera2CameraInfo;
|
|
29
34
|
import androidx.camera.camera2.interop.ExperimentalCamera2Interop;
|
|
30
35
|
import androidx.camera.core.AspectRatio;
|
|
@@ -447,10 +452,29 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
447
452
|
String aspectRatio = sessionConfig.getAspectRatio();
|
|
448
453
|
|
|
449
454
|
// Get comprehensive display information
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
455
|
+
int screenWidthPx, screenHeightPx;
|
|
456
|
+
float density;
|
|
457
|
+
|
|
458
|
+
// Get density using DisplayMetrics (available on all API levels)
|
|
459
|
+
WindowManager windowManager = (WindowManager) this.context.getSystemService(
|
|
460
|
+
Context.WINDOW_SERVICE
|
|
461
|
+
);
|
|
462
|
+
DisplayMetrics displayMetrics = new DisplayMetrics();
|
|
463
|
+
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
|
|
464
|
+
density = displayMetrics.density;
|
|
465
|
+
|
|
466
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
467
|
+
// API 30+ (Android 11+) - use WindowMetrics for screen dimensions
|
|
468
|
+
WindowMetrics metrics = windowManager.getCurrentWindowMetrics();
|
|
469
|
+
Rect bounds = metrics.getBounds();
|
|
470
|
+
screenWidthPx = bounds.width();
|
|
471
|
+
screenHeightPx = bounds.height();
|
|
472
|
+
} else {
|
|
473
|
+
// API < 30 - use legacy DisplayMetrics for screen dimensions
|
|
474
|
+
screenWidthPx = displayMetrics.widthPixels;
|
|
475
|
+
screenHeightPx = displayMetrics.heightPixels;
|
|
476
|
+
}
|
|
477
|
+
|
|
454
478
|
int screenWidthDp = (int) (screenWidthPx / density);
|
|
455
479
|
int screenHeightDp = (int) (screenHeightPx / density);
|
|
456
480
|
|
|
@@ -544,8 +568,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
544
568
|
);
|
|
545
569
|
|
|
546
570
|
// For centered mode with aspect ratio, calculate maximum size that fits
|
|
547
|
-
int availableWidth =
|
|
548
|
-
int availableHeight =
|
|
571
|
+
int availableWidth = screenWidthPx;
|
|
572
|
+
int availableHeight = screenHeightPx;
|
|
549
573
|
|
|
550
574
|
Log.d(
|
|
551
575
|
TAG,
|
|
@@ -3091,10 +3115,28 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
3091
3115
|
);
|
|
3092
3116
|
|
|
3093
3117
|
// Get comprehensive display information
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3118
|
+
WindowManager windowManager = (WindowManager) this.context.getSystemService(
|
|
3119
|
+
Context.WINDOW_SERVICE
|
|
3120
|
+
);
|
|
3121
|
+
int screenWidthPx, screenHeightPx;
|
|
3122
|
+
float density;
|
|
3123
|
+
|
|
3124
|
+
// Get density using DisplayMetrics (available on all API levels)
|
|
3125
|
+
DisplayMetrics displayMetrics = new DisplayMetrics();
|
|
3126
|
+
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
|
|
3127
|
+
density = displayMetrics.density;
|
|
3128
|
+
|
|
3129
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
3130
|
+
// API 30+ (Android 11+) - use WindowMetrics for screen dimensions
|
|
3131
|
+
WindowMetrics metrics = windowManager.getCurrentWindowMetrics();
|
|
3132
|
+
Rect bounds = metrics.getBounds();
|
|
3133
|
+
screenWidthPx = bounds.width();
|
|
3134
|
+
screenHeightPx = bounds.height();
|
|
3135
|
+
} else {
|
|
3136
|
+
// API < 30 - use legacy DisplayMetrics for screen dimensions
|
|
3137
|
+
screenWidthPx = displayMetrics.widthPixels;
|
|
3138
|
+
screenHeightPx = displayMetrics.heightPixels;
|
|
3139
|
+
}
|
|
3098
3140
|
|
|
3099
3141
|
// Get WebView dimensions
|
|
3100
3142
|
int webViewWidth = webView.getWidth();
|