Skip to content

Commit

Permalink
Added Anyline 41.0.0-preview.1
Browse files Browse the repository at this point in the history
  • Loading branch information
aldrichanyline committed Jul 20, 2022
1 parent 7c5d637 commit 2c13cec
Show file tree
Hide file tree
Showing 577 changed files with 3,708 additions and 3,318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@
- (ALExample *)exampleForIndexPath:(NSIndexPath *)indexPath;

@end

extern NSString * const processTitle;
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#import "ALDocumentScanViewController.h"
#import "ALLicensePlateViewController.h"

NSString * const processTitle = @"Processes";

@interface ALExampleManager ()

@property (nonatomic, strong) NSDictionary *examples;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,15 @@ - (void)initExampleData {
image:[UIImage imageNamed:@"dial meter"]
viewController:[ALDialMeterScanViewController class]];


ALExample *selfScanning = [[ALExample alloc] initWithName:NSLocalizedString(@"Self Reading", nil)
image:[UIImage imageNamed:@"Self Reading"]
viewController:[CustomerSelfReadingViewController class]];

ALExample *workforce = [[ALExample alloc] initWithName:NSLocalizedString(@"Workforce", nil)
image:[UIImage imageNamed:@"Workforce"]
viewController:[WorkForceViewController class]];

ALExample *serialScanning = [[ALExample alloc] initWithName:NSLocalizedString(@"Serial Number", nil)
image:[UIImage imageNamed:@"serial number"]
viewController:[ALMeterSerialNumberScanViewController class]];

self.sectionNames = @[@"Meter Types", @"Processes", @"Others"];
self.sectionNames = @[@"Meter Types"];
self.examples = @{
self.sectionNames[0] : @[autoAnalogDigitalMeterScanning,
dialMeterScanning,],
self.sectionNames[1] : @[selfScanning,
workforce,],
self.sectionNames[2] : @[serialScanning,],
dialMeterScanning,
serialScanning]
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#import "ALCattleTagScanViewController.h"
#import "ALContainerScanViewController.h"
#import "ALVerticalContainerScanViewController.h"
#import "ALParallelMeterWithJSONScanViewController.h"


@interface ALOthersExampleManager ()

Expand Down Expand Up @@ -67,10 +69,10 @@ - (void)initExampleData {
ALExample *voucherCodeScanning = [[ALExample alloc] initWithName:NSLocalizedString(@"Voucher Code", nil)
image:[UIImage imageNamed:@"voucher"]
viewController:[ALVoucherCodeScanViewController class]];

ALExample *documentScanner = [[ALExample alloc] initWithName:NSLocalizedString(@"Document Scanner", nil)
image:[UIImage imageNamed:@"document"]
viewController:[ALDocumentScanViewController class]];
image:[UIImage imageNamed:@"document"]
viewController:[ALDocumentScanViewController class]];

ALExample *scrabbleScanning = [[ALExample alloc] initWithName:NSLocalizedString(@"Scrabble Anagram", nil)
image:[UIImage imageNamed:@"scrabble"]
Expand All @@ -88,11 +90,15 @@ - (void)initExampleData {
image:[UIImage imageNamed:@"cow-tag"]
viewController:[ALCattleTagScanViewController class]];

ALExample *parallelScanning = [[ALExample alloc] initWithName:NSLocalizedString(@"Parallel Scanning (Meter + Barcode)", nil)
image:[UIImage imageNamed:@"parallel-scanning"]
viewController:[ALParallelMeterWithJSONScanViewController class]];


self.sectionNames = @[@"Others",];
self.examples = @{
self.sectionNames[0] : @[serialNumberScanning, containerScanning, verticalContainerScanning, cattleTagScanning, ibanScanning, rbScanning, voucherCodeScanning, scrabbleScanning, recordScanning, isbnScanning, documentScanner],
};
self.sectionNames[0] : @[serialNumberScanning, containerScanning, verticalContainerScanning, cattleTagScanning, ibanScanning, rbScanning, voucherCodeScanning, scrabbleScanning, recordScanning, isbnScanning, documentScanner, parallelScanning],
};
}

@end
2 changes: 1 addition & 1 deletion AnylineExamples/Anyline Demo App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>39.0.0</string>
<string>41.0.0-preview.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ - (void)viewDidLoad {
config.scanFeedbackConfig.blinkAnimationOnResult = NO;
config.scanFeedbackConfig.beepOnResult = NO;
config.scanFeedbackConfig.strokeWidth = 3;
config.cutoutConfig.path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, frame.size.width, frame.size.height)];
config.cutoutConfig.maxPercentWidth = 1;
config.cutoutConfig.maxPercentHeight = 1;
config.cutoutConfig.widthPercent = 1;
config.cutoutConfig.strokeColor = [UIColor clearColor];
config.cutoutConfig.feedbackStrokeColor = [UIColor clearColor];
config.cutoutConfig.usesAnimatedRect = YES;

