capacitor-community-multilens-camerapreview 5.0.1 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorCommunityMultilensCamerapreview.podspec +17 -17
- package/README.md +16 -16
- package/android/build.gradle +57 -55
- package/android/src/main/AndroidManifest.xml +4 -4
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +1005 -1008
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +543 -544
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomSurfaceView.java +23 -23
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomTextureView.java +29 -29
- package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +386 -386
- package/android/src/main/java/com/ahm/capacitor/camera/preview/TapGestureDetector.java +24 -24
- package/android/src/main/res/layout/bridge_layout_main.xml +15 -15
- package/android/src/main/res/layout/camera_activity.xml +68 -68
- package/android/src/main/res/values/camera_ids.xml +4 -4
- package/android/src/main/res/values/camera_theme.xml +9 -9
- package/android/src/main/res/values/colors.xml +3 -3
- package/android/src/main/res/values/strings.xml +3 -3
- package/android/src/main/res/values/styles.xml +3 -3
- package/dist/esm/definitions.d.ts +82 -80
- package/dist/esm/definitions.js +1 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +6 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +30 -28
- package/dist/esm/web.js +146 -155
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +146 -150
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +147 -151
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CameraController.swift +732 -733
- package/ios/Plugin/Info.plist +24 -24
- package/ios/Plugin/Plugin.h +10 -10
- package/ios/Plugin/Plugin.m +18 -18
- package/ios/Plugin/Plugin.swift +309 -308
- package/package.json +85 -78
- package/dist/docs.json +0 -408
|
@@ -1,544 +1,543 @@
|
|
|
1
|
-
package com.ahm.capacitor.camera.preview;
|
|
2
|
-
|
|
3
|
-
import static android.Manifest.permission.CAMERA;
|
|
4
|
-
|
|
5
|
-
import android.app.FragmentManager;
|
|
6
|
-
import android.app.FragmentTransaction;
|
|
7
|
-
import android.content.pm.ActivityInfo;
|
|
8
|
-
import android.graphics.Color;
|
|
9
|
-
import android.graphics.Point;
|
|
10
|
-
import android.hardware.Camera;
|
|
11
|
-
import android.content.Context;
|
|
12
|
-
import android.hardware.camera2.*;
|
|
13
|
-
import android.hardware.camera2.params.OutputConfiguration;
|
|
14
|
-
import android.util.DisplayMetrics;
|
|
15
|
-
import android.util.TypedValue;
|
|
16
|
-
import android.view.Display;
|
|
17
|
-
import android.view.MotionEvent;
|
|
18
|
-
import android.view.View;
|
|
19
|
-
import android.view.ViewGroup;
|
|
20
|
-
import android.widget.FrameLayout;
|
|
21
|
-
import com.getcapacitor.JSObject;
|
|
22
|
-
import com.getcapacitor.Logger;
|
|
23
|
-
import com.getcapacitor.PermissionState;
|
|
24
|
-
import com.getcapacitor.Plugin;
|
|
25
|
-
import com.getcapacitor.PluginCall;
|
|
26
|
-
import com.getcapacitor.PluginMethod;
|
|
27
|
-
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
28
|
-
import com.getcapacitor.annotation.Permission;
|
|
29
|
-
import com.getcapacitor.annotation.PermissionCallback;
|
|
30
|
-
import java.io.File;
|
|
31
|
-
import java.util.List;
|
|
32
|
-
import java.util.Set;
|
|
33
|
-
import org.json.JSONArray;
|
|
34
|
-
|
|
35
|
-
@CapacitorPlugin(name = "CameraPreview", permissions = { @Permission(strings = { CAMERA }, alias = CameraPreview.CAMERA_PERMISSION_ALIAS) })
|
|
36
|
-
public class CameraPreview extends Plugin implements CameraActivity.CameraPreviewListener {
|
|
37
|
-
|
|
38
|
-
static final String CAMERA_PERMISSION_ALIAS = "camera";
|
|
39
|
-
|
|
40
|
-
private static String VIDEO_FILE_PATH = "";
|
|
41
|
-
private static String VIDEO_FILE_EXTENSION = ".mp4";
|
|
42
|
-
|
|
43
|
-
private String captureCallbackId = "";
|
|
44
|
-
private String snapshotCallbackId = "";
|
|
45
|
-
private String recordCallbackId = "";
|
|
46
|
-
private String cameraStartCallbackId = "";
|
|
47
|
-
|
|
48
|
-
// keep track of previously specified orientation to support locking orientation:
|
|
49
|
-
private int previousOrientationRequest = -1;
|
|
50
|
-
|
|
51
|
-
private static CameraActivity fragment;
|
|
52
|
-
private int containerViewId = 21;
|
|
53
|
-
private int zoomLevel = 0;
|
|
54
|
-
|
|
55
|
-
@PluginMethod
|
|
56
|
-
public void echo(PluginCall call) {
|
|
57
|
-
String value = call.getString("value");
|
|
58
|
-
|
|
59
|
-
JSObject ret = new JSObject();
|
|
60
|
-
ret.put("value", value);
|
|
61
|
-
call.resolve(ret);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@PluginMethod
|
|
65
|
-
public void start(PluginCall call) {
|
|
66
|
-
if (PermissionState.GRANTED.equals(getPermissionState(CAMERA_PERMISSION_ALIAS))) {
|
|
67
|
-
startCamera(call);
|
|
68
|
-
} else {
|
|
69
|
-
requestPermissionForAlias(CAMERA_PERMISSION_ALIAS, call, "handleCameraPermissionResult");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
@PluginMethod
|
|
74
|
-
public void flip(PluginCall call) {
|
|
75
|
-
try {
|
|
76
|
-
fragment.switchCamera();
|
|
77
|
-
call.resolve();
|
|
78
|
-
} catch (Exception e) {
|
|
79
|
-
Logger.debug(getLogTag(), "Camera flip exception: " + e);
|
|
80
|
-
call.reject("failed to flip camera");
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
@PluginMethod
|
|
85
|
-
public void setOpacity(PluginCall call) {
|
|
86
|
-
if (this.hasCamera(call) == false) {
|
|
87
|
-
call.error("Camera is not running");
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
bridge.saveCall(call);
|
|
92
|
-
Float opacity = call.getFloat("opacity", 1F);
|
|
93
|
-
fragment.setOpacity(opacity);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@PluginMethod
|
|
97
|
-
public void capture(PluginCall call) {
|
|
98
|
-
if (this.hasCamera(call) == false) {
|
|
99
|
-
call.reject("Camera is not running");
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
bridge.saveCall(call);
|
|
103
|
-
captureCallbackId = call.getCallbackId();
|
|
104
|
-
|
|
105
|
-
Integer quality = call.getInt("quality", 85);
|
|
106
|
-
// Image Dimensions - Optional
|
|
107
|
-
Integer width = call.getInt("width", 0);
|
|
108
|
-
Integer height = call.getInt("height", 0);
|
|
109
|
-
fragment.takePicture(width, height, quality);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@PluginMethod
|
|
113
|
-
public void captureSample(PluginCall call) {
|
|
114
|
-
if (this.hasCamera(call) == false) {
|
|
115
|
-
call.reject("Camera is not running");
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
bridge.saveCall(call);
|
|
119
|
-
snapshotCallbackId = call.getCallbackId();
|
|
120
|
-
|
|
121
|
-
Integer quality = call.getInt("quality", 85);
|
|
122
|
-
fragment.takeSnapshot(quality);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
@PluginMethod
|
|
126
|
-
public void stop(final PluginCall call) {
|
|
127
|
-
bridge
|
|
128
|
-
.getActivity()
|
|
129
|
-
.runOnUiThread(
|
|
130
|
-
new Runnable() {
|
|
131
|
-
@Override
|
|
132
|
-
public void run() {
|
|
133
|
-
FrameLayout containerView = getBridge().getActivity().findViewById(containerViewId);
|
|
134
|
-
|
|
135
|
-
// allow orientation changes after closing camera:
|
|
136
|
-
getBridge().getActivity().setRequestedOrientation(previousOrientationRequest);
|
|
137
|
-
|
|
138
|
-
if (containerView != null) {
|
|
139
|
-
((ViewGroup) getBridge().getWebView().getParent()).removeView(containerView);
|
|
140
|
-
getBridge().getWebView().setBackgroundColor(Color.WHITE);
|
|
141
|
-
FragmentManager fragmentManager = getActivity().getFragmentManager();
|
|
142
|
-
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
|
143
|
-
fragmentTransaction.remove(fragment);
|
|
144
|
-
fragmentTransaction.commit();
|
|
145
|
-
fragment = null;
|
|
146
|
-
|
|
147
|
-
call.resolve();
|
|
148
|
-
} else {
|
|
149
|
-
call.reject("camera already stopped");
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
@PluginMethod
|
|
157
|
-
public void getSupportedFlashModes(PluginCall call) {
|
|
158
|
-
if (this.hasCamera(call) == false) {
|
|
159
|
-
call.reject("Camera is not running");
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
Camera camera = fragment.getCamera();
|
|
164
|
-
Camera.Parameters params = camera.getParameters();
|
|
165
|
-
List<String> supportedFlashModes;
|
|
166
|
-
supportedFlashModes = params.getSupportedFlashModes();
|
|
167
|
-
JSONArray jsonFlashModes = new JSONArray();
|
|
168
|
-
|
|
169
|
-
if (supportedFlashModes != null) {
|
|
170
|
-
for (int i = 0; i < supportedFlashModes.size(); i++) {
|
|
171
|
-
jsonFlashModes.put(new String(supportedFlashModes.get(i)));
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
JSObject jsObject = new JSObject();
|
|
176
|
-
jsObject.put("result", jsonFlashModes);
|
|
177
|
-
call.resolve(jsObject);
|
|
178
|
-
}
|
|
179
|
-
@PluginMethod
|
|
180
|
-
public void getSupportedZoomLevels(PluginCall call) {
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
JSONArray jsonZoomLevels = new JSONArray();
|
|
184
|
-
Context context = getContext();
|
|
185
|
-
CameraManager cameraManager = (CameraManager)context.getSystemService(Context.CAMERA_SERVICE);
|
|
186
|
-
String[] cameraIdList = cameraManager.getCameraIdList(); // may be empty
|
|
187
|
-
// iterate over available camera devices
|
|
188
|
-
for (String cameraId : cameraIdList) {
|
|
189
|
-
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
|
|
190
|
-
Set<String> physicalIds = characteristics.getPhysicalCameraIds();
|
|
191
|
-
System.out.println(physicalIds);
|
|
192
|
-
for(String id : physicalIds){
|
|
193
|
-
jsonZoomLevels.put(id);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
JSObject jsObject = new JSObject();
|
|
197
|
-
jsObject.put("result", jsonZoomLevels);
|
|
198
|
-
call.resolve(jsObject);
|
|
199
|
-
} catch (CameraAccessException e) {
|
|
200
|
-
call.reject("Can't get Camera Id's");
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
@PluginMethod
|
|
204
|
-
public void setZoom(PluginCall call) {
|
|
205
|
-
int zoomFactor = call.getInt("zoomFactor", 0);
|
|
206
|
-
//this does nothing in android
|
|
207
|
-
call.resolve();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
@PluginMethod
|
|
211
|
-
public void setFlashMode(PluginCall call) {
|
|
212
|
-
if (this.hasCamera(call) == false) {
|
|
213
|
-
call.reject("Camera is not running");
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
String flashMode = call.getString("flashMode");
|
|
218
|
-
if (flashMode == null || flashMode.isEmpty() == true) {
|
|
219
|
-
call.reject("flashMode required parameter is missing");
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
Camera camera = fragment.getCamera();
|
|
224
|
-
Camera.Parameters params = camera.getParameters();
|
|
225
|
-
|
|
226
|
-
List<String> supportedFlashModes;
|
|
227
|
-
supportedFlashModes = camera.getParameters().getSupportedFlashModes();
|
|
228
|
-
if (supportedFlashModes.indexOf(flashMode) > -1) {
|
|
229
|
-
params.setFlashMode(flashMode);
|
|
230
|
-
} else {
|
|
231
|
-
call.reject("Flash mode not recognised: " + flashMode);
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
fragment.setCameraParameters(params);
|
|
236
|
-
|
|
237
|
-
call.resolve();
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
@PluginMethod
|
|
241
|
-
public void startRecordVideo(final PluginCall call) {
|
|
242
|
-
if (this.hasCamera(call) == false) {
|
|
243
|
-
call.reject("Camera is not running");
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
final String filename = "videoTmp";
|
|
247
|
-
VIDEO_FILE_PATH = getActivity().getCacheDir().toString() + "/";
|
|
248
|
-
|
|
249
|
-
final String position = call.getString("position", "front");
|
|
250
|
-
final Integer width = call.getInt("width", 0);
|
|
251
|
-
final Integer height = call.getInt("height", 0);
|
|
252
|
-
final Boolean withFlash = call.getBoolean("withFlash", false);
|
|
253
|
-
final Integer maxDuration = call.getInt("maxDuration", 0);
|
|
254
|
-
final String lens = call.getString("zoomFactor", "0");
|
|
255
|
-
// final Integer quality = call.getInt("quality", 0);
|
|
256
|
-
bridge.saveCall(call);
|
|
257
|
-
recordCallbackId = call.getCallbackId();
|
|
258
|
-
|
|
259
|
-
bridge
|
|
260
|
-
.getActivity()
|
|
261
|
-
.runOnUiThread(
|
|
262
|
-
new Runnable() {
|
|
263
|
-
@Override
|
|
264
|
-
public void run() {
|
|
265
|
-
// fragment.startRecord(getFilePath(filename), position, width, height, quality, withFlash);
|
|
266
|
-
fragment.startRecord(getFilePath(filename), position, width, height, 70, withFlash, maxDuration, lens);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
call.resolve();
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
@PluginMethod
|
|
275
|
-
public void stopRecordVideo(PluginCall call) {
|
|
276
|
-
if (this.hasCamera(call) == false) {
|
|
277
|
-
call.reject("Camera is not running");
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
System.out.println("stopRecordVideo - Callbackid=" + call.getCallbackId());
|
|
282
|
-
|
|
283
|
-
bridge.saveCall(call);
|
|
284
|
-
recordCallbackId = call.getCallbackId();
|
|
285
|
-
|
|
286
|
-
// bridge.getActivity().runOnUiThread(new Runnable() {
|
|
287
|
-
// @Override
|
|
288
|
-
// public void run() {
|
|
289
|
-
// fragment.stopRecord();
|
|
290
|
-
// }
|
|
291
|
-
// });
|
|
292
|
-
|
|
293
|
-
fragment.stopRecord();
|
|
294
|
-
// call.resolve();
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
@PermissionCallback
|
|
298
|
-
private void handleCameraPermissionResult(PluginCall call) {
|
|
299
|
-
if (PermissionState.GRANTED.equals(getPermissionState(CAMERA_PERMISSION_ALIAS))) {
|
|
300
|
-
startCamera(call);
|
|
301
|
-
} else {
|
|
302
|
-
Logger.debug(getLogTag(), "User denied camera permission: " + getPermissionState(CAMERA_PERMISSION_ALIAS).toString());
|
|
303
|
-
call.reject("Permission failed: user denied access to camera.");
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
position = "
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
final Integer
|
|
319
|
-
final Integer
|
|
320
|
-
final Integer
|
|
321
|
-
final
|
|
322
|
-
final
|
|
323
|
-
final Boolean
|
|
324
|
-
final Boolean
|
|
325
|
-
final Boolean
|
|
326
|
-
final Boolean
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
fragment =
|
|
332
|
-
fragment.
|
|
333
|
-
fragment.
|
|
334
|
-
fragment.
|
|
335
|
-
fragment.
|
|
336
|
-
fragment.
|
|
337
|
-
fragment.
|
|
338
|
-
fragment.
|
|
339
|
-
fragment.
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
int
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
int
|
|
360
|
-
int
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
containerView
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
getBridge().getWebView().
|
|
399
|
-
(
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
fragmentTransaction.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
//
|
|
411
|
-
//
|
|
412
|
-
//
|
|
413
|
-
//
|
|
414
|
-
//
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
getBridge()
|
|
530
|
-
|
|
531
|
-
.
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
1
|
+
package com.ahm.capacitor.camera.preview;
|
|
2
|
+
|
|
3
|
+
import static android.Manifest.permission.CAMERA;
|
|
4
|
+
|
|
5
|
+
import android.app.FragmentManager;
|
|
6
|
+
import android.app.FragmentTransaction;
|
|
7
|
+
import android.content.pm.ActivityInfo;
|
|
8
|
+
import android.graphics.Color;
|
|
9
|
+
import android.graphics.Point;
|
|
10
|
+
import android.hardware.Camera;
|
|
11
|
+
import android.content.Context;
|
|
12
|
+
import android.hardware.camera2.*;
|
|
13
|
+
import android.hardware.camera2.params.OutputConfiguration;
|
|
14
|
+
import android.util.DisplayMetrics;
|
|
15
|
+
import android.util.TypedValue;
|
|
16
|
+
import android.view.Display;
|
|
17
|
+
import android.view.MotionEvent;
|
|
18
|
+
import android.view.View;
|
|
19
|
+
import android.view.ViewGroup;
|
|
20
|
+
import android.widget.FrameLayout;
|
|
21
|
+
import com.getcapacitor.JSObject;
|
|
22
|
+
import com.getcapacitor.Logger;
|
|
23
|
+
import com.getcapacitor.PermissionState;
|
|
24
|
+
import com.getcapacitor.Plugin;
|
|
25
|
+
import com.getcapacitor.PluginCall;
|
|
26
|
+
import com.getcapacitor.PluginMethod;
|
|
27
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
28
|
+
import com.getcapacitor.annotation.Permission;
|
|
29
|
+
import com.getcapacitor.annotation.PermissionCallback;
|
|
30
|
+
import java.io.File;
|
|
31
|
+
import java.util.List;
|
|
32
|
+
import java.util.Set;
|
|
33
|
+
import org.json.JSONArray;
|
|
34
|
+
|
|
35
|
+
@CapacitorPlugin(name = "CameraPreview", permissions = { @Permission(strings = { CAMERA }, alias = CameraPreview.CAMERA_PERMISSION_ALIAS) })
|
|
36
|
+
public class CameraPreview extends Plugin implements CameraActivity.CameraPreviewListener {
|
|
37
|
+
|
|
38
|
+
static final String CAMERA_PERMISSION_ALIAS = "camera";
|
|
39
|
+
|
|
40
|
+
private static String VIDEO_FILE_PATH = "";
|
|
41
|
+
private static String VIDEO_FILE_EXTENSION = ".mp4";
|
|
42
|
+
|
|
43
|
+
private String captureCallbackId = "";
|
|
44
|
+
private String snapshotCallbackId = "";
|
|
45
|
+
private String recordCallbackId = "";
|
|
46
|
+
private String cameraStartCallbackId = "";
|
|
47
|
+
|
|
48
|
+
// keep track of previously specified orientation to support locking orientation:
|
|
49
|
+
private int previousOrientationRequest = -1;
|
|
50
|
+
|
|
51
|
+
private static CameraActivity fragment;
|
|
52
|
+
private int containerViewId = 21;
|
|
53
|
+
private int zoomLevel = 0;
|
|
54
|
+
|
|
55
|
+
@PluginMethod
|
|
56
|
+
public void echo(PluginCall call) {
|
|
57
|
+
String value = call.getString("value");
|
|
58
|
+
|
|
59
|
+
JSObject ret = new JSObject();
|
|
60
|
+
ret.put("value", value);
|
|
61
|
+
call.resolve(ret);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@PluginMethod
|
|
65
|
+
public void start(PluginCall call) {
|
|
66
|
+
if (PermissionState.GRANTED.equals(getPermissionState(CAMERA_PERMISSION_ALIAS))) {
|
|
67
|
+
startCamera(call);
|
|
68
|
+
} else {
|
|
69
|
+
requestPermissionForAlias(CAMERA_PERMISSION_ALIAS, call, "handleCameraPermissionResult");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@PluginMethod
|
|
74
|
+
public void flip(PluginCall call) {
|
|
75
|
+
try {
|
|
76
|
+
fragment.switchCamera();
|
|
77
|
+
call.resolve();
|
|
78
|
+
} catch (Exception e) {
|
|
79
|
+
Logger.debug(getLogTag(), "Camera flip exception: " + e);
|
|
80
|
+
call.reject("failed to flip camera");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@PluginMethod
|
|
85
|
+
public void setOpacity(PluginCall call) {
|
|
86
|
+
if (this.hasCamera(call) == false) {
|
|
87
|
+
call.error("Camera is not running");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
bridge.saveCall(call);
|
|
92
|
+
Float opacity = call.getFloat("opacity", 1F);
|
|
93
|
+
fragment.setOpacity(opacity);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@PluginMethod
|
|
97
|
+
public void capture(PluginCall call) {
|
|
98
|
+
if (this.hasCamera(call) == false) {
|
|
99
|
+
call.reject("Camera is not running");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
bridge.saveCall(call);
|
|
103
|
+
captureCallbackId = call.getCallbackId();
|
|
104
|
+
|
|
105
|
+
Integer quality = call.getInt("quality", 85);
|
|
106
|
+
// Image Dimensions - Optional
|
|
107
|
+
Integer width = call.getInt("width", 0);
|
|
108
|
+
Integer height = call.getInt("height", 0);
|
|
109
|
+
fragment.takePicture(width, height, quality);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@PluginMethod
|
|
113
|
+
public void captureSample(PluginCall call) {
|
|
114
|
+
if (this.hasCamera(call) == false) {
|
|
115
|
+
call.reject("Camera is not running");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
bridge.saveCall(call);
|
|
119
|
+
snapshotCallbackId = call.getCallbackId();
|
|
120
|
+
|
|
121
|
+
Integer quality = call.getInt("quality", 85);
|
|
122
|
+
fragment.takeSnapshot(quality);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@PluginMethod
|
|
126
|
+
public void stop(final PluginCall call) {
|
|
127
|
+
bridge
|
|
128
|
+
.getActivity()
|
|
129
|
+
.runOnUiThread(
|
|
130
|
+
new Runnable() {
|
|
131
|
+
@Override
|
|
132
|
+
public void run() {
|
|
133
|
+
FrameLayout containerView = getBridge().getActivity().findViewById(containerViewId);
|
|
134
|
+
|
|
135
|
+
// allow orientation changes after closing camera:
|
|
136
|
+
getBridge().getActivity().setRequestedOrientation(previousOrientationRequest);
|
|
137
|
+
|
|
138
|
+
if (containerView != null) {
|
|
139
|
+
((ViewGroup) getBridge().getWebView().getParent()).removeView(containerView);
|
|
140
|
+
getBridge().getWebView().setBackgroundColor(Color.WHITE);
|
|
141
|
+
FragmentManager fragmentManager = getActivity().getFragmentManager();
|
|
142
|
+
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
|
143
|
+
fragmentTransaction.remove(fragment);
|
|
144
|
+
fragmentTransaction.commit();
|
|
145
|
+
fragment = null;
|
|
146
|
+
|
|
147
|
+
call.resolve();
|
|
148
|
+
} else {
|
|
149
|
+
call.reject("camera already stopped");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@PluginMethod
|
|
157
|
+
public void getSupportedFlashModes(PluginCall call) {
|
|
158
|
+
if (this.hasCamera(call) == false) {
|
|
159
|
+
call.reject("Camera is not running");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
Camera camera = fragment.getCamera();
|
|
164
|
+
Camera.Parameters params = camera.getParameters();
|
|
165
|
+
List<String> supportedFlashModes;
|
|
166
|
+
supportedFlashModes = params.getSupportedFlashModes();
|
|
167
|
+
JSONArray jsonFlashModes = new JSONArray();
|
|
168
|
+
|
|
169
|
+
if (supportedFlashModes != null) {
|
|
170
|
+
for (int i = 0; i < supportedFlashModes.size(); i++) {
|
|
171
|
+
jsonFlashModes.put(new String(supportedFlashModes.get(i)));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
JSObject jsObject = new JSObject();
|
|
176
|
+
jsObject.put("result", jsonFlashModes);
|
|
177
|
+
call.resolve(jsObject);
|
|
178
|
+
}
|
|
179
|
+
@PluginMethod
|
|
180
|
+
public void getSupportedZoomLevels(PluginCall call) {
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
JSONArray jsonZoomLevels = new JSONArray();
|
|
184
|
+
Context context = getContext();
|
|
185
|
+
CameraManager cameraManager = (CameraManager)context.getSystemService(Context.CAMERA_SERVICE);
|
|
186
|
+
String[] cameraIdList = cameraManager.getCameraIdList(); // may be empty
|
|
187
|
+
// iterate over available camera devices
|
|
188
|
+
for (String cameraId : cameraIdList) {
|
|
189
|
+
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
|
|
190
|
+
Set<String> physicalIds = characteristics.getPhysicalCameraIds();
|
|
191
|
+
System.out.println(physicalIds);
|
|
192
|
+
for(String id : physicalIds){
|
|
193
|
+
jsonZoomLevels.put(id);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
JSObject jsObject = new JSObject();
|
|
197
|
+
jsObject.put("result", jsonZoomLevels);
|
|
198
|
+
call.resolve(jsObject);
|
|
199
|
+
} catch (CameraAccessException e) {
|
|
200
|
+
call.reject("Can't get Camera Id's");
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
@PluginMethod
|
|
204
|
+
public void setZoom(PluginCall call) {
|
|
205
|
+
int zoomFactor = call.getInt("zoomFactor", 0);
|
|
206
|
+
//this does nothing in android
|
|
207
|
+
call.resolve();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@PluginMethod
|
|
211
|
+
public void setFlashMode(PluginCall call) {
|
|
212
|
+
if (this.hasCamera(call) == false) {
|
|
213
|
+
call.reject("Camera is not running");
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
String flashMode = call.getString("flashMode");
|
|
218
|
+
if (flashMode == null || flashMode.isEmpty() == true) {
|
|
219
|
+
call.reject("flashMode required parameter is missing");
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
Camera camera = fragment.getCamera();
|
|
224
|
+
Camera.Parameters params = camera.getParameters();
|
|
225
|
+
|
|
226
|
+
List<String> supportedFlashModes;
|
|
227
|
+
supportedFlashModes = camera.getParameters().getSupportedFlashModes();
|
|
228
|
+
if (supportedFlashModes.indexOf(flashMode) > -1) {
|
|
229
|
+
params.setFlashMode(flashMode);
|
|
230
|
+
} else {
|
|
231
|
+
call.reject("Flash mode not recognised: " + flashMode);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
fragment.setCameraParameters(params);
|
|
236
|
+
|
|
237
|
+
call.resolve();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
@PluginMethod
|
|
241
|
+
public void startRecordVideo(final PluginCall call) {
|
|
242
|
+
if (this.hasCamera(call) == false) {
|
|
243
|
+
call.reject("Camera is not running");
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
final String filename = "videoTmp";
|
|
247
|
+
VIDEO_FILE_PATH = getActivity().getCacheDir().toString() + "/";
|
|
248
|
+
|
|
249
|
+
final String position = call.getString("position", "front");
|
|
250
|
+
final Integer width = call.getInt("width", 0);
|
|
251
|
+
final Integer height = call.getInt("height", 0);
|
|
252
|
+
final Boolean withFlash = call.getBoolean("withFlash", false);
|
|
253
|
+
final Integer maxDuration = call.getInt("maxDuration", 0);
|
|
254
|
+
final String lens = call.getString("zoomFactor", "0");
|
|
255
|
+
// final Integer quality = call.getInt("quality", 0);
|
|
256
|
+
bridge.saveCall(call);
|
|
257
|
+
recordCallbackId = call.getCallbackId();
|
|
258
|
+
|
|
259
|
+
bridge
|
|
260
|
+
.getActivity()
|
|
261
|
+
.runOnUiThread(
|
|
262
|
+
new Runnable() {
|
|
263
|
+
@Override
|
|
264
|
+
public void run() {
|
|
265
|
+
// fragment.startRecord(getFilePath(filename), position, width, height, quality, withFlash);
|
|
266
|
+
fragment.startRecord(getFilePath(filename), position, width, height, 70, withFlash, maxDuration, lens);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
call.resolve();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
@PluginMethod
|
|
275
|
+
public void stopRecordVideo(PluginCall call) {
|
|
276
|
+
if (this.hasCamera(call) == false) {
|
|
277
|
+
call.reject("Camera is not running");
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
System.out.println("stopRecordVideo - Callbackid=" + call.getCallbackId());
|
|
282
|
+
|
|
283
|
+
bridge.saveCall(call);
|
|
284
|
+
recordCallbackId = call.getCallbackId();
|
|
285
|
+
|
|
286
|
+
// bridge.getActivity().runOnUiThread(new Runnable() {
|
|
287
|
+
// @Override
|
|
288
|
+
// public void run() {
|
|
289
|
+
// fragment.stopRecord();
|
|
290
|
+
// }
|
|
291
|
+
// });
|
|
292
|
+
|
|
293
|
+
fragment.stopRecord();
|
|
294
|
+
// call.resolve();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
@PermissionCallback
|
|
298
|
+
private void handleCameraPermissionResult(PluginCall call) {
|
|
299
|
+
if (PermissionState.GRANTED.equals(getPermissionState(CAMERA_PERMISSION_ALIAS))) {
|
|
300
|
+
startCamera(call);
|
|
301
|
+
} else {
|
|
302
|
+
Logger.debug(getLogTag(), "User denied camera permission: " + getPermissionState(CAMERA_PERMISSION_ALIAS).toString());
|
|
303
|
+
call.reject("Permission failed: user denied access to camera.");
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
private void startCamera(final PluginCall call) {
|
|
308
|
+
String position = call.getString("position");
|
|
309
|
+
|
|
310
|
+
if (position == null || position.isEmpty() || "rear".equals(position)) {
|
|
311
|
+
position = "back";
|
|
312
|
+
} else {
|
|
313
|
+
position = "front";
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
final Integer x = call.getInt("x", 0);
|
|
317
|
+
final Integer y = call.getInt("y", 0);
|
|
318
|
+
final Integer width = call.getInt("width", 0);
|
|
319
|
+
final Integer height = call.getInt("height", 0);
|
|
320
|
+
final Integer paddingBottom = call.getInt("paddingBottom", 0);
|
|
321
|
+
final Boolean toBack = call.getBoolean("toBack", false);
|
|
322
|
+
final Boolean storeToFile = call.getBoolean("storeToFile", false);
|
|
323
|
+
final Boolean enableOpacity = call.getBoolean("enableOpacity", false);
|
|
324
|
+
final Boolean enableZoom = call.getBoolean("enableZoom", false);
|
|
325
|
+
final Boolean disableExifHeaderStripping = call.getBoolean("disableExifHeaderStripping", true);
|
|
326
|
+
final Boolean lockOrientation = call.getBoolean("lockAndroidOrientation", false);
|
|
327
|
+
previousOrientationRequest = getBridge().getActivity().getRequestedOrientation();
|
|
328
|
+
|
|
329
|
+
fragment = new CameraActivity();
|
|
330
|
+
fragment.setEventListener(this);
|
|
331
|
+
fragment.defaultCamera = position;
|
|
332
|
+
fragment.tapToTakePicture = false;
|
|
333
|
+
fragment.dragEnabled = false;
|
|
334
|
+
fragment.tapToFocus = true;
|
|
335
|
+
fragment.disableExifHeaderStripping = disableExifHeaderStripping;
|
|
336
|
+
fragment.storeToFile = storeToFile;
|
|
337
|
+
fragment.toBack = toBack;
|
|
338
|
+
fragment.enableOpacity = enableOpacity;
|
|
339
|
+
fragment.enableZoom = enableZoom;
|
|
340
|
+
|
|
341
|
+
bridge
|
|
342
|
+
.getActivity()
|
|
343
|
+
.runOnUiThread(
|
|
344
|
+
new Runnable() {
|
|
345
|
+
@Override
|
|
346
|
+
public void run() {
|
|
347
|
+
DisplayMetrics metrics = getBridge().getActivity().getResources().getDisplayMetrics();
|
|
348
|
+
// lock orientation if specified in options:
|
|
349
|
+
if (lockOrientation) {
|
|
350
|
+
getBridge().getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// offset
|
|
354
|
+
int computedX = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, x, metrics);
|
|
355
|
+
int computedY = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, y, metrics);
|
|
356
|
+
|
|
357
|
+
// size
|
|
358
|
+
int computedWidth;
|
|
359
|
+
int computedHeight;
|
|
360
|
+
int computedPaddingBottom;
|
|
361
|
+
|
|
362
|
+
if (paddingBottom != 0) {
|
|
363
|
+
computedPaddingBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, paddingBottom, metrics);
|
|
364
|
+
} else {
|
|
365
|
+
computedPaddingBottom = 0;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (width != 0) {
|
|
369
|
+
computedWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, width, metrics);
|
|
370
|
+
} else {
|
|
371
|
+
Display defaultDisplay = getBridge().getActivity().getWindowManager().getDefaultDisplay();
|
|
372
|
+
final Point size = new Point();
|
|
373
|
+
defaultDisplay.getSize(size);
|
|
374
|
+
|
|
375
|
+
computedWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size.x, metrics);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (height != 0) {
|
|
379
|
+
computedHeight =
|
|
380
|
+
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, height, metrics) - computedPaddingBottom;
|
|
381
|
+
} else {
|
|
382
|
+
Display defaultDisplay = getBridge().getActivity().getWindowManager().getDefaultDisplay();
|
|
383
|
+
final Point size = new Point();
|
|
384
|
+
defaultDisplay.getSize(size);
|
|
385
|
+
|
|
386
|
+
computedHeight =
|
|
387
|
+
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size.y, metrics) - computedPaddingBottom;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
fragment.setRect(computedX, computedY, computedWidth, computedHeight);
|
|
391
|
+
|
|
392
|
+
FrameLayout containerView = getBridge().getActivity().findViewById(containerViewId);
|
|
393
|
+
if (containerView == null) {
|
|
394
|
+
containerView = new FrameLayout(getActivity().getApplicationContext());
|
|
395
|
+
containerView.setId(containerViewId);
|
|
396
|
+
|
|
397
|
+
getBridge().getWebView().setBackgroundColor(Color.TRANSPARENT);
|
|
398
|
+
((ViewGroup) getBridge().getWebView().getParent()).addView(containerView);
|
|
399
|
+
if (toBack == true) {
|
|
400
|
+
getBridge().getWebView().getParent().bringChildToFront(getBridge().getWebView());
|
|
401
|
+
setupBroadcast();
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
FragmentManager fragmentManager = getBridge().getActivity().getFragmentManager();
|
|
405
|
+
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
|
406
|
+
fragmentTransaction.add(containerView.getId(), fragment);
|
|
407
|
+
fragmentTransaction.commit();
|
|
408
|
+
|
|
409
|
+
// NOTE: we don't return invoke call.resolve here because it must be invoked in onCameraStarted
|
|
410
|
+
// otherwise the plugin start method might resolve/return before the camera is actually set in CameraActivity
|
|
411
|
+
// onResume method (see this line mCamera = Camera.open(defaultCameraId);) and the next subsequent plugin
|
|
412
|
+
// method invocations (for example, getSupportedFlashModes) might fails with "Camera is not running" error
|
|
413
|
+
// because camera is not available yet and hasCamera method will return false
|
|
414
|
+
// Please also see https://developer.android.com/reference/android/hardware/Camera.html#open%28int%29
|
|
415
|
+
bridge.saveCall(call);
|
|
416
|
+
cameraStartCallbackId = call.getCallbackId();
|
|
417
|
+
} else {
|
|
418
|
+
call.reject("camera already started");
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
@Override
|
|
426
|
+
protected void handleOnResume() {
|
|
427
|
+
super.handleOnResume();
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
@Override
|
|
431
|
+
public void onPictureTaken(String originalPicture) {
|
|
432
|
+
JSObject jsObject = new JSObject();
|
|
433
|
+
jsObject.put("value", originalPicture);
|
|
434
|
+
bridge.getSavedCall(captureCallbackId).resolve(jsObject);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
@Override
|
|
438
|
+
public void onPictureTakenError(String message) {
|
|
439
|
+
bridge.getSavedCall(captureCallbackId).reject(message);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
@Override
|
|
443
|
+
public void onSnapshotTaken(String originalPicture) {
|
|
444
|
+
JSObject jsObject = new JSObject();
|
|
445
|
+
jsObject.put("value", originalPicture);
|
|
446
|
+
bridge.getSavedCall(snapshotCallbackId).resolve(jsObject);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
@Override
|
|
450
|
+
public void onSnapshotTakenError(String message) {
|
|
451
|
+
bridge.getSavedCall(snapshotCallbackId).reject(message);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
@Override
|
|
455
|
+
public void onFocusSet(int pointX, int pointY) {}
|
|
456
|
+
|
|
457
|
+
@Override
|
|
458
|
+
public void onFocusSetError(String message) {}
|
|
459
|
+
|
|
460
|
+
@Override
|
|
461
|
+
public void onBackButton() {}
|
|
462
|
+
|
|
463
|
+
@Override
|
|
464
|
+
public void onCameraStarted() {
|
|
465
|
+
PluginCall pluginCall = bridge.getSavedCall(cameraStartCallbackId);
|
|
466
|
+
pluginCall.resolve();
|
|
467
|
+
bridge.releaseCall(pluginCall);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
@Override
|
|
471
|
+
public void onStartRecordVideo() {}
|
|
472
|
+
|
|
473
|
+
@Override
|
|
474
|
+
public void onStartRecordVideoError(String message) {
|
|
475
|
+
bridge.getSavedCall(recordCallbackId).reject(message);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
@Override
|
|
479
|
+
public void onStopRecordVideo(String file) {
|
|
480
|
+
PluginCall pluginCall = bridge.getSavedCall(recordCallbackId);
|
|
481
|
+
JSObject jsObject = new JSObject();
|
|
482
|
+
jsObject.put("videoFilePath", file);
|
|
483
|
+
pluginCall.resolve(jsObject);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
@Override
|
|
487
|
+
public void onStopRecordVideoError(String error) {
|
|
488
|
+
bridge.getSavedCall(recordCallbackId).reject(error);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
private boolean hasView(PluginCall call) {
|
|
492
|
+
if (fragment == null) {
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return true;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
private boolean hasCamera(PluginCall call) {
|
|
500
|
+
if (this.hasView(call) == false) {
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (fragment.getCamera() == null) {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
private String getFilePath(String filename) {
|
|
512
|
+
String fileName = filename;
|
|
513
|
+
|
|
514
|
+
int i = 1;
|
|
515
|
+
|
|
516
|
+
while (new File(VIDEO_FILE_PATH + fileName + VIDEO_FILE_EXTENSION).exists()) {
|
|
517
|
+
// Add number suffix if file exists
|
|
518
|
+
fileName = filename + '_' + i;
|
|
519
|
+
i++;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return VIDEO_FILE_PATH + fileName + VIDEO_FILE_EXTENSION;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
private void setupBroadcast() {
|
|
526
|
+
/** When touch event is triggered, relay it to camera view if needed so it can support pinch zoom */
|
|
527
|
+
|
|
528
|
+
getBridge().getWebView().setClickable(true);
|
|
529
|
+
getBridge()
|
|
530
|
+
.getWebView()
|
|
531
|
+
.setOnTouchListener(
|
|
532
|
+
new View.OnTouchListener() {
|
|
533
|
+
@Override
|
|
534
|
+
public boolean onTouch(View v, MotionEvent event) {
|
|
535
|
+
if ((null != fragment) && (fragment.toBack == true)) {
|
|
536
|
+
fragment.frameContainerLayout.dispatchTouchEvent(event);
|
|
537
|
+
}
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
}
|