anyline-ocr-react-native-module 42.2.0 → 43.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/android/build.gradle +7 -3
  2. package/android/src/main/AndroidManifest.xml +9 -8
  3. package/android/src/main/assets/cow_tag_scanner.ale +46 -0
  4. package/android/src/main/java/com/anyline/reactnative/AnylinePackage.java +1 -2
  5. package/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java +25 -71
  6. package/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java +12 -2
  7. package/android/src/main/java/com/anyline/reactnative/ScanActivity.java +206 -0
  8. package/android/src/main/res/drawable/rotate_screen_background.xml +18 -0
  9. package/android/src/main/res/drawable/rotate_screen_white.png +0 -0
  10. package/android/src/main/res/layout/activity_scan.xml +27 -0
  11. package/android/src/main/res/values/anyline_sdk_plugin_strings.xml +2 -28
  12. package/ios/ALJsonUIConfiguration.h +29 -36
  13. package/ios/ALJsonUIConfiguration.m +136 -76
  14. package/ios/ALNFCScanViewController.h +3 -16
  15. package/ios/ALNFCScanViewController.m +361 -232
  16. package/ios/ALPluginHelper.h +19 -62
  17. package/ios/ALPluginHelper.m +208 -529
  18. package/ios/ALPluginScanViewController.h +5 -32
  19. package/ios/ALPluginScanViewController.m +339 -287
  20. package/ios/AnylineReact.podspec +4 -3
  21. package/ios/AnylineSDKPlugin.m +39 -82
  22. package/package.json +8 -8
  23. package/android/.gradle/6.7/executionHistory/executionHistory.lock +0 -0
  24. package/android/.gradle/6.7/fileChanges/last-build.bin +0 -0
  25. package/android/.gradle/6.7/fileHashes/fileHashes.bin +0 -0
  26. package/android/.gradle/6.7/fileHashes/fileHashes.lock +0 -0
  27. package/android/.gradle/6.7/gc.properties +0 -0
  28. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  29. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  30. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  31. package/android/.gradle/checksums/checksums.lock +0 -0
  32. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  33. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  34. package/android/.gradle/configuration-cache/gc.properties +0 -0
  35. package/android/.gradle/vcs-1/gc.properties +0 -0
  36. package/android/.idea/compiler.xml +0 -6
  37. package/android/.idea/gradle.xml +0 -18
  38. package/android/.idea/jarRepositories.xml +0 -35
  39. package/android/.idea/misc.xml +0 -10
  40. package/android/.idea/vcs.xml +0 -6
  41. package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
  42. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  43. package/android/local.properties +0 -8
  44. package/android/src/main/java/com/anyline/reactnative/Anyline4Activity.java +0 -621
  45. package/android/src/main/java/com/anyline/reactnative/AnylineBaseActivity.java +0 -267
  46. package/android/src/main/java/com/anyline/reactnative/AnylinePluginHelper.java +0 -324
  47. package/android/src/main/java/com/anyline/reactnative/AnylineUIConfig.java +0 -88
  48. package/android/src/main/java/com/anyline/reactnative/Document4Activity.java +0 -595
  49. package/android/src/main/res/layout/activity_scan_document.xml +0 -63
  50. package/android/src/main/res/layout/activity_scan_scanview.xml +0 -52
  51. package/android/src/main/res/values/com_crashlytics_export_strings.xml +0 -10
