@capgo/capacitor-flash 7.1.10 → 7.1.12
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.
|
@@ -19,7 +19,7 @@ import com.getcapacitor.annotation.PermissionCallback;
|
|
|
19
19
|
@CapacitorPlugin(name = "CapacitorFlash", permissions = { @Permission(alias = "camera", strings = { Manifest.permission.CAMERA }) })
|
|
20
20
|
public class CapacitorFlashPlugin extends Plugin {
|
|
21
21
|
|
|
22
|
-
private final String pluginVersion = "7.1.
|
|
22
|
+
private final String pluginVersion = "7.1.12";
|
|
23
23
|
|
|
24
24
|
private String cameraId;
|
|
25
25
|
boolean isFlashStateOn = false;
|
|
@@ -68,7 +68,7 @@ public class CapacitorFlashPlugin extends Plugin {
|
|
|
68
68
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
69
69
|
@PluginMethod
|
|
70
70
|
public void switchOn(PluginCall call) {
|
|
71
|
-
|
|
71
|
+
Float intensity = call.getFloat("intensity", 1.0f);
|
|
72
72
|
JSObject ret = new JSObject();
|
|
73
73
|
if (cameraManager == null) {
|
|
74
74
|
ret.put("value", false);
|
|
@@ -76,7 +76,13 @@ public class CapacitorFlashPlugin extends Plugin {
|
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
try {
|
|
79
|
-
|
|
79
|
+
// Android 13+ (API 33) supports torch brightness control
|
|
80
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
81
|
+
switchOnWithIntensity(intensity);
|
|
82
|
+
} else {
|
|
83
|
+
// For older Android versions, only on/off is supported
|
|
84
|
+
cameraManager.setTorchMode(cameraId, true);
|
|
85
|
+
}
|
|
80
86
|
isFlashStateOn = true;
|
|
81
87
|
ret.put("value", true);
|
|
82
88
|
} catch (Exception e) {
|
|
@@ -86,6 +92,33 @@ public class CapacitorFlashPlugin extends Plugin {
|
|
|
86
92
|
call.resolve(ret);
|
|
87
93
|
}
|
|
88
94
|
|
|
95
|
+
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
|
|
96
|
+
private void switchOnWithIntensity(Float intensity) throws CameraAccessException {
|
|
97
|
+
// Clamp intensity between 0.0 and 1.0
|
|
98
|
+
float clampedIntensity = Math.max(0.0f, Math.min(1.0f, intensity));
|
|
99
|
+
|
|
100
|
+
// Get max torch strength level using reflection for API 33+ compatibility
|
|
101
|
+
try {
|
|
102
|
+
// CameraCharacteristics.FLASH_INFO_STRENGTH_MAX_LEVEL is an API 33+ constant
|
|
103
|
+
java.lang.reflect.Field field = CameraCharacteristics.class.getField("FLASH_INFO_STRENGTH_MAX_LEVEL");
|
|
104
|
+
CameraCharacteristics.Key<Integer> key = (CameraCharacteristics.Key<Integer>) field.get(null);
|
|
105
|
+
Integer maxLevel = cameraManager.getCameraCharacteristics(cameraId).get(key);
|
|
106
|
+
|
|
107
|
+
if (maxLevel != null && maxLevel > 1) {
|
|
108
|
+
// Convert 0.0-1.0 range to device's torch level range (1 to maxLevel)
|
|
109
|
+
// Level 1 is minimum brightness, maxLevel is maximum
|
|
110
|
+
int torchLevel = Math.max(1, Math.round(clampedIntensity * maxLevel));
|
|
111
|
+
cameraManager.turnOnTorchWithStrengthLevel(cameraId, torchLevel);
|
|
112
|
+
} else {
|
|
113
|
+
// Fallback if max level is not available
|
|
114
|
+
cameraManager.setTorchMode(cameraId, true);
|
|
115
|
+
}
|
|
116
|
+
} catch (Exception e) {
|
|
117
|
+
// If reflection fails, fall back to simple on mode
|
|
118
|
+
cameraManager.setTorchMode(cameraId, true);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
89
122
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
90
123
|
@PluginMethod
|
|
91
124
|
public void switchOff(PluginCall call) {
|
|
@@ -7,7 +7,7 @@ import Capacitor
|
|
|
7
7
|
*/
|
|
8
8
|
@objc(CapacitorFlashPlugin)
|
|
9
9
|
public class CapacitorFlashPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
10
|
-
private let pluginVersion: String = "7.1.
|
|
10
|
+
private let pluginVersion: String = "7.1.12"
|
|
11
11
|
public let identifier = "CapacitorFlashPlugin"
|
|
12
12
|
public let jsName = "CapacitorFlash"
|
|
13
13
|
public let pluginMethods: [CAPPluginMethod] = [
|