Expand Down Expand Up @@ -170,11 +165,6 @@ - (void)viewDidLoad {
scanButton.alpha = 0;
self.scanButton = scanButton;

ALRoundedView * feedback = [[ALRoundedView alloc] initWithFrame:CGRectMake(20, frame.size.height/3, frame.size.width - 40, frame.size.height/3)];
feedback.borderColor = [UIColor colorWithWhite:1 alpha:0.8];
feedback.borderWidth = 2;
feedback.cornerRadius = 15;
[self.scanView addSubview:feedback];
}

#pragma mark - IBAction methods
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#import "ALBaseScanViewController.h"

NS_ASSUME_NONNULL_BEGIN

@interface ALParallelMeterWithJSONScanViewController : ALBaseScanViewController

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#import "ALParallelMeterWithJSONScanViewController.h"
#import "UIViewController+ALExamplesAdditions.h"

const bool parallel_scan_view_uses_json_config_for_setup = true;
NSString * const parallel_scan_plugin_config_json_filename = @"meter_barcode_parallel"; // without the .json extension

@interface ALParallelMeterWithJSONScanViewController () <ALBarcodeScanPluginDelegate, ALMeterScanPluginDelegate, ALCompositeScanPluginDelegate>

@property (nonatomic, strong) ALMeterScanViewPlugin *meterScanViewPlugin;

@property (nonatomic, strong) ALBarcodeScanViewPlugin *barcodeScanViewPlugin;

@property (nonatomic, strong) ALParallelScanViewPluginComposite *parallelScanViewPlugin;

@property (nonatomic, strong) ALScanView *scanView;

@end


@implementation ALParallelMeterWithJSONScanViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.title = @"Parallel Meter and Barcode Scanning";
[self setupAndStartPlugins];
}

- (void)setupAndStartPlugins {

if (parallel_scan_view_uses_json_config_for_setup) {
[self setupPluginsWithJSON];
} else {
[self setupPluginsWithManually];
}

NSAssert(self.parallelScanViewPlugin, @"parallelScanViewPlugin was not set up properly!");

self.scanView = [[ALScanView alloc] initWithFrame:[self scanViewFrame]
scanViewPlugin:self.parallelScanViewPlugin];

[self.view addSubview:self.scanView];

[self.scanView startCamera];

[self.parallelScanViewPlugin startAndReturnError:nil];
}

- (void)setupPluginsWithJSON {

NSError *error = nil;

// NOTE: we made an assumption here that the JSON is an appropriately-defined config of
// a parallel scan view with two members: a barcode scan plugin and a meter scan plugin.

self.parallelScanViewPlugin = (ALParallelScanViewPluginComposite *)[ALAbstractScanViewPluginComposite
scanViewPluginForConfigDict:self.configDict
delegate:self
error:&error];

for (ALAbstractScanViewPlugin *scanPlugin in self.parallelScanViewPlugin.childPlugins) {
if ([scanPlugin isKindOfClass:ALBarcodeScanViewPlugin.class]) {
self.barcodeScanViewPlugin = (ALBarcodeScanViewPlugin *)scanPlugin;
} else if ([scanPlugin isKindOfClass:ALMeterScanViewPlugin.class]) {
self.meterScanViewPlugin = (ALMeterScanViewPlugin *)scanPlugin;
}
}

// (Optional) If desired, you may set scan delegates for individual scan view plugins,
// allowing you to read scan results individually as they detected:
NSAssert(self.barcodeScanViewPlugin != nil, @"barcodeScanViewPlugin should not be nil");
NSAssert(self.meterScanViewPlugin != nil, @"meterScanViewPlugin should not be nil");

[self.barcodeScanViewPlugin.barcodeScanPlugin addDelegate:self];
[self.meterScanViewPlugin.meterScanPlugin addDelegate:self];

}

- (void)setupPluginsWithManually {

// you can set up the parallel scan without a JSON config file, if you wish.
NSError *error = nil;

// Meter Plugin
ALMeterScanPlugin *meterScanPlugin = [[ALMeterScanPlugin alloc] initWithPluginID:@"METER"
delegate:self
error:&error];
self.meterScanViewPlugin = [[ALMeterScanViewPlugin alloc] initWithScanPlugin:meterScanPlugin];

// Barcode Plugin
ALBarcodeScanPlugin *barcodeScanPlugin = [[ALBarcodeScanPlugin alloc] initWithPluginID:@"BARCODE"
delegate:self
error:&error];
[barcodeScanPlugin setBarcodeFormatOptions:@[ kCodeTypeAll ]];
self.barcodeScanViewPlugin = [[ALBarcodeScanViewPlugin alloc]
initWithScanPlugin:barcodeScanPlugin];

// Parallel Scan View Plugin
self.parallelScanViewPlugin = [[ALParallelScanViewPluginComposite alloc]
initWithPluginID:@"Energy and Meter Parallel"];

// (Optional) - make certain child plugins return without a scan result after a timeout
//
// A timeout delay determines how long the parallel plugin waits for any "optional"
// child plugins to be scanned, before ignoring them. After all non-optional child plugins
// have already been scanned, the parallel scan plugin waits for an extra, predetermined
// time period (the so-called timeout delay), and then returns with all the results gathered
// up to that point through its delegate. NOTE: To use it, at least one child plugin must
// have been marked as optional when adding to it. Otherwise all child plugins are waited
// on before the delegate callback is invoked.

// When not explicitly set, the default delay is 3.0 seconds.
self.parallelScanViewPlugin.optionalTimeoutDelay = @3.5;

// You can make a member ScanViewPlugin (in this case, for the barcode) by setting its
// isOptional property to YES. (NOTE: make sure to set this BEFORE it is added to the
// parallel plugin.)
self.barcodeScanViewPlugin.isOptional = YES;

// Add the component plugins.
[self.parallelScanViewPlugin addPlugin:self.meterScanViewPlugin];
[self.parallelScanViewPlugin addPlugin:self.barcodeScanViewPlugin];

// make oneself a ALCompositeScanPluginDelegate (for the aggregated results)
[self.parallelScanViewPlugin addDelegate:self];
}

- (void)displayResults:(NSString *)resultsMsg {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Results"
message:resultsMsg
preferredStyle:UIAlertControllerStyleAlert];
__weak __block typeof(self) weakSelf = self;
[alertController addAction:[UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {

[weakSelf.parallelScanViewPlugin startAndReturnError:nil];
}]];

[self.navigationController presentViewController:alertController animated:YES completion:nil];
}

- (NSDictionary * _Nonnull)configDict {
// read the JSON config file
NSString *jsonFilePath = [[NSBundle mainBundle] pathForResource:parallel_scan_plugin_config_json_filename
ofType:@"json"];
NSData *data = [NSData dataWithContentsOfFile:jsonFilePath];

NSError *error = nil;
NSDictionary *configDict = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:&error];
NSAssert(configDict != nil, @"unable to read configuration JSON file!");
return configDict;
}

// MARK: - ALCompositeScanPluginDelegate

- (void)anylineCompositeScanPlugin:(ALAbstractScanViewPluginComposite * _Nonnull)anylineCompositeScanPlugin
didFindResult:(ALCompositeResult * _Nonnull)scanResult {

// this method is executed when all 'required' component plugins have
// been scanned.

NSMutableArray<NSString *> *resultStrs = [NSMutableArray arrayWithCapacity:2];
for (NSString *key in scanResult.result.allKeys) {
id res = scanResult.result[key];
if ([res isKindOfClass:ALMeterResult.class]) {
[resultStrs addObject:
[NSString stringWithFormat:@"meter result: %@",
[(ALMeterResult *)res result]]
];
} else if ([res isKindOfClass:ALBarcodeResult.class]) {
[resultStrs addObject:
[NSString stringWithFormat:@"barcode result: %@",
[(ALBarcodeResult *)res result].firstObject.value]
];
}
}
NSString *message = [resultStrs componentsJoinedByString:@" | "];
NSLog(@"Parallel Scan: aggregate result: %@", message);
[self displayResults:message];
}

// MARK: - ALBarcodeScanPluginDelegate

- (void)anylineBarcodeScanPlugin:(ALBarcodeScanPlugin * _Nonnull)anylineBarcodeScanPlugin
didFindResult:(ALBarcodeResult * _Nonnull)scanResult {
NSString *barcodeResultStr = [[scanResult.result firstObject] value];

// by setting a ALBarcodeScanPluginDelegate you can detect a barcode scan before the
// composite (parallel) plugin delegate is called.
NSLog(@"Parallel Scan: barcode result: %@", barcodeResultStr);
}


// MARK: - ALMeterScanPluginDelegate

- (void)anylineMeterScanPlugin:(ALMeterScanPlugin * _Nonnull)anylineMeterScanPlugin
didFindResult:(ALMeterResult * _Nonnull)scanResult {

// by setting a ALMeterScanPluginDelegate you can detect a meter scan before the
// composite (parallel) plugin delegate is called.
NSString *meterResultStr = scanResult.result;
NSLog(@"Parallel Scan: meter result: %@", meterResultStr);
}

@end
Loading

0 comments on commit 2c13cec

Please sign in to comment.