@@ -1,595 +0,0 @@
1
- package com.anyline.reactnative;
2
-
3
- import android.animation.ObjectAnimator;
4
- import android.animation.ValueAnimator;
5
- import android.app.ProgressDialog;
6
- import android.content.DialogInterface;
7
- import android.graphics.Bitmap;
8
- import android.graphics.Color;
9
- import android.graphics.PointF;
10
- import android.os.Bundle;
11
- import android.os.Handler;
12
- import android.util.Log;
13
- import android.util.TypedValue;
14
- import android.view.View;
15
- import android.view.ViewGroup;
16
- import android.view.WindowManager;
17
- import android.view.animation.AccelerateInterpolator;
18
- import android.view.animation.DecelerateInterpolator;
19
- import android.widget.FrameLayout;
20
- import android.widget.ImageButton;
21
- import android.widget.ImageView;
22
- import android.widget.TextView;
23
- import android.widget.Toast;
24
-
25
- import androidx.core.content.ContextCompat;
26
-
27
- import org.json.JSONException;
28
- import org.json.JSONObject;
29
-
30
- import java.io.File;
31
- import java.io.IOException;
32
- import java.util.List;
33
- import java.util.UUID;
34
-
35
- import at.nineyards.anyline.core.LicenseException;
36
- import io.anyline.AnylineSDK;
37
- import io.anyline.camera.CameraController;
38
- import io.anyline.camera.CameraOpenListener;
39
- import io.anyline.models.AnylineImage;
40
- import io.anyline.plugin.ScanResult;
41
- import io.anyline.plugin.document.DocumentScanResultListener;
42
- import io.anyline.plugin.document.DocumentScanViewPlugin;
43
- import io.anyline.util.TempFileUtil;
44
- import io.anyline.view.ScanView;
45
-
46
- /**
47
- * Example activity for the Anyline-Document-Detection-Module
48
- */
49
- public class Document4Activity extends AnylineBaseActivity implements CameraOpenListener {
50
-
51
- private static final long ERROR_MESSAGE_DELAY = 2000;
52
- private static final String TAG = Document4Activity.class.getSimpleName();
53
- private ScanView documentScanView;
54
- private Toast notificationToast;
55
- private ImageView imageViewResult;
56
- private ProgressDialog progressDialog;
57
- private List<PointF> lastOutline;
58
- private ObjectAnimator errorMessageAnimator;
59
- private FrameLayout errorMessageLayout;
60
- private TextView errorMessage;
61
- private long lastErrorRecieved = 0;
62
- private int quality = 100;
63
- private Runnable errorMessageCleanup;
64
- private ImageButton btnCapture;
65
- JSONObject jsonResult;
66
-
67
- private android.os.Handler handler = new android.os.Handler();
68
-
69
- @Override
70
- protected void onCreate(Bundle savedInstanceState) {
71
- super.onCreate(savedInstanceState);
72
- setContentView(getResources().getIdentifier("activity_scan_document", "layout", getPackageName()));
73
-
74
-
75
- // takes care of fading the error message out after some time with no error reported from the SDK
76
- errorMessageCleanup = new Runnable() {
77
- @Override
78
- public void run() {
79
- if (Document4Activity.this.isFinishing()) {
80
- return;
81
- }
82
- if (System.currentTimeMillis() > lastErrorRecieved + ERROR_MESSAGE_DELAY) {
83
- if (errorMessage == null || errorMessageAnimator == null) {
84
- return;
85
- }
86
- if (errorMessage.getAlpha() == 0f) {
87
- errorMessage.setText("");
88
- } else if (!errorMessageAnimator.isRunning()) {
89
- errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", errorMessage.getAlpha(), 0f);
90
- errorMessageAnimator.setDuration(ERROR_MESSAGE_DELAY);
91
- errorMessageAnimator.setInterpolator(new AccelerateInterpolator());
92
- errorMessageAnimator.start();
93
- }
94
- }
95
- handler.postDelayed(errorMessageCleanup, ERROR_MESSAGE_DELAY);
96
-
97
- }
98
- };
99
-
100
- // Set the flag to keep the screen on (otherwise the screen may go dark during scanning)
101
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
102
-
103
- imageViewResult = (ImageView) findViewById(getResources().getIdentifier("image_result", "id", getPackageName()));
104
- errorMessageLayout = (FrameLayout) findViewById(getResources().getIdentifier("error_message_layout", "id", getPackageName()));
105
- errorMessage = (TextView) findViewById(getResources().getIdentifier("error_message", "id", getPackageName()));
106
-
107
- documentScanView = (ScanView) findViewById(getResources().getIdentifier("document_scan_view", "id", getPackageName()));
108
- // add a camera open listener that will be called when the camera is opened or an error occurred
109
- // this is optional (if not set a RuntimeException will be thrown if an error occurs)
110
- documentScanView.setCameraOpenListener(this);
111
- // the view can be configured via a json file in the assets, and this config is set here
112
-
113
- try {
114
- AnylineSDK.init(licenseKey, this);
115
- } catch (LicenseException e) {
116
- finishWithError(getString(getResources().getIdentifier("error_license_init", "string", getPackageName())));
117
- }
118
-
119
- JSONObject json = null;
120
- try {
121
- json = new JSONObject(configJson);
122
- documentScanView.setScanConfig(json);
123
- } catch (Exception e) {
124
- e.printStackTrace();
125
- Log.i(TAG, "**************** Exception: " + e);
126
- }
127
-
128
- btnCapture = findViewById(getResources().getIdentifier("capture", "id", getPackageName()));
129
-
130
- // get Document specific Configs
131
- if (json.has("document")) {
132
- try {
133
- // Get the Document specific Config
134
- JSONObject documentConfig = json.getJSONObject("document");
135
-
136
- // set manual capture Button Config
137
- if (documentConfig.has("manualCaptureButton")) {
138
- JSONObject manCapBtnConf = documentConfig.getJSONObject("manualCaptureButton");
139
-
140
- if (manCapBtnConf.has("buttonColor")) {
141
- //btnCapture.setBackgroundColor(Color.parseColor("#" + manCapBtnConf.getString("buttonColor")));
142
- btnCapture.setColorFilter(Color.parseColor("#" + manCapBtnConf.getString("buttonColor")));
143
-
144
- }
145
-
146
- // init Manual Capture Button
147
- btnCapture.setVisibility(View.VISIBLE);
148
- btnCapture.setOnClickListener(new View.OnClickListener() {
149
-
150
- @Override
151
- public void onClick(View v) {
152
- btnCapture.setClickable(false);
153
- documentScanView.stop();
154
- ((DocumentScanViewPlugin) documentScanView.getScanViewPlugin()).triggerPictureCornerDetection();
155
- }
156
- });
157
-
158
- } else {
159
- btnCapture.setVisibility(View.GONE);
160
- }
161
-
162
- } catch (JSONException e) {
163
- Log.e(TAG, e.getMessage());
164
- }
165
- }
166
-
167
- // initialize Anyline with the license key and a Listener that is called if a result is found
168
- documentScanView.getScanViewPlugin().addScanResultListener(new DocumentScanResultListener() {
169
- @Override
170
- public void onResult(ScanResult documentResult) {
171
-
172
- // handle the result document images here
173
- if (progressDialog != null && progressDialog.isShowing()) {
174
- progressDialog.dismiss();
175
- }
176
- btnCapture.setClickable(false);
177
-
178
- AnylineImage transformedImage = (AnylineImage) documentResult.getResult();
179
- AnylineImage fullFrame = documentResult.getFullImage();
180
-
181
-
182
- // resize display view based on larger side of document, and display document
183
- int widthDP, heightDP;
184
- Bitmap bmpTransformedImage = transformedImage.getBitmap();
185
-
186
- if (bmpTransformedImage.getHeight() > bmpTransformedImage.getWidth()) {
187
- widthDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
188
- heightDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, getResources().getDisplayMetrics());
189
- //Add a comment to this line
190
-
191
- imageViewResult.getLayoutParams().width = widthDP;
192
- imageViewResult.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
193
- } else {
194
- widthDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, getResources().getDisplayMetrics());
195
- heightDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
196
-
197
- imageViewResult.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
198
- imageViewResult.getLayoutParams().height = heightDP;
199
- }
200
-
201
- imageViewResult.setImageBitmap(Bitmap.createScaledBitmap(transformedImage.getBitmap(), widthDP, heightDP, false));
202
-
203
- /**
204
- * IMPORTANT: cache provided frames here, and release them at the end of this onResult. Because
205
- * keeping them in memory (e.g. setting the full frame to an ImageView)
206
- * will result in a OutOfMemoryError soon. This error is reported in {@link #onTakePictureError
207
- * (Throwable)}
208
- *
209
- * Use a DiskCache http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#disk-cache
210
- * for example
211
- *
212
- */
213
- File outDir = new File(getCacheDir(), "ok");
214
- outDir.mkdir();
215
- // change the file ending to png if you want a png
216
- //JSONObject
217
- jsonResult = new JSONObject();
218
- try {
219
- // convert the transformed image into a gray scaled image internally
220
- // transformedImage.getGrayCvMat(false);
221
- // get the transformed image as bitmap
222
- // Bitmap bmp = transformedImage.getBitmap();
223
- // save the image with quality 100 (only used for jpeg, ignored for png)
224
- File imageFile = TempFileUtil.createTempFileCheckCache(Document4Activity.this,
225
- UUID.randomUUID().toString(), ".jpg");
226
- transformedImage.save(imageFile, quality);
227
- // showToast(getString(
228
- // getResources().getIdentifier("document_image_saved_to", "string", getPackageName())) + " " + imageFile.getAbsolutePath());
229
-
230
- jsonResult.put("imagePath", imageFile.getAbsolutePath());
231
-
232
-
233
- // Save the Full Frame Image
234
- if (fullFrame != null) {
235
- imageFile = TempFileUtil.createTempFileCheckCache(Document4Activity.this,
236
- UUID.randomUUID().toString(), ".jpg");
237
- fullFrame.save(imageFile, quality);
238
- jsonResult.put("fullImagePath", imageFile.getAbsolutePath());
239
- }
240
- // Put outline and conficence to result
241
- jsonResult.put("outline", jsonForOutline(documentResult.getOutline()));
242
- jsonResult.put("confidence", documentResult.getConfidence());
243
- } catch (IOException e) {
244
- e.printStackTrace();
245
- } catch (JSONException jsonException) {
246
- //should not be possible
247
- Log.e(TAG, "Error while putting image path to json.", jsonException);
248
- }
249
-
250
- // release the images
251
- transformedImage.release();
252
- fullFrame.release();
253
-
254
- Boolean cancelOnResult = true;
255
-
256
- JSONObject jsonObject;
257
- try {
258
- jsonObject = new JSONObject(configJson);
259
- cancelOnResult = jsonObject.getBoolean("cancelOnResult");
260
- } catch (Exception e) {
261
- Log.d(TAG, e.getLocalizedMessage());
262
- }
263
-
264
- if (cancelOnResult) {
265
- ResultReporter.onResult(jsonResult, true);
266
- setResult(AnylineSDKPlugin.RESULT_OK);
267
- finish();
268
- } else {
269
- btnCapture.setClickable(true);
270
- ResultReporter.onResult(jsonResult, false);
271
- }
272
- }
273
-
274
-
275
- @Override
276
- public void onPreviewProcessingSuccess(AnylineImage anylineImage) {
277
- // this is called after the preview of the document is completed, and a full picture will be
278
- // processed automatically
279
- }
280
-
281
- @Override
282
- public void onPreviewProcessingFailure(DocumentScanViewPlugin.DocumentError documentError) {
283
- // this is called on any error while processing the document image
284
- // Note: this is called every time an error occurs in a run, so that might be quite often
285
- // An error message should only be presented to the user after some time
286
-
287
- showErrorMessageFor(documentError);
288
- }
289
-
290
- @Override
291
- public void onPictureProcessingFailure(DocumentScanViewPlugin.DocumentError documentError) {
292
-
293
- showErrorMessageFor(documentError, true);
294
- if (progressDialog != null && progressDialog.isShowing()) {
295
- progressDialog.dismiss();
296
- }
297
-
298
- // if there is a problem, here is how images could be saved in the error case
299
- // this will be a full, not cropped, not transformed image
300
- AnylineImage image = ((DocumentScanViewPlugin) documentScanView.getScanViewPlugin()).getCurrentFullImage();
301
-
302
- if (image != null) {
303
- File outDir = new File(getCacheDir(), "error");
304
- outDir.mkdir();
305
- File outFile = new File(outDir, "" + System.currentTimeMillis() + documentError.name() + ".jpg");
306
- try {
307
- image.save(outFile, 100);
308
- Log.d(TAG, "error image saved to " + outFile.getAbsolutePath());
309
- } catch (IOException e) {
310
- e.printStackTrace();
311
- }
312
- image.release();
313
- }
314
- }
315
-
316
- @Override
317
- public boolean onDocumentOutlineDetected(List rect, boolean documentShapeAndBrightnessValid) {
318
- // is called when the outline of the document is detected. return true if the outline is consumed by
319
- // the implementation here, false if the outline should be drawn by the DocumentScanView
320
- lastOutline = rect; // saving the outline for the animations
321
- return false;
322
- }
323
-
324
- @Override
325
- public void onTakePictureSuccess() {
326
- // this is called after the image has been captured from the camera and is about to be processed
327
- if (progressDialog != null && progressDialog.isShowing()) {
328
- progressDialog.dismiss();
329
- }
330
-
331
- // do not display error messages while "processing picture" progress dialog is shown:
332
- errorMessageLayout.setVisibility(View.GONE);
333
-
334
- progressDialog = ProgressDialog.show(Document4Activity.this, getString(
335
- getResources().getIdentifier("document_processing_picture_header", "string", getPackageName())),
336
- getString(
337
- getResources().getIdentifier("document_processing_picture", "string", getPackageName())),
338
- true);
339
-
340
- // there is a bug in the sdk that onTakePictureSuccess is called but onResult not.
341
- // so implement a workaround: hide the progressDialog after 2 seconds, the phone will continue scanning
342
- final Handler handler1 = new Handler();
343
- final Runnable runnable = new Runnable() {
344
- @Override
345
- public void run() {
346
- if (progressDialog.isShowing()) {
347
- progressDialog.dismiss();
348
- }
349
- }
350
- };
351
-
352
- progressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
353
- @Override
354
- public void onDismiss(DialogInterface dialog) {
355
- handler1.removeCallbacks(runnable);
356
- }
357
- });
358
-
359
- handler1.postDelayed(runnable, 2000);
360
- // workaround end
361
-
362
- if (errorMessageAnimator != null && errorMessageAnimator.isRunning()) {
363
-
364
- handler.post(new Runnable() {
365
- @Override
366
- public void run() {
367
- errorMessageAnimator.cancel();
368
- errorMessageLayout.setVisibility(View.GONE);
369
- }
370
- });
371
-
372
- }
373
- }
374
-
375
- @Override
376
- public void onTakePictureError(Throwable throwable) {
377
- // This is called if the image could not be captured from the camera (most probably because of an
378
- // OutOfMemoryError)
379
- throw new RuntimeException(throwable);
380
- }
381
-
382
- @Override
383
- public void onPictureCornersDetected(AnylineImage anylineImage, List list) {
384
- // this is called after manual corner detection was requested
385
-
386
- // save fullFrame
387
- //JSONObject
388
- jsonResult = new JSONObject();
389
-
390
- try {
391
- File imageFile = TempFileUtil.createTempFileCheckCache(Document4Activity.this, UUID.randomUUID().toString(), ".jpg");
392
- anylineImage.save(imageFile, quality);
393
- //manualResult.put("fullImagePath", imageFile.getAbsolutePath());
394
- jsonResult.put("fullImagePath", imageFile.getAbsolutePath());
395
- jsonResult.put("outline", jsonForOutline(list));
396
- } catch (IOException e) {
397
- e.printStackTrace();
398
- } catch (JSONException e) {
399
- e.printStackTrace();
400
- }
401
-
402
- ((DocumentScanViewPlugin) documentScanView.getScanViewPlugin()).transformPicture(anylineImage, list);
403
- anylineImage.release();
404
- }
405
-
406
-
407
- @Override
408
- public void onPictureTransformed(AnylineImage anylineImage) {
409
- // this is called after a full frame image and 4 corners were passed to the SDK for
410
- // transformation (e.g. when a user manually selected the corners in an image)
411
-
412
- // handle the result document images here
413
- if (progressDialog != null && progressDialog.isShowing()) {
414
- progressDialog.dismiss();
415
- }
416
-
417
- // save fullFrame
418
- try {
419
- File imageFile = TempFileUtil.createTempFileCheckCache(Document4Activity.this, UUID.randomUUID().toString(), ".jpg");
420
- anylineImage.save(imageFile, quality);
421
- jsonResult.put("imagePath", imageFile.getAbsolutePath());
422
-
423
- // if (showSuccessToast) {
424
- // // Only show toast if user has specified it should be shown
425
- // showToast(getString(getResources().getIdentifier("document_image_saved_to", "string", getPackageName())) + " " + imageFile.getAbsolutePath());
426
- // }
427
-
428
- } catch (IOException e) {
429
- e.printStackTrace();
430
- } catch (JSONException e) {
431
- e.printStackTrace();
432
- }
433
-
434
- anylineImage.release();
435
-
436
- Boolean cancelOnResult = true;
437
- JSONObject jsonObject;
438
- try {
439
- jsonObject = new JSONObject(configJson);
440
- cancelOnResult = jsonObject.getBoolean("cancelOnResult");
441
- } catch (Exception e) {
442
- e.printStackTrace();
443
- }
444
-
445
- if (cancelOnResult) {
446
- ResultReporter.onResult(jsonResult, true);
447
- setResult(AnylineSDKPlugin.RESULT_OK);
448
- finish();
449
- } else {
450
- btnCapture.setClickable(true);
451
- ResultReporter.onResult(jsonResult, false);
452
- }
453
- }
454
-
455
- @Override
456
- public void onPictureTransformError(DocumentScanViewPlugin.DocumentError documentError) {
457
- // this is called on any error while transforming the document image from the 4 corners
458
- // Note: not implemented in this example
459
- }
460
-
461
- });
462
-
463
- // optionally stop the scan once a valid result was returned
464
- // documentScanView.setCancelOnResult(cancelOnResult);
465
-
466
- }
467
-
468
-
469
- private void showErrorMessageFor(DocumentScanViewPlugin.DocumentError documentError) {
470
- showErrorMessageFor(documentError, false);
471
- }
472
-
473
- private void showErrorMessageFor(DocumentScanViewPlugin.DocumentError documentError, boolean highlight) {
474
- String text = getString(getResources().getIdentifier("document_picture_error", "string", getPackageName()));
475
- switch (documentError) {
476
- case DOCUMENT_NOT_SHARP:
477
- text += getString(getResources().getIdentifier("document_error_not_sharp", "string", getPackageName()));
478
- break;
479
- case DOCUMENT_SKEW_TOO_HIGH:
480
- text += getString(getResources().getIdentifier("document_error_skew_too_high", "string", getPackageName()));
481
- break;
482
- case DOCUMENT_OUTLINE_NOT_FOUND:
483
- //text += getString(R.string.document_error_outline_not_found);
484
- return; // exit and show no error message for now!
485
- case IMAGE_TOO_DARK:
486
- text += getString(getResources().getIdentifier("document_error_too_dark", "string", getPackageName()));
487
- break;
488
- case SHAKE_DETECTED:
489
- text += getString(getResources().getIdentifier("document_error_shake", "string", getPackageName()));
490
- break;
491
- case DOCUMENT_BOUNDS_OUTSIDE_OF_TOLERANCE:
492
- text += getString(getResources().getIdentifier("document_error_closer", "string", getPackageName()));
493
- break;
494
- case DOCUMENT_RATIO_OUTSIDE_OF_TOLERANCE:
495
- text += getString(getResources().getIdentifier("document_error_format", "string", getPackageName()));
496
- break;
497
- case UNKNOWN:
498
- break;
499
- default:
500
- text += getString(getResources().getIdentifier("document_error_unknown", "string", getPackageName()));
501
- return; // exit and show no error message for now!
502
- }
503
-
504
- if (highlight) {
505
- showHighlightErrorMessageUiAnimated(text);
506
- } else {
507
- showErrorMessageUiAnimated(text);
508
- }
509
- }
510
-
511
- private void showErrorMessageUiAnimated(String message) {
512
- if (lastErrorRecieved == 0) {
513
- // the cleanup takes care of removing the message after some time if the error did not show up again
514
- handler.post(errorMessageCleanup);
515
- }
516
- lastErrorRecieved = System.currentTimeMillis();
517
- if (errorMessageAnimator != null && (errorMessageAnimator.isRunning() || errorMessage.getText().equals
518
- (message))) {
519
- return;
520
- }
521
-
522
- errorMessageLayout.setVisibility(View.VISIBLE);
523
- errorMessage.setBackgroundColor(ContextCompat.getColor(this, getResources().getIdentifier("anyline_blue_darker", "color", getPackageName())));
524
- errorMessage.setAlpha(0f);
525
- errorMessage.setText(message);
526
- errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", 0f, 1f);
527
- errorMessageAnimator.setDuration(ERROR_MESSAGE_DELAY);
528
- errorMessageAnimator.setInterpolator(new DecelerateInterpolator());
529
- errorMessageAnimator.start();
530
- }
531
-
532
- private void showHighlightErrorMessageUiAnimated(String message) {
533
- lastErrorRecieved = System.currentTimeMillis();
534
- errorMessageLayout.setVisibility(View.VISIBLE);
535
- errorMessage.setBackgroundColor(ContextCompat.getColor(this, getResources().getIdentifier("anyline_red", "color", getPackageName())));
536
- errorMessage.setAlpha(0f);
537
- errorMessage.setText(message);
538
-
539
- if (errorMessageAnimator != null && errorMessageAnimator.isRunning()) {
540
- errorMessageAnimator.cancel();
541
- }
542
-
543
- errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", 0f, 1f);
544
- errorMessageAnimator.setDuration(ERROR_MESSAGE_DELAY);
545
- errorMessageAnimator.setInterpolator(new DecelerateInterpolator());
546
- errorMessageAnimator.setRepeatMode(ValueAnimator.REVERSE);
547
- errorMessageAnimator.setRepeatCount(1);
548
- errorMessageAnimator.start();
549
- }
550
-
551
- private void showToast(String text) {
552
- try {
553
- notificationToast.setText(text);
554
- } catch (Exception e) {
555
- notificationToast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
556
- }
557
- notificationToast.show();
558
- }
559
-
560
- @Override
561
- protected void onResume() {
562
- super.onResume();
563
- //start the actual scanning
564
- documentScanView.start();
565
- }
566
-
567
- @Override
568
- protected void onPause() {
569
- super.onPause();
570
- //stop the scanning
571
- documentScanView.stop();
572
- //release the camera (must be called in onPause, because there are situations where
573
- // it cannot be auto-detected that the camera should be released)
574
- documentScanView.releaseCameraInBackground();
575
- }
576
-
577
- @Override
578
- protected void onStop() {
579
- super.onStop();
580
- }
581
-
582
- @Override
583
- public void onCameraOpened(CameraController cameraController, int width, int height) {
584
- //the camera is opened async and this is called when the opening is finished
585
- Log.d(TAG, "Camera opened successfully. Frame resolution " + width + " x " + height);
586
- }
587
-
588
- @Override
589
- public void onCameraError(Exception e) {
590
- //This is called if the camera could not be opened.
591
- // (e.g. If there is no camera or the permission is denied)
592
- // This is useful to present an alternative way to enter the required data if no camera exists.
593
- throw new RuntimeException(e);
594
- }
595
- }
@@ -1,63 +0,0 @@
1
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
- xmlns:app="http://schemas.android.com/apk/res-auto"
3
- xmlns:tools="http://schemas.android.com/tools"
4
- android:layout_width="match_parent"
5
- android:layout_height="match_parent">
6
-
7
- <io.anyline.view.ScanView
8
- android:id="@+id/document_scan_view"
9
- android:layout_width="match_parent"
10
- android:layout_height="match_parent"
11
- app:api_2_enabled="false" />
12
-
13
- <ImageView
14
- android:id="@+id/image_result"
15
- android:layout_width="100dp"
16
- android:layout_height="wrap_content"
17
- android:layout_alignParentRight="true"
18
- android:layout_alignParentBottom="true"
19
- android:adjustViewBounds="true" />
20
-
21
- <ImageView
22
- android:id="@+id/full_image"
23
- android:layout_width="fill_parent"
24
- android:layout_height="fill_parent"
25
- android:layout_alignParentLeft="true"
26
- android:layout_alignParentBottom="true"
27
- android:adjustViewBounds="true" />
28
-
29
- <ImageButton
30
- android:id="@+id/capture"
31
- android:layout_width="60dp"
32
- android:layout_height="60dp"
33
- android:layout_alignParentBottom="true"
34
- android:layout_centerHorizontal="true"
35
- android:layout_marginHorizontal="90dp"
36
- android:layout_marginBottom="25dp"
37
- android:background="#00000000"
38
- android:adjustViewBounds="true"
39
- android:scaleType="centerInside"
40
- android:src="@drawable/manual_picture" />
41
-
42
- <FrameLayout
43
- android:id="@+id/error_message_layout"
44
- android:layout_width="match_parent"
45
- android:layout_height="wrap_content"
46
- android:layout_alignParentTop="true"
47
- android:visibility="gone"
48
- tools:visibility="visible">
49
-
50
- <TextView
51
- android:id="@+id/error_message"
52
- android:layout_width="wrap_content"
53
- android:layout_height="wrap_content"
54
- android:layout_gravity="center"
55
- android:layout_margin="24dp"
56
- android:background="@android:color/background_dark"
57
- android:gravity="center"
58
- android:padding="16dp"
59
- android:textColor="@android:color/primary_text_dark"
60
- tools:text="Error: image to dark! but I am very very very long and you can not read me" />
61
-
62
- </FrameLayout>
63
- </RelativeLayout>