scoplan.camera 1.2.5

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.
Files changed (171) hide show
  1. package/package.json +18 -0
  2. package/plugin.xml +119 -0
  3. package/src/android/AutoFitSurfaceView.java +66 -0
  4. package/src/android/CCropActivity.java +17 -0
  5. package/src/android/CDrawActivity.java +16 -0
  6. package/src/android/CTextActivity.java +17 -0
  7. package/src/android/CameraEventListener.java +8 -0
  8. package/src/android/CameraFragment.java +635 -0
  9. package/src/android/CameraSeekBarListener.java +105 -0
  10. package/src/android/CameraUtils.java +94 -0
  11. package/src/android/CustomI.java +37 -0
  12. package/src/android/FakeR.java +31 -0
  13. package/src/android/ImageCameraAvailableListener.java +65 -0
  14. package/src/android/OnImageCaptureListener.java +11 -0
  15. package/src/android/PhotoEditorActivity.java +128 -0
  16. package/src/android/PhotoEditorMenu.java +111 -0
  17. package/src/android/PhotoEditorMesureCustomActivity.java +218 -0
  18. package/src/android/PhotoEditorStore.java +50 -0
  19. package/src/android/ScoplanCamera.java +98 -0
  20. package/src/android/gradle/scoplanCamera.gradle +9 -0
  21. package/src/android/libs/ds-photo-editor-sdk-v9.aar +0 -0
  22. package/src/android/res/drawable/back_arrow.xml +5 -0
  23. package/src/android/res/drawable/camsicon.png +0 -0
  24. package/src/android/res/drawable/custom_spinner.xml +14 -0
  25. package/src/android/res/drawable/delete_img.png +0 -0
  26. package/src/android/res/drawable/draw_img.png +0 -0
  27. package/src/android/res/drawable/flash.png +0 -0
  28. package/src/android/res/drawable/flash_on.png +0 -0
  29. package/src/android/res/drawable/mesure.png +0 -0
  30. package/src/android/res/drawable/mesure_bar.xml +19 -0
  31. package/src/android/res/drawable/shape_back.xml +12 -0
  32. package/src/android/res/drawable/shape_cancel.xml +12 -0
  33. package/src/android/res/drawable/shape_rectangle.xml +4 -0
  34. package/src/android/res/layout/fragment_camera.xml +157 -0
  35. package/src/android/res/layout/fragment_photo_editor_menu.xml +122 -0
  36. package/src/ios/AVCamPhotoCaptureDelegate.h +20 -0
  37. package/src/ios/AVCamPhotoCaptureDelegate.m +244 -0
  38. package/src/ios/AVCamPreviewView.h +18 -0
  39. package/src/ios/AVCamPreviewView.m +33 -0
  40. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDK +0 -0
  41. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Assets.car +0 -0
  42. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/0dZ-3o-Xdu-view-Uan-aZ-nTR.nib/objects-11.0+.nib +0 -0
  43. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/0dZ-3o-Xdu-view-Uan-aZ-nTR.nib/objects-13.0+.nib +0 -0
  44. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/0dZ-3o-Xdu-view-Uan-aZ-nTR.nib/runtime.nib +0 -0
  45. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/DSDrawViewController.nib/objects-11.0+.nib +0 -0
  46. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/DSDrawViewController.nib/objects-13.0+.nib +0 -0
  47. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/DSDrawViewController.nib/runtime.nib +0 -0
  48. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/DSPhotoEditor.nib/objects-11.0+.nib +0 -0
  49. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/DSPhotoEditor.nib/objects-13.0+.nib +0 -0
  50. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/DSPhotoEditor.nib/runtime.nib +0 -0
  51. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/Info.plist +0 -0
  52. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/Okc-Jl-tk5-view-siV-MN-Zgc.nib/objects-11.0+.nib +0 -0
  53. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/Okc-Jl-tk5-view-siV-MN-Zgc.nib/objects-13.0+.nib +0 -0
  54. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDK.storyboardc/Okc-Jl-tk5-view-siV-MN-Zgc.nib/runtime.nib +0 -0
  55. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Base.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  56. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/Info.plist +0 -0
  57. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/ar.lproj/DSPhotoEditorSDK.strings +57 -0
  58. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/ar.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  59. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/de.lproj/DSPhotoEditorSDK.strings +57 -0
  60. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/de.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  61. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/es.lproj/DSPhotoEditorSDK.strings +57 -0
  62. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/es.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  63. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/fr.lproj/DSPhotoEditorSDK.strings +57 -0
  64. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/fr.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  65. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/id.lproj/DSPhotoEditorSDK.strings +57 -0
  66. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/id.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  67. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/it.lproj/DSPhotoEditorSDK.strings +57 -0
  68. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/it.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  69. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/ja.lproj/DSPhotoEditorSDK.strings +57 -0
  70. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/ja.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  71. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/ko.lproj/DSPhotoEditorSDK.strings +57 -0
  72. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/ko.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  73. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/ms.lproj/DSPhotoEditorSDK.strings +57 -0
  74. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/ms.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  75. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/pt-PT.lproj/DSPhotoEditorSDK.strings +57 -0
  76. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/pt-PT.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  77. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/ru.lproj/DSPhotoEditorSDK.strings +57 -0
  78. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/ru.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  79. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/th.lproj/DSPhotoEditorSDK.strings +57 -0
  80. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/th.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  81. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/tr.lproj/DSPhotoEditorSDK.strings +57 -0
  82. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/tr.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  83. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/vi.lproj/DSPhotoEditorSDK.strings +57 -0
  84. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/vi.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  85. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/zh-Hans.lproj/DSPhotoEditorSDK.strings +57 -0
  86. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/zh-Hans.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  87. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/zh-Hant.lproj/DSPhotoEditorSDK.strings +57 -0
  88. package/src/ios/DSPhotoEditorSDK.framework/DSPhotoEditorSDKResourceBundle.bundle/zh-Hant.lproj/DSPhotoEditorSDKLocalizable.strings +0 -0
  89. package/src/ios/DSPhotoEditorSDK.framework/Headers/DSPhotoEditorSDK.h +18 -0
  90. package/src/ios/DSPhotoEditorSDK.framework/Headers/DSPhotoEditorViewController.h +112 -0
  91. package/src/ios/DSPhotoEditorSDK.framework/Info.plist +0 -0
  92. package/src/ios/DSPhotoEditorSDK.framework/License.md +70 -0
  93. package/src/ios/DSPhotoEditorSDK.framework/Modules/module.modulemap +6 -0
  94. package/src/ios/DSPhotoEditorSDK.framework/framework_version.txt +5 -0
  95. package/src/ios/DSPhotoEditorSDK.framework/strip-frameworks.sh +80 -0
  96. package/src/ios/Resources/Overlay.png +0 -0
  97. package/src/ios/Resources/Overlay@2x.png +0 -0
  98. package/src/ios/Resources/back_arrows.png +0 -0
  99. package/src/ios/Resources/ds_btn_calc.png +0 -0
  100. package/src/ios/Resources/ds_btn_crop.png +0 -0
  101. package/src/ios/Resources/ds_btn_del.png +0 -0
  102. package/src/ios/Resources/ds_btn_draw.png +0 -0
  103. package/src/ios/Resources/ds_btn_text.png +0 -0
  104. package/src/ios/Resources/measure_0.png +0 -0
  105. package/src/ios/Resources/measure_1.png +0 -0
  106. package/src/ios/Resources/measure_10.png +0 -0
  107. package/src/ios/Resources/measure_11.png +0 -0
  108. package/src/ios/Resources/measure_2.png +0 -0
  109. package/src/ios/Resources/measure_3.png +0 -0
  110. package/src/ios/Resources/measure_4.png +0 -0
  111. package/src/ios/Resources/measure_5.png +0 -0
  112. package/src/ios/Resources/measure_6.png +0 -0
  113. package/src/ios/Resources/measure_7.png +0 -0
  114. package/src/ios/Resources/measure_8.png +0 -0
  115. package/src/ios/Resources/measure_9.png +0 -0
  116. package/src/ios/Resources/no.png +0 -0
  117. package/src/ios/Resources/ok.png +0 -0
  118. package/src/ios/Resources/toward_arrows.png +0 -0
  119. package/src/ios/ScoplanCamera.h +18 -0
  120. package/src/ios/ScoplanCamera.m +179 -0
  121. package/src/ios/ScoplanCamera.storyboard +115 -0
  122. package/src/ios/UICustomPickerController.h +11 -0
  123. package/src/ios/UICustomPickerController.m +119 -0
  124. package/src/ios/UIImagePickerDelegate.h +11 -0
  125. package/src/ios/UIImagePickerDelegate.m +161 -0
  126. package/src/ios/UIScoplanCamera.h +20 -0
  127. package/src/ios/UIScoplanCamera.m +1098 -0
  128. package/src/ios/bottomPhotoEditor.xib +222 -0
  129. package/src/ios/camsicons.xcassets/Contents.json +6 -0
  130. package/src/ios/camsicons.xcassets/cameraicon.imageset/Contents.json +21 -0
  131. package/src/ios/camsicons.xcassets/cameraicon.imageset/camsicon.png +0 -0
  132. package/src/ios/camsicons.xcassets/image000001.imageset/Contents.json +21 -0
  133. package/src/ios/camsicons.xcassets/image000001.imageset/image0000002.png +0 -0
  134. package/src/ios/camsicons.xcassets/image0000010.imageset/Contents.json +21 -0
  135. package/src/ios/camsicons.xcassets/image0000010.imageset/image0000010.png +0 -0
  136. package/src/ios/camsicons.xcassets/image0000011.imageset/Contents.json +21 -0
  137. package/src/ios/camsicons.xcassets/image0000011.imageset/image0000011.png +0 -0
  138. package/src/ios/camsicons.xcassets/image0000012.imageset/Contents.json +21 -0
  139. package/src/ios/camsicons.xcassets/image0000012.imageset/image0000012.png +0 -0
  140. package/src/ios/camsicons.xcassets/image0000013.imageset/Contents.json +21 -0
  141. package/src/ios/camsicons.xcassets/image0000013.imageset/image0000013.png +0 -0
  142. package/src/ios/camsicons.xcassets/image0000014.imageset/Contents.json +21 -0
  143. package/src/ios/camsicons.xcassets/image0000014.imageset/image0000014.png +0 -0
  144. package/src/ios/camsicons.xcassets/image0000015.imageset/Contents.json +21 -0
  145. package/src/ios/camsicons.xcassets/image0000015.imageset/image0000015.png +0 -0
  146. package/src/ios/camsicons.xcassets/image0000016.imageset/Contents.json +21 -0
  147. package/src/ios/camsicons.xcassets/image0000016.imageset/image0000016.png +0 -0
  148. package/src/ios/camsicons.xcassets/image0000017.imageset/Contents.json +21 -0
  149. package/src/ios/camsicons.xcassets/image0000017.imageset/image0000017.png +0 -0
  150. package/src/ios/camsicons.xcassets/image0000018.imageset/Contents.json +21 -0
  151. package/src/ios/camsicons.xcassets/image0000018.imageset/image0000018.png +0 -0
  152. package/src/ios/camsicons.xcassets/image0000019.imageset/Contents.json +21 -0
  153. package/src/ios/camsicons.xcassets/image0000019.imageset/image0000019.png +0 -0
  154. package/src/ios/camsicons.xcassets/image000002.imageset/Contents.json +21 -0
  155. package/src/ios/camsicons.xcassets/image000002.imageset/image0000001.png +0 -0
  156. package/src/ios/camsicons.xcassets/image000003.imageset/Contents.json +21 -0
  157. package/src/ios/camsicons.xcassets/image000003.imageset/image0000003.png +0 -0
  158. package/src/ios/camsicons.xcassets/image000004.imageset/Contents.json +21 -0
  159. package/src/ios/camsicons.xcassets/image000004.imageset/image0000004.png +0 -0
  160. package/src/ios/camsicons.xcassets/image000005.imageset/Contents.json +21 -0
  161. package/src/ios/camsicons.xcassets/image000005.imageset/image0000005.png +0 -0
  162. package/src/ios/camsicons.xcassets/image000006.imageset/Contents.json +21 -0
  163. package/src/ios/camsicons.xcassets/image000006.imageset/image0000006.png +0 -0
  164. package/src/ios/camsicons.xcassets/image000007.imageset/Contents.json +21 -0
  165. package/src/ios/camsicons.xcassets/image000007.imageset/image0000007.png +0 -0
  166. package/src/ios/camsicons.xcassets/image000008.imageset/Contents.json +21 -0
  167. package/src/ios/camsicons.xcassets/image000008.imageset/image0000008.png +0 -0
  168. package/src/ios/camsicons.xcassets/image000009.imageset/Contents.json +21 -0
  169. package/src/ios/camsicons.xcassets/image000009.imageset/image0000009.png +0 -0
  170. package/src/ios/multicam.xib +113 -0
  171. package/www/ScoplanCamera.js +5 -0
