anyline-ocr-react-native-module 55.2.0 → 55.5.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 (69) hide show
  1. package/{ios/AnylineReact.podspec → AnylineReact.podspec} +3 -3
  2. package/android/build.gradle +1 -3
  3. package/android/src/main/AndroidManifest.xml +1 -3
  4. package/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java +251 -252
  5. package/index.js +3 -16
  6. package/ios/AnylineSDKPlugin.h +4 -4
  7. package/ios/AnylineSDKPlugin.m +285 -207
  8. package/package.json +12 -2
  9. package/android/.gradle/7.6/checksums/checksums.lock +0 -0
  10. package/android/.gradle/7.6/checksums/md5-checksums.bin +0 -0
  11. package/android/.gradle/7.6/checksums/sha1-checksums.bin +0 -0
  12. package/android/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock +0 -0
  13. package/android/.gradle/7.6/dependencies-accessors/gc.properties +0 -0
  14. package/android/.gradle/7.6/executionHistory/executionHistory.lock +0 -0
  15. package/android/.gradle/7.6/fileChanges/last-build.bin +0 -0
  16. package/android/.gradle/7.6/fileHashes/fileHashes.bin +0 -0
  17. package/android/.gradle/7.6/fileHashes/fileHashes.lock +0 -0
  18. package/android/.gradle/7.6/gc.properties +0 -0
  19. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  20. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  21. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  22. package/android/.gradle/config.properties +0 -2
  23. package/android/.gradle/vcs-1/gc.properties +0 -0
  24. package/android/.idea/PipelineViewerConfig.xml +0 -6
  25. package/android/.idea/appInsightsSettings.xml +0 -28
  26. package/android/.idea/caches/deviceStreaming.xml +0 -486
  27. package/android/.idea/compiler.xml +0 -6
  28. package/android/.idea/gradle.xml +0 -19
  29. package/android/.idea/jarRepositories.xml +0 -30
  30. package/android/.idea/material_theme_project_new.xml +0 -13
  31. package/android/.idea/migrations.xml +0 -10
  32. package/android/.idea/misc.xml +0 -9
  33. package/android/.idea/runConfigurations.xml +0 -17
  34. package/android/.idea/vcs.xml +0 -6
  35. package/android/local.properties +0 -8
  36. package/android/src/main/java/com/anyline/reactnative/FeedbackConfig.java +0 -59
  37. package/android/src/main/java/com/anyline/reactnative/ImageTextConfig.java +0 -49
  38. package/android/src/main/java/com/anyline/reactnative/InstructionConfig.java +0 -20
  39. package/android/src/main/java/com/anyline/reactnative/Offset.java +0 -21
  40. package/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java +0 -32
  41. package/android/src/main/java/com/anyline/reactnative/ScanActivity.java +0 -426
  42. package/android/src/main/java/com/anyline/reactnative/updateAsset/AnylineUpdateDelegateImpl.java +0 -50
  43. package/android/src/main/java/com/anyline/reactnative/updateAsset/AssetContextJsonParser.java +0 -28
  44. package/android/src/main/res/drawable/rotate_screen_background.xml +0 -18
  45. package/android/src/main/res/drawable/rotate_screen_white.png +0 -0
  46. package/android/src/main/res/drawable-hdpi/ic_flash_auto.png +0 -0
  47. package/android/src/main/res/drawable-hdpi/ic_flash_off.png +0 -0
  48. package/android/src/main/res/drawable-hdpi/ic_flash_on.png +0 -0
  49. package/android/src/main/res/drawable-mdpi/ic_flash_auto.png +0 -0
  50. package/android/src/main/res/drawable-mdpi/ic_flash_off.png +0 -0
  51. package/android/src/main/res/drawable-mdpi/ic_flash_on.png +0 -0
  52. package/android/src/main/res/drawable-xhdpi/ic_flash_auto.png +0 -0
  53. package/android/src/main/res/drawable-xhdpi/ic_flash_off.png +0 -0
  54. package/android/src/main/res/drawable-xhdpi/ic_flash_on.png +0 -0
  55. package/android/src/main/res/drawable-xxhdpi/ic_flash_auto.png +0 -0
  56. package/android/src/main/res/drawable-xxhdpi/ic_flash_off.png +0 -0
  57. package/android/src/main/res/drawable-xxhdpi/ic_flash_on.png +0 -0
  58. package/android/src/main/res/drawable-xxxhdpi/ic_flash_auto.png +0 -0
  59. package/android/src/main/res/drawable-xxxhdpi/ic_flash_off.png +0 -0
  60. package/android/src/main/res/drawable-xxxhdpi/ic_flash_on.png +0 -0
  61. package/android/src/main/res/layout/activity_scan.xml +0 -93
  62. package/ios/ALJsonUIConfiguration.h +0 -54
  63. package/ios/ALJsonUIConfiguration.m +0 -251
  64. package/ios/ALPluginHelper.h +0 -48
  65. package/ios/ALPluginHelper.m +0 -332
  66. package/ios/ALPluginScanViewController.h +0 -18
  67. package/ios/ALPluginScanViewController.m +0 -476
  68. package/ios/ALRoundedView.h +0 -25
  69. package/ios/ALRoundedView.m +0 -107
