@capacitor-community/camera-preview 3.0.0 → 3.1.2
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 +11 -2
- package/android/build.gradle +14 -7
- package/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java +3 -3
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +869 -798
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +184 -173
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomSurfaceView.java +12 -14
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomTextureView.java +16 -18
- package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +327 -323
- package/android/src/main/java/com/ahm/capacitor/camera/preview/TapGestureDetector.java +15 -14
- package/android/src/test/java/com/getcapacitor/ExampleUnitTest.java +4 -3
- package/dist/esm/definitions.d.ts +10 -8
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +3 -3
- package/dist/esm/web.js +36 -25
- package/dist/esm/web.js.map +1 -1
- package/ios/Plugin/CameraController.swift +107 -129
- package/ios/Plugin/Plugin.swift +76 -90
- package/ios/PluginTests/PluginTests.swift +8 -8
- package/package.json +27 -2
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
package com.ahm.capacitor.camera.preview;
|
|
2
2
|
|
|
3
|
+
import static android.Manifest.permission.CAMERA;
|
|
4
|
+
|
|
3
5
|
import android.app.FragmentManager;
|
|
4
6
|
import android.app.FragmentTransaction;
|
|
5
7
|
import android.content.pm.ActivityInfo;
|
|
@@ -13,7 +15,6 @@ import android.view.MotionEvent;
|
|
|
13
15
|
import android.view.View;
|
|
14
16
|
import android.view.ViewGroup;
|
|
15
17
|
import android.widget.FrameLayout;
|
|
16
|
-
|
|
17
18
|
import com.getcapacitor.JSObject;
|
|
18
19
|
import com.getcapacitor.Logger;
|
|
19
20
|
import com.getcapacitor.PermissionState;
|
|
@@ -23,21 +24,13 @@ import com.getcapacitor.PluginMethod;
|
|
|
23
24
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
24
25
|
import com.getcapacitor.annotation.Permission;
|
|
25
26
|
import com.getcapacitor.annotation.PermissionCallback;
|
|
26
|
-
|
|
27
|
-
import org.json.JSONArray;
|
|
28
|
-
|
|
29
27
|
import java.io.File;
|
|
30
28
|
import java.util.List;
|
|
29
|
+
import org.json.JSONArray;
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@CapacitorPlugin(
|
|
35
|
-
name = "CameraPreview",
|
|
36
|
-
permissions = {
|
|
37
|
-
@Permission(strings = {CAMERA}, alias = CameraPreview.CAMERA_PERMISSION_ALIAS)
|
|
38
|
-
}
|
|
39
|
-
)
|
|
31
|
+
@CapacitorPlugin(name = "CameraPreview", permissions = { @Permission(strings = { CAMERA }, alias = CameraPreview.CAMERA_PERMISSION_ALIAS) })
|
|
40
32
|
public class CameraPreview extends Plugin implements CameraActivity.CameraPreviewListener {
|
|
33
|
+
|
|
41
34
|
static final String CAMERA_PERMISSION_ALIAS = "camera";
|
|
42
35
|
|
|
43
36
|
private static String VIDEO_FILE_PATH = "";
|
|
@@ -46,6 +39,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
46
39
|
private String captureCallbackId = "";
|
|
47
40
|
private String snapshotCallbackId = "";
|
|
48
41
|
private String recordCallbackId = "";
|
|
42
|
+
private String cameraStartCallbackId = "";
|
|
49
43
|
|
|
50
44
|
// keep track of previously specified orientation to support locking orientation:
|
|
51
45
|
private int previousOrientationRequest = -1;
|
|
@@ -53,7 +47,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
53
47
|
private CameraActivity fragment;
|
|
54
48
|
private int containerViewId = 20;
|
|
55
49
|
|
|
56
|
-
@PluginMethod
|
|
50
|
+
@PluginMethod
|
|
57
51
|
public void echo(PluginCall call) {
|
|
58
52
|
String value = call.getString("value");
|
|
59
53
|
|
|
@@ -62,7 +56,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
62
56
|
call.resolve(ret);
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
@PluginMethod
|
|
59
|
+
@PluginMethod
|
|
66
60
|
public void start(PluginCall call) {
|
|
67
61
|
if (PermissionState.GRANTED.equals(getPermissionState(CAMERA_PERMISSION_ALIAS))) {
|
|
68
62
|
startCamera(call);
|
|
@@ -71,7 +65,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
71
65
|
}
|
|
72
66
|
}
|
|
73
67
|
|
|
74
|
-
@PluginMethod
|
|
68
|
+
@PluginMethod
|
|
75
69
|
public void flip(PluginCall call) {
|
|
76
70
|
try {
|
|
77
71
|
fragment.switchCamera();
|
|
@@ -84,19 +78,19 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
84
78
|
|
|
85
79
|
@PluginMethod
|
|
86
80
|
public void setOpacity(PluginCall call) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
81
|
+
if (this.hasCamera(call) == false) {
|
|
82
|
+
call.error("Camera is not running");
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
bridge.saveCall(call);
|
|
87
|
+
Float opacity = call.getFloat("opacity", 1F);
|
|
88
|
+
fragment.setOpacity(opacity);
|
|
95
89
|
}
|
|
96
90
|
|
|
97
|
-
@PluginMethod
|
|
91
|
+
@PluginMethod
|
|
98
92
|
public void capture(PluginCall call) {
|
|
99
|
-
if(this.hasCamera(call) == false){
|
|
93
|
+
if (this.hasCamera(call) == false) {
|
|
100
94
|
call.reject("Camera is not running");
|
|
101
95
|
return;
|
|
102
96
|
}
|
|
@@ -110,9 +104,9 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
110
104
|
fragment.takePicture(width, height, quality);
|
|
111
105
|
}
|
|
112
106
|
|
|
113
|
-
@PluginMethod
|
|
107
|
+
@PluginMethod
|
|
114
108
|
public void captureSample(PluginCall call) {
|
|
115
|
-
if(this.hasCamera(call) == false){
|
|
109
|
+
if (this.hasCamera(call) == false) {
|
|
116
110
|
call.reject("Camera is not running");
|
|
117
111
|
return;
|
|
118
112
|
}
|
|
@@ -123,36 +117,40 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
123
117
|
fragment.takeSnapshot(quality);
|
|
124
118
|
}
|
|
125
119
|
|
|
126
|
-
@PluginMethod
|
|
120
|
+
@PluginMethod
|
|
127
121
|
public void stop(final PluginCall call) {
|
|
128
|
-
bridge
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
122
|
+
bridge
|
|
123
|
+
.getActivity()
|
|
124
|
+
.runOnUiThread(
|
|
125
|
+
new Runnable() {
|
|
126
|
+
@Override
|
|
127
|
+
public void run() {
|
|
128
|
+
FrameLayout containerView = getBridge().getActivity().findViewById(containerViewId);
|
|
129
|
+
|
|
130
|
+
// allow orientation changes after closing camera:
|
|
131
|
+
getBridge().getActivity().setRequestedOrientation(previousOrientationRequest);
|
|
132
|
+
|
|
133
|
+
if (containerView != null) {
|
|
134
|
+
((ViewGroup) getBridge().getWebView().getParent()).removeView(containerView);
|
|
135
|
+
getBridge().getWebView().setBackgroundColor(Color.WHITE);
|
|
136
|
+
FragmentManager fragmentManager = getActivity().getFragmentManager();
|
|
137
|
+
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
|
138
|
+
fragmentTransaction.remove(fragment);
|
|
139
|
+
fragmentTransaction.commit();
|
|
140
|
+
fragment = null;
|
|
141
|
+
|
|
142
|
+
call.resolve();
|
|
143
|
+
} else {
|
|
144
|
+
call.reject("camera already stopped");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
148
147
|
}
|
|
149
|
-
|
|
150
|
-
});
|
|
148
|
+
);
|
|
151
149
|
}
|
|
152
150
|
|
|
153
|
-
@PluginMethod
|
|
151
|
+
@PluginMethod
|
|
154
152
|
public void getSupportedFlashModes(PluginCall call) {
|
|
155
|
-
if(this.hasCamera(call) == false){
|
|
153
|
+
if (this.hasCamera(call) == false) {
|
|
156
154
|
call.reject("Camera is not running");
|
|
157
155
|
return;
|
|
158
156
|
}
|
|
@@ -164,7 +162,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
164
162
|
JSONArray jsonFlashModes = new JSONArray();
|
|
165
163
|
|
|
166
164
|
if (supportedFlashModes != null) {
|
|
167
|
-
for (int i=0; i<supportedFlashModes.size(); i++) {
|
|
165
|
+
for (int i = 0; i < supportedFlashModes.size(); i++) {
|
|
168
166
|
jsonFlashModes.put(new String(supportedFlashModes.get(i)));
|
|
169
167
|
}
|
|
170
168
|
}
|
|
@@ -172,18 +170,17 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
172
170
|
JSObject jsObject = new JSObject();
|
|
173
171
|
jsObject.put("result", jsonFlashModes);
|
|
174
172
|
call.resolve(jsObject);
|
|
175
|
-
|
|
176
173
|
}
|
|
177
174
|
|
|
178
|
-
@PluginMethod
|
|
175
|
+
@PluginMethod
|
|
179
176
|
public void setFlashMode(PluginCall call) {
|
|
180
|
-
if(this.hasCamera(call) == false){
|
|
177
|
+
if (this.hasCamera(call) == false) {
|
|
181
178
|
call.reject("Camera is not running");
|
|
182
179
|
return;
|
|
183
180
|
}
|
|
184
181
|
|
|
185
182
|
String flashMode = call.getString("flashMode");
|
|
186
|
-
if(flashMode == null || flashMode.isEmpty() == true) {
|
|
183
|
+
if (flashMode == null || flashMode.isEmpty() == true) {
|
|
187
184
|
call.reject("flashMode required parameter is missing");
|
|
188
185
|
return;
|
|
189
186
|
}
|
|
@@ -205,9 +202,9 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
205
202
|
call.resolve();
|
|
206
203
|
}
|
|
207
204
|
|
|
208
|
-
@PluginMethod
|
|
205
|
+
@PluginMethod
|
|
209
206
|
public void startRecordVideo(final PluginCall call) {
|
|
210
|
-
if(this.hasCamera(call) == false){
|
|
207
|
+
if (this.hasCamera(call) == false) {
|
|
211
208
|
call.reject("Camera is not running");
|
|
212
209
|
return;
|
|
213
210
|
}
|
|
@@ -223,20 +220,24 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
223
220
|
bridge.saveCall(call);
|
|
224
221
|
recordCallbackId = call.getCallbackId();
|
|
225
222
|
|
|
226
|
-
bridge
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
223
|
+
bridge
|
|
224
|
+
.getActivity()
|
|
225
|
+
.runOnUiThread(
|
|
226
|
+
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);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
);
|
|
233
234
|
|
|
234
235
|
call.resolve();
|
|
235
236
|
}
|
|
236
237
|
|
|
237
|
-
@PluginMethod
|
|
238
|
+
@PluginMethod
|
|
238
239
|
public void stopRecordVideo(PluginCall call) {
|
|
239
|
-
if(this.hasCamera(call) == false){
|
|
240
|
+
if (this.hasCamera(call) == false) {
|
|
240
241
|
call.reject("Camera is not running");
|
|
241
242
|
return;
|
|
242
243
|
}
|
|
@@ -268,7 +269,6 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
268
269
|
}
|
|
269
270
|
|
|
270
271
|
private void startCamera(final PluginCall call) {
|
|
271
|
-
|
|
272
272
|
String position = call.getString("position");
|
|
273
273
|
|
|
274
274
|
if (position == null || position.isEmpty() || "rear".equals(position)) {
|
|
@@ -284,8 +284,8 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
284
284
|
final Integer paddingBottom = call.getInt("paddingBottom", 0);
|
|
285
285
|
final Boolean toBack = call.getBoolean("toBack", false);
|
|
286
286
|
final Boolean storeToFile = call.getBoolean("storeToFile", false);
|
|
287
|
-
|
|
288
|
-
|
|
287
|
+
final Boolean enableOpacity = call.getBoolean("enableOpacity", false);
|
|
288
|
+
final Boolean enableZoom = call.getBoolean("enableZoom", false);
|
|
289
289
|
final Boolean disableExifHeaderStripping = call.getBoolean("disableExifHeaderStripping", true);
|
|
290
290
|
final Boolean lockOrientation = call.getBoolean("lockAndroidOrientation", false);
|
|
291
291
|
previousOrientationRequest = getBridge().getActivity().getRequestedOrientation();
|
|
@@ -299,78 +299,91 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
299
299
|
fragment.disableExifHeaderStripping = disableExifHeaderStripping;
|
|
300
300
|
fragment.storeToFile = storeToFile;
|
|
301
301
|
fragment.toBack = toBack;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
bridge
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
302
|
+
fragment.enableOpacity = enableOpacity;
|
|
303
|
+
fragment.enableZoom = enableZoom;
|
|
304
|
+
|
|
305
|
+
bridge
|
|
306
|
+
.getActivity()
|
|
307
|
+
.runOnUiThread(
|
|
308
|
+
new Runnable() {
|
|
309
|
+
@Override
|
|
310
|
+
public void run() {
|
|
311
|
+
DisplayMetrics metrics = getBridge().getActivity().getResources().getDisplayMetrics();
|
|
312
|
+
// lock orientation if specified in options:
|
|
313
|
+
if (lockOrientation) {
|
|
314
|
+
getBridge().getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// offset
|
|
318
|
+
int computedX = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, x, metrics);
|
|
319
|
+
int computedY = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, y, metrics);
|
|
320
|
+
|
|
321
|
+
// size
|
|
322
|
+
int computedWidth;
|
|
323
|
+
int computedHeight;
|
|
324
|
+
int computedPaddingBottom;
|
|
325
|
+
|
|
326
|
+
if (paddingBottom != 0) {
|
|
327
|
+
computedPaddingBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, paddingBottom, metrics);
|
|
328
|
+
} else {
|
|
329
|
+
computedPaddingBottom = 0;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (width != 0) {
|
|
333
|
+
computedWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, width, metrics);
|
|
334
|
+
} else {
|
|
335
|
+
Display defaultDisplay = getBridge().getActivity().getWindowManager().getDefaultDisplay();
|
|
336
|
+
final Point size = new Point();
|
|
337
|
+
defaultDisplay.getSize(size);
|
|
338
|
+
|
|
339
|
+
computedWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size.x, metrics);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (height != 0) {
|
|
343
|
+
computedHeight =
|
|
344
|
+
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, height, metrics) - computedPaddingBottom;
|
|
345
|
+
} else {
|
|
346
|
+
Display defaultDisplay = getBridge().getActivity().getWindowManager().getDefaultDisplay();
|
|
347
|
+
final Point size = new Point();
|
|
348
|
+
defaultDisplay.getSize(size);
|
|
349
|
+
|
|
350
|
+
computedHeight =
|
|
351
|
+
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size.y, metrics) - computedPaddingBottom;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
fragment.setRect(computedX, computedY, computedWidth, computedHeight);
|
|
355
|
+
|
|
356
|
+
FrameLayout containerView = getBridge().getActivity().findViewById(containerViewId);
|
|
357
|
+
if (containerView == null) {
|
|
358
|
+
containerView = new FrameLayout(getActivity().getApplicationContext());
|
|
359
|
+
containerView.setId(containerViewId);
|
|
360
|
+
|
|
361
|
+
getBridge().getWebView().setBackgroundColor(Color.TRANSPARENT);
|
|
362
|
+
((ViewGroup) getBridge().getWebView().getParent()).addView(containerView);
|
|
363
|
+
if (toBack == true) {
|
|
364
|
+
getBridge().getWebView().getParent().bringChildToFront(getBridge().getWebView());
|
|
365
|
+
setupBroadcast();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
FragmentManager fragmentManager = getBridge().getActivity().getFragmentManager();
|
|
369
|
+
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
|
370
|
+
fragmentTransaction.add(containerView.getId(), fragment);
|
|
371
|
+
fragmentTransaction.commit();
|
|
372
|
+
|
|
373
|
+
// NOTE: we don't return invoke call.resolve here because it must be invoked in onCameraStarted
|
|
374
|
+
// otherwise the plugin start method might resolve/return before the camera is actually set in CameraActivity
|
|
375
|
+
// onResume method (see this line mCamera = Camera.open(defaultCameraId);) and the next subsequent plugin
|
|
376
|
+
// method invocations (for example, getSupportedFlashModes) might fails with "Camera is not running" error
|
|
377
|
+
// because camera is not available yet and hasCamera method will return false
|
|
378
|
+
// Please also see https://developer.android.com/reference/android/hardware/Camera.html#open%28int%29
|
|
379
|
+
bridge.saveCall(call);
|
|
380
|
+
cameraStartCallbackId = call.getCallbackId();
|
|
381
|
+
} else {
|
|
382
|
+
call.reject("camera already started");
|
|
383
|
+
}
|
|
361
384
|
}
|
|
362
|
-
|
|
363
|
-
FragmentManager fragmentManager = getBridge().getActivity().getFragmentManager();
|
|
364
|
-
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
|
365
|
-
fragmentTransaction.add(containerView.getId(), fragment);
|
|
366
|
-
fragmentTransaction.commit();
|
|
367
|
-
|
|
368
|
-
call.resolve();
|
|
369
|
-
} else {
|
|
370
|
-
call.reject("camera already started");
|
|
371
385
|
}
|
|
372
|
-
|
|
373
|
-
});
|
|
386
|
+
);
|
|
374
387
|
}
|
|
375
388
|
|
|
376
389
|
@Override
|
|
@@ -403,33 +416,29 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
403
416
|
}
|
|
404
417
|
|
|
405
418
|
@Override
|
|
406
|
-
public void onFocusSet(int pointX, int pointY) {
|
|
407
|
-
|
|
408
|
-
}
|
|
419
|
+
public void onFocusSet(int pointX, int pointY) {}
|
|
409
420
|
|
|
410
421
|
@Override
|
|
411
|
-
public void onFocusSetError(String message) {
|
|
412
|
-
|
|
413
|
-
}
|
|
422
|
+
public void onFocusSetError(String message) {}
|
|
414
423
|
|
|
415
424
|
@Override
|
|
416
|
-
public void onBackButton() {
|
|
417
|
-
|
|
418
|
-
}
|
|
425
|
+
public void onBackButton() {}
|
|
419
426
|
|
|
420
427
|
@Override
|
|
421
428
|
public void onCameraStarted() {
|
|
422
|
-
|
|
429
|
+
PluginCall pluginCall = bridge.getSavedCall(cameraStartCallbackId);
|
|
430
|
+
pluginCall.resolve();
|
|
431
|
+
bridge.releaseCall(pluginCall);
|
|
423
432
|
}
|
|
424
433
|
|
|
425
434
|
@Override
|
|
426
|
-
public void onStartRecordVideo() {
|
|
435
|
+
public void onStartRecordVideo() {}
|
|
427
436
|
|
|
428
|
-
}
|
|
429
437
|
@Override
|
|
430
438
|
public void onStartRecordVideoError(String message) {
|
|
431
439
|
bridge.getSavedCall(recordCallbackId).reject(message);
|
|
432
440
|
}
|
|
441
|
+
|
|
433
442
|
@Override
|
|
434
443
|
public void onStopRecordVideo(String file) {
|
|
435
444
|
PluginCall pluginCall = bridge.getSavedCall(recordCallbackId);
|
|
@@ -437,15 +446,14 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
437
446
|
jsObject.put("videoFilePath", file);
|
|
438
447
|
pluginCall.resolve(jsObject);
|
|
439
448
|
}
|
|
449
|
+
|
|
440
450
|
@Override
|
|
441
451
|
public void onStopRecordVideoError(String error) {
|
|
442
452
|
bridge.getSavedCall(recordCallbackId).reject(error);
|
|
443
453
|
}
|
|
444
454
|
|
|
445
|
-
|
|
446
|
-
|
|
447
455
|
private boolean hasView(PluginCall call) {
|
|
448
|
-
if(fragment == null) {
|
|
456
|
+
if (fragment == null) {
|
|
449
457
|
return false;
|
|
450
458
|
}
|
|
451
459
|
|
|
@@ -453,11 +461,11 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
453
461
|
}
|
|
454
462
|
|
|
455
463
|
private boolean hasCamera(PluginCall call) {
|
|
456
|
-
if(this.hasView(call) == false){
|
|
464
|
+
if (this.hasView(call) == false) {
|
|
457
465
|
return false;
|
|
458
466
|
}
|
|
459
467
|
|
|
460
|
-
if(fragment.getCamera() == null) {
|
|
468
|
+
if (fragment.getCamera() == null) {
|
|
461
469
|
return false;
|
|
462
470
|
}
|
|
463
471
|
|
|
@@ -478,19 +486,22 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
478
486
|
return VIDEO_FILE_PATH + fileName + VIDEO_FILE_EXTENSION;
|
|
479
487
|
}
|
|
480
488
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
489
|
+
private void setupBroadcast() {
|
|
490
|
+
/** When touch event is triggered, relay it to camera view if needed so it can support pinch zoom */
|
|
491
|
+
|
|
492
|
+
getBridge().getWebView().setClickable(true);
|
|
493
|
+
getBridge()
|
|
494
|
+
.getWebView()
|
|
495
|
+
.setOnTouchListener(
|
|
496
|
+
new View.OnTouchListener() {
|
|
497
|
+
@Override
|
|
498
|
+
public boolean onTouch(View v, MotionEvent event) {
|
|
499
|
+
if ((null != fragment) && (fragment.toBack == true)) {
|
|
500
|
+
fragment.frameContainerLayout.dispatchTouchEvent(event);
|
|
501
|
+
}
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
);
|
|
506
|
+
}
|
|
496
507
|
}
|
|
@@ -4,22 +4,20 @@ import android.content.Context;
|
|
|
4
4
|
import android.view.SurfaceHolder;
|
|
5
5
|
import android.view.SurfaceView;
|
|
6
6
|
|
|
7
|
-
class CustomSurfaceView extends SurfaceView implements SurfaceHolder.Callback{
|
|
8
|
-
private final String TAG = "CustomSurfaceView";
|
|
7
|
+
class CustomSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
super(context);
|
|
12
|
-
}
|
|
9
|
+
private final String TAG = "CustomSurfaceView";
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
CustomSurfaceView(Context context) {
|
|
12
|
+
super(context);
|
|
13
|
+
}
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
15
|
+
@Override
|
|
16
|
+
public void surfaceCreated(SurfaceHolder holder) {}
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
@Override
|
|
19
|
+
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
|
|
20
|
+
|
|
21
|
+
@Override
|
|
22
|
+
public void surfaceDestroyed(SurfaceHolder holder) {}
|
|
25
23
|
}
|
|
@@ -5,27 +5,25 @@ import android.graphics.SurfaceTexture;
|
|
|
5
5
|
import android.view.SurfaceHolder;
|
|
6
6
|
import android.view.TextureView;
|
|
7
7
|
|
|
8
|
-
class CustomTextureView extends TextureView implements TextureView.SurfaceTextureListener{
|
|
9
|
-
private final String TAG = "CustomTextureView";
|
|
8
|
+
class CustomTextureView extends TextureView implements TextureView.SurfaceTextureListener {
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
super(context);
|
|
13
|
-
}
|
|
10
|
+
private final String TAG = "CustomTextureView";
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
CustomTextureView(Context context) {
|
|
13
|
+
super(context);
|
|
14
|
+
}
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
16
|
+
@Override
|
|
17
|
+
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {}
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
19
|
+
@Override
|
|
20
|
+
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {}
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
@Override
|
|
23
|
+
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Override
|
|
28
|
+
public void onSurfaceTextureUpdated(SurfaceTexture surface) {}
|
|
31
29
|
}
|