@capacitor-community/camera-preview 2.0.0-beta.2 → 2.0.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/README.md +18 -5
- 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/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +128 -70
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +36 -0
- 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 +10 -1
- package/dist/esm/web.d.ts +2 -1
- package/dist/esm/web.js +6 -0
- package/dist/esm/web.js.map +1 -1
- package/ios/Plugin/Plugin.swift +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module external.linked.project.id="android" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
|
3
|
+
<component name="FacetManager">
|
|
4
|
+
<facet type="android-gradle" name="Android-Gradle">
|
|
5
|
+
<configuration>
|
|
6
|
+
<option name="GRADLE_PROJECT_PATH" value=":" />
|
|
7
|
+
<option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" />
|
|
8
|
+
<option name="LAST_KNOWN_AGP_VERSION" value="3.3.2" />
|
|
9
|
+
</configuration>
|
|
10
|
+
</facet>
|
|
11
|
+
<facet type="android" name="Android">
|
|
12
|
+
<configuration>
|
|
13
|
+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
|
14
|
+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
|
15
|
+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
|
16
|
+
<afterSyncTasks>
|
|
17
|
+
<task>generateDebugSources</task>
|
|
18
|
+
</afterSyncTasks>
|
|
19
|
+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
|
20
|
+
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
|
21
|
+
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
|
22
|
+
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/../../src/main/res;file://$MODULE_DIR$/../../src/debug/res;file://$MODULE_DIR$/../../build/generated/res/rs/debug;file://$MODULE_DIR$/../../build/generated/res/resValues/debug" />
|
|
23
|
+
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/../../src/androidTest/res;file://$MODULE_DIR$/../../src/androidTestDebug/res;file://$MODULE_DIR$/../../build/generated/res/rs/androidTest/debug;file://$MODULE_DIR$/../../build/generated/res/resValues/androidTest/debug" />
|
|
24
|
+
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
|
25
|
+
<option name="PROJECT_TYPE" value="1" />
|
|
26
|
+
</configuration>
|
|
27
|
+
</facet>
|
|
28
|
+
</component>
|
|
29
|
+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
|
|
30
|
+
<output url="file://$MODULE_DIR$/../../build/intermediates/javac/debug/compileDebugJavaWithJavac/classes" />
|
|
31
|
+
<output-test url="file://$MODULE_DIR$/../../build/intermediates/javac/debugUnitTest/compileDebugUnitTestJavaWithJavac/classes" />
|
|
32
|
+
<exclude-output />
|
|
33
|
+
<content url="file://$MODULE_DIR$/../..">
|
|
34
|
+
<sourceFolder url="file://$MODULE_DIR$/../../build/generated/res/resValues/debug" type="java-resource" />
|
|
35
|
+
<sourceFolder url="file://$MODULE_DIR$/../../build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
|
36
|
+
<sourceFolder url="file://$MODULE_DIR$/../../src/androidTest/java" isTestSource="true" />
|
|
37
|
+
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
|
|
38
|
+
<sourceFolder url="file://$MODULE_DIR$/../../src/main/res" type="java-resource" />
|
|
39
|
+
<sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />
|
|
40
|
+
<excludeFolder url="file://$MODULE_DIR$/../../.gradle" />
|
|
41
|
+
<excludeFolder url="file://$MODULE_DIR$/../../build" />
|
|
42
|
+
</content>
|
|
43
|
+
<orderEntry type="jdk" jdkName="Android API 30 Platform" jdkType="Android SDK" />
|
|
44
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
45
|
+
<orderEntry type="library" scope="TEST" name="Gradle: junit:junit:4.12" level="project" />
|
|
46
|
+
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.3" level="project" />
|
|
47
|
+
<orderEntry type="library" scope="TEST" name="Gradle: net.sf.kxml:kxml2:2.3.0" level="project" />
|
|
48
|
+
<orderEntry type="library" scope="TEST" name="Gradle: com.squareup:javawriter:2.1.1" level="project" />
|
|
49
|
+
<orderEntry type="library" scope="TEST" name="Gradle: javax.inject:javax.inject:1" level="project" />
|
|
50
|
+
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-integration:1.3" level="project" />
|
|
51
|
+
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-library:1.3" level="project" />
|
|
52
|
+
<orderEntry type="library" scope="TEST" name="Gradle: com.google.code.findbugs:jsr305:2.0.1" level="project" />
|
|
53
|
+
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test.espresso:espresso-core:3.1.0-alpha3@aar" level="project" />
|
|
54
|
+
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test:runner:1.1.0-alpha3@aar" level="project" />
|
|
55
|
+
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test:monitor:1.1.0-alpha3@aar" level="project" />
|
|
56
|
+
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test.espresso:espresso-idling-resource:3.1.0-alpha3@aar" level="project" />
|
|
57
|
+
<orderEntry type="library" name="Gradle: androidx.collection:collection:1.1.0" level="project" />
|
|
58
|
+
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-common:2.3.1" level="project" />
|
|
59
|
+
<orderEntry type="library" name="Gradle: androidx.arch.core:core-common:2.1.0" level="project" />
|
|
60
|
+
<orderEntry type="library" name="Gradle: androidx.annotation:annotation:1.2.0" level="project" />
|
|
61
|
+
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat:1.3.0@aar" level="project" />
|
|
62
|
+
<orderEntry type="library" name="Gradle: androidx.exifinterface:exifinterface:1.3.2@aar" level="project" />
|
|
63
|
+
<orderEntry type="library" name="Gradle: androidx.fragment:fragment:1.3.4@aar" level="project" />
|
|
64
|
+
<orderEntry type="library" name="Gradle: androidx.activity:activity:1.2.3@aar" level="project" />
|
|
65
|
+
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat-resources:1.3.0@aar" level="project" />
|
|
66
|
+
<orderEntry type="library" name="Gradle: androidx.drawerlayout:drawerlayout:1.0.0@aar" level="project" />
|
|
67
|
+
<orderEntry type="library" name="Gradle: androidx.viewpager:viewpager:1.0.0@aar" level="project" />
|
|
68
|
+
<orderEntry type="library" name="Gradle: androidx.loader:loader:1.0.0@aar" level="project" />
|
|
69
|
+
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable-animated:1.1.0@aar" level="project" />
|
|
70
|
+
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable:1.1.0@aar" level="project" />
|
|
71
|
+
<orderEntry type="library" name="Gradle: androidx.customview:customview:1.0.0@aar" level="project" />
|
|
72
|
+
<orderEntry type="library" name="Gradle: androidx.core:core:1.5.0@aar" level="project" />
|
|
73
|
+
<orderEntry type="library" name="Gradle: androidx.cursoradapter:cursoradapter:1.0.0@aar" level="project" />
|
|
74
|
+
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1@aar" level="project" />
|
|
75
|
+
<orderEntry type="library" name="Gradle: androidx.savedstate:savedstate:1.1.0@aar" level="project" />
|
|
76
|
+
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-runtime:2.3.1@aar" level="project" />
|
|
77
|
+
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-viewmodel:2.3.1@aar" level="project" />
|
|
78
|
+
<orderEntry type="library" name="Gradle: androidx.versionedparcelable:versionedparcelable:1.1.1@aar" level="project" />
|
|
79
|
+
<orderEntry type="library" name="Gradle: androidx.tracing:tracing:1.0.0@aar" level="project" />
|
|
80
|
+
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-livedata:2.0.0@aar" level="project" />
|
|
81
|
+
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-livedata-core:2.3.1@aar" level="project" />
|
|
82
|
+
<orderEntry type="library" name="Gradle: androidx.arch.core:core-runtime:2.1.0@aar" level="project" />
|
|
83
|
+
<orderEntry type="library" name="Gradle: androidx.interpolator:interpolator:1.0.0@aar" level="project" />
|
|
84
|
+
<orderEntry type="library" name="Gradle: androidx.annotation:annotation-experimental:1.0.0@aar" level="project" />
|
|
85
|
+
<orderEntry type="module" module-name="android.capacitor-android" />
|
|
86
|
+
</component>
|
|
87
|
+
</module>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/modules/android.iml" filepath="$PROJECT_DIR$/.idea/modules/android.iml" />
|
|
6
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/modules/1419750366/android.capacitor-android.iml" filepath="$PROJECT_DIR$/.idea/modules/1419750366/android.capacitor-android.iml" />
|
|
7
|
+
</modules>
|
|
8
|
+
</component>
|
|
9
|
+
</project>
|
|
@@ -81,6 +81,8 @@ public class CameraActivity extends Fragment {
|
|
|
81
81
|
private RecordingState mRecordingState = RecordingState.INITIALIZING;
|
|
82
82
|
private MediaRecorder mRecorder = null;
|
|
83
83
|
private String recordFilePath;
|
|
84
|
+
private float opacity;
|
|
85
|
+
|
|
84
86
|
|
|
85
87
|
// The first rear facing camera
|
|
86
88
|
private int defaultCameraId;
|
|
@@ -91,6 +93,9 @@ public class CameraActivity extends Fragment {
|
|
|
91
93
|
public boolean disableExifHeaderStripping;
|
|
92
94
|
public boolean storeToFile;
|
|
93
95
|
public boolean toBack;
|
|
96
|
+
public boolean enableOpacity = false;
|
|
97
|
+
public boolean enableZoom = false;
|
|
98
|
+
|
|
94
99
|
|
|
95
100
|
public int width;
|
|
96
101
|
public int height;
|
|
@@ -131,15 +136,15 @@ public class CameraActivity extends Fragment {
|
|
|
131
136
|
frameContainerLayout.setLayoutParams(layoutParams);
|
|
132
137
|
|
|
133
138
|
//video view
|
|
134
|
-
mPreview = new Preview(getActivity());
|
|
139
|
+
mPreview = new Preview(getActivity(), enableOpacity);
|
|
135
140
|
mainLayout = (FrameLayout) view.findViewById(getResources().getIdentifier("video_view", "id", appResourcesPackage));
|
|
136
141
|
mainLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
|
|
137
142
|
mainLayout.addView(mPreview);
|
|
138
143
|
mainLayout.setEnabled(false);
|
|
139
144
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
145
|
+
if (enableZoom) {
|
|
146
|
+
this.setupTouchAndBackButton();
|
|
147
|
+
}
|
|
143
148
|
|
|
144
149
|
}
|
|
145
150
|
}
|
|
@@ -164,75 +169,88 @@ public class CameraActivity extends Fragment {
|
|
|
164
169
|
|
|
165
170
|
|
|
166
171
|
boolean isSingleTapTouch = gestureDetector.onTouchEvent(event);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
} else if (tapToTakePicture) {
|
|
180
|
-
takePicture(0, 0, 85);
|
|
181
|
-
|
|
182
|
-
} else if (tapToFocus) {
|
|
183
|
-
setFocusArea((int) event.getX(0), (int) event.getY(0), new Camera.AutoFocusCallback() {
|
|
184
|
-
public void onAutoFocus(boolean success, Camera camera) {
|
|
185
|
-
if (success) {
|
|
186
|
-
// A callback to JS might make sense here.
|
|
187
|
-
} else {
|
|
188
|
-
Log.d(TAG, "onTouch:" + " setFocusArea() did not suceed");
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
});
|
|
172
|
+
int action = event.getAction();
|
|
173
|
+
int eventCount = event.getPointerCount();
|
|
174
|
+
Log.d(TAG, "onTouch event, action, count: " + event + ", " + action + ", " + eventCount);
|
|
175
|
+
if (eventCount > 1) {
|
|
176
|
+
// handle multi-touch events
|
|
177
|
+
Camera.Parameters params = mCamera.getParameters();
|
|
178
|
+
if (action == MotionEvent.ACTION_POINTER_DOWN) {
|
|
179
|
+
mDist = getFingerSpacing(event);
|
|
180
|
+
} else if (action == MotionEvent.ACTION_MOVE && params.isZoomSupported()) {
|
|
181
|
+
handleZoom(event, params);
|
|
192
182
|
}
|
|
193
|
-
return true;
|
|
194
183
|
} else {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
184
|
+
if (action != MotionEvent.ACTION_MOVE && isSingleTapTouch) {
|
|
185
|
+
if (tapToTakePicture && tapToFocus) {
|
|
186
|
+
setFocusArea((int) event.getX(0), (int) event.getY(0), new Camera.AutoFocusCallback() {
|
|
187
|
+
public void onAutoFocus(boolean success, Camera camera) {
|
|
188
|
+
if (success) {
|
|
189
|
+
takePicture(0, 0, 85);
|
|
190
|
+
} else {
|
|
191
|
+
Log.d(TAG, "onTouch:" + " setFocusArea() did not suceed");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
} else if (tapToTakePicture) {
|
|
197
|
+
takePicture(0, 0, 85);
|
|
198
|
+
|
|
199
|
+
} else if (tapToFocus) {
|
|
200
|
+
setFocusArea((int) event.getX(0), (int) event.getY(0), new Camera.AutoFocusCallback() {
|
|
201
|
+
public void onAutoFocus(boolean success, Camera camera) {
|
|
202
|
+
if (success) {
|
|
203
|
+
// A callback to JS might make sense here.
|
|
204
|
+
} else {
|
|
205
|
+
Log.d(TAG, "onTouch:" + " setFocusArea() did not suceed");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return true;
|
|
211
|
+
} else {
|
|
212
|
+
if (dragEnabled) {
|
|
213
|
+
int x;
|
|
214
|
+
int y;
|
|
215
|
+
|
|
216
|
+
switch (event.getAction()) {
|
|
217
|
+
case MotionEvent.ACTION_DOWN:
|
|
218
|
+
if (mLastTouchX == 0 || mLastTouchY == 0) {
|
|
219
|
+
mLastTouchX = (int) event.getRawX() - layoutParams.leftMargin;
|
|
220
|
+
mLastTouchY = (int) event.getRawY() - layoutParams.topMargin;
|
|
221
|
+
} else {
|
|
222
|
+
mLastTouchX = (int) event.getRawX();
|
|
223
|
+
mLastTouchY = (int) event.getRawY();
|
|
224
|
+
}
|
|
225
|
+
break;
|
|
226
|
+
case MotionEvent.ACTION_MOVE:
|
|
227
|
+
|
|
228
|
+
x = (int) event.getRawX();
|
|
229
|
+
y = (int) event.getRawY();
|
|
230
|
+
|
|
231
|
+
final float dx = x - mLastTouchX;
|
|
232
|
+
final float dy = y - mLastTouchY;
|
|
233
|
+
|
|
234
|
+
mPosX += dx;
|
|
235
|
+
mPosY += dy;
|
|
236
|
+
|
|
237
|
+
layoutParams.leftMargin = mPosX;
|
|
238
|
+
layoutParams.topMargin = mPosY;
|
|
239
|
+
|
|
240
|
+
frameContainerLayout.setLayoutParams(layoutParams);
|
|
241
|
+
|
|
242
|
+
// Remember this touch position for the next move event
|
|
243
|
+
mLastTouchX = x;
|
|
244
|
+
mLastTouchY = y;
|
|
245
|
+
|
|
246
|
+
break;
|
|
247
|
+
default:
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
234
252
|
}
|
|
235
|
-
|
|
253
|
+
return true;
|
|
236
254
|
}
|
|
237
255
|
});
|
|
238
256
|
frameContainerLayout.setFocusableInTouchMode(true);
|
|
@@ -248,7 +266,30 @@ public class CameraActivity extends Fragment {
|
|
|
248
266
|
return false;
|
|
249
267
|
}
|
|
250
268
|
});
|
|
269
|
+
|
|
251
270
|
}
|
|
271
|
+
private float mDist = 0F;
|
|
272
|
+
|
|
273
|
+
private void handleZoom(MotionEvent event, Camera.Parameters params) {
|
|
274
|
+
if (mCamera != null) {
|
|
275
|
+
mCamera.cancelAutoFocus();
|
|
276
|
+
int maxZoom = params.getMaxZoom();
|
|
277
|
+
int zoom = params.getZoom();
|
|
278
|
+
float newDist = getFingerSpacing(event);
|
|
279
|
+
if (newDist > mDist) {
|
|
280
|
+
//zoom in
|
|
281
|
+
if (zoom < maxZoom)
|
|
282
|
+
zoom++;
|
|
283
|
+
} else if (newDist < mDist) {
|
|
284
|
+
//zoom out
|
|
285
|
+
if (zoom > 0)
|
|
286
|
+
zoom--;
|
|
287
|
+
}
|
|
288
|
+
mDist = newDist;
|
|
289
|
+
params.setZoom(zoom);
|
|
290
|
+
mCamera.setParameters(params);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
252
293
|
});
|
|
253
294
|
|
|
254
295
|
}
|
|
@@ -596,6 +637,12 @@ public class CameraActivity extends Fragment {
|
|
|
596
637
|
}
|
|
597
638
|
return output;
|
|
598
639
|
}
|
|
640
|
+
|
|
641
|
+
public void setOpacity(final float opacity) {
|
|
642
|
+
Log.d(TAG, "set opacity:" + opacity);
|
|
643
|
+
this.opacity = opacity;
|
|
644
|
+
mPreview.setOpacity(opacity);
|
|
645
|
+
}
|
|
599
646
|
public void takeSnapshot(final int quality) {
|
|
600
647
|
mCamera.setPreviewCallback(new Camera.PreviewCallback() {
|
|
601
648
|
@Override
|
|
@@ -870,4 +917,15 @@ public class CameraActivity extends Fragment {
|
|
|
870
917
|
Math.round((y + 100) * 2000 / height - 1000)
|
|
871
918
|
);
|
|
872
919
|
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* Determine the space between the first two fingers
|
|
923
|
+
*/
|
|
924
|
+
private static float getFingerSpacing(MotionEvent event) {
|
|
925
|
+
// ...
|
|
926
|
+
float x = event.getX(0) - event.getX(1);
|
|
927
|
+
float y = event.getY(0) - event.getY(1);
|
|
928
|
+
return (float) Math.sqrt(x * x + y * y);
|
|
929
|
+
}
|
|
930
|
+
|
|
873
931
|
}
|
|
@@ -9,6 +9,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
|
|
|
@@ -75,10 +77,23 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
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){
|
|
@@ -269,6 +284,8 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
269
284
|
final Integer paddingBottom = call.getInt("paddingBottom", 0);
|
|
270
285
|
final Boolean toBack = call.getBoolean("toBack", false);
|
|
271
286
|
final Boolean storeToFile = call.getBoolean("storeToFile", false);
|
|
287
|
+
final Boolean enableOpacity = call.getBoolean("enableOpacity", false);
|
|
288
|
+
final Boolean enableZoom = call.getBoolean("enableZoom", false);
|
|
272
289
|
final Boolean disableExifHeaderStripping = call.getBoolean("disableExifHeaderStripping", true);
|
|
273
290
|
final Boolean lockOrientation = call.getBoolean("lockAndroidOrientation", false);
|
|
274
291
|
previousOrientationRequest = getBridge().getActivity().getRequestedOrientation();
|
|
@@ -282,6 +299,8 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
282
299
|
fragment.disableExifHeaderStripping = disableExifHeaderStripping;
|
|
283
300
|
fragment.storeToFile = storeToFile;
|
|
284
301
|
fragment.toBack = toBack;
|
|
302
|
+
fragment.enableOpacity = enableOpacity;
|
|
303
|
+
fragment.enableZoom = enableZoom;
|
|
285
304
|
|
|
286
305
|
bridge.getActivity().runOnUiThread(new Runnable() {
|
|
287
306
|
@Override
|
|
@@ -338,6 +357,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
338
357
|
((ViewGroup)getBridge().getWebView().getParent()).addView(containerView);
|
|
339
358
|
if(toBack == true) {
|
|
340
359
|
getBridge().getWebView().getParent().bringChildToFront(getBridge().getWebView());
|
|
360
|
+
setupBroadcast();
|
|
341
361
|
}
|
|
342
362
|
|
|
343
363
|
FragmentManager fragmentManager = getBridge().getActivity().getFragmentManager();
|
|
@@ -457,4 +477,20 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
457
477
|
|
|
458
478
|
return VIDEO_FILE_PATH + fileName + VIDEO_FILE_EXTENSION;
|
|
459
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
|
+
|
|
460
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
|
+
}
|
|
@@ -2,22 +2,27 @@ package com.ahm.capacitor.camera.preview;
|
|
|
2
2
|
|
|
3
3
|
import android.app.Activity;
|
|
4
4
|
import android.content.Context;
|
|
5
|
+
import android.graphics.SurfaceTexture;
|
|
5
6
|
import android.hardware.Camera;
|
|
6
7
|
import android.util.DisplayMetrics;
|
|
7
8
|
import android.util.Log;
|
|
8
9
|
import android.view.Surface;
|
|
9
10
|
import android.view.SurfaceHolder;
|
|
11
|
+
import android.view.TextureView;
|
|
10
12
|
import android.view.View;
|
|
11
13
|
import android.widget.RelativeLayout;
|
|
12
14
|
|
|
13
15
|
import java.io.IOException;
|
|
14
16
|
import java.util.List;
|
|
15
17
|
|
|
16
|
-
class Preview extends RelativeLayout implements SurfaceHolder.Callback
|
|
18
|
+
class Preview extends RelativeLayout implements SurfaceHolder.Callback,
|
|
19
|
+
TextureView.SurfaceTextureListener {
|
|
17
20
|
private final String TAG = "Preview";
|
|
18
21
|
|
|
19
22
|
CustomSurfaceView mSurfaceView;
|
|
23
|
+
CustomTextureView mTextureView;
|
|
20
24
|
SurfaceHolder mHolder;
|
|
25
|
+
SurfaceTexture mSurface;
|
|
21
26
|
Camera.Size mPreviewSize;
|
|
22
27
|
List<Camera.Size> mSupportedPreviewSizes;
|
|
23
28
|
Camera mCamera;
|
|
@@ -26,20 +31,36 @@ class Preview extends RelativeLayout implements SurfaceHolder.Callback {
|
|
|
26
31
|
int facing = Camera.CameraInfo.CAMERA_FACING_BACK;
|
|
27
32
|
int viewWidth;
|
|
28
33
|
int viewHeight;
|
|
34
|
+
private boolean enableOpacity = false;
|
|
35
|
+
private float opacity = 1F;
|
|
29
36
|
|
|
30
37
|
Preview(Context context) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
mSurfaceView = new CustomSurfaceView(context);
|
|
34
|
-
addView(mSurfaceView);
|
|
38
|
+
this(context, false);
|
|
39
|
+
}
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
Preview(Context context, boolean enableOpacity) {
|
|
42
|
+
super(context);
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
this.enableOpacity = enableOpacity;
|
|
45
|
+
if (!enableOpacity) {
|
|
46
|
+
mSurfaceView = new CustomSurfaceView(context);
|
|
47
|
+
addView(mSurfaceView);
|
|
48
|
+
requestLayout();
|
|
49
|
+
|
|
50
|
+
// Install a SurfaceHolder.Callback so we get notified when the
|
|
51
|
+
// underlying surface is created and destroyed.
|
|
52
|
+
mHolder = mSurfaceView.getHolder();
|
|
53
|
+
mHolder.addCallback(this);
|
|
54
|
+
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
|
55
|
+
} else {
|
|
56
|
+
// Use a TextureView so we can manage opacity
|
|
57
|
+
mTextureView = new CustomTextureView(context);
|
|
58
|
+
// Install a SurfaceTextureListener so we get notified
|
|
59
|
+
mTextureView.setSurfaceTextureListener(this);
|
|
60
|
+
mTextureView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
61
|
+
addView(mTextureView);
|
|
62
|
+
requestLayout();
|
|
63
|
+
}
|
|
43
64
|
}
|
|
44
65
|
|
|
45
66
|
public void setCamera(Camera camera, int cameraId) {
|
|
@@ -123,7 +144,14 @@ class Preview extends RelativeLayout implements SurfaceHolder.Callback {
|
|
|
123
144
|
|
|
124
145
|
Log.d("CameraPreview", "before set camera");
|
|
125
146
|
|
|
126
|
-
|
|
147
|
+
View v;
|
|
148
|
+
if (enableOpacity) {
|
|
149
|
+
camera.setPreviewTexture(mSurface);
|
|
150
|
+
v = mTextureView;
|
|
151
|
+
} else {
|
|
152
|
+
camera.setPreviewDisplay(mHolder);
|
|
153
|
+
v = mSurfaceView;
|
|
154
|
+
}
|
|
127
155
|
|
|
128
156
|
Log.d("CameraPreview", "before getParameters");
|
|
129
157
|
|
|
@@ -132,7 +160,7 @@ class Preview extends RelativeLayout implements SurfaceHolder.Callback {
|
|
|
132
160
|
Log.d("CameraPreview", "before setPreviewSize");
|
|
133
161
|
|
|
134
162
|
mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
|
|
135
|
-
mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes,
|
|
163
|
+
mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, v.getWidth(), v.getHeight());
|
|
136
164
|
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
|
|
137
165
|
Log.d(TAG, mPreviewSize.width + " " + mPreviewSize.height);
|
|
138
166
|
|
|
@@ -285,21 +313,70 @@ class Preview extends RelativeLayout implements SurfaceHolder.Callback {
|
|
|
285
313
|
if (mSupportedPreviewSizes != null) {
|
|
286
314
|
mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, w, h);
|
|
287
315
|
}
|
|
288
|
-
|
|
289
|
-
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
|
|
290
|
-
requestLayout();
|
|
291
|
-
//mCamera.setDisplayOrientation(90);
|
|
292
|
-
mCamera.setParameters(parameters);
|
|
293
|
-
mCamera.startPreview();
|
|
316
|
+
startCamera();
|
|
294
317
|
} catch (Exception exception) {
|
|
295
318
|
Log.e(TAG, "Exception caused by surfaceChanged()", exception);
|
|
296
319
|
}
|
|
297
320
|
}
|
|
298
321
|
}
|
|
299
322
|
|
|
323
|
+
private void startCamera() {
|
|
324
|
+
Camera.Parameters parameters = mCamera.getParameters();
|
|
325
|
+
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
|
|
326
|
+
requestLayout();
|
|
327
|
+
//mCamera.setDisplayOrientation(90);
|
|
328
|
+
mCamera.setParameters(parameters);
|
|
329
|
+
mCamera.startPreview();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Texture Callbacks
|
|
333
|
+
|
|
334
|
+
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
|
|
335
|
+
// The Surface has been created, acquire the camera and tell it where
|
|
336
|
+
// to draw.
|
|
337
|
+
try {
|
|
338
|
+
mSurface = surface;
|
|
339
|
+
if (mSupportedPreviewSizes != null) {
|
|
340
|
+
mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, width, height);
|
|
341
|
+
}
|
|
342
|
+
if (mCamera != null) {
|
|
343
|
+
mTextureView.setAlpha(opacity);
|
|
344
|
+
mCamera.setPreviewTexture(surface);
|
|
345
|
+
startCamera();
|
|
346
|
+
}
|
|
347
|
+
} catch (Exception exception) {
|
|
348
|
+
Log.e(TAG, "Exception caused by onSurfaceTextureAvailable()", exception);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
|
356
|
+
try {
|
|
357
|
+
if (mCamera != null) {
|
|
358
|
+
mCamera.stopPreview();
|
|
359
|
+
}
|
|
360
|
+
} catch (Exception exception) {
|
|
361
|
+
Log.e(TAG, "Exception caused by onSurfaceTextureDestroyed()", exception);
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
return true;
|
|
365
|
+
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
|
|
369
|
+
}
|
|
300
370
|
public void setOneShotPreviewCallback(Camera.PreviewCallback callback) {
|
|
301
371
|
if(mCamera != null) {
|
|
302
372
|
mCamera.setOneShotPreviewCallback(callback);
|
|
303
373
|
}
|
|
304
374
|
}
|
|
375
|
+
|
|
376
|
+
public void setOpacity(final float opacity) {
|
|
377
|
+
this.opacity = opacity;
|
|
378
|
+
if (mCamera != null && enableOpacity) {
|
|
379
|
+
mTextureView.setAlpha(opacity);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
305
382
|
}
|