@@ -1,54 +0,0 @@
1
- #import <Foundation/Foundation.h>
2
- #import <UIKit/UIKit.h>
3
-
4
- typedef NS_ENUM(NSUInteger, ALButtonXAlignment) {
5
- ALButtonXAlignmentLeft=0,
6
- ALButtonXAlignmentCenter=1,
7
- ALButtonXAlignmentRight=2
8
- };
9
-
10
- typedef NS_ENUM(NSUInteger, ALButtonYAlignment) {
11
- ALButtonYAlignmentTop=0,
12
- ALButtonYAlignmentCenter=1,
13
- ALButtonYAlignmentBottom=2
14
- };
15
-
16
- typedef NS_ENUM(NSUInteger, ALButtonType) {
17
- ALButtonTypeFullWidth=0,
18
- ALButtonTypeRect=1,
19
- };
20
-
21
-
22
- @interface ALJSONUIConfiguration : NSObject
23
-
24
- // Done Button
25
- @property (nonatomic, strong) NSString *buttonDoneTitle;
26
- @property (nonatomic, assign) CGFloat buttonDoneFontSize;
27
- @property (nonatomic, strong) NSString *buttonDoneFontName;
28
- @property (nonatomic, strong) UIColor *buttonDoneTextColor;
29
- @property (nonatomic, strong) UIColor *buttonDoneTextColorHighlighted;
30
- @property (nonatomic, strong) UIColor *buttonDoneBackgroundColor;
31
- @property (nonatomic, assign) ALButtonType buttonType;
32
- @property (nonatomic, assign) CGFloat buttonDoneCornerRadius;
33
- @property (nonatomic, assign) ALButtonXAlignment buttonDoneXAlignment;
34
- @property (nonatomic, assign) ALButtonYAlignment buttonDoneYAlignment;
35
- @property (nonatomic, assign) CGFloat buttonDoneXPositionOffset;
36
- @property (nonatomic, assign) CGFloat buttonDoneYPositionOffset;
37
-
38
- @property (nonatomic, strong) NSArray<NSString *> *segmentTitles;
39
- @property (nonatomic, strong) NSArray<NSString *> *segmentModes;
40
- @property (nonatomic, strong) UIColor *segmentTintColor;
41
- @property (nonatomic, assign) CGFloat segmentXPositionOffset;
42
- @property (nonatomic, assign) CGFloat segmentYPositionOffset;
43
-
44
- @property (nonatomic, copy) NSString *labelText;
45
- @property (nonatomic, assign) CGFloat labelSize;
46
- @property (nonatomic, strong) UIColor *labelColor;
47
- @property (nonatomic, assign) CGFloat labelXPositionOffset;
48
- @property (nonatomic, assign) CGFloat labelYPositionOffset;
49
-
50
- @property (nonatomic, strong) NSArray<NSString *> *nativeBarcodeFormats;
51
-
52
- - (instancetype)initWithDictionary:(NSDictionary *)dictionary;
53
-
54
- @end
@@ -1,251 +0,0 @@
1
- #import "ALJsonUIConfiguration.h"
2
- #import <Anyline/Anyline.h>
3
-
4
- NSString * const DONE_BUTTON = @"doneButtonConfig";
5
- NSString * const DONE_BUTTON_TITLE = @"title";
6
- NSString * const DONE_BUTTON_COLOR = @"textColor";
7
- NSString * const DONE_BUTTON_COLOR_HIGHLIGHTED = @"textColorHighlighted";
8
- NSString * const DONE_BUTTON_FONT_SIZE = @"fontSize";
9
- NSString * const DONE_BUTTON_FONT_NAME = @"fontName";
10
- NSString * const DONE_BUTTON_X_ALIGNMENT = @"positionXAlignment";
11
- NSString * const DONE_BUTTON_Y_ALIGNMENT = @"positionYAlignment";
12
- NSString * const DONE_BUTTON_BACKGROUND_COLOR = @"backgroundColor";
13
- NSString * const DONE_BUTTON_TYPE = @"type";
14
- NSString * const DONE_BUTTON_CORNER_RADIUS = @"cornerRadius";
15
-
16
- NSString * const SEGMENT = @"segmentConfig";
17
- NSString * const SEGMENT_TITLES = @"titles";
18
- NSString * const SEGMENT_MODES = @"modes";
19
- NSString * const SEGMENT_TINT_COLOR = @"tintColor";
20
-
21
- NSString * const OFFSET = @"offset";
22
- NSString * const OFFSET_X = @"offset.x";
23
- NSString * const OFFSET_Y = @"offset.y";
24
-
25
- NSString * const LABEL = @"labelConfig";
26
- NSString * const LABEL_TEXT = @"text";
27
- NSString * const LABEL_COLOR = @"color";
28
- NSString * const LABEL_SIZE = @"size";
29
-
30
- NSString * const LABEL_OFFSET = @"labelOffset";
31
- NSString * const LABEL_OFFSET_X = @"offset.x";
32
- NSString * const LABEL_OFFSET_Y = @"offset.y";
33
-
34
- NSString * const ENABLE_NATIVE_BARCODE = @"nativeBarcodeScanningFormats";
35
-
36
- @implementation ALJSONUIConfiguration
37
-
38
- - (instancetype)initWithDictionary:(NSDictionary *)dictionary {
39
- if (self = [super init]) {
40
-
41
- _buttonDoneFontName = @"Avenir Next"; // @"HelveticaNeue";
42
- _buttonDoneTextColor = [UIColor whiteColor];
43
- _buttonDoneTextColorHighlighted = [UIColor grayColor];
44
- _buttonDoneBackgroundColor = [UIColor clearColor];
45
- _buttonDoneFontSize = 32.0;
46
- _buttonType = ALButtonTypeFullWidth;
47
- _buttonDoneTitle = NSLocalizedString(@"OK", @"Done button title");
48
- _buttonDoneXAlignment = ALButtonXAlignmentCenter;
49
- _buttonDoneYAlignment = ALButtonYAlignmentBottom;
50
- _buttonDoneYPositionOffset = -88.0;
51
- _buttonDoneXPositionOffset = 0;
52
- _buttonDoneCornerRadius = 4.0;
53
-
54
- _labelSize = 32.0f;
55
- _labelText = @"";
56
- _labelColor = UIColor.whiteColor;
57
- _labelXPositionOffset = 0.0f;
58
- _labelYPositionOffset = 0.0f;
59
-
60
- // (ACO) 20230313
61
- // nativeBarcodeFormats = [] would be interpreted as ['ALL']
62
- _nativeBarcodeFormats = nil;
63
-
64
- if ([dictionary valueForKey:ENABLE_NATIVE_BARCODE]) {
65
- NSArray<NSString *> *formats = [dictionary valueForKey:ENABLE_NATIVE_BARCODE];
66
-
67
- NSMutableArray *nativeBarcodeFormats = [NSMutableArray arrayWithCapacity:formats.count];
68
-
69
- for (NSString *format in formats) {
70
- NSString *nativeBarcodeFormat = [self.class barcodeFormatToNativeString:format];
71
- if (nativeBarcodeFormat) {
72
- [nativeBarcodeFormats addObject:nativeBarcodeFormat];
73
- }
74
- }
75
-
76
- self.nativeBarcodeFormats = nativeBarcodeFormats;
77
- }
78
-
79
- if ([dictionary valueForKey:DONE_BUTTON]) {
80
- NSDictionary *btnDict = [dictionary valueForKey:DONE_BUTTON];
81
-
82
- if ([btnDict valueForKey:DONE_BUTTON_FONT_NAME]) {
83
- _buttonDoneFontName = [btnDict valueForKeyPath:DONE_BUTTON_FONT_NAME];
84
- }
85
-
86
- if ([btnDict valueForKey:DONE_BUTTON_COLOR]) {
87
- _buttonDoneTextColor = [ALJSONUIConfiguration colorFromHexString:[btnDict valueForKeyPath:DONE_BUTTON_COLOR]];
88
- }
89
-
90
- if ([btnDict valueForKey:DONE_BUTTON_COLOR_HIGHLIGHTED]) {
91
- _buttonDoneTextColorHighlighted = [ALJSONUIConfiguration colorFromHexString:[btnDict valueForKeyPath:DONE_BUTTON_COLOR_HIGHLIGHTED]];
92
- }
93
-
94
- if ([btnDict valueForKey:DONE_BUTTON_FONT_SIZE]) {
95
- _buttonDoneFontSize = [[btnDict valueForKeyPath:DONE_BUTTON_FONT_SIZE] floatValue];
96
- }
97
-
98
- if ([btnDict valueForKey:DONE_BUTTON_TYPE]) {
99
- _buttonType = [ALJSONUIConfiguration stringToButtonType:[btnDict valueForKeyPath:DONE_BUTTON_TYPE]];
100
- }
101
-
102
- if ([btnDict valueForKey:DONE_BUTTON_BACKGROUND_COLOR]) {
103
- _buttonDoneBackgroundColor = [ALJSONUIConfiguration colorFromHexString:[btnDict valueForKey:DONE_BUTTON_BACKGROUND_COLOR]];
104
- }
105
-
106
- if ([btnDict valueForKey:DONE_BUTTON_TITLE]) {
107
- _buttonDoneTitle = [btnDict valueForKeyPath:DONE_BUTTON_TITLE];
108
- }
109
-
110
- if ([btnDict valueForKey:DONE_BUTTON_X_ALIGNMENT]) {
111
- _buttonDoneXAlignment = [ALJSONUIConfiguration stringToButtonXAlignment:[btnDict valueForKeyPath:DONE_BUTTON_X_ALIGNMENT]];
112
- }
113
-
114
- if ([btnDict valueForKey:DONE_BUTTON_Y_ALIGNMENT]) {
115
- _buttonDoneYAlignment = [ALJSONUIConfiguration stringToButtonYAlignment:[btnDict valueForKeyPath:DONE_BUTTON_Y_ALIGNMENT]];
116
- }
117
-
118
- if ([btnDict valueForKeyPath:OFFSET_X]) {
119
- _buttonDoneXPositionOffset = [[btnDict valueForKeyPath:OFFSET_X] floatValue];
120
- }
121
-
122
- if ([btnDict valueForKeyPath:OFFSET_Y]) {
123
- _buttonDoneYPositionOffset = [[btnDict valueForKeyPath:OFFSET_Y] floatValue];
124
- }
125
-
126
- if ([btnDict valueForKey:DONE_BUTTON_CORNER_RADIUS]) {
127
- _buttonDoneCornerRadius = [[btnDict valueForKeyPath:DONE_BUTTON_CORNER_RADIUS] floatValue];
128
- }
129
- }
130
-
131
- if ([dictionary valueForKey:SEGMENT]) {
132
- NSDictionary *segDict = [dictionary valueForKey:SEGMENT];
133
-
134
- if ([segDict valueForKey:SEGMENT_TITLES]) {
135
- _segmentTitles = [segDict valueForKey:SEGMENT_TITLES];
136
- }
137
-
138
- if ([segDict valueForKey:SEGMENT_MODES]) {
139
- _segmentModes = [segDict valueForKey:SEGMENT_MODES];
140
- }
141
-
142
- if ([segDict valueForKey:SEGMENT_TINT_COLOR]) {
143
- _segmentTintColor = [ALJSONUIConfiguration colorFromHexString:[segDict valueForKey:SEGMENT_TINT_COLOR]];
144
- }
145
-
146
- if ([segDict valueForKeyPath:OFFSET_X]) {
147
- _segmentXPositionOffset = [[segDict valueForKeyPath:OFFSET_X] floatValue];
148
- }
149
-
150
- if ([segDict valueForKeyPath:OFFSET_Y]) {
151
- _segmentYPositionOffset = [[segDict valueForKeyPath:OFFSET_Y] floatValue];
152
- }
153
- }
154
-
155
- if ([dictionary valueForKey:LABEL]) {
156
- NSDictionary *labDict = [dictionary valueForKey:LABEL];
157
-
158
- if ([labDict valueForKey:LABEL_TEXT]) {
159
- _labelText = [labDict valueForKey:LABEL_TEXT];
160
- }
161
-
162
- if ([labDict valueForKey:LABEL_SIZE]) {
163
- _labelSize = [[labDict valueForKeyPath:LABEL_SIZE] floatValue];
164
- }
165
-
166
- if ([labDict valueForKey:LABEL_COLOR]) {
167
- _labelColor = [ALJSONUIConfiguration colorFromHexString:[labDict valueForKey:LABEL_COLOR]];
168
- }
169
-
170
- if ([labDict valueForKeyPath:LABEL_OFFSET_X]) {
171
- _labelXPositionOffset = [[labDict valueForKeyPath:LABEL_OFFSET_X] floatValue];
172
- }
173
-
174
- if ([labDict valueForKeyPath:LABEL_OFFSET_Y]) {
175
- _labelYPositionOffset = [[labDict valueForKeyPath:LABEL_OFFSET_Y] floatValue];
176
- }
177
- }
178
-
179
- }
180
- return self;
181
- }
182
-
183
- + (ALButtonXAlignment)stringToButtonXAlignment:(NSString *)str {
184
- NSDictionary *map = @{
185
- @"LEFT": @(ALButtonXAlignmentLeft),
186
- @"CENTER": @(ALButtonXAlignmentCenter),
187
- @"RIGHT": @(ALButtonXAlignmentRight),
188
- };
189
-
190
- return [[map valueForKey:str.uppercaseString] integerValue];
191
- }
192
-
193
- + (ALButtonYAlignment)stringToButtonYAlignment:(NSString *)str {
194
- NSDictionary *map = @{
195
- @"TOP": @(ALButtonYAlignmentTop),
196
- @"CENTER": @(ALButtonYAlignmentCenter),
197
- @"BOTTOM": @(ALButtonYAlignmentBottom),
198
- };
199
- return [[map valueForKey:str.uppercaseString] integerValue];
200
- }
201
-
202
- + (ALButtonType)stringToButtonType:(NSString *)str {
203
- NSDictionary *map = @{
204
- @"FULLWIDTH": @(ALButtonTypeFullWidth),
205
- @"RECT": @(ALButtonTypeRect)
206
- };
207
- return [[map valueForKey:str.uppercaseString] integerValue];
208
- }
209
-
210
- + (UIColor *)colorFromHexString:(NSString *)hexString {
211
- if (!hexString) {
212
- return nil;
213
- }
214
- unsigned rgbValue = 0;
215
- NSScanner *scanner = [NSScanner scannerWithString:hexString];
216
- // [scanner setScanLocation:1]; // bypass '#' character
217
- [scanner scanHexInt:&rgbValue];
218
- return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0
219
- green:((rgbValue & 0xFF00) >> 8)/255.0
220
- blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
221
- }
222
-
223
-
224
- + (NSString * _Nullable)barcodeFormatToNativeString:(NSString *)barcodeType {
225
- static NSDictionary<NSString *, NSString *> * barcodeFormats = nil;
226
- static dispatch_once_t onceToken;
227
- dispatch_once(&onceToken, ^{
228
- barcodeFormats = @{
229
- kCodeTypeAztec: @"org.iso.Aztec",
230
- kCodeTypeCode128: @"org.iso.Code128",
231
- kCodeTypeCode39: @"org.iso.Code39",
232
- kCodeTypeCode93: @"com.intermec.Code93",
233
- kCodeTypeDataMatrix: @"org.iso.DataMatrix",
234
- kCodeTypeEAN13: @"org.gs1.EAN-13",
235
- kCodeTypeEAN8: @"org.gs1.EAN-8",
236
- kCodeTypeMATRIX_2_5: @"org.ansi.Interleaved2of5",
237
- kCodeTypeITF: @"org.gs1.ITF14",
238
- kCodeTypePDF417: @"org.iso.PDF417",
239
- kCodeTypeQR: @"org.iso.QRCode",
240
- kCodeTypeUPCE: @"org.gs1.UPC-E",
241
- kCodeTypeCodabar: @"Codabar",
242
- kCodeTypeDATABAR: @"org.gs1.GS1DataBar",
243
- kCodeTypeMICRO_QR: @"org.iso.MicroQR",
244
- kCodeTypeMICRO_PDF: @"org.iso.MicroPDF417"
245
- };
246
- });
247
- return barcodeFormats[barcodeType.uppercaseString];
248
- }
249
-
250
- @end
251
-
@@ -1,48 +0,0 @@
1
- #import "ALJsonUIConfiguration.h"
2
- #import "ALRoundedView.h"
3
-
4
- NS_ASSUME_NONNULL_BEGIN
5
-
6
- @class ALPluginConfig;
7
-
8
- typedef void (^ALPluginCallback)(NSDictionary * _Nullable callbackObj, NSError * _Nullable error);
9
-
10
-
11
- @interface ALPluginHelper : NSObject
12
-
13
- + (void)startScan:(NSDictionary *)config initializationParamsStr:(NSString *)initializationParamsStr finished:(ALPluginCallback)callback;
14
-
15
- + (NSString *)saveImageToFileSystem:(UIImage *)image;
16
-
17
- + (NSString *)saveImageToFileSystem:(UIImage *)image
18
- compressionQuality:(CGFloat)compressionQuality;
19
-
20
- + (NSString * _Nullable)applicationCachePath;
21
-
22
- + (UILabel *)createLabelForView:(UIView *)view;
23
-
24
- + (UIButton *)createButtonForViewController:(UIViewController *)viewController
25
- config:(ALJSONUIConfiguration *)config;
26
-
27
- + (ALRoundedView *)createRoundedViewForViewController:(UIViewController *)viewController;
28
-
29
- + (UISegmentedControl * _Nullable)createSegmentForViewController:(UIViewController *)viewController
30
- config:(ALJSONUIConfiguration *)config
31
- initialScanMode:(NSString *)scanMode;
32
-
33
-
34
- + (void)showErrorAlertWithTitle:(NSString *)title
35
- message:(NSString *)message
36
- presentingViewController:(UIViewController *)presentingViewController;
37
-
38
- + (BOOL)showErrorAlertIfNeeded:(NSError *)error pluginCallback:(ALPluginCallback)callback;
39
-
40
- + (NSError *)errorWithMessage:(NSString *)message;
41
-
42
- + (NSString *)stringForDate:(NSDate *)date;
43
-
44
- + (NSString * _Nullable)confPropKeyWithScanModeForPluginConfig:(ALPluginConfig *)pluginConfig;
45
-
46
- @end
47
-
48
- NS_ASSUME_NONNULL_END
@@ -1,332 +0,0 @@
1
- #import "ALPluginHelper.h"
2
- #import "ALPluginScanViewController.h"
3
- #import <Anyline/Anyline.h>
4
- #import <objc/runtime.h>
5
-
6
- // Predefined domain for errors from most AppKit and Foundation APIs.
7
- NSErrorDomain const ALDefaultDomain = @"ALDefaultErrorDomain";
8
-
9
- @implementation ALPluginHelper
10
-
11
- #pragma mark - Launch Anyline
12
-
13
- + (void)startScan:(NSDictionary *)config initializationParamsStr:(NSString *)initializationParamsStr finished:(ALPluginCallback)callback {
14
-
15
- NSDictionary *pluginConf = config;
16
-
17
- NSString *licenseKey = [config objectForKey:@"licenseKey"];
18
-
19
- [[UIApplication sharedApplication] keyWindow].rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
20
-
21
- NSDictionary *optionsDict = [config objectForKey:@"options"];
22
- ALJSONUIConfiguration *jsonUIConf = [[ALJSONUIConfiguration alloc] initWithDictionary:optionsDict];
23
-
24
- ALPluginScanViewController *pluginScanViewController = [[ALPluginScanViewController alloc] initWithLicensekey:licenseKey
25
- configuration:pluginConf
26
- uiConfiguration:jsonUIConf
27
- initializationParamsStr:initializationParamsStr
28
- finished:callback];
29
-
30
- if ([pluginConf valueForKey:@"quality"]){
31
- pluginScanViewController.quality = [[pluginConf valueForKey:@"quality"] integerValue];
32
- }
33
-
34
- if (pluginScanViewController) {
35
- [pluginScanViewController setModalPresentationStyle:UIModalPresentationFullScreen];
36
- [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:pluginScanViewController
37
- animated:YES
38
- completion:nil];
39
- }
40
-
41
- }
42
-
43
- #pragma mark - Filesystem handling
44
-
45
- + (NSString *)saveImageToFileSystem:(UIImage *)image {
46
- return [self saveImageToFileSystem:image compressionQuality:0.9];
47
- }
48
-
49
- + (NSString *)saveImageToFileSystem:(UIImage *)image compressionQuality:(CGFloat)compressionQuality {
50
- NSString *basePath = [self applicationCachePath];
51
- NSData *binaryImageData = UIImageJPEGRepresentation(image, compressionQuality);
52
- NSString *uuid = [NSUUID UUID].UUIDString;
53
- NSString *imagePath = [NSString stringWithFormat:@"%@.jpg",uuid];
54
- NSString *fullPath = [basePath stringByAppendingPathComponent:imagePath];
55
- [binaryImageData writeToFile:fullPath atomically:YES];
56
- return fullPath;
57
- }
58
-
59
- + (NSString *)applicationCachePath {
60
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
61
- return ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
62
- }
63
-
64
- #pragma mark - UI helpers
65
-
66
- + (UILabel *)createLabelForView:(UIView *)view {
67
-
68
- UILabel *scannedLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, 44)];
69
- scannedLabel.center = CGPointMake(view.center.x, view.center.y + 166);
70
- scannedLabel.alpha = 0.0;
71
- scannedLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:32];
72
- scannedLabel.textColor = [UIColor whiteColor];
73
- scannedLabel.numberOfLines = 0;
74
- scannedLabel.textAlignment = NSTextAlignmentCenter;
75
-
76
- [view addSubview:scannedLabel];
77
-
78
- return scannedLabel;
79
- }
80
-
81
- + (UISegmentedControl *)createSegmentForViewController:(UIViewController *)viewController
82
- config:(ALJSONUIConfiguration *)config
83
- initialScanMode:(NSString *)initialScanMode {
84
- UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:config.segmentTitles];
85
-
86
- // This doesn't appear to be changing the color
87
- // segment.tintColor = ...
88
-
89
- segment.backgroundColor = [UIColor colorWithWhite:1 alpha:0.6];
90
- if (@available(iOS 13.0, *)) {
91
- segment.selectedSegmentTintColor = config.segmentTintColor;
92
- }
93
-
94
- segment.hidden = YES;
95
-
96
- NSUInteger index = [config.segmentModes indexOfObject:initialScanMode];
97
- if (index == NSNotFound) {
98
- return nil;
99
- }
100
-
101
- [segment setSelectedSegmentIndex:index];
102
-
103
- // has a warning here but is okay as long as the target implements this selector.
104
- [segment addTarget:viewController action:@selector(segmentChange:) forControlEvents:UIControlEventValueChanged];
105
-
106
- [viewController.view addSubview:segment];
107
-
108
- return segment;
109
- }
110
-
111
- + (UIButton *)createButtonForViewController:(UIViewController *)viewController
112
- config:(ALJSONUIConfiguration *)config {
113
-
114
- UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
115
- [doneButton setTitle:config.buttonDoneTitle forState:UIControlStateNormal];
116
-
117
- // NOTE: there'll be a warning here from Xcode but just have to make sure
118
- // doneButtonPressed: is a valid selector in the target
119
- [doneButton addTarget:viewController action:@selector(doneButtonPressed:)
120
- forControlEvents:UIControlEventTouchUpInside];
121
-
122
- [viewController.view addSubview:doneButton];
123
-
124
- [ALPluginHelper updateButtonPosition:doneButton
125
- withConfiguration:config
126
- onView:viewController.view];
127
-
128
- return doneButton;
129
- }
130
-
131
- + (ALRoundedView *)createRoundedViewForViewController:(UIViewController *)viewController {
132
- ALRoundedView *roundedView = [[ALRoundedView alloc] initWithFrame:CGRectMake(20, 115, viewController.view.bounds.size.width - 40, 30)];
133
- roundedView.fillColor = [UIColor colorWithRed:98.0/255.0 green:39.0/255.0 blue:232.0/255.0 alpha:0.6];
134
- roundedView.textLabel.text = @"";
135
- roundedView.alpha = 0;
136
- [viewController.view addSubview:roundedView];
137
- return roundedView;
138
- }
139
-
140
- + (void)updateButtonPosition:(UIButton *)button withConfiguration:(ALJSONUIConfiguration *)config
141
- onView:(UIView *)view {
142
-
143
- button.titleLabel.font = [UIFont fontWithName:config.buttonDoneFontName size:config.buttonDoneFontSize];
144
- [button setTitleColor:config.buttonDoneTextColor forState:UIControlStateNormal];
145
- [button setTitleColor:config.buttonDoneTextColorHighlighted forState:UIControlStateHighlighted];
146
- button.contentEdgeInsets = UIEdgeInsetsMake(6, 10, 6, 10);
147
-
148
-
149
- button.backgroundColor = config.buttonDoneBackgroundColor;
150
- button.translatesAutoresizingMaskIntoConstraints = NO;
151
-
152
- // corner radius is overridden to 0 when "full-width" type is used
153
- button.layer.cornerRadius = config.buttonDoneCornerRadius;
154
-
155
- switch (config.buttonType) {
156
- case ALButtonTypeFullWidth: // "FULLWIDTH"
157
- [view addConstraint:[button.leftAnchor constraintEqualToAnchor:view.leftAnchor constant:0]];
158
- [view addConstraint:[button.rightAnchor constraintEqualToAnchor:view.rightAnchor constant:0]];
159
- button.layer.cornerRadius = 0;
160
- break;
161
- case ALButtonTypeRect: // "RECT"
162
- [button sizeToFit];
163
- break;
164
-
165
- default:
166
- break;
167
- }
168
-
169
- switch (config.buttonDoneXAlignment) {
170
- case ALButtonXAlignmentCenter:
171
- [view addConstraint:[NSLayoutConstraint constraintWithItem:button
172
- attribute:NSLayoutAttributeCenterX
173
- relatedBy:NSLayoutRelationEqual
174
- toItem:view
175
- attribute:NSLayoutAttributeCenterX
176
- multiplier:1.0
177
- constant:config.buttonDoneXPositionOffset]];
178
- break;
179
- case ALButtonXAlignmentLeft:
180
- [view addConstraint:[NSLayoutConstraint constraintWithItem:button
181
- attribute:NSLayoutAttributeLeft
182
- relatedBy:NSLayoutRelationEqual
183
- toItem:view
184
- attribute:NSLayoutAttributeLeft
185
- multiplier:1.0
186
- constant:MAX(config.buttonDoneXPositionOffset, 0)]];
187
- break;
188
- case ALButtonXAlignmentRight:
189
- [view addConstraint:[NSLayoutConstraint constraintWithItem:button
190
- attribute:NSLayoutAttributeRight
191
- relatedBy:NSLayoutRelationEqual
192
- toItem:view
193
- attribute:NSLayoutAttributeRight
194
- multiplier:1.0
195
- constant:MIN(config.buttonDoneXPositionOffset, 0)]];
196
- break;
197
-
198
- default:
199
- break;
200
- }
201
-
202
- switch (config.buttonDoneYAlignment) {
203
- case ALButtonYAlignmentTop:
204
- // Align Top
205
- [view addConstraint:[NSLayoutConstraint constraintWithItem:button
206
- attribute:NSLayoutAttributeTop
207
- relatedBy:NSLayoutRelationEqual
208
- toItem:view
209
- attribute:NSLayoutAttributeTop
210
- multiplier:1.0
211
- constant:MAX(config.buttonDoneYPositionOffset, 0)]];
212
- break;
213
- case ALButtonYAlignmentBottom:
214
- // Align Bottom
215
- [view addConstraint:[NSLayoutConstraint constraintWithItem:button
216
- attribute:NSLayoutAttributeBottom
217
- relatedBy:NSLayoutRelationEqual
218
- toItem:view
219
- attribute:NSLayoutAttributeBottom
220
- multiplier:1.0
221
- constant:MIN(config.buttonDoneYPositionOffset, 0)]];
222
-
223
- break;
224
- case ALButtonYAlignmentCenter:
225
- // Center vertically
226
- [view addConstraint:
227
- [button.centerYAnchor constraintEqualToAnchor:view.centerYAnchor constant:config.buttonDoneYPositionOffset]
228
- ];
229
- break;
230
-
231
- default:
232
- break;
233
- }
234
- }
235
-
236
- #pragma mark - Date Parsing Utils
237
-
238
- // MARK: Utilities
239
-
240
- + (void)showErrorAlertWithTitle:(NSString *)title
241
- message:(NSString *)message
242
- presentingViewController:(UIViewController *)presentingViewController {
243
-
244
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
245
- message:message
246
- preferredStyle:UIAlertControllerStyleAlert];
247
- UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil];
248
- [alertController addAction:dismissAction];
249
- [presentingViewController presentViewController:alertController animated:YES completion:nil];
250
- }
251
-
252
- + (BOOL)showErrorAlertIfNeeded:(NSError *)error pluginCallback:(ALPluginCallback)callback {
253
- if (!error) {
254
- return NO;
255
- }
256
-
257
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Could not start scanning"
258
- message:error.localizedDescription
259
- preferredStyle:UIAlertControllerStyleAlert];
260
-
261
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok"
262
- style:UIAlertActionStyleDefault
263
- handler:^(UIAlertAction * _Nonnull action) {
264
-
265
- [[UIApplication sharedApplication].keyWindow.rootViewController
266
- dismissViewControllerAnimated:YES completion:^{
267
- callback(nil, [NSError errorWithDomain:@"" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Canceled"}]);
268
- }];
269
- }];
270
-
271
- [alert addAction:action];
272
- [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert
273
- animated:YES
274
- completion:NULL];
275
- return YES;
276
- }
277
-
278
- + (NSError *)errorWithMessage:(NSString *)message {
279
- return [NSError errorWithDomain:ALDefaultDomain code:1000 userInfo:@{ NSLocalizedDescriptionKey: message }];
280
- }
281
-
282
- // MARK: - Date Utils
283
- + (NSString *)stringForDate:(NSDate *)date {
284
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
285
- [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+0:00"]];
286
- dateFormatter.dateStyle = NSDateFormatterMediumStyle;
287
- dateFormatter.timeStyle = NSDateFormatterNoStyle;
288
- return [dateFormatter stringFromDate:date];
289
- }
290
-
291
- // MARK: - Plugin Reflection
292
-
293
- // return the ALPluginConfig property whose name ends with 'Config', is nonnull, AND which has a `scanMode` property
294
- + (NSString * _Nullable)confPropKeyWithScanModeForPluginConfig:(ALPluginConfig *)pluginConfig {
295
- unsigned int count;
296
- Ivar *ivars = class_copyIvarList(ALPluginConfig.class, &count);
297
- if (!ivars) {
298
- return nil;
299
- }
300
- for (int i = 0; i < count; i++) {
301
- const char *ivarName = ivar_getName(ivars[i]);
302
- NSString *key = [NSString stringWithCString:(const char * _Nonnull)ivarName encoding:NSUTF8StringEncoding];
303
- key = [key stringByTrimmingCharactersInSet:NSCharacterSet.punctuationCharacterSet];
304
-
305
- // Looking for "Config" at the end of the property name.
306
- NSRange range = [key rangeOfString:@"Config"];
307
- if (range.location == NSNotFound) { continue; }
308
- if (range.location + @"Config".length == key.length) {
309
- id obj;
310
- if ((obj = [pluginConfig valueForKey:key])) { // config property is non-null
311
- // one last check: does the value associated with this key have a scanMode property (that is a string type)?
312
- if ([obj respondsToSelector:NSSelectorFromString(@"scanMode")]) {
313
- return key; // this key is valid for self.pluginConfig, obj is the object tied to this key
314
- }
315
- // the rest wouldn't meet the requirements, so don't bother with them.
316
- return nil;
317
- }
318
- }
319
- }
320
- free(ivars);
321
- return nil;
322
- }
323
-
324
- // MARK: - Miscellaneous
325
-
326
- // actual implementation are in the view controllers
327
- - (void)segmentChange:(id)segment {}
328
-
329
- - (void)doneButtonPressed:(id)doneButton {}
330
-
331
-
332
- @end