@capgo/camera-preview 7.13.11 → 7.14.0
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.
|
@@ -51,6 +51,7 @@ import androidx.camera.core.MeteringPoint;
|
|
|
51
51
|
import androidx.camera.core.MeteringPointFactory;
|
|
52
52
|
import androidx.camera.core.Preview;
|
|
53
53
|
import androidx.camera.core.ResolutionInfo;
|
|
54
|
+
import androidx.camera.core.TorchState;
|
|
54
55
|
import androidx.camera.core.UseCase;
|
|
55
56
|
import androidx.camera.core.ZoomState;
|
|
56
57
|
import androidx.camera.core.resolutionselector.AspectRatioStrategy;
|
|
@@ -2321,7 +2322,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2321
2322
|
try {
|
|
2322
2323
|
boolean hasFlash = camera.getCameraInfo().hasFlashUnit();
|
|
2323
2324
|
if (hasFlash) {
|
|
2324
|
-
|
|
2325
|
+
// Include torch for devices with a flash unit
|
|
2326
|
+
return Arrays.asList("off", "on", "auto", "torch");
|
|
2325
2327
|
} else {
|
|
2326
2328
|
return Collections.singletonList("off");
|
|
2327
2329
|
}
|
|
@@ -2332,6 +2334,16 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2332
2334
|
}
|
|
2333
2335
|
|
|
2334
2336
|
public String getFlashMode() {
|
|
2337
|
+
// If torch is enabled, report torch regardless of ImageCapture flash mode
|
|
2338
|
+
try {
|
|
2339
|
+
if (camera != null) {
|
|
2340
|
+
Integer torch = camera.getCameraInfo().getTorchState().getValue();
|
|
2341
|
+
if (torch != null && torch == TorchState.ON) {
|
|
2342
|
+
return "torch";
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
} catch (Exception ignore) {}
|
|
2346
|
+
|
|
2335
2347
|
switch (currentFlashMode) {
|
|
2336
2348
|
case ImageCapture.FLASH_MODE_ON:
|
|
2337
2349
|
return "on";
|
|
@@ -2343,6 +2355,35 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2343
2355
|
}
|
|
2344
2356
|
|
|
2345
2357
|
public void setFlashMode(String mode) {
|
|
2358
|
+
// Handle torch separately via CameraControl
|
|
2359
|
+
if ("torch".equals(mode)) {
|
|
2360
|
+
try {
|
|
2361
|
+
if (camera != null) {
|
|
2362
|
+
camera.getCameraControl().enableTorch(true);
|
|
2363
|
+
}
|
|
2364
|
+
} catch (Exception e) {
|
|
2365
|
+
Log.e(TAG, "setFlashMode: Failed to enable torch", e);
|
|
2366
|
+
}
|
|
2367
|
+
// Keep ImageCapture flash mode OFF to avoid conflicts with torch
|
|
2368
|
+
currentFlashMode = ImageCapture.FLASH_MODE_OFF;
|
|
2369
|
+
if (imageCapture != null) {
|
|
2370
|
+
imageCapture.setFlashMode(ImageCapture.FLASH_MODE_OFF);
|
|
2371
|
+
}
|
|
2372
|
+
if (sampleImageCapture != null) {
|
|
2373
|
+
sampleImageCapture.setFlashMode(ImageCapture.FLASH_MODE_OFF);
|
|
2374
|
+
}
|
|
2375
|
+
return;
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
// For non-torch modes, ensure torch is disabled
|
|
2379
|
+
try {
|
|
2380
|
+
if (camera != null) {
|
|
2381
|
+
camera.getCameraControl().enableTorch(false);
|
|
2382
|
+
}
|
|
2383
|
+
} catch (Exception e) {
|
|
2384
|
+
Log.w(TAG, "setFlashMode: Failed to disable torch", e);
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2346
2387
|
int flashMode;
|
|
2347
2388
|
switch (mode) {
|
|
2348
2389
|
case "on":
|