@@ -0,0 +1,635 @@
1
+ package scoplan.camera;
2
+
3
+ import android.Manifest;
4
+ import android.app.AlertDialog;
5
+ import android.content.Context;
6
+ import android.content.DialogInterface;
7
+ import android.content.Intent;
8
+ import android.content.pm.PackageManager;
9
+ import android.graphics.Bitmap;
10
+ import android.graphics.Color;
11
+ import android.graphics.ImageFormat;
12
+ import android.graphics.SurfaceTexture;
13
+ import android.hardware.SensorManager;
14
+ import android.hardware.camera2.CameraCaptureSession;
15
+ import android.hardware.camera2.CameraCharacteristics;
16
+ import android.hardware.camera2.CameraDevice;
17
+ import android.hardware.camera2.CameraManager;
18
+ import android.hardware.camera2.CameraMetadata;
19
+ import android.hardware.camera2.CaptureFailure;
20
+ import android.hardware.camera2.CaptureRequest;
21
+ import android.hardware.camera2.TotalCaptureResult;
22
+ import android.hardware.camera2.params.StreamConfigurationMap;
23
+ import android.media.ImageReader;
24
+ import android.net.Uri;
25
+ import android.os.Build;
26
+ import android.os.Bundle;
27
+
28
+ import com.dsphotoeditor.sdk.utils.DsPhotoEditorConstants;
29
+
30
+ import androidx.activity.result.ActivityResult;
31
+ import androidx.activity.result.ActivityResultLauncher;
32
+ import androidx.activity.result.contract.ActivityResultContracts;
33
+ import androidx.annotation.NonNull;
34
+ import androidx.core.app.ActivityCompat;
35
+ import androidx.core.view.WindowCompat;
36
+ import androidx.core.view.WindowInsetsControllerCompat;
37
+ import androidx.fragment.app.Fragment;
38
+
39
+ import android.os.Environment;
40
+ import android.os.Handler;
41
+ import android.os.HandlerThread;
42
+ import android.util.Log;
43
+ import android.util.Size;
44
+ import android.view.LayoutInflater;
45
+ import android.view.OrientationEventListener;
46
+ import android.view.Surface;
47
+ import android.view.SurfaceHolder;
48
+ import android.view.SurfaceView;
49
+ import android.view.View;
50
+ import android.view.ViewGroup;
51
+ import android.view.Window;
52
+ import android.view.WindowInsets;
53
+ import android.view.WindowInsetsController;
54
+ import android.widget.Button;
55
+ import android.widget.ImageButton;
56
+ import android.widget.ImageView;
57
+ import android.widget.LinearLayout;
58
+ import android.widget.ProgressBar;
59
+ import android.widget.SeekBar;
60
+ import android.widget.Toast;
61
+
62
+ import java.io.File;
63
+ import java.text.SimpleDateFormat;
64
+ import java.util.ArrayList;
65
+ import java.util.Arrays;
66
+ import java.util.Date;
67
+ import java.util.List;
68
+
69
+ import io.sentry.Sentry;
70
+
71
+ public class CameraFragment extends Fragment implements scoplan.camera.OnImageCaptureListener, View.OnClickListener {
72
+ public static String SCOPLAN_TAG = "SCOPLAN_TAG";
73
+ private scoplan.camera.FakeR fakeR;
74
+ private ImageButton camButton;
75
+ private SeekBar zoomBar;
76
+ private Button validationButton;
77
+ private ProgressBar progressBar;
78
+ private SurfaceView surfaceView;
79
+ private CameraDevice cameraDevice;
80
+ private View cameraTopBar;
81
+ private ImageView souche;
82
+ private Button drawOn2;
83
+ private ImageButton drawOn;
84
+ private ImageButton cancelBtn;
85
+ private Button cancelBtn2;
86
+ private ImageButton flashBtn;
87
+ private OrientationEventListener orientationEventListener;
88
+ private CameraCaptureSession cameraCaptureSessions;
89
+ private CaptureRequest.Builder captureRequestBuilder;
90
+ private String cameraId;
91
+ private int CAMERA_REQUEST_PERMISSION = 5000;
92
+ private Handler mBackgroundHandler;
93
+ private HandlerThread mBackgroundThread;
94
+ private scoplan.camera.CameraSeekBarListener cameraSeekBarListener;
95
+ private CameraManager manager;
96
+ private List<String> pictures = new ArrayList<String>();
97
+ private int pictureCount = 0;
98
+ private int photoLimit = 15;
99
+ private ActivityResultLauncher<Intent> activityResultLauncher;
100
+ private CameraEventListener cameraEventListener;
101
+ private int currentOrientation = -1;
102
+ private boolean flashOn = false;
103
+ private boolean cameraIsOpen = false;
104
+
105
+ private SurfaceHolder mSurfaceHolder;
106
+
107
+ private boolean surfaceAvailable = false;
108
+ private LinearLayout cameraFrameLayout;
109
+
110
+ private final SurfaceHolder.Callback surfaceHolderCallBack = new SurfaceHolder.Callback() {
111
+ @Override
112
+ public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder) {
113
+ surfaceAvailable = true;
114
+ openCamera();
115
+ }
116
+
117
+ @Override
118
+ public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int i, int i1, int i2) {
119
+ createCameraPreview();
120
+ }
121
+
122
+ @Override
123
+ public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder) {
124
+ //TODO close
125
+ surfaceAvailable = false;
126
+ release();
127
+ }
128
+ };
129
+
130
+ CameraDevice.StateCallback stateCallback = new CameraDevice.StateCallback() {
131
+ @Override
132
+ public void onOpened(@NonNull CameraDevice camera) {
133
+ cameraDevice = camera;
134
+ cameraIsOpen = true;
135
+ createCameraPreview();
136
+ }
137
+
138
+ @Override
139
+ public void onDisconnected(@NonNull CameraDevice cameraDevice) {
140
+ cameraDevice.close();
141
+ cameraIsOpen = false;
142
+ release();
143
+ }
144
+
145
+ @Override
146
+ public void onError(@NonNull CameraDevice cameraDevice, int i) {
147
+ cameraDevice.close();
148
+ release();
149
+ }
150
+ };
151
+
152
+ public CameraFragment() {
153
+ // Required empty public constructor
154
+ activityResultLauncher = registerForActivityResult(
155
+ new ActivityResultContracts.StartActivityForResult(),
156
+ result -> {
157
+ photoEditorCallBack(result);
158
+ }
159
+ );
160
+ }
161
+
162
+ public void setCameraEventListener(CameraEventListener cameraEventListener) {
163
+ this.cameraEventListener = cameraEventListener;
164
+ }
165
+
166
+ private void photoEditorCallBack(ActivityResult result) {
167
+ if(result.getData() != null) {
168
+ Uri outputUri = result.getData().getData();
169
+ if(outputUri != null && outputUri.compareTo(Uri.parse("remove")) == 0){
170
+ pictures.remove(pictures.size() - 1);
171
+
172
+ } else if(outputUri != null){
173
+ pictures.set(pictures.size() - 1, outputUri.getPath());
174
+ }
175
+ defineViewVisibility();
176
+ }
177
+ }
178
+
179
+ @Override
180
+ public void onCreate(Bundle savedInstanceState) {
181
+ super.onCreate(savedInstanceState);
182
+ manager = (CameraManager) getActivity().getSystemService(Context.CAMERA_SERVICE);
183
+
184
+ this.orientationEventListener = new OrientationEventListener(this.getContext(), SensorManager.SENSOR_DELAY_NORMAL) {
185
+ @Override
186
+ public void onOrientationChanged(int i) {
187
+ if(i != OrientationEventListener.ORIENTATION_UNKNOWN) {
188
+ if(i >= 315 || i <= 45) {
189
+ currentOrientation = 90; // Portrait
190
+ } else if(i > 45 && i <= 135) {
191
+ currentOrientation = 180;
192
+ } else if(i > 135 && i <= 225) {
193
+ currentOrientation = 270;
194
+ } else {
195
+ currentOrientation = 0;
196
+ }
197
+ }
198
+ }
199
+ };
200
+
201
+ this.fakeR = new FakeR(getContext());
202
+ }
203
+
204
+ @Override
205
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
206
+ Bundle savedInstanceState) {
207
+ // Inflate the layout for this fragment
208
+ View view = inflater.inflate(this.fakeR.getLayout("fragment_camera"), container, false);
209
+ camButton = view.findViewById(this.fakeR.getId("button_capture"));
210
+ zoomBar = view.findViewById(this.fakeR.getId("camera_zoom"));
211
+ validationButton = view.findViewById(this.fakeR.getId("valid_btn"));
212
+ progressBar = view.findViewById(this.fakeR.getId("progressBar"));
213
+ cameraFrameLayout = view.findViewById(this.fakeR.getId("camera_frame_layout"));
214
+ cameraFrameLayout.setBackgroundColor(Color.rgb(0, 0, 0));
215
+ surfaceView = view.findViewById(this.fakeR.getId("cameraView"));
216
+ drawOn2 = view.findViewById(this.fakeR.getId("draw_on_2"));
217
+ drawOn = view.findViewById(this.fakeR.getId("draw_on"));
218
+ assert surfaceView != null;
219
+ mSurfaceHolder = surfaceView.getHolder();
220
+ mSurfaceHolder.addCallback(surfaceHolderCallBack);
221
+ souche = view.findViewById(this.fakeR.getId("image_souche"));
222
+ cameraTopBar = view.findViewById(this.fakeR.getId("cameraTopBar"));
223
+ cancelBtn = view.findViewById(this.fakeR.getId("cancel"));
224
+ cancelBtn2 = view.findViewById(this.fakeR.getId("cancel_btn"));
225
+ flashBtn = view.findViewById(this.fakeR.getId("flash_btn"));
226
+
227
+ camButton.setOnClickListener(this);
228
+ drawOn2.setOnClickListener(this);
229
+ drawOn.setOnClickListener(this);
230
+ souche.setOnClickListener(this);
231
+ cancelBtn.setOnClickListener(this);
232
+ cancelBtn2.setOnClickListener(this);
233
+ validationButton.setOnClickListener(this);
234
+ flashBtn.setOnClickListener(this);
235
+ this.defineViewVisibility();
236
+ return view;
237
+ }
238
+
239
+ private void createCameraPreview() {
240
+ if(cameraDevice == null || !surfaceAvailable)
241
+ return;
242
+ if(!cameraIsOpen) {
243
+ this.openCamera();
244
+ }
245
+ try{
246
+ Surface surface = mSurfaceHolder.getSurface();
247
+ captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
248
+ captureRequestBuilder.addTarget(surface);
249
+ cameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback() {
250
+ @Override
251
+ public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
252
+ if(cameraDevice == null)
253
+ return;
254
+ cameraCaptureSessions = cameraCaptureSession;
255
+ updatePreview();
256
+ }
257
+
258
+ @Override
259
+ public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
260
+ Sentry.captureMessage(cameraCaptureSession.toString());
261
+ }
262
+ },null);
263
+ } catch (Exception e) {
264
+ Sentry.captureException(e);
265
+ this.failedCapture();
266
+ }
267
+ }
268
+
269
+ private void openCamera() {
270
+ try{
271
+ for (String id : manager.getCameraIdList()) {
272
+ CameraCharacteristics cameraCharacteristics =
273
+ manager.getCameraCharacteristics(id);
274
+ if (cameraCharacteristics.get(cameraCharacteristics.LENS_FACING) ==
275
+ CameraCharacteristics.LENS_FACING_BACK) {
276
+ cameraId = id;
277
+ break;
278
+ }
279
+ }
280
+ cameraId = manager.getCameraIdList()[0];
281
+ CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
282
+ StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
283
+ assert map != null;
284
+ //Check realtime permission if run higher API 23
285
+ if(ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
286
+ {
287
+ ActivityCompat.requestPermissions(getActivity(), new String[]{
288
+ Manifest.permission.CAMERA,
289
+ Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ? Manifest.permission.WRITE_EXTERNAL_STORAGE : Manifest.permission.READ_MEDIA_IMAGES
290
+ }, CAMERA_REQUEST_PERMISSION);
291
+ return;
292
+ }
293
+ manager.openCamera(cameraId, stateCallback,null);
294
+ } catch (Exception e) {
295
+ Sentry.captureException(e);
296
+ this.failedCapture();
297
+ }
298
+ }
299
+
300
+ private Size chooseOptimalSize(Size[] sizes, int desiredWidth, int desiredHeight) {
301
+ // Choose the smallest size that is at least as large as the desired size
302
+ for (Size size : sizes) {
303
+ if (size.getWidth() >= desiredWidth && size.getHeight() >= desiredHeight) {
304
+ return size;
305
+ }
306
+ }
307
+
308
+ // If no size is large enough, choose the largest available size
309
+ return sizes[sizes.length - 1];
310
+ }
311
+
312
+ private void updatePreview() {
313
+ if(cameraDevice == null)
314
+ Log.e(SCOPLAN_TAG, "Error camera");
315
+ captureRequestBuilder.set(CaptureRequest.CONTROL_MODE,CaptureRequest.CONTROL_MODE_AUTO);
316
+ try{
317
+ CameraCharacteristics cameraCharacteristics =
318
+ manager.getCameraCharacteristics(cameraId);
319
+ StreamConfigurationMap map = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
320
+ if(map != null) {
321
+ Size[] outputSizes = map.getOutputSizes(SurfaceTexture.class);
322
+ Size preferredSize = selectedPreviewSize(outputSizes);
323
+ if(preferredSize != null) {
324
+ ViewGroup.LayoutParams layoutParams = surfaceView.getLayoutParams();
325
+ Size surfaceSize = calculateSurfaceSize(preferredSize);
326
+ getActivity().runOnUiThread(() -> {
327
+ layoutParams.width = surfaceSize.getWidth();
328
+ layoutParams.height = surfaceSize.getHeight();
329
+ mSurfaceHolder.setFixedSize(surfaceSize.getWidth(), surfaceSize.getHeight());
330
+ surfaceView.setLayoutParams(layoutParams);
331
+ });
332
+ }
333
+ }
334
+ cameraCaptureSessions.setRepeatingRequest(captureRequestBuilder.build(),null, mBackgroundHandler);
335
+ this.cameraSeekBarListener = new scoplan.camera.CameraSeekBarListener(cameraId, manager, zoomBar, captureRequestBuilder, cameraCaptureSessions, mBackgroundHandler);
336
+ } catch (Exception e) {
337
+ Sentry.captureException(e);
338
+ this.failedCapture();
339
+ }
340
+ }
341
+
342
+ private Size calculateSurfaceSize(Size selectedSize) {
343
+ int parentWidth = this.cameraFrameLayout.getWidth();
344
+ Size correctSize = new Size(selectedSize.getHeight(), selectedSize.getWidth()); // We are in portrait mode
345
+
346
+ float aspectRatio = (float) correctSize.getWidth() / correctSize.getHeight();
347
+
348
+ int height = (int) (parentWidth / aspectRatio);
349
+ return new Size(parentWidth, height);
350
+ }
351
+
352
+ private Size selectedPreviewSize(Size[] outputSizes) {
353
+ float targetAspectRatio = 1f; // For example, 16:9 aspect ratio
354
+ // Choose a suitable size from outputSizes based on the aspect ratio
355
+ Size selectedSize = null;
356
+ for (Size size : outputSizes) {
357
+ float aspectRatio = (float) size.getWidth() / size.getHeight();
358
+ if (Math.abs(aspectRatio - targetAspectRatio) < 0.1) {
359
+ selectedSize = size;
360
+ break;
361
+ }
362
+ }
363
+ return selectedSize;
364
+ }
365
+
366
+ @Override
367
+ public void onResume() {
368
+ super.onResume();
369
+ startBackgroundThread();
370
+ if(surfaceAvailable)
371
+ openCamera();
372
+ else {
373
+ mSurfaceHolder.addCallback(surfaceHolderCallBack);
374
+ }
375
+ this.orientationEventListener.enable();
376
+
377
+ Window window = requireActivity().getWindow();
378
+
379
+ WindowInsetsControllerCompat controller =
380
+ WindowCompat.getInsetsController(window, window.getDecorView());
381
+
382
+ if (controller != null) {
383
+ controller.hide(WindowInsets.Type.statusBars());
384
+ controller.setSystemBarsBehavior(
385
+ WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
386
+ );
387
+ }
388
+ }
389
+
390
+ @Override
391
+ public void onPause() {
392
+ stopBackgroundThread();
393
+ super.onPause();
394
+ this.orientationEventListener.disable();
395
+ Window window = requireActivity().getWindow();
396
+ WindowInsetsControllerCompat controller =
397
+ WindowCompat.getInsetsController(window, window.getDecorView());
398
+
399
+ if (controller != null) {
400
+ controller.show(WindowInsets.Type.statusBars());
401
+ }
402
+ release();
403
+ }
404
+
405
+ @Override
406
+ public void onDestroy() {
407
+ super.onDestroy();
408
+ release();
409
+ }
410
+
411
+ private void release() {
412
+ if(cameraDevice != null) {
413
+ cameraDevice.close();
414
+ cameraIsOpen = false;
415
+ cameraDevice = null;
416
+ }
417
+ }
418
+
419
+ private void stopBackgroundThread() {
420
+ mBackgroundThread.quitSafely();
421
+ try{
422
+ mBackgroundThread.join();
423
+ mBackgroundThread= null;
424
+ mBackgroundHandler = null;
425
+ } catch (InterruptedException e) {
426
+ e.printStackTrace();
427
+ }
428
+ }
429
+
430
+ private void startBackgroundThread() {
431
+ mBackgroundThread = new HandlerThread("Camera Background");
432
+ mBackgroundThread.start();
433
+ mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
434
+ }
435
+
436
+ public void setPhotoLimit(int limit){
437
+ this.photoLimit = limit;
438
+ }
439
+
440
+ public void setCurrentCount(int currentCount){
441
+ this.pictureCount = currentCount;
442
+ }
443
+
444
+ private void takePicture() {
445
+ if(this.pictureCount >= this.photoLimit){
446
+ Toast toast = Toast.makeText(this.getContext(), "La prise de photos est limitée à " + this.photoLimit + " par envoi", Toast.LENGTH_SHORT);
447
+ toast.show();
448
+ return;
449
+ }
450
+ if(this.mBackgroundThread == null || !this.mBackgroundThread.isInterrupted() || !this.mBackgroundThread.isAlive()) {
451
+ this.startBackgroundThread();
452
+ }
453
+ if(cameraDevice == null) {
454
+ return;
455
+ }
456
+ this.pictureCount++;
457
+ camButton.setVisibility(View.GONE);
458
+ progressBar.setVisibility(View.VISIBLE);
459
+ try {
460
+ CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
461
+ Size[] jpegSizes = null;
462
+ if(characteristics != null)
463
+ jpegSizes = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
464
+ .getOutputSizes(ImageFormat.JPEG);
465
+ //Capture image with custom size
466
+ int width = 640;
467
+ int height = 480;
468
+ if(jpegSizes != null && jpegSizes.length > 0)
469
+ {
470
+ width = jpegSizes[0].getWidth();
471
+ height = jpegSizes[0].getHeight();
472
+ }
473
+ final ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG,1);
474
+ List<Surface> outputSurface = new ArrayList<>(2);
475
+ outputSurface.add(reader.getSurface());
476
+ outputSurface.add(mSurfaceHolder.getSurface());
477
+ final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
478
+ captureBuilder.addTarget(reader.getSurface());
479
+ captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
480
+ captureBuilder.set(CaptureRequest.FLASH_MODE, flashOn ? CaptureRequest.FLASH_MODE_TORCH : CaptureRequest.FLASH_MODE_OFF);
481
+ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
482
+ String fileName = "IMG_"+ timeStamp + ".jpg";
483
+ File file = new File( this.getContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName);
484
+ ImageReader.OnImageAvailableListener readerListener = new scoplan.camera.ImageCameraAvailableListener(file, reader, this, currentOrientation);
485
+
486
+ reader.setOnImageAvailableListener(readerListener, mBackgroundHandler);
487
+ final CameraCaptureSession.CaptureCallback captureListener = new CameraCaptureSession.CaptureCallback() {
488
+ @Override
489
+ public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
490
+ super.onCaptureCompleted(session, request, result);
491
+ createCameraPreview();
492
+ }
493
+
494
+ @Override
495
+ public void onCaptureFailed(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull CaptureFailure failure) {
496
+ super.onCaptureFailed(session, request, failure);
497
+ Sentry.captureMessage("Failed capture _" + failure.getReason());
498
+ Log.e(SCOPLAN_TAG, "Error FAILED Capture " + failure.getReason());
499
+ failedCapture();
500
+ }
501
+ };
502
+
503
+ cameraDevice.createCaptureSession(outputSurface, new CameraCaptureSession.StateCallback() {
504
+ @Override
505
+ public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
506
+ try{
507
+ cameraCaptureSession.capture(captureBuilder.build(), captureListener, mBackgroundHandler);
508
+ } catch (Exception e) {
509
+ Log.e(SCOPLAN_TAG, "Error - " + e.getMessage());
510
+ Sentry.captureException(e);
511
+ failedCapture();
512
+ }
513
+ }
514
+
515
+ @Override
516
+ public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
517
+ Log.e(SCOPLAN_TAG, "Error FAILED Configuration ");
518
+ Sentry.captureMessage("Failed configure cameraCaptureSession");
519
+ failedCapture();
520
+ }
521
+ }, mBackgroundHandler);
522
+
523
+ } catch (Exception e) {
524
+ Sentry.captureException(e);
525
+ throw new RuntimeException(e);
526
+ }
527
+ }
528
+
529
+ @Override
530
+ public void onImageCapture(File file, Bitmap bitmap) {
531
+ pictures.add(file.getAbsolutePath());
532
+ getActivity().runOnUiThread(() -> {
533
+ souche.setImageBitmap(bitmap);
534
+ defineViewVisibility();
535
+ });
536
+ }
537
+
538
+ @Override
539
+ public void onImageBuildFailed(Exception e) {
540
+ Sentry.captureException(e);
541
+ failedCapture();
542
+ }
543
+
544
+ public void failedCapture() {
545
+ Toast toast = Toast.makeText(getContext(), "Oups! une erreur pendant la capture. Veuillez rééssayer.", Toast.LENGTH_LONG);
546
+ toast.show();
547
+ getActivity().runOnUiThread(() -> {
548
+ defineViewVisibility();
549
+ });
550
+ }
551
+
552
+ public void defineViewVisibility() {
553
+ if(pictures.size() > 0) {
554
+ souche.setVisibility(View.VISIBLE);
555
+ cameraTopBar.setVisibility(View.VISIBLE);
556
+ validationButton.setVisibility(View.VISIBLE);
557
+ cancelBtn2.setVisibility(View.GONE);
558
+ } else {
559
+ souche.setVisibility(View.GONE);
560
+ cameraTopBar.setVisibility(View.GONE);
561
+ validationButton.setVisibility(View.GONE);
562
+ cancelBtn2.setVisibility(View.VISIBLE);
563
+ }
564
+ camButton.setVisibility(View.VISIBLE);
565
+ progressBar.setVisibility(View.GONE);
566
+ }
567
+
568
+ private void startDrawing() {
569
+ Intent dsPhotoEditorIntent = new Intent(getContext(), PhotoEditorActivity.class);
570
+ String pc = pictures.get(pictures.size() - 1);
571
+ dsPhotoEditorIntent.setData(Uri.fromFile(new File(pc)));
572
+ int[] toolsToHide = {
573
+ PhotoEditorActivity.TOOL_ORIENTATION,
574
+ PhotoEditorActivity.TOOL_FRAME,
575
+ PhotoEditorActivity.TOOL_FILTER,
576
+ PhotoEditorActivity.TOOL_ROUND,
577
+ PhotoEditorActivity.TOOL_EXPOSURE,
578
+ PhotoEditorActivity.TOOL_CONTRAST,
579
+ PhotoEditorActivity.TOOL_VIGNETTE,
580
+ PhotoEditorActivity.TOOL_SATURATION,
581
+ PhotoEditorActivity.TOOL_SHARPNESS,
582
+ PhotoEditorActivity.TOOL_WARMTH,
583
+ PhotoEditorActivity.TOOL_PIXELATE,
584
+ PhotoEditorActivity.TOOL_STICKER
585
+ };
586
+ dsPhotoEditorIntent.putExtra(DsPhotoEditorConstants.DS_PHOTO_EDITOR_TOOLS_TO_HIDE, toolsToHide);
587
+ activityResultLauncher.launch(dsPhotoEditorIntent);
588
+ }
589
+
590
+ @Override
591
+ public void onClick(View view) {
592
+ if(view.getId() == this.fakeR.getId("button_capture")) {
593
+ this.takePicture();
594
+ } else if(
595
+ view.getId() == this.fakeR.getId("draw_on_2") ||
596
+ view.getId() == this.fakeR.getId("image_souche") ||
597
+ view.getId() == this.fakeR.getId("draw_on")
598
+ ) {
599
+ this.startDrawing();
600
+ } else if(
601
+ view.getId() == this.fakeR.getId("cancel") ||
602
+ view.getId() == this.fakeR.getId("cancel_btn")
603
+ ) {
604
+ this.cancelTakePhoto();
605
+ this.pictures = new ArrayList<>();
606
+ } else if(
607
+ view.getId() == this.fakeR.getId("valid_btn")
608
+ ) {
609
+ this.cameraEventListener.onUserValid(this.pictures);
610
+ this.pictures = new ArrayList<>();
611
+ } else if(
612
+ view.getId() == this.fakeR.getId("flash_btn")
613
+ ) {
614
+ this.flashOn = !this.flashOn;
615
+ this.flashBtn.setImageResource(this.fakeR.getDrawable(flashOn ? "flash_on" : "flash"));
616
+ }
617
+ }
618
+
619
+ private void cancelTakePhoto() {
620
+ AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
621
+ alert.setMessage("Voulez-vous sortir sans enregistrer la photo")
622
+ .setPositiveButton("Oui", new DialogInterface.OnClickListener() {
623
+ @Override
624
+ public void onClick(DialogInterface dialogInterface, int i) {
625
+ cameraEventListener.onUserCancel();
626
+ }
627
+ })
628
+ .setNegativeButton("Non", new DialogInterface.OnClickListener() {
629
+ @Override
630
+ public void onClick(DialogInterface dialogInterface, int i) {
631
+ }
632
+ });
633
+ alert.create().show();
634
+ }
635
+ }