@capacitor-community/camera-preview 2.0.0-beta.0 → 2.1.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.
- package/CapacitorCommunityCameraPreview.podspec +3 -2
- package/LICENSE +21 -0
- package/README.md +80 -61
- package/android/.gradle/4.10.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/4.10.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/4.10.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/4.10.1/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/compiler.xml +6 -0
- package/android/.idea/gradle.xml +20 -0
- package/android/.idea/jarRepositories.xml +45 -0
- package/android/.idea/libraries/Gradle__androidx_activity_activity_1_2_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_activity_activity_1_2_3_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_1_0.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_2_0.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_annotation_annotation_experimental_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_2_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_3_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_resources_1_2_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_resources_1_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_common_2_1_0.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_1_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_collection_collection_1_1_0.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_coordinatorlayout_coordinatorlayout_1_1_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_core_core_1_3_2_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_core_core_1_5_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_customview_customview_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_exifinterface_exifinterface_1_3_2_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_3_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_3_4_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_3_0.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_3_1.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_3_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_3_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_3_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_savedstate_2_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_savedstate_2_3_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_loader_loader_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_savedstate_savedstate_1_1_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_core_1_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_core_3_1_0_alpha3_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_core_3_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_idling_resource_3_1_0_alpha3_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_idling_resource_3_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_ext_junit_1_1_2_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_monitor_1_1_0_alpha3_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_monitor_1_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_runner_1_1_0_alpha3_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_runner_1_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_tracing_tracing_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_1_1_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_animated_1_1_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_2_0_1.xml +9 -0
- package/android/.idea/libraries/Gradle__com_squareup_javawriter_2_1_1.xml +9 -0
- package/android/.idea/libraries/Gradle__javax_inject_javax_inject_1.xml +9 -0
- package/android/.idea/libraries/Gradle__junit_junit_4_12.xml +9 -0
- package/android/.idea/libraries/Gradle__junit_junit_4_13_1.xml +9 -0
- package/android/.idea/libraries/Gradle__net_bytebuddy_byte_buddy_1_10_18.xml +9 -0
- package/android/.idea/libraries/Gradle__net_bytebuddy_byte_buddy_agent_1_10_18.xml +9 -0
- package/android/.idea/libraries/Gradle__net_sf_kxml_kxml2_2_3_0.xml +9 -0
- package/android/.idea/libraries/Gradle__org_apache_cordova_framework_7_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml +9 -0
- package/android/.idea/libraries/Gradle__org_hamcrest_hamcrest_integration_1_3.xml +9 -0
- package/android/.idea/libraries/Gradle__org_hamcrest_hamcrest_library_1_3.xml +9 -0
- package/android/.idea/libraries/Gradle__org_json_json_20140107.xml +9 -0
- package/android/.idea/libraries/Gradle__org_mockito_mockito_core_3_6_28.xml +9 -0
- package/android/.idea/libraries/Gradle__org_mockito_mockito_inline_3_6_28.xml +9 -0
- package/android/.idea/libraries/Gradle__org_objenesis_objenesis_3_1.xml +9 -0
- package/android/.idea/misc.xml +9 -0
- package/android/.idea/modules/1419750366/android.capacitor-android.iml +92 -0
- package/android/.idea/modules/android.iml +87 -0
- package/android/.idea/modules.xml +9 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +4 -4
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +128 -70
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +163 -118
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomTextureView.java +31 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +96 -19
- package/dist/esm/definitions.d.ts +18 -5
- package/dist/esm/definitions.js +1 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +8 -1
- package/dist/esm/web.js +95 -77
- package/dist/esm/web.js.map +1 -1
- package/ios/Plugin/CameraController.swift +237 -48
- package/ios/Plugin/Plugin.m +3 -0
- package/ios/Plugin/Plugin.swift +130 -46
- package/ios/Plugin.xcodeproj/project.pbxproj +2 -6
- package/ios/Podfile +2 -2
- package/ios/Podfile.lock +4 -4
- package/package.json +7 -6
- package/android/local.properties +0 -8
- package/ios/Plugin.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/ios/Plugin.xcodeproj/xcuserdata/nielsvanharen.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/ios/Plugin.xcworkspace/xcuserdata/ahernandez.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Plugin.xcworkspace/xcuserdata/arielhernandezmusa.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Plugin.xcworkspace/xcuserdata/nielsvanharen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Pods/CapacitorCordova/LICENSE +0 -23
- package/ios/Pods/CapacitorCordova/README.md +0 -39
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/CapacitorCordova.h +0 -21
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.h +0 -8
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.m +0 -5
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDV.h +0 -28
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVAvailability.h +0 -109
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegate.h +0 -51
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.h +0 -39
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.m +0 -154
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.h +0 -31
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.m +0 -81
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.h +0 -52
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.m +0 -116
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.h +0 -81
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.m +0 -154
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.h +0 -25
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.m +0 -77
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.h +0 -82
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.m +0 -216
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVScreenOrientationDelegate.h +0 -33
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUIWebViewDelegate.h +0 -41
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUIWebViewDelegate.m +0 -399
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.h +0 -27
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.m +0 -74
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUserAgentUtil.h +0 -27
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUserAgentUtil.m +0 -156
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.h +0 -30
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.m +0 -34
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.h +0 -35
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.m +0 -63
- package/ios/Pods/Local Podspecs/Capacitor.podspec.json +0 -31
- package/ios/Pods/Manifest.lock +0 -23
- package/ios/Pods/Pods.xcodeproj/project.pbxproj +0 -1296
- package/ios/Pods/Pods.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/Capacitor.xcscheme +0 -60
- package/ios/Pods/Pods.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/CapacitorCordova.xcscheme +0 -58
- package/ios/Pods/Pods.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/Pods-Plugin.xcscheme +0 -58
- package/ios/Pods/Pods.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/Pods-PluginTests.xcscheme +0 -58
- package/ios/Pods/Pods.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/xcschememanagement.plist +0 -39
- package/ios/Pods/Target Support Files/Capacitor/Capacitor-Info.plist +0 -26
- package/ios/Pods/Target Support Files/Capacitor/Capacitor-dummy.m +0 -5
- package/ios/Pods/Target Support Files/Capacitor/Capacitor-prefix.pch +0 -12
- package/ios/Pods/Target Support Files/Capacitor/Capacitor.debug.xcconfig +0 -13
- package/ios/Pods/Target Support Files/Capacitor/Capacitor.modulemap +0 -7
- package/ios/Pods/Target Support Files/Capacitor/Capacitor.release.xcconfig +0 -13
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-Info.plist +0 -26
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-dummy.m +0 -5
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-prefix.pch +0 -12
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-umbrella.h +0 -32
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.debug.xcconfig +0 -12
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.modulemap +0 -6
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.release.xcconfig +0 -12
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-Info.plist +0 -26
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-acknowledgements.markdown +0 -57
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-acknowledgements.plist +0 -95
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-dummy.m +0 -5
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-umbrella.h +0 -16
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.debug.xcconfig +0 -13
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.modulemap +0 -6
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.release.xcconfig +0 -13
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-Info.plist +0 -26
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-acknowledgements.markdown +0 -57
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-acknowledgements.plist +0 -95
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-dummy.m +0 -5
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-frameworks.sh +0 -187
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-umbrella.h +0 -16
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.debug.xcconfig +0 -14
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.modulemap +0 -6
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.release.xcconfig +0 -14
|
@@ -1,45 +1,54 @@
|
|
|
1
1
|
package com.ahm.capacitor.camera.preview;
|
|
2
2
|
|
|
3
|
-
import android.Manifest;
|
|
4
3
|
import android.app.FragmentManager;
|
|
5
4
|
import android.app.FragmentTransaction;
|
|
5
|
+
import android.content.pm.ActivityInfo;
|
|
6
6
|
import android.graphics.Color;
|
|
7
7
|
import android.graphics.Point;
|
|
8
8
|
import android.hardware.Camera;
|
|
9
9
|
import android.util.DisplayMetrics;
|
|
10
10
|
import android.util.TypedValue;
|
|
11
11
|
import android.view.Display;
|
|
12
|
+
import android.view.MotionEvent;
|
|
13
|
+
import android.view.View;
|
|
12
14
|
import android.view.ViewGroup;
|
|
13
15
|
import android.widget.FrameLayout;
|
|
14
16
|
|
|
15
17
|
import com.getcapacitor.JSObject;
|
|
16
|
-
import com.getcapacitor.
|
|
18
|
+
import com.getcapacitor.Logger;
|
|
19
|
+
import com.getcapacitor.PermissionState;
|
|
17
20
|
import com.getcapacitor.Plugin;
|
|
18
21
|
import com.getcapacitor.PluginCall;
|
|
19
22
|
import com.getcapacitor.PluginMethod;
|
|
23
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
24
|
+
import com.getcapacitor.annotation.Permission;
|
|
25
|
+
import com.getcapacitor.annotation.PermissionCallback;
|
|
20
26
|
|
|
21
27
|
import org.json.JSONArray;
|
|
22
|
-
import org.json.JSONException;
|
|
23
|
-
import org.json.JSONObject;
|
|
24
28
|
|
|
25
|
-
import java.util.List;
|
|
26
29
|
import java.io.File;
|
|
30
|
+
import java.util.List;
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
import static android.Manifest.permission.CAMERA;
|
|
33
|
+
|
|
34
|
+
@CapacitorPlugin(
|
|
35
|
+
name = "CameraPreview",
|
|
29
36
|
permissions = {
|
|
30
|
-
|
|
31
|
-
Manifest.permission.RECORD_AUDIO,
|
|
32
|
-
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
33
|
-
Manifest.permission.READ_EXTERNAL_STORAGE
|
|
34
|
-
},
|
|
35
|
-
requestCodes = {
|
|
36
|
-
CameraPreview.REQUEST_CAMERA_PERMISSION
|
|
37
|
+
@Permission(strings = {CAMERA}, alias = CameraPreview.CAMERA_PERMISSION_ALIAS)
|
|
37
38
|
}
|
|
38
39
|
)
|
|
39
40
|
public class CameraPreview extends Plugin implements CameraActivity.CameraPreviewListener {
|
|
41
|
+
static final String CAMERA_PERMISSION_ALIAS = "camera";
|
|
42
|
+
|
|
40
43
|
private static String VIDEO_FILE_PATH = "";
|
|
41
44
|
private static String VIDEO_FILE_EXTENSION = ".mp4";
|
|
42
|
-
|
|
45
|
+
|
|
46
|
+
private String captureCallbackId = "";
|
|
47
|
+
private String snapshotCallbackId = "";
|
|
48
|
+
private String recordCallbackId = "";
|
|
49
|
+
|
|
50
|
+
// keep track of previously specified orientation to support locking orientation:
|
|
51
|
+
private int previousOrientationRequest = -1;
|
|
43
52
|
|
|
44
53
|
private CameraActivity fragment;
|
|
45
54
|
private int containerViewId = 20;
|
|
@@ -50,43 +59,49 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
50
59
|
|
|
51
60
|
JSObject ret = new JSObject();
|
|
52
61
|
ret.put("value", value);
|
|
53
|
-
call.
|
|
62
|
+
call.resolve(ret);
|
|
54
63
|
}
|
|
55
64
|
|
|
56
65
|
@PluginMethod()
|
|
57
66
|
public void start(PluginCall call) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (hasRequiredPermissions()) {
|
|
67
|
+
if (PermissionState.GRANTED.equals(getPermissionState(CAMERA_PERMISSION_ALIAS))) {
|
|
61
68
|
startCamera(call);
|
|
62
69
|
} else {
|
|
63
|
-
|
|
64
|
-
Manifest.permission.CAMERA,
|
|
65
|
-
Manifest.permission.RECORD_AUDIO,
|
|
66
|
-
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
67
|
-
Manifest.permission.READ_EXTERNAL_STORAGE
|
|
68
|
-
}, REQUEST_CAMERA_PERMISSION);
|
|
70
|
+
requestPermissionForAlias(CAMERA_PERMISSION_ALIAS, call, "handleCameraPermissionResult");
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
@PluginMethod
|
|
74
|
+
@PluginMethod()
|
|
73
75
|
public void flip(PluginCall call) {
|
|
74
76
|
try {
|
|
75
77
|
fragment.switchCamera();
|
|
76
78
|
call.resolve();
|
|
77
79
|
} catch (Exception e) {
|
|
80
|
+
Logger.debug(getLogTag(), "Camera flip exception: " + e);
|
|
78
81
|
call.reject("failed to flip camera");
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
|
|
85
|
+
@PluginMethod
|
|
86
|
+
public void setOpacity(PluginCall call) {
|
|
87
|
+
if (this.hasCamera(call) == false) {
|
|
88
|
+
call.error("Camera is not running");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
bridge.saveCall(call);
|
|
93
|
+
Float opacity = call.getFloat("opacity", 1F);
|
|
94
|
+
fragment.setOpacity(opacity);
|
|
95
|
+
}
|
|
96
|
+
|
|
82
97
|
@PluginMethod()
|
|
83
98
|
public void capture(PluginCall call) {
|
|
84
99
|
if(this.hasCamera(call) == false){
|
|
85
|
-
call.
|
|
100
|
+
call.reject("Camera is not running");
|
|
86
101
|
return;
|
|
87
102
|
}
|
|
88
|
-
|
|
89
|
-
|
|
103
|
+
bridge.saveCall(call);
|
|
104
|
+
captureCallbackId = call.getCallbackId();
|
|
90
105
|
|
|
91
106
|
Integer quality = call.getInt("quality", 85);
|
|
92
107
|
// Image Dimensions - Optional
|
|
@@ -95,6 +110,19 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
95
110
|
fragment.takePicture(width, height, quality);
|
|
96
111
|
}
|
|
97
112
|
|
|
113
|
+
@PluginMethod()
|
|
114
|
+
public void captureSample(PluginCall call) {
|
|
115
|
+
if(this.hasCamera(call) == false){
|
|
116
|
+
call.reject("Camera is not running");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
bridge.saveCall(call);
|
|
120
|
+
snapshotCallbackId = call.getCallbackId();
|
|
121
|
+
|
|
122
|
+
Integer quality = call.getInt("quality", 85);
|
|
123
|
+
fragment.takeSnapshot(quality);
|
|
124
|
+
}
|
|
125
|
+
|
|
98
126
|
@PluginMethod()
|
|
99
127
|
public void stop(final PluginCall call) {
|
|
100
128
|
bridge.getActivity().runOnUiThread(new Runnable() {
|
|
@@ -102,6 +130,9 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
102
130
|
public void run() {
|
|
103
131
|
FrameLayout containerView = getBridge().getActivity().findViewById(containerViewId);
|
|
104
132
|
|
|
133
|
+
// allow orientation changes after closing camera:
|
|
134
|
+
getBridge().getActivity().setRequestedOrientation(previousOrientationRequest);
|
|
135
|
+
|
|
105
136
|
if (containerView != null) {
|
|
106
137
|
((ViewGroup)getBridge().getWebView().getParent()).removeView(containerView);
|
|
107
138
|
getBridge().getWebView().setBackgroundColor(Color.WHITE);
|
|
@@ -111,7 +142,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
111
142
|
fragmentTransaction.commit();
|
|
112
143
|
fragment = null;
|
|
113
144
|
|
|
114
|
-
call.
|
|
145
|
+
call.resolve();
|
|
115
146
|
} else {
|
|
116
147
|
call.reject("camera already stopped");
|
|
117
148
|
}
|
|
@@ -122,7 +153,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
122
153
|
@PluginMethod()
|
|
123
154
|
public void getSupportedFlashModes(PluginCall call) {
|
|
124
155
|
if(this.hasCamera(call) == false){
|
|
125
|
-
call.
|
|
156
|
+
call.reject("Camera is not running");
|
|
126
157
|
return;
|
|
127
158
|
}
|
|
128
159
|
|
|
@@ -140,20 +171,20 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
140
171
|
|
|
141
172
|
JSObject jsObject = new JSObject();
|
|
142
173
|
jsObject.put("result", jsonFlashModes);
|
|
143
|
-
call.
|
|
174
|
+
call.resolve(jsObject);
|
|
144
175
|
|
|
145
176
|
}
|
|
146
177
|
|
|
147
178
|
@PluginMethod()
|
|
148
179
|
public void setFlashMode(PluginCall call) {
|
|
149
180
|
if(this.hasCamera(call) == false){
|
|
150
|
-
call.
|
|
181
|
+
call.reject("Camera is not running");
|
|
151
182
|
return;
|
|
152
183
|
}
|
|
153
184
|
|
|
154
185
|
String flashMode = call.getString("flashMode");
|
|
155
186
|
if(flashMode == null || flashMode.isEmpty() == true) {
|
|
156
|
-
call.
|
|
187
|
+
call.reject("flashMode required parameter is missing");
|
|
157
188
|
return;
|
|
158
189
|
}
|
|
159
190
|
|
|
@@ -165,36 +196,75 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
165
196
|
if (supportedFlashModes.indexOf(flashMode) > -1) {
|
|
166
197
|
params.setFlashMode(flashMode);
|
|
167
198
|
} else {
|
|
168
|
-
call.
|
|
199
|
+
call.reject("Flash mode not recognised: " + flashMode);
|
|
169
200
|
return;
|
|
170
201
|
}
|
|
171
202
|
|
|
172
203
|
fragment.setCameraParameters(params);
|
|
173
204
|
|
|
174
|
-
call.
|
|
205
|
+
call.resolve();
|
|
175
206
|
}
|
|
176
207
|
|
|
177
|
-
@
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
}
|
|
208
|
+
@PluginMethod()
|
|
209
|
+
public void startRecordVideo(final PluginCall call) {
|
|
210
|
+
if(this.hasCamera(call) == false){
|
|
211
|
+
call.reject("Camera is not running");
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
final String filename = "videoTmp";
|
|
215
|
+
VIDEO_FILE_PATH = getActivity().getCacheDir().toString() + "/";
|
|
187
216
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
217
|
+
final String position = call.getString("position", "front");
|
|
218
|
+
final Integer width = call.getInt("width", 0);
|
|
219
|
+
final Integer height = call.getInt("height", 0);
|
|
220
|
+
final Boolean withFlash = call.getBoolean("withFlash", false);
|
|
221
|
+
final Integer maxDuration = call.getInt("maxDuration", 0);
|
|
222
|
+
// final Integer quality = call.getInt("quality", 0);
|
|
223
|
+
bridge.saveCall(call);
|
|
224
|
+
recordCallbackId = call.getCallbackId();
|
|
225
|
+
|
|
226
|
+
bridge.getActivity().runOnUiThread(new Runnable() {
|
|
227
|
+
@Override
|
|
228
|
+
public void run() {
|
|
229
|
+
// fragment.startRecord(getFilePath(filename), position, width, height, quality, withFlash);
|
|
230
|
+
fragment.startRecord(getFilePath(filename), position, width, height, 70, withFlash, maxDuration);
|
|
193
231
|
}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
call.resolve();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
@PluginMethod()
|
|
238
|
+
public void stopRecordVideo(PluginCall call) {
|
|
239
|
+
if(this.hasCamera(call) == false){
|
|
240
|
+
call.reject("Camera is not running");
|
|
241
|
+
return;
|
|
194
242
|
}
|
|
195
243
|
|
|
244
|
+
System.out.println("stopRecordVideo - Callbackid=" + call.getCallbackId());
|
|
196
245
|
|
|
246
|
+
bridge.saveCall(call);
|
|
247
|
+
recordCallbackId = call.getCallbackId();
|
|
197
248
|
|
|
249
|
+
// bridge.getActivity().runOnUiThread(new Runnable() {
|
|
250
|
+
// @Override
|
|
251
|
+
// public void run() {
|
|
252
|
+
// fragment.stopRecord();
|
|
253
|
+
// }
|
|
254
|
+
// });
|
|
255
|
+
|
|
256
|
+
fragment.stopRecord();
|
|
257
|
+
// call.resolve();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
@PermissionCallback
|
|
261
|
+
private void handleCameraPermissionResult(PluginCall call) {
|
|
262
|
+
if (PermissionState.GRANTED.equals(getPermissionState(CAMERA_PERMISSION_ALIAS))) {
|
|
263
|
+
startCamera(call);
|
|
264
|
+
} else {
|
|
265
|
+
Logger.debug(getLogTag(), "User denied camera permission: " + getPermissionState(CAMERA_PERMISSION_ALIAS).toString());
|
|
266
|
+
call.reject("Permission failed: user denied access to camera.");
|
|
267
|
+
}
|
|
198
268
|
}
|
|
199
269
|
|
|
200
270
|
private void startCamera(final PluginCall call) {
|
|
@@ -214,7 +284,11 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
214
284
|
final Integer paddingBottom = call.getInt("paddingBottom", 0);
|
|
215
285
|
final Boolean toBack = call.getBoolean("toBack", false);
|
|
216
286
|
final Boolean storeToFile = call.getBoolean("storeToFile", false);
|
|
287
|
+
final Boolean enableOpacity = call.getBoolean("enableOpacity", false);
|
|
288
|
+
final Boolean enableZoom = call.getBoolean("enableZoom", false);
|
|
217
289
|
final Boolean disableExifHeaderStripping = call.getBoolean("disableExifHeaderStripping", true);
|
|
290
|
+
final Boolean lockOrientation = call.getBoolean("lockAndroidOrientation", false);
|
|
291
|
+
previousOrientationRequest = getBridge().getActivity().getRequestedOrientation();
|
|
218
292
|
|
|
219
293
|
fragment = new CameraActivity();
|
|
220
294
|
fragment.setEventListener(this);
|
|
@@ -225,11 +299,18 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
225
299
|
fragment.disableExifHeaderStripping = disableExifHeaderStripping;
|
|
226
300
|
fragment.storeToFile = storeToFile;
|
|
227
301
|
fragment.toBack = toBack;
|
|
302
|
+
fragment.enableOpacity = enableOpacity;
|
|
303
|
+
fragment.enableZoom = enableZoom;
|
|
228
304
|
|
|
229
305
|
bridge.getActivity().runOnUiThread(new Runnable() {
|
|
230
306
|
@Override
|
|
231
307
|
public void run() {
|
|
232
308
|
DisplayMetrics metrics = getBridge().getActivity().getResources().getDisplayMetrics();
|
|
309
|
+
// lock orientation if specified in options:
|
|
310
|
+
if (lockOrientation) {
|
|
311
|
+
getBridge().getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
|
|
312
|
+
}
|
|
313
|
+
|
|
233
314
|
// offset
|
|
234
315
|
int computedX = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, x, metrics);
|
|
235
316
|
int computedY = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, y, metrics);
|
|
@@ -276,6 +357,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
276
357
|
((ViewGroup)getBridge().getWebView().getParent()).addView(containerView);
|
|
277
358
|
if(toBack == true) {
|
|
278
359
|
getBridge().getWebView().getParent().bringChildToFront(getBridge().getWebView());
|
|
360
|
+
setupBroadcast();
|
|
279
361
|
}
|
|
280
362
|
|
|
281
363
|
FragmentManager fragmentManager = getBridge().getActivity().getFragmentManager();
|
|
@@ -283,7 +365,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
283
365
|
fragmentTransaction.add(containerView.getId(), fragment);
|
|
284
366
|
fragmentTransaction.commit();
|
|
285
367
|
|
|
286
|
-
call.
|
|
368
|
+
call.resolve();
|
|
287
369
|
} else {
|
|
288
370
|
call.reject("camera already started");
|
|
289
371
|
}
|
|
@@ -291,7 +373,6 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
291
373
|
});
|
|
292
374
|
}
|
|
293
375
|
|
|
294
|
-
|
|
295
376
|
@Override
|
|
296
377
|
protected void handleOnResume() {
|
|
297
378
|
super.handleOnResume();
|
|
@@ -301,29 +382,24 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
301
382
|
public void onPictureTaken(String originalPicture) {
|
|
302
383
|
JSObject jsObject = new JSObject();
|
|
303
384
|
jsObject.put("value", originalPicture);
|
|
304
|
-
getSavedCall().
|
|
385
|
+
bridge.getSavedCall(captureCallbackId).resolve(jsObject);
|
|
305
386
|
}
|
|
306
387
|
|
|
307
388
|
@Override
|
|
308
389
|
public void onPictureTakenError(String message) {
|
|
309
|
-
getSavedCall().reject(message);
|
|
390
|
+
bridge.getSavedCall(captureCallbackId).reject(message);
|
|
310
391
|
}
|
|
311
392
|
|
|
312
393
|
@Override
|
|
313
394
|
public void onSnapshotTaken(String originalPicture) {
|
|
314
|
-
JSONArray data = new JSONArray();
|
|
315
|
-
data.put(originalPicture);
|
|
316
|
-
|
|
317
|
-
PluginCall call = getSavedCall();
|
|
318
|
-
|
|
319
395
|
JSObject jsObject = new JSObject();
|
|
320
|
-
jsObject.put("
|
|
321
|
-
|
|
396
|
+
jsObject.put("value", originalPicture);
|
|
397
|
+
bridge.getSavedCall(snapshotCallbackId).resolve(jsObject);
|
|
322
398
|
}
|
|
323
399
|
|
|
324
400
|
@Override
|
|
325
401
|
public void onSnapshotTakenError(String message) {
|
|
326
|
-
getSavedCall().reject(message);
|
|
402
|
+
bridge.getSavedCall(snapshotCallbackId).reject(message);
|
|
327
403
|
}
|
|
328
404
|
|
|
329
405
|
@Override
|
|
@@ -343,9 +419,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
343
419
|
|
|
344
420
|
@Override
|
|
345
421
|
public void onCameraStarted() {
|
|
346
|
-
PluginCall pluginCall = getSavedCall();
|
|
347
422
|
System.out.println("camera started");
|
|
348
|
-
pluginCall.success();
|
|
349
423
|
}
|
|
350
424
|
|
|
351
425
|
@Override
|
|
@@ -354,20 +428,22 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
354
428
|
}
|
|
355
429
|
@Override
|
|
356
430
|
public void onStartRecordVideoError(String message) {
|
|
357
|
-
getSavedCall().reject(message);
|
|
431
|
+
bridge.getSavedCall(recordCallbackId).reject(message);
|
|
358
432
|
}
|
|
359
433
|
@Override
|
|
360
434
|
public void onStopRecordVideo(String file) {
|
|
361
|
-
PluginCall pluginCall = getSavedCall();
|
|
435
|
+
PluginCall pluginCall = bridge.getSavedCall(recordCallbackId);
|
|
362
436
|
JSObject jsObject = new JSObject();
|
|
363
437
|
jsObject.put("videoFilePath", file);
|
|
364
|
-
pluginCall.
|
|
438
|
+
pluginCall.resolve(jsObject);
|
|
365
439
|
}
|
|
366
440
|
@Override
|
|
367
441
|
public void onStopRecordVideoError(String error) {
|
|
368
|
-
getSavedCall().reject(error);
|
|
442
|
+
bridge.getSavedCall(recordCallbackId).reject(error);
|
|
369
443
|
}
|
|
370
444
|
|
|
445
|
+
|
|
446
|
+
|
|
371
447
|
private boolean hasView(PluginCall call) {
|
|
372
448
|
if(fragment == null) {
|
|
373
449
|
return false;
|
|
@@ -388,64 +464,33 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
388
464
|
return true;
|
|
389
465
|
}
|
|
390
466
|
|
|
391
|
-
@PluginMethod()
|
|
392
|
-
public void startRecordVideo(final PluginCall call) {
|
|
393
|
-
if(this.hasCamera(call) == false){
|
|
394
|
-
call.error("Camera is not running");
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
final String filename = "videoTmp";
|
|
398
|
-
VIDEO_FILE_PATH = getActivity().getCacheDir().toString() + "/";
|
|
399
|
-
|
|
400
|
-
final String position = call.getString("position", "front");
|
|
401
|
-
final Integer width = call.getInt("width", 0);
|
|
402
|
-
final Integer height = call.getInt("height", 0);
|
|
403
|
-
final Boolean withFlash = call.getBoolean("withFlash", false);
|
|
404
|
-
final Integer maxDuration = call.getInt("maxDuration", 0);
|
|
405
|
-
// final Integer quality = call.getInt("quality", 0);
|
|
406
|
-
|
|
407
|
-
bridge.getActivity().runOnUiThread(new Runnable() {
|
|
408
|
-
@Override
|
|
409
|
-
public void run() {
|
|
410
|
-
// fragment.startRecord(getFilePath(filename), position, width, height, quality, withFlash);
|
|
411
|
-
fragment.startRecord(getFilePath(filename), position, width, height, 70, withFlash, maxDuration);
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
call.success();
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
@PluginMethod()
|
|
419
|
-
public void stopRecordVideo(PluginCall call) {
|
|
420
|
-
if(this.hasCamera(call) == false){
|
|
421
|
-
call.error("Camera is not running");
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
saveCall(call);
|
|
426
|
-
|
|
427
|
-
// bridge.getActivity().runOnUiThread(new Runnable() {
|
|
428
|
-
// @Override
|
|
429
|
-
// public void run() {
|
|
430
|
-
// fragment.stopRecord();
|
|
431
|
-
// }
|
|
432
|
-
// });
|
|
433
|
-
|
|
434
|
-
fragment.stopRecord();
|
|
435
|
-
// call.success();
|
|
436
|
-
}
|
|
437
|
-
|
|
438
467
|
private String getFilePath(String filename) {
|
|
439
468
|
String fileName = filename;
|
|
440
469
|
|
|
441
470
|
int i = 1;
|
|
442
471
|
|
|
443
472
|
while (new File(VIDEO_FILE_PATH + fileName + VIDEO_FILE_EXTENSION).exists()) {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
473
|
+
// Add number suffix if file exists
|
|
474
|
+
fileName = filename + '_' + i;
|
|
475
|
+
i++;
|
|
447
476
|
}
|
|
448
477
|
|
|
449
478
|
return VIDEO_FILE_PATH + fileName + VIDEO_FILE_EXTENSION;
|
|
450
479
|
}
|
|
480
|
+
|
|
481
|
+
private void setupBroadcast() {
|
|
482
|
+
/** When touch event is triggered, relay it to camera view if needed so it can support pinch zoom */
|
|
483
|
+
|
|
484
|
+
getBridge().getWebView().setClickable(true);
|
|
485
|
+
getBridge().getWebView().setOnTouchListener(new View.OnTouchListener() {
|
|
486
|
+
@Override
|
|
487
|
+
public boolean onTouch(View v, MotionEvent event) {
|
|
488
|
+
if ((null != fragment) && (fragment.toBack == true)) {
|
|
489
|
+
fragment.frameContainerLayout.dispatchTouchEvent(event);
|
|
490
|
+
}
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
451
496
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.ahm.capacitor.camera.preview;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.graphics.SurfaceTexture;
|
|
5
|
+
import android.view.SurfaceHolder;
|
|
6
|
+
import android.view.TextureView;
|
|
7
|
+
|
|
8
|
+
class CustomTextureView extends TextureView implements TextureView.SurfaceTextureListener{
|
|
9
|
+
private final String TAG = "CustomTextureView";
|
|
10
|
+
|
|
11
|
+
CustomTextureView(Context context){
|
|
12
|
+
super(context);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Override
|
|
16
|
+
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Override
|
|
20
|
+
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Override
|
|
24
|
+
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Override
|
|
29
|
+
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
|
|
30
|
+
}
|
|
31
|
+
}
|