@capgo/camera-preview 4.0.0 → 5.0.1
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.
- package/README.md +22 -30
- package/android/.gradle/8.0.2/checksums/checksums.lock +0 -0
- package/android/.gradle/8.0.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/8.0.2/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.0.2/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/8.0.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.0.2/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.0.2/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.0.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.0.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/8.0.2/gc.properties +0 -0
- package/android/.gradle/8.2.1/checksums/checksums.lock +0 -0
- package/android/.gradle/8.2.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/8.2.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.2.1/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/8.2.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.2.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.2.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.2.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.2.1/gc.properties +0 -0
- package/android/.gradle/8.7/checksums/checksums.lock +0 -0
- package/android/.gradle/8.7/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.7/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/8.7/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.7/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.7/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.7/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.7/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/8.7/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/file-system.probe +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +1 -1
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -0
- package/android/gradlew +17 -12
- package/android/gradlew.bat +10 -10
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +219 -219
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +108 -85
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomSurfaceView.java +4 -3
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomTextureView.java +5 -5
- package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +44 -23
- package/dist/docs.json +29 -22
- package/dist/esm/definitions.d.ts +6 -2
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +2 -2
- package/dist/esm/web.js +44 -45
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +45 -46
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +45 -46
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CameraController.swift +35 -14
- package/ios/Plugin/Plugin.swift +25 -26
- package/ios/Plugin.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/ios/Plugin.xcworkspace/xcuserdata/martindonadieu.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/PluginTests/PluginTests.swift +61 -13
- package/ios/Podfile.lock +3 -3
- package/ios/Pods/CapacitorCordova/LICENSE +23 -0
- package/ios/Pods/CapacitorCordova/README.md +39 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/CapacitorCordova.h +21 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.h +8 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.m +5 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDV.h +28 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVAvailability.h +109 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegate.h +51 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.h +39 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.m +154 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.h +31 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.m +81 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.h +52 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.m +116 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.h +81 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.m +154 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.h +25 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.m +77 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.h +82 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.m +216 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVScreenOrientationDelegate.h +33 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUIWebViewDelegate.h +41 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUIWebViewDelegate.m +399 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.h +27 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.m +74 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUserAgentUtil.h +27 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUserAgentUtil.m +156 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.h +30 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.m +34 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.h +35 -0
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.m +63 -0
- package/ios/Pods/Local Podspecs/Capacitor.podspec.json +31 -0
- package/ios/Pods/Manifest.lock +23 -0
- package/ios/Pods/Pods.xcodeproj/project.pbxproj +1489 -0
- package/ios/Pods/Pods.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/Capacitor.xcscheme +58 -0
- package/ios/Pods/Pods.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/CapacitorCordova.xcscheme +58 -0
- package/ios/Pods/Pods.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/Pods-Plugin.xcscheme +58 -0
- package/ios/Pods/Pods.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/Pods-PluginTests.xcscheme +58 -0
- package/ios/Pods/Pods.xcodeproj/xcuserdata/martindonadieu.xcuserdatad/xcschemes/xcschememanagement.plist +39 -0
- package/ios/Pods/Target Support Files/Capacitor/Capacitor-Info.plist +26 -0
- package/ios/Pods/Target Support Files/Capacitor/Capacitor-dummy.m +5 -0
- package/ios/Pods/Target Support Files/Capacitor/Capacitor-prefix.pch +12 -0
- package/ios/Pods/Target Support Files/Capacitor/Capacitor.debug.xcconfig +16 -0
- package/ios/Pods/Target Support Files/Capacitor/Capacitor.modulemap +8 -0
- package/ios/Pods/Target Support Files/Capacitor/Capacitor.release.xcconfig +16 -0
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-Info.plist +26 -0
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-dummy.m +5 -0
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-prefix.pch +12 -0
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-umbrella.h +32 -0
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.debug.xcconfig +13 -0
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.modulemap +6 -0
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.release.xcconfig +13 -0
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-Info.plist +26 -0
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-acknowledgements.markdown +55 -0
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-acknowledgements.plist +93 -0
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-dummy.m +5 -0
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-umbrella.h +16 -0
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.debug.xcconfig +14 -0
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.modulemap +6 -0
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.release.xcconfig +14 -0
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-Info.plist +26 -0
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-acknowledgements.markdown +55 -0
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-acknowledgements.plist +93 -0
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-dummy.m +5 -0
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-frameworks.sh +188 -0
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-umbrella.h +16 -0
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.debug.xcconfig +15 -0
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.modulemap +6 -0
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.release.xcconfig +15 -0
- package/package.json +41 -48
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.ahm.capacitor.camera.preview;
|
|
2
2
|
|
|
3
3
|
import static android.Manifest.permission.CAMERA;
|
|
4
|
+
import static android.Manifest.permission.RECORD_AUDIO;
|
|
4
5
|
|
|
5
6
|
import android.app.FragmentManager;
|
|
6
7
|
import android.app.FragmentTransaction;
|
|
@@ -15,6 +16,7 @@ import android.view.MotionEvent;
|
|
|
15
16
|
import android.view.View;
|
|
16
17
|
import android.view.ViewGroup;
|
|
17
18
|
import android.widget.FrameLayout;
|
|
19
|
+
import androidx.annotation.NonNull;
|
|
18
20
|
import com.getcapacitor.JSObject;
|
|
19
21
|
import com.getcapacitor.Logger;
|
|
20
22
|
import com.getcapacitor.PermissionState;
|
|
@@ -26,13 +28,14 @@ import com.getcapacitor.annotation.Permission;
|
|
|
26
28
|
import com.getcapacitor.annotation.PermissionCallback;
|
|
27
29
|
import java.io.File;
|
|
28
30
|
import java.util.List;
|
|
31
|
+
import java.util.Objects;
|
|
29
32
|
import org.json.JSONArray;
|
|
30
33
|
|
|
31
34
|
@CapacitorPlugin(
|
|
32
35
|
name = "CameraPreview",
|
|
33
36
|
permissions = {
|
|
34
37
|
@Permission(
|
|
35
|
-
strings = { CAMERA },
|
|
38
|
+
strings = { CAMERA, RECORD_AUDIO },
|
|
36
39
|
alias = CameraPreview.CAMERA_PERMISSION_ALIAS
|
|
37
40
|
),
|
|
38
41
|
}
|
|
@@ -44,7 +47,7 @@ public class CameraPreview
|
|
|
44
47
|
static final String CAMERA_PERMISSION_ALIAS = "camera";
|
|
45
48
|
|
|
46
49
|
private static String VIDEO_FILE_PATH = "";
|
|
47
|
-
private static String VIDEO_FILE_EXTENSION = ".mp4";
|
|
50
|
+
private static final String VIDEO_FILE_EXTENSION = ".mp4";
|
|
48
51
|
|
|
49
52
|
private String captureCallbackId = "";
|
|
50
53
|
private String snapshotCallbackId = "";
|
|
@@ -52,10 +55,11 @@ public class CameraPreview
|
|
|
52
55
|
private String cameraStartCallbackId = "";
|
|
53
56
|
|
|
54
57
|
// keep track of previously specified orientation to support locking orientation:
|
|
55
|
-
private int previousOrientationRequest =
|
|
58
|
+
private int previousOrientationRequest =
|
|
59
|
+
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
|
56
60
|
|
|
57
61
|
private CameraActivity fragment;
|
|
58
|
-
private int containerViewId = 20;
|
|
62
|
+
private final int containerViewId = 20;
|
|
59
63
|
|
|
60
64
|
@PluginMethod
|
|
61
65
|
public void start(PluginCall call) {
|
|
@@ -87,42 +91,42 @@ public class CameraPreview
|
|
|
87
91
|
|
|
88
92
|
@PluginMethod
|
|
89
93
|
public void setOpacity(PluginCall call) {
|
|
90
|
-
if (this.hasCamera(call)
|
|
94
|
+
if (!this.hasCamera(call)) {
|
|
91
95
|
call.error("Camera is not running");
|
|
92
96
|
return;
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
bridge.saveCall(call);
|
|
96
|
-
Float opacity = call.getFloat("opacity", 1F);
|
|
100
|
+
Float opacity = Objects.requireNonNull(call.getFloat("opacity", 1F));
|
|
97
101
|
fragment.setOpacity(opacity);
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
@PluginMethod
|
|
101
105
|
public void capture(PluginCall call) {
|
|
102
|
-
if (this.hasCamera(call)
|
|
106
|
+
if (!this.hasCamera(call)) {
|
|
103
107
|
call.reject("Camera is not running");
|
|
104
108
|
return;
|
|
105
109
|
}
|
|
106
110
|
bridge.saveCall(call);
|
|
107
111
|
captureCallbackId = call.getCallbackId();
|
|
108
112
|
|
|
109
|
-
Integer quality = call.getInt("quality", 85);
|
|
113
|
+
Integer quality = Objects.requireNonNull(call.getInt("quality", 85));
|
|
110
114
|
// Image Dimensions - Optional
|
|
111
|
-
Integer width = call.getInt("width", 0);
|
|
112
|
-
Integer height = call.getInt("height", 0);
|
|
115
|
+
Integer width = Objects.requireNonNull(call.getInt("width", 0));
|
|
116
|
+
Integer height = Objects.requireNonNull(call.getInt("height", 0));
|
|
113
117
|
fragment.takePicture(width, height, quality);
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
@PluginMethod
|
|
117
121
|
public void captureSample(PluginCall call) {
|
|
118
|
-
if (this.hasCamera(call)
|
|
122
|
+
if (!this.hasCamera(call)) {
|
|
119
123
|
call.reject("Camera is not running");
|
|
120
124
|
return;
|
|
121
125
|
}
|
|
122
126
|
bridge.saveCall(call);
|
|
123
127
|
snapshotCallbackId = call.getCallbackId();
|
|
124
128
|
|
|
125
|
-
Integer quality = call.getInt("quality", 85);
|
|
129
|
+
Integer quality = Objects.requireNonNull(call.getInt("quality", 85));
|
|
126
130
|
fragment.takeSnapshot(quality);
|
|
127
131
|
}
|
|
128
132
|
|
|
@@ -167,7 +171,7 @@ public class CameraPreview
|
|
|
167
171
|
|
|
168
172
|
@PluginMethod
|
|
169
173
|
public void getSupportedFlashModes(PluginCall call) {
|
|
170
|
-
if (this.hasCamera(call)
|
|
174
|
+
if (!this.hasCamera(call)) {
|
|
171
175
|
call.reject("Camera is not running");
|
|
172
176
|
return;
|
|
173
177
|
}
|
|
@@ -180,7 +184,7 @@ public class CameraPreview
|
|
|
180
184
|
|
|
181
185
|
if (supportedFlashModes != null) {
|
|
182
186
|
for (int i = 0; i < supportedFlashModes.size(); i++) {
|
|
183
|
-
jsonFlashModes.put(
|
|
187
|
+
jsonFlashModes.put(supportedFlashModes.get(i));
|
|
184
188
|
}
|
|
185
189
|
}
|
|
186
190
|
|
|
@@ -191,7 +195,7 @@ public class CameraPreview
|
|
|
191
195
|
|
|
192
196
|
@PluginMethod
|
|
193
197
|
public void getHorizontalFov(PluginCall call) {
|
|
194
|
-
if (this.hasCamera(call)
|
|
198
|
+
if (!this.hasCamera(call)) {
|
|
195
199
|
call.reject("Camera is not running");
|
|
196
200
|
return;
|
|
197
201
|
}
|
|
@@ -208,13 +212,13 @@ public class CameraPreview
|
|
|
208
212
|
|
|
209
213
|
@PluginMethod
|
|
210
214
|
public void setFlashMode(PluginCall call) {
|
|
211
|
-
if (this.hasCamera(call)
|
|
215
|
+
if (!this.hasCamera(call)) {
|
|
212
216
|
call.reject("Camera is not running");
|
|
213
217
|
return;
|
|
214
218
|
}
|
|
215
219
|
|
|
216
220
|
String flashMode = call.getString("flashMode");
|
|
217
|
-
if (flashMode == null || flashMode.isEmpty()
|
|
221
|
+
if (flashMode == null || flashMode.isEmpty()) {
|
|
218
222
|
call.reject("flashMode required parameter is missing");
|
|
219
223
|
return;
|
|
220
224
|
}
|
|
@@ -225,7 +229,7 @@ public class CameraPreview
|
|
|
225
229
|
List<String> supportedFlashModes;
|
|
226
230
|
supportedFlashModes = camera.getParameters().getSupportedFlashModes();
|
|
227
231
|
if (
|
|
228
|
-
supportedFlashModes != null && supportedFlashModes.
|
|
232
|
+
supportedFlashModes != null && supportedFlashModes.contains(flashMode)
|
|
229
233
|
) {
|
|
230
234
|
params.setFlashMode(flashMode);
|
|
231
235
|
} else {
|
|
@@ -240,19 +244,25 @@ public class CameraPreview
|
|
|
240
244
|
|
|
241
245
|
@PluginMethod
|
|
242
246
|
public void startRecordVideo(final PluginCall call) {
|
|
243
|
-
if (this.hasCamera(call)
|
|
247
|
+
if (!this.hasCamera(call)) {
|
|
244
248
|
call.reject("Camera is not running");
|
|
245
249
|
return;
|
|
246
250
|
}
|
|
247
251
|
final String filename = "videoTmp";
|
|
248
252
|
VIDEO_FILE_PATH = getActivity().getCacheDir().toString() + "/";
|
|
249
253
|
|
|
250
|
-
final String position =
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
final
|
|
254
|
-
final Integer
|
|
255
|
-
|
|
254
|
+
final String position = Objects.requireNonNull(
|
|
255
|
+
call.getString("position", "front")
|
|
256
|
+
);
|
|
257
|
+
final Integer width = Objects.requireNonNull(call.getInt("width", 0));
|
|
258
|
+
final Integer height = Objects.requireNonNull(call.getInt("height", 0));
|
|
259
|
+
final Boolean withFlash = Objects.requireNonNull(
|
|
260
|
+
call.getBoolean("withFlash", false)
|
|
261
|
+
);
|
|
262
|
+
final Integer maxDuration = Objects.requireNonNull(
|
|
263
|
+
call.getInt("maxDuration", 0)
|
|
264
|
+
);
|
|
265
|
+
// final Integer quality = Objects.requireNonNull(call.getInt("quality", 0));
|
|
256
266
|
bridge.saveCall(call);
|
|
257
267
|
recordCallbackId = call.getCallbackId();
|
|
258
268
|
|
|
@@ -262,9 +272,8 @@ public class CameraPreview
|
|
|
262
272
|
new Runnable() {
|
|
263
273
|
@Override
|
|
264
274
|
public void run() {
|
|
265
|
-
// fragment.startRecord(getFilePath(filename), position, width, height, quality, withFlash);
|
|
266
275
|
fragment.startRecord(
|
|
267
|
-
getFilePath(
|
|
276
|
+
getFilePath(),
|
|
268
277
|
position,
|
|
269
278
|
width,
|
|
270
279
|
height,
|
|
@@ -281,7 +290,7 @@ public class CameraPreview
|
|
|
281
290
|
|
|
282
291
|
@PluginMethod
|
|
283
292
|
public void stopRecordVideo(PluginCall call) {
|
|
284
|
-
if (this.hasCamera(call)
|
|
293
|
+
if (!this.hasCamera(call)) {
|
|
285
294
|
call.reject("Camera is not running");
|
|
286
295
|
return;
|
|
287
296
|
}
|
|
@@ -329,25 +338,39 @@ public class CameraPreview
|
|
|
329
338
|
position = "front";
|
|
330
339
|
}
|
|
331
340
|
|
|
332
|
-
|
|
333
|
-
final Integer
|
|
334
|
-
|
|
335
|
-
final Integer
|
|
336
|
-
|
|
337
|
-
final
|
|
338
|
-
|
|
339
|
-
final
|
|
340
|
-
|
|
341
|
-
final
|
|
342
|
-
"
|
|
343
|
-
|
|
341
|
+
@NonNull
|
|
342
|
+
final Integer x = Objects.requireNonNull(call.getInt("x", 0));
|
|
343
|
+
@NonNull
|
|
344
|
+
final Integer y = Objects.requireNonNull(call.getInt("y", 0));
|
|
345
|
+
@NonNull
|
|
346
|
+
final Integer width = Objects.requireNonNull(call.getInt("width", 0));
|
|
347
|
+
@NonNull
|
|
348
|
+
final Integer height = Objects.requireNonNull(call.getInt("height", 0));
|
|
349
|
+
@NonNull
|
|
350
|
+
final Integer paddingBottom = Objects.requireNonNull(
|
|
351
|
+
call.getInt("paddingBottom", 0)
|
|
352
|
+
);
|
|
353
|
+
final Boolean toBack = Objects.requireNonNull(
|
|
354
|
+
call.getBoolean("toBack", false)
|
|
355
|
+
);
|
|
356
|
+
final Boolean storeToFile = Objects.requireNonNull(
|
|
357
|
+
call.getBoolean("storeToFile", false)
|
|
358
|
+
);
|
|
359
|
+
final Boolean enableOpacity = Objects.requireNonNull(
|
|
360
|
+
call.getBoolean("enableOpacity", false)
|
|
344
361
|
);
|
|
345
|
-
final Boolean
|
|
346
|
-
"
|
|
347
|
-
false
|
|
362
|
+
final Boolean enableZoom = Objects.requireNonNull(
|
|
363
|
+
call.getBoolean("enableZoom", false)
|
|
348
364
|
);
|
|
349
|
-
|
|
350
|
-
|
|
365
|
+
final Boolean disableExifHeaderStripping = Objects.requireNonNull(
|
|
366
|
+
call.getBoolean("disableExifHeaderStripping", false)
|
|
367
|
+
);
|
|
368
|
+
final Boolean lockOrientation = Objects.requireNonNull(
|
|
369
|
+
call.getBoolean("lockAndroidOrientation", false)
|
|
370
|
+
);
|
|
371
|
+
previousOrientationRequest = getBridge()
|
|
372
|
+
.getActivity()
|
|
373
|
+
.getRequestedOrientation();
|
|
351
374
|
|
|
352
375
|
fragment = new CameraActivity();
|
|
353
376
|
fragment.setEventListener(this);
|
|
@@ -398,23 +421,21 @@ public class CameraPreview
|
|
|
398
421
|
int computedPaddingBottom;
|
|
399
422
|
|
|
400
423
|
if (paddingBottom != 0) {
|
|
401
|
-
computedPaddingBottom =
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
);
|
|
424
|
+
computedPaddingBottom = (int) TypedValue.applyDimension(
|
|
425
|
+
TypedValue.COMPLEX_UNIT_DIP,
|
|
426
|
+
paddingBottom,
|
|
427
|
+
metrics
|
|
428
|
+
);
|
|
407
429
|
} else {
|
|
408
430
|
computedPaddingBottom = 0;
|
|
409
431
|
}
|
|
410
432
|
|
|
411
433
|
if (width != 0) {
|
|
412
|
-
computedWidth =
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
);
|
|
434
|
+
computedWidth = (int) TypedValue.applyDimension(
|
|
435
|
+
TypedValue.COMPLEX_UNIT_DIP,
|
|
436
|
+
width,
|
|
437
|
+
metrics
|
|
438
|
+
);
|
|
418
439
|
} else {
|
|
419
440
|
Display defaultDisplay = getBridge()
|
|
420
441
|
.getActivity()
|
|
@@ -423,22 +444,20 @@ public class CameraPreview
|
|
|
423
444
|
final Point size = new Point();
|
|
424
445
|
defaultDisplay.getSize(size);
|
|
425
446
|
|
|
426
|
-
computedWidth =
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
);
|
|
447
|
+
computedWidth = (int) TypedValue.applyDimension(
|
|
448
|
+
TypedValue.COMPLEX_UNIT_PX,
|
|
449
|
+
size.x,
|
|
450
|
+
metrics
|
|
451
|
+
);
|
|
432
452
|
}
|
|
433
453
|
|
|
434
454
|
if (height != 0) {
|
|
435
|
-
computedHeight =
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
computedPaddingBottom;
|
|
455
|
+
computedHeight = (int) TypedValue.applyDimension(
|
|
456
|
+
TypedValue.COMPLEX_UNIT_DIP,
|
|
457
|
+
height,
|
|
458
|
+
metrics
|
|
459
|
+
) -
|
|
460
|
+
computedPaddingBottom;
|
|
442
461
|
} else {
|
|
443
462
|
Display defaultDisplay = getBridge()
|
|
444
463
|
.getActivity()
|
|
@@ -447,13 +466,12 @@ public class CameraPreview
|
|
|
447
466
|
final Point size = new Point();
|
|
448
467
|
defaultDisplay.getSize(size);
|
|
449
468
|
|
|
450
|
-
computedHeight =
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
computedPaddingBottom;
|
|
469
|
+
computedHeight = (int) TypedValue.applyDimension(
|
|
470
|
+
TypedValue.COMPLEX_UNIT_PX,
|
|
471
|
+
size.y,
|
|
472
|
+
metrics
|
|
473
|
+
) -
|
|
474
|
+
computedPaddingBottom;
|
|
457
475
|
}
|
|
458
476
|
|
|
459
477
|
fragment.setRect(
|
|
@@ -467,15 +485,16 @@ public class CameraPreview
|
|
|
467
485
|
.getActivity()
|
|
468
486
|
.findViewById(containerViewId);
|
|
469
487
|
if (containerView == null) {
|
|
470
|
-
containerView =
|
|
471
|
-
|
|
488
|
+
containerView = new FrameLayout(
|
|
489
|
+
getActivity().getApplicationContext()
|
|
490
|
+
);
|
|
472
491
|
containerView.setId(containerViewId);
|
|
473
492
|
|
|
474
493
|
getBridge().getWebView().setBackgroundColor(Color.TRANSPARENT);
|
|
475
494
|
((ViewGroup) getBridge().getWebView().getParent()).addView(
|
|
476
495
|
containerView
|
|
477
496
|
);
|
|
478
|
-
if (toBack
|
|
497
|
+
if (toBack) {
|
|
479
498
|
getBridge()
|
|
480
499
|
.getWebView()
|
|
481
500
|
.getParent()
|
|
@@ -582,7 +601,7 @@ public class CameraPreview
|
|
|
582
601
|
}
|
|
583
602
|
|
|
584
603
|
private boolean hasCamera(PluginCall call) {
|
|
585
|
-
if (this.hasView(call)
|
|
604
|
+
if (!this.hasView(call)) {
|
|
586
605
|
return false;
|
|
587
606
|
}
|
|
588
607
|
|
|
@@ -593,8 +612,8 @@ public class CameraPreview
|
|
|
593
612
|
return true;
|
|
594
613
|
}
|
|
595
614
|
|
|
596
|
-
private String getFilePath(
|
|
597
|
-
String fileName =
|
|
615
|
+
private String getFilePath() {
|
|
616
|
+
String fileName = "videoTmp";
|
|
598
617
|
|
|
599
618
|
int i = 1;
|
|
600
619
|
|
|
@@ -602,7 +621,7 @@ public class CameraPreview
|
|
|
602
621
|
new File(VIDEO_FILE_PATH + fileName + VIDEO_FILE_EXTENSION).exists()
|
|
603
622
|
) {
|
|
604
623
|
// Add number suffix if file exists
|
|
605
|
-
fileName =
|
|
624
|
+
fileName = "videoTmp" + '_' + i;
|
|
606
625
|
i++;
|
|
607
626
|
}
|
|
608
627
|
|
|
@@ -619,7 +638,11 @@ public class CameraPreview
|
|
|
619
638
|
new View.OnTouchListener() {
|
|
620
639
|
@Override
|
|
621
640
|
public boolean onTouch(View v, MotionEvent event) {
|
|
622
|
-
if (
|
|
641
|
+
if (
|
|
642
|
+
(null != fragment) &&
|
|
643
|
+
(fragment.toBack == true) &&
|
|
644
|
+
null != fragment.frameContainerLayout
|
|
645
|
+
) {
|
|
623
646
|
fragment.frameContainerLayout.dispatchTouchEvent(event);
|
|
624
647
|
}
|
|
625
648
|
return false;
|
|
@@ -3,6 +3,7 @@ package com.ahm.capacitor.camera.preview;
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.view.SurfaceHolder;
|
|
5
5
|
import android.view.SurfaceView;
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
6
7
|
|
|
7
8
|
class CustomSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
|
|
8
9
|
|
|
@@ -13,16 +14,16 @@ class CustomSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
@Override
|
|
16
|
-
public void surfaceCreated(SurfaceHolder holder) {}
|
|
17
|
+
public void surfaceCreated(@NonNull SurfaceHolder holder) {}
|
|
17
18
|
|
|
18
19
|
@Override
|
|
19
20
|
public void surfaceChanged(
|
|
20
|
-
SurfaceHolder holder,
|
|
21
|
+
@NonNull SurfaceHolder holder,
|
|
21
22
|
int format,
|
|
22
23
|
int width,
|
|
23
24
|
int height
|
|
24
25
|
) {}
|
|
25
26
|
|
|
26
27
|
@Override
|
|
27
|
-
public void surfaceDestroyed(SurfaceHolder holder) {}
|
|
28
|
+
public void surfaceDestroyed(@NonNull SurfaceHolder holder) {}
|
|
28
29
|
}
|
|
@@ -2,8 +2,8 @@ package com.ahm.capacitor.camera.preview;
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.graphics.SurfaceTexture;
|
|
5
|
-
import android.view.SurfaceHolder;
|
|
6
5
|
import android.view.TextureView;
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
7
|
|
|
8
8
|
class CustomTextureView
|
|
9
9
|
extends TextureView
|
|
@@ -17,23 +17,23 @@ class CustomTextureView
|
|
|
17
17
|
|
|
18
18
|
@Override
|
|
19
19
|
public void onSurfaceTextureAvailable(
|
|
20
|
-
SurfaceTexture surface,
|
|
20
|
+
@NonNull SurfaceTexture surface,
|
|
21
21
|
int width,
|
|
22
22
|
int height
|
|
23
23
|
) {}
|
|
24
24
|
|
|
25
25
|
@Override
|
|
26
26
|
public void onSurfaceTextureSizeChanged(
|
|
27
|
-
SurfaceTexture surface,
|
|
27
|
+
@NonNull SurfaceTexture surface,
|
|
28
28
|
int width,
|
|
29
29
|
int height
|
|
30
30
|
) {}
|
|
31
31
|
|
|
32
32
|
@Override
|
|
33
|
-
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
|
33
|
+
public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) {
|
|
34
34
|
return true;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
@Override
|
|
38
|
-
public void onSurfaceTextureUpdated(SurfaceTexture surface) {}
|
|
38
|
+
public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {}
|
|
39
39
|
}
|
|
@@ -67,8 +67,9 @@ class Preview
|
|
|
67
67
|
if (camera != null) {
|
|
68
68
|
mCamera = camera;
|
|
69
69
|
this.cameraId = cameraId;
|
|
70
|
-
mSupportedPreviewSizes =
|
|
71
|
-
|
|
70
|
+
mSupportedPreviewSizes = mCamera
|
|
71
|
+
.getParameters()
|
|
72
|
+
.getSupportedPreviewSizes();
|
|
72
73
|
setCameraDisplayOrientation();
|
|
73
74
|
|
|
74
75
|
List<String> mFocusModes = mCamera
|
|
@@ -84,6 +85,12 @@ class Preview
|
|
|
84
85
|
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
|
|
85
86
|
}
|
|
86
87
|
mCamera.setParameters(params);
|
|
88
|
+
} else {
|
|
89
|
+
// Release the camera and set it to null when the camera parameter is null
|
|
90
|
+
if (mCamera != null) {
|
|
91
|
+
mCamera.release();
|
|
92
|
+
mCamera = null;
|
|
93
|
+
}
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
96
|
|
|
@@ -154,9 +161,9 @@ class Preview
|
|
|
154
161
|
Log.d(TAG, "screen is rotated " + degrees + "deg from natural");
|
|
155
162
|
Log.d(
|
|
156
163
|
TAG,
|
|
157
|
-
(
|
|
158
|
-
|
|
159
|
-
|
|
164
|
+
(info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT
|
|
165
|
+
? "front"
|
|
166
|
+
: "back") +
|
|
160
167
|
" camera is oriented -" +
|
|
161
168
|
info.orientation +
|
|
162
169
|
"deg from natural"
|
|
@@ -187,12 +194,11 @@ class Preview
|
|
|
187
194
|
Log.d("CameraPreview", "before setPreviewSize");
|
|
188
195
|
|
|
189
196
|
mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
|
|
190
|
-
mPreviewSize =
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
);
|
|
197
|
+
mPreviewSize = getOptimalPreviewSize(
|
|
198
|
+
mSupportedPreviewSizes,
|
|
199
|
+
v.getWidth(),
|
|
200
|
+
v.getHeight()
|
|
201
|
+
);
|
|
196
202
|
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
|
|
197
203
|
Log.d(TAG, mPreviewSize.width + " " + mPreviewSize.height);
|
|
198
204
|
|
|
@@ -215,8 +221,11 @@ class Preview
|
|
|
215
221
|
setMeasuredDimension(width, height);
|
|
216
222
|
|
|
217
223
|
if (mSupportedPreviewSizes != null) {
|
|
218
|
-
mPreviewSize =
|
|
219
|
-
|
|
224
|
+
mPreviewSize = getOptimalPreviewSize(
|
|
225
|
+
mSupportedPreviewSizes,
|
|
226
|
+
width,
|
|
227
|
+
height
|
|
228
|
+
);
|
|
220
229
|
}
|
|
221
230
|
}
|
|
222
231
|
|
|
@@ -252,18 +261,18 @@ class Preview
|
|
|
252
261
|
// Center the child SurfaceView within the parent.
|
|
253
262
|
if (width * previewHeight < height * previewWidth) {
|
|
254
263
|
Log.d(TAG, "center horizontally");
|
|
255
|
-
int scaledChildWidth = (int) (
|
|
256
|
-
|
|
257
|
-
|
|
264
|
+
int scaledChildWidth = (int) (((previewWidth * height) /
|
|
265
|
+
previewHeight) *
|
|
266
|
+
scale);
|
|
258
267
|
nW = (width + scaledChildWidth) / 2;
|
|
259
268
|
nH = (int) (height * scale);
|
|
260
269
|
top = 0;
|
|
261
270
|
left = (width - scaledChildWidth) / 2;
|
|
262
271
|
} else {
|
|
263
272
|
Log.d(TAG, "center vertically");
|
|
264
|
-
int scaledChildHeight = (int) (
|
|
265
|
-
|
|
266
|
-
|
|
273
|
+
int scaledChildHeight = (int) (((previewHeight * width) /
|
|
274
|
+
previewWidth) *
|
|
275
|
+
scale);
|
|
267
276
|
nW = (int) (width * scale);
|
|
268
277
|
nH = (height + scaledChildHeight) / 2;
|
|
269
278
|
top = (height - scaledChildHeight) / 2;
|
|
@@ -355,12 +364,21 @@ class Preview
|
|
|
355
364
|
}
|
|
356
365
|
|
|
357
366
|
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
|
367
|
+
Log.d(
|
|
368
|
+
TAG,
|
|
369
|
+
"Preview size in surfaceChanged: " +
|
|
370
|
+
mPreviewSize.width +
|
|
371
|
+
"x" +
|
|
372
|
+
mPreviewSize.height
|
|
373
|
+
);
|
|
374
|
+
|
|
358
375
|
if (mCamera != null) {
|
|
359
376
|
try {
|
|
360
377
|
// Now that the size is known, set up the camera parameters and begin
|
|
361
378
|
// the preview.
|
|
362
|
-
mSupportedPreviewSizes =
|
|
363
|
-
|
|
379
|
+
mSupportedPreviewSizes = mCamera
|
|
380
|
+
.getParameters()
|
|
381
|
+
.getSupportedPreviewSizes();
|
|
364
382
|
if (mSupportedPreviewSizes != null) {
|
|
365
383
|
mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, w, h);
|
|
366
384
|
}
|
|
@@ -392,8 +410,11 @@ class Preview
|
|
|
392
410
|
try {
|
|
393
411
|
mSurface = surface;
|
|
394
412
|
if (mSupportedPreviewSizes != null) {
|
|
395
|
-
mPreviewSize =
|
|
396
|
-
|
|
413
|
+
mPreviewSize = getOptimalPreviewSize(
|
|
414
|
+
mSupportedPreviewSizes,
|
|
415
|
+
width,
|
|
416
|
+
height
|
|
417
|
+
);
|
|
397
418
|
}
|
|
398
419
|
if (mCamera != null) {
|
|
399
420
|
mTextureView.setAlpha(opacity);
|