From ca9d7b07d124cc454c38b984677c511476fd8d9b Mon Sep 17 00:00:00 2001 From: "christian.brunschen" Date: Tue, 24 Jun 2008 16:24:36 +0000 Subject: [PATCH] scan archive UI improvements, phase 3 git-svn-id: http://zxing.googlecode.com/svn/trunk@471 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- iphone/Classes/ArchiveController.h | 2 + iphone/Classes/ArchiveController.m | 27 +++++++++---- iphone/Classes/Decoder.m | 41 +++++++++++++++---- iphone/Classes/DecoderViewController.m | 12 +++++- iphone/Classes/OpenUrlAction.m | 1 - iphone/Classes/ParsedResult.m | 15 ++++--- iphone/Classes/ScanViewController.m | 9 +++-- iphone/Classes/URIParsedResult.m | 3 ++ iphone/Classes/ZXingAppDelegate.m | 2 - iphone/en.lproj/DecoderView.xib | 54 +------------------------- 10 files changed, 88 insertions(+), 78 deletions(-) diff --git a/iphone/Classes/ArchiveController.h b/iphone/Classes/ArchiveController.h index 069121b9..ed88d6b1 100644 --- a/iphone/Classes/ArchiveController.h +++ b/iphone/Classes/ArchiveController.h @@ -25,11 +25,13 @@ @interface ArchiveController : UITableViewController { NSMutableArray *scans; + NSMutableArray *results; DecoderViewController *decoderViewController; NSDateFormatter *dateFormatter; } @property (nonatomic, retain) NSMutableArray *scans; +@property (nonatomic, retain) NSMutableArray *results; @property (nonatomic, retain) DecoderViewController *decoderViewController; @property (nonatomic, retain) NSDateFormatter *dateFormatter; diff --git a/iphone/Classes/ArchiveController.m b/iphone/Classes/ArchiveController.m index 3b379674..89d03c41 100644 --- a/iphone/Classes/ArchiveController.m +++ b/iphone/Classes/ArchiveController.m @@ -31,13 +31,14 @@ #define TEXT_VIEW_TAG 0x19 #define VIEW_PADDING 2 -#define IMAGE_VIEW_SIDE 50 +#define IMAGE_VIEW_SIDE 40 #define CONTENT_HEIGHT IMAGE_VIEW_SIDE -#define DATE_VIEW_WIDTH 70 +#define DATE_VIEW_WIDTH 50 @implementation ArchiveController @synthesize scans; +@synthesize results; @synthesize decoderViewController; @synthesize dateFormatter; @@ -45,6 +46,7 @@ if (self = [super initWithStyle:UITableViewStylePlain]) { decoderViewController = [dc retain]; scans = [[NSMutableArray alloc] init]; + results = [[NSMutableArray alloc] init]; dateFormatter = [[NSDateFormatter alloc] init]; } return self; @@ -106,8 +108,9 @@ UILabel *textView = (UILabel *)[cell.contentView viewWithTag:TEXT_VIEW_TAG]; UITextView *dateView = (UITextView *)[cell.contentView viewWithTag:DATE_VIEW_TAG]; // Configure the cell - Scan *scan = [scans objectAtIndex:[self scanIndexForRow:indexPath.row]]; - ParsedResult *result = [ParsedResult parsedResultForString:scan.text]; + int index = [self scanIndexForRow:indexPath.row]; + Scan *scan = [scans objectAtIndex:index]; + ParsedResult *result = [results objectAtIndex:index]; imageView.image = nil; NSDate *stamp = [scan stamp]; NSTimeInterval interval = -[stamp timeIntervalSinceNow]; @@ -130,8 +133,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //[decoderViewController showScan:[scans objectAtIndex:[self scanIndexForRow:indexPath.row]]]; - Scan *scan = [scans objectAtIndex:[self scanIndexForRow:indexPath.row]]; - ParsedResult *result = [ParsedResult parsedResultForString:scan.text]; + int index = [self scanIndexForRow:indexPath.row]; + Scan *scan = [scans objectAtIndex:index]; + ParsedResult *result = [results objectAtIndex:index]; ScanViewController *scanViewController = [[ScanViewController alloc] initWithResult:result forScan:scan]; [self.navigationController pushViewController:scanViewController animated:YES]; [scanViewController release]; @@ -144,7 +148,9 @@ // delete the scan from the database ... [[Database sharedDatabase] deleteScan:scan]; // ... delete the scan from our in-memory cache of the database ... - [self.scans removeObjectAtIndex:index]; + [scans removeObjectAtIndex:index]; + // ... delete the corresponding result from our in-memory cache ... + [results removeObjectAtIndex:index]; // ... and remove the row from the table view. [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; // [tableView reloadData]; @@ -167,6 +173,7 @@ - (void)dealloc { [scans release]; + [results release]; [decoderViewController release]; [dateFormatter release]; [super dealloc]; @@ -183,6 +190,10 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.scans = [NSMutableArray arrayWithArray:[[Database sharedDatabase] scans]]; + self.results = [NSMutableArray arrayWithCapacity:self.scans.count]; + for (Scan *scan in scans) { + [results addObject:[ParsedResult parsedResultForString:scan.text]]; + } } - (void)viewDidAppear:(BOOL)animated { @@ -190,6 +201,8 @@ } - (void)viewWillDisappear:(BOOL)animated { + self.scans = nil; + self.results = nil; } - (void)viewDidDisappear:(BOOL)animated { diff --git a/iphone/Classes/Decoder.m b/iphone/Classes/Decoder.m index e285dcbe..e6f5fc9b 100644 --- a/iphone/Classes/Decoder.m +++ b/iphone/Classes/Decoder.m @@ -62,16 +62,22 @@ using namespace qrcode; - (void) prepareSubset { CGImageRef cgImage = self.image.CGImage; CGSize size = CGSizeMake(CGImageGetWidth(cgImage), CGImageGetHeight(cgImage)); +#ifdef DEBUG NSLog(@"decoding: image is (%.1f x %.1f)", size.width, size.height); +#endif float scale = min(1.0f, max(0.25f, (float)max(400.0f / size.width, 400.0f / size.height))); subsetWidth = size.width * scale; subsetHeight = size.height * scale; subsetBytesPerRow = ((subsetWidth + 0xf) >> 4) << 4; +#ifdef DEBUG NSLog(@"decoding: image to decode is (%d x %d) (%d bytes/row)", subsetWidth, subsetHeight, subsetBytesPerRow); +#endif subsetData = (unsigned char *)malloc(subsetBytesPerRow * subsetHeight); +#ifdef DEBUG NSLog(@"allocated %d bytes of memory", subsetBytesPerRow * subsetHeight); +#endif CGColorSpaceRef grayColorSpace = CGColorSpaceCreateDeviceGray(); @@ -83,37 +89,48 @@ using namespace qrcode; CGContextSetInterpolationQuality(ctx, kCGInterpolationNone); CGContextSetAllowsAntialiasing(ctx, false); +#ifdef DEBUG NSLog(@"created %dx%d bitmap context", subsetWidth, subsetHeight); +#endif CGRect rect = CGRectMake(0, 0, subsetWidth, subsetHeight); CGContextDrawImage(ctx, rect, cgImage); +#ifdef DEBUG NSLog(@"drew image into %d(%d)x%d bitmap context", subsetWidth, subsetBytesPerRow, subsetHeight); +#endif CGContextFlush(ctx); +#ifdef DEBUG NSLog(@"flushed context"); +#endif CGImageRef subsetImageRef = CGBitmapContextCreateImage(ctx); +#ifdef DEBUG NSLog(@"created CGImage from context"); +#endif self.subsetImage = [UIImage imageWithCGImage:subsetImageRef]; CGImageRelease(subsetImageRef); CGContextRelease(ctx); - +#ifdef DEBUG NSLog(@"released context"); +#endif } - (void)decode:(id)arg { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; { QRCodeReader reader; +#ifdef DEBUG + NSLog(@"created QRCoreReader"); +#endif Ref grayImage (new GrayBytesMonochromeBitmapSource(subsetData, subsetWidth, subsetHeight, subsetBytesPerRow)); - NSLog(@"grayImage count = %d", grayImage->count()); - +#ifdef DEBUG NSLog(@"created GrayBytesMonochromeBitmapSource", subsetWidth, subsetHeight); - - NSLog(@"created QRCoreReader"); + NSLog(@"grayImage count = %d", grayImage->count()); +#endif TwoDDecoderResult *decoderResult = nil; @@ -122,9 +139,13 @@ using namespace qrcode; #endif try { +#ifdef DEBUG NSLog(@"decoding gray image"); +#endif Ref result(reader.decode(grayImage)); - NSLog(@"gray image decoed"); +#ifdef DEBUG + NSLog(@"gray image decoded"); +#endif Ref resultText(result->getText()); const char *cString = resultText->getText().c_str(); @@ -152,14 +173,18 @@ using namespace qrcode; iex->what()); delete iex; } catch (...) { - NSLog(@"Caught unknown exception, trying again"); + NSLog(@"Caught unknown exception!"); } #ifdef TRY_ROTATIONS if (!decoderResult) { +#ifdef DEBUG NSLog(@"rotating gray image"); +#endif grayImage = grayImage->rotateCounterClockwise(); +#ifdef DEBUG NSLog(@"gray image rotated"); +#endif } } #endif @@ -178,7 +203,9 @@ using namespace qrcode; self.subsetData = NULL; } [pool release]; +#ifdef DEBUG NSLog(@"finished decoding."); +#endif // if this is not the main thread, then we end it if (![NSThread isMainThread]) { diff --git a/iphone/Classes/DecoderViewController.m b/iphone/Classes/DecoderViewController.m index 31037e20..73cb0750 100644 --- a/iphone/Classes/DecoderViewController.m +++ b/iphone/Classes/DecoderViewController.m @@ -158,7 +158,9 @@ } - (void)showMessage:(NSString *)message { - NSLog(message); +#ifdef DEBUG + NSLog(@"Showing message '%@'", message); +#endif self.messageView.text = message; [self.messageView sizeToFit]; } @@ -182,7 +184,9 @@ self.result = [ParsedResult parsedResultForString:resultString]; [self showMessage:[self.result stringForDisplay]]; self.actions = self.result.actions; +#ifdef DEBUG NSLog(@"result has %d actions", actions ? 0 : actions.count); +#endif [self updateToolbar]; } @@ -207,6 +211,7 @@ didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { +#ifdef DEBUG NSLog(@"picked image size = (%f, %f)", image.size.width, image.size.height); if (editingInfo) { UIImage *originalImage = [editingInfo objectForKey:UIImagePickerControllerOriginalImage]; @@ -219,6 +224,7 @@ NSLog(@"crop rect = (%f, %f) x (%f, %f)", CGRectGetMinX(cropRect), CGRectGetMinY(cropRect), CGRectGetWidth(cropRect), CGRectGetHeight(cropRect)); } } +#endif [[picker parentViewController] dismissModalViewControllerAnimated:YES]; [image retain]; @@ -269,13 +275,17 @@ if (self.actions.count == 1) { ResultAction *action = [self.actions lastObject]; +#ifdef DEBUG NSLog(@"Result has the single action, (%@) '%@', performing it", NSStringFromClass([action class]), [action title]); +#endif [self performSelector:@selector(confirmAndPerformAction:) withObject:action afterDelay:0.0]; } else { +#ifdef DEBUG NSLog(@"Result has multiple actions, popping up an action sheet"); +#endif UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithFrame:self.view.bounds]; for (ResultAction *action in self.actions) { diff --git a/iphone/Classes/OpenUrlAction.m b/iphone/Classes/OpenUrlAction.m index ab9c8ff0..7e95c382 100644 --- a/iphone/Classes/OpenUrlAction.m +++ b/iphone/Classes/OpenUrlAction.m @@ -28,7 +28,6 @@ - initWithURL:(NSURL *)url { if ((self = [super init]) != nil) { - NSLog(@"initialising with URL with retain count %d", [url retainCount]); self.URL = url; } return self; diff --git a/iphone/Classes/ParsedResult.m b/iphone/Classes/ParsedResult.m index 9dee7fdc..d82a83a6 100644 --- a/iphone/Classes/ParsedResult.m +++ b/iphone/Classes/ParsedResult.m @@ -56,7 +56,9 @@ static NSMutableDictionary *iconsByClass = nil; } + parsedResultForString:(NSString *)s { +#ifdef DEBUG NSLog(@"parsing result:\n<<<\n%@\n>>>\n", s); +#endif for (Class c in [self parsedResultTypes]) { ParsedResult *result = [c parsedResultForString:s]; if (result != nil) { @@ -74,26 +76,29 @@ static NSMutableDictionary *iconsByClass = nil; return @"{none}"; } +#define ICON_SIZE 40 +#define ICON_INSIDE 36 + + (UIImage *)icon { if (iconsByClass == nil) { iconsByClass = [[NSMutableDictionary alloc] initWithCapacity:16]; } UIImage *icon = [iconsByClass objectForKey:[self class]]; if (icon == nil) { - UIGraphicsBeginImageContext(CGSizeMake(60, 60)); + UIGraphicsBeginImageContext(CGSizeMake(ICON_SIZE, ICON_SIZE)); CGContextRef ctx = UIGraphicsGetCurrentContext(); [[UIColor lightGrayColor] set]; - UIRectFill(CGRectMake(0, 0, 60, 60)); + UIRectFill(CGRectMake(0, 0, ICON_SIZE, ICON_SIZE)); [[UIColor blackColor] set]; NSString *s = [[self class] typeName]; UIFont *font = [UIFont systemFontOfSize:16]; CGSize stringSize = [s sizeWithFont:font]; - float xScale = fminf(1.0, 54.0 / stringSize.width); - float yScale = fminf(1.0, 54.0 / stringSize.height); + float xScale = fminf(1.0, ICON_INSIDE / stringSize.width); + float yScale = fminf(1.0, ICON_INSIDE / stringSize.height); - CGContextTranslateCTM(ctx, 30, 30); + CGContextTranslateCTM(ctx, (ICON_SIZE / 2), (ICON_SIZE / 2)); CGContextRotateCTM(ctx, -M_PI / 6.0); CGContextScaleCTM(ctx, xScale, yScale); CGContextTranslateCTM(ctx, diff --git a/iphone/Classes/ScanViewController.m b/iphone/Classes/ScanViewController.m index 2362a5e0..5f1cef0d 100644 --- a/iphone/Classes/ScanViewController.m +++ b/iphone/Classes/ScanViewController.m @@ -11,8 +11,8 @@ #define TEXT_VIEW_TAG 0x17 -#define TITLE_HEIGHT 60 -#define BODY_HEIGHT 100 +#define TITLE_HEIGHT 44 +#define BODY_HEIGHT 88 @implementation ScanViewController @@ -75,7 +75,10 @@ - (UITableViewCell *)buttonCellInTableView:(UITableView *)tableView { static NSString *ButtonIdentifier = @"ScanViewButtonIdentifier"; - return [self cellWithIdentifier:ButtonIdentifier inTableView:tableView]; + UITableViewCell *cell = [self cellWithIdentifier:ButtonIdentifier inTableView:tableView]; + cell.textAlignment = UITextAlignmentCenter; + cell.textColor = [UIColor grayColor]; + return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/iphone/Classes/URIParsedResult.m b/iphone/Classes/URIParsedResult.m index 5d900a20..355003b2 100644 --- a/iphone/Classes/URIParsedResult.m +++ b/iphone/Classes/URIParsedResult.m @@ -113,7 +113,10 @@ - (void)populateActions { +#ifdef DEBUG NSLog(@"creating action to open URL '%@'", self.urlString); +#endif + [actions addObject:[self createAction]]; } diff --git a/iphone/Classes/ZXingAppDelegate.m b/iphone/Classes/ZXingAppDelegate.m index f872c60e..1b06e088 100644 --- a/iphone/Classes/ZXingAppDelegate.m +++ b/iphone/Classes/ZXingAppDelegate.m @@ -64,8 +64,6 @@ } #undef N_SOURCE_TYPES } - - NSLog(@"current locale is %@", [NSLocale currentLocale]); } - (void)dealloc { diff --git a/iphone/en.lproj/DecoderView.xib b/iphone/en.lproj/DecoderView.xib index 44a7cc7d..8194c645 100644 --- a/iphone/en.lproj/DecoderView.xib +++ b/iphone/en.lproj/DecoderView.xib @@ -3,7 +3,7 @@ 512 9D34 - 667 + 670 949.33 352.00 @@ -406,56 +406,6 @@ YES - - DecodingController - UIViewController - - YES - - YES - performResultAction: - pickAndDecode: - showArchive: - - - YES - id - id - id - - - - YES - - YES - actionBarItem - archiveBarItem - cameraBarItem - imageView - libraryBarItem - messageView - resultView - savedPhotosBarItem - toolbar - - - YES - UIBarItem - UIBarItem - UIBarItem - UIImageView - UIBarItem - UITextView - UIView - UIBarItem - UIToolbar - - - - IBProjectSource - Classes/DecodingController.h - - DecodingController UIViewController @@ -467,7 +417,7 @@ 0 - ZXing.xcodeproj + ../ZXing.xcodeproj 3 -- 2.20.1