scan archive UI improvements, phase 1

git-svn-id: https://zxing.googlecode.com/svn/trunk@469 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
christian.brunschen 2008-06-24 10:04:08 +00:00
parent 584564a594
commit 8c345b81e8
14 changed files with 161 additions and 27 deletions

View file

@ -76,10 +76,6 @@
return [NSString stringWithString:result]; return [NSString stringWithString:result];
} }
- (NSString *)typeName {
return @"DoCoMo MeCard";
}
- (void)populateActions { - (void)populateActions {
[actions addObject:[AddContactAction actionWithName:self.name [actions addObject:[AddContactAction actionWithName:self.name
phoneNumbers:self.phoneNumbers phoneNumbers:self.phoneNumbers
@ -99,4 +95,8 @@
[super dealloc]; [super dealloc];
} }
+ (NSString *)typeName {
return @"MeCard";
}
@end @end

View file

@ -26,10 +26,12 @@
@interface ArchiveController : UITableViewController { @interface ArchiveController : UITableViewController {
NSMutableArray *scans; NSMutableArray *scans;
DecoderViewController *decoderViewController; DecoderViewController *decoderViewController;
NSDateFormatter *dateFormatter;
} }
@property (nonatomic, retain) NSMutableArray *scans; @property (nonatomic, retain) NSMutableArray *scans;
@property (nonatomic, retain) DecoderViewController *decoderViewController; @property (nonatomic, retain) DecoderViewController *decoderViewController;
@property (nonatomic, retain) NSDateFormatter *dateFormatter;
- (NSInteger)scanIndexForRow:(NSInteger)row; - (NSInteger)scanIndexForRow:(NSInteger)row;
- initWithDecoderViewController:(DecoderViewController *)dc; - initWithDecoderViewController:(DecoderViewController *)dc;

View file

@ -25,15 +25,26 @@
#import "ParsedResult.h" #import "ParsedResult.h"
#import "DecoderViewController.h" #import "DecoderViewController.h"
#define IMAGE_VIEW_TAG 0x17
#define DATE_VIEW_TAG 0x18
#define TEXT_VIEW_TAG 0x19
#define VIEW_PADDING 2
#define IMAGE_VIEW_SIDE 50
#define CONTENT_HEIGHT IMAGE_VIEW_SIDE
#define DATE_VIEW_WIDTH 70
@implementation ArchiveController @implementation ArchiveController
@synthesize scans; @synthesize scans;
@synthesize decoderViewController; @synthesize decoderViewController;
@synthesize dateFormatter;
- initWithDecoderViewController:(DecoderViewController *)dc { - initWithDecoderViewController:(DecoderViewController *)dc {
if (self = [super initWithStyle:UITableViewStylePlain]) { if (self = [super initWithStyle:UITableViewStylePlain]) {
self.decoderViewController = dc; decoderViewController = [dc retain];
self.scans = [NSMutableArray array]; scans = [[NSMutableArray alloc] init];
dateFormatter = [[NSDateFormatter alloc] init];
} }
return self; return self;
} }
@ -46,19 +57,73 @@
return [scans count]; return [scans count];
} }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return IMAGE_VIEW_SIDE + 2 * VIEW_PADDING;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ScanIdentifier = @"ScanIdentifier"; static NSString *ScanIdentifier = @"ScanIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ScanIdentifier]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ScanIdentifier];
if (cell == nil) { if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:ScanIdentifier] autorelease]; cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:ScanIdentifier] autorelease];
cell.font = [cell.font fontWithSize:10.0];
cell.lineBreakMode = UILineBreakModeCharacterWrap; // clean out all existing subviews
NSArray *subviews = [[NSArray alloc] initWithArray:cell.contentView.subviews];
for (UIView *subview in subviews) {
[subview removeFromSuperview];
}
[subviews release];
float cellWidth = cell.contentView.bounds.size.width;
// add the views
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(VIEW_PADDING, VIEW_PADDING, IMAGE_VIEW_SIDE, CONTENT_HEIGHT)];
[imageView setTag:IMAGE_VIEW_TAG];
[imageView setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
[cell.contentView addSubview:imageView];
[imageView release];
UILabel *textView = [[UILabel alloc] initWithFrame:CGRectMake(2*VIEW_PADDING + IMAGE_VIEW_SIDE, VIEW_PADDING, cellWidth - 4*VIEW_PADDING - IMAGE_VIEW_SIDE - DATE_VIEW_WIDTH, CONTENT_HEIGHT)];
[textView setTag:TEXT_VIEW_TAG];
[textView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[cell.contentView addSubview:textView];
[textView release];
UITextView *dateView = [[UITextView alloc] initWithFrame:CGRectMake(cellWidth - VIEW_PADDING - DATE_VIEW_WIDTH, VIEW_PADDING, DATE_VIEW_WIDTH, CONTENT_HEIGHT)];
[dateView setTag:DATE_VIEW_TAG];
[dateView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
dateView.font = [UIFont systemFontOfSize:9.0];
dateView.textColor = [UIColor grayColor];
dateView.textAlignment = UITextAlignmentRight;
dateView.editable = NO;
[cell.contentView addSubview:dateView];
[dateView release];
} }
UIImageView *imageView = (UIImageView *)[cell.contentView viewWithTag:IMAGE_VIEW_TAG];
UILabel *textView = (UILabel *)[cell.contentView viewWithTag:TEXT_VIEW_TAG];
UITextView *dateView = (UITextView *)[cell.contentView viewWithTag:DATE_VIEW_TAG];
// Configure the cell // Configure the cell
Scan *scan = [scans objectAtIndex:[self scanIndexForRow:indexPath.row]]; Scan *scan = [scans objectAtIndex:[self scanIndexForRow:indexPath.row]];
ParsedResult *result = [ParsedResult parsedResultForString:scan.text]; ParsedResult *result = [ParsedResult parsedResultForString:scan.text];
cell.text = [result stringForDisplay]; imageView.image = nil;
NSDate *stamp = [scan stamp];
NSTimeInterval interval = -[stamp timeIntervalSinceNow];
if (interval < 24 * 3600) { // last 24 hours
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
} else if (interval < 30 * 24 * 3600) { // last 30 days
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
} else {
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
}
dateView.text = [dateFormatter stringFromDate:[scan stamp]];
[dateView sizeToFit];
textView.text = [result stringForDisplay];
imageView.image = [result icon];
return cell; return cell;
} }
@ -70,34 +135,34 @@
if (editingStyle == UITableViewCellEditingStyleDelete) { if (editingStyle == UITableViewCellEditingStyleDelete) {
int index = [self scanIndexForRow:indexPath.row]; int index = [self scanIndexForRow:indexPath.row];
Scan *scan = [self.scans objectAtIndex:index]; Scan *scan = [self.scans objectAtIndex:index];
// delete the scan from the database ...
[[Database sharedDatabase] deleteScan:scan]; [[Database sharedDatabase] deleteScan:scan];
// ... delete the scan from our in-memory cache of the database ...
[self.scans removeObjectAtIndex:index]; [self.scans removeObjectAtIndex:index];
// ... and remove the row from the table view.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView reloadData]; // [tableView reloadData];
} else if (editingStyle == UITableViewCellEditingStyleInsert) { } else if (editingStyle == UITableViewCellEditingStyleInsert) {
// no insertions! // no insertions!
} }
} }
/*
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES; return YES;
} }
*/
/*
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
} }
*/
/*
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES; return NO;
} }
*/
- (void)dealloc { - (void)dealloc {
[scans release]; [scans release];
[decoderViewController release]; [decoderViewController release];
[dateFormatter release];
[super dealloc]; [super dealloc];
} }

View file

@ -49,4 +49,10 @@
} }
} }
+ (NSString *)typeName {
return @"Bookmark";
}
@end @end

View file

@ -300,8 +300,9 @@
} }
- (void)showScan:(Scan *)scan { - (void)showScan:(Scan *)scan {
[[self navigationController] popToViewController:self animated:YES]; [self.imageView setImage:nil];
[self presentResultForString:scan.text]; [self presentResultForString:scan.text];
[[self navigationController] popToViewController:self animated:YES];
} }
@end @end

View file

@ -72,8 +72,8 @@ bool LooksLikeAnEmailAddress(NSString *s) {
return [NSString stringWithString:result]; return [NSString stringWithString:result];
} }
- (NSString *)typeName { + (NSString *)typeName {
return @"DoCoMo Email"; return @"Email";
} }
- (NSArray *)actions { - (NSArray *)actions {

View file

@ -44,12 +44,10 @@
autorelease]; autorelease];
} }
return nil; return nil;
} }
+ (NSString *)typeName { + (NSString *)typeName {
return @"Geographic Location"; return @"GeoLoc";
} }
- (NSString *)stringForDisplay { - (NSString *)stringForDisplay {

View file

@ -30,6 +30,7 @@
+ (NSString *)typeName; + (NSString *)typeName;
- (NSString *)stringForDisplay; - (NSString *)stringForDisplay;
- (UIImage *)icon;
- (NSArray *)actions; - (NSArray *)actions;
- (void)populateActions; - (void)populateActions;

View file

@ -30,9 +30,13 @@
#import "BookmarkDoCoMoParsedResult.h" #import "BookmarkDoCoMoParsedResult.h"
#import "GeoParsedResult.h" #import "GeoParsedResult.h"
#import "UIKit/UIStringDrawing.h"
#import <math.h>
@implementation ParsedResult @implementation ParsedResult
static NSArray *parsedResultTypes = nil; static NSArray *parsedResultTypes = nil;
static NSMutableDictionary *iconsByClass = nil;
+ (NSArray *)parsedResultTypes { + (NSArray *)parsedResultTypes {
if (parsedResultTypes == nil) { if (parsedResultTypes == nil) {
@ -63,13 +67,52 @@ static NSArray *parsedResultTypes = nil;
} }
+ (NSString *)typeName { + (NSString *)typeName {
return @"ABSTRACT"; return NSStringFromClass(self);
} }
- (NSString *)stringForDisplay { - (NSString *)stringForDisplay {
return @"{none}"; return @"{none}";
} }
+ (UIImage *)icon {
if (iconsByClass == nil) {
iconsByClass = [[NSMutableDictionary alloc] initWithCapacity:16];
}
UIImage *icon = [iconsByClass objectForKey:[self class]];
if (icon == nil) {
UIGraphicsBeginImageContext(CGSizeMake(60, 60));
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor lightGrayColor] set];
UIRectFill(CGRectMake(0, 0, 60, 60));
[[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);
CGContextTranslateCTM(ctx, 30, 30);
CGContextRotateCTM(ctx, -M_PI / 6.0);
CGContextScaleCTM(ctx, xScale, yScale);
CGContextTranslateCTM(ctx,
-(stringSize.width)/2.0,
-(stringSize.height)/2.0);
[s drawAtPoint:CGPointMake(0, 0) withFont:font];
icon = [UIGraphicsGetImageFromCurrentImageContext() retain];
[iconsByClass setObject:icon forKey:[self class]];
UIGraphicsEndImageContext();
}
return icon;
}
- (UIImage *)icon {
return [[self class] icon];
}
- (NSArray *)actions { - (NSArray *)actions {
if (!actions) { if (!actions) {
actions = [[NSMutableArray alloc] init]; actions = [[NSMutableArray alloc] init];

View file

@ -49,6 +49,12 @@
return self.number; return self.number;
} }
+ (NSString *)typeName {
return @"Tel";
}
- (NSArray *)actions { - (NSArray *)actions {
return [NSArray arrayWithObject:[CallAction actionWithNumber:self.number]]; return [NSArray arrayWithObject:[CallAction actionWithNumber:self.number]];
} }

View file

@ -38,7 +38,7 @@
} }
+ (NSString *)typeName { + (NSString *)typeName {
return @"TEXT"; return @"Text";
} }
- (NSString *)stringForDisplay { - (NSString *)stringForDisplay {

View file

@ -106,6 +106,12 @@
return self.urlString; return self.urlString;
} }
+ (NSString *)typeName {
return @"URI";
}
- (void)populateActions { - (void)populateActions {
NSLog(@"creating action to open URL '%@'", self.urlString); NSLog(@"creating action to open URL '%@'", self.urlString);
[actions addObject:[self createAction]]; [actions addObject:[self createAction]];

View file

@ -59,4 +59,9 @@
} }
+ (NSString *)typeName {
return @"UrlTo";
}
@end @end

View file

@ -25,7 +25,7 @@
8514EAF70DF88F0500EE78D3 /* Counted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65E60DF5E739007B394F /* Counted.cpp */; }; 8514EAF70DF88F0500EE78D3 /* Counted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65E60DF5E739007B394F /* Counted.cpp */; };
8514EAF80DF88F0500EE78D3 /* DecoderResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65E80DF5E739007B394F /* DecoderResult.cpp */; }; 8514EAF80DF88F0500EE78D3 /* DecoderResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65E80DF5E739007B394F /* DecoderResult.cpp */; };
8514EAF90DF88F0500EE78D3 /* DetectorResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65EA0DF5E739007B394F /* DetectorResult.cpp */; }; 8514EAF90DF88F0500EE78D3 /* DetectorResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65EA0DF5E739007B394F /* DetectorResult.cpp */; };
8514EAFA0DF88F0500EE78D3 /* GridSampler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65EC0DF5E739007B394F /* GridSampler.cpp */; }; 8514EAFA0DF88F0500EE78D3 /* GridSampler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65EC0DF5E739007B394F /* GridSampler.cpp */; settings = {COMPILER_FLAGS = "-mno-thumb"; }; };
8514EAFB0DF88F0500EE78D3 /* IllegalArgumentException.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65EE0DF5E739007B394F /* IllegalArgumentException.cpp */; }; 8514EAFB0DF88F0500EE78D3 /* IllegalArgumentException.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65EE0DF5E739007B394F /* IllegalArgumentException.cpp */; };
8514EAFC0DF88F0500EE78D3 /* PerspectiveTransform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65F00DF5E739007B394F /* PerspectiveTransform.cpp */; }; 8514EAFC0DF88F0500EE78D3 /* PerspectiveTransform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65F00DF5E739007B394F /* PerspectiveTransform.cpp */; };
8514EAFD0DF88F0500EE78D3 /* GF256.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65F30DF5E739007B394F /* GF256.cpp */; }; 8514EAFD0DF88F0500EE78D3 /* GF256.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65F30DF5E739007B394F /* GF256.cpp */; };
@ -176,7 +176,7 @@
855A65E90DF5E739007B394F /* DecoderResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DecoderResult.h; sourceTree = "<group>"; }; 855A65E90DF5E739007B394F /* DecoderResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DecoderResult.h; sourceTree = "<group>"; };
855A65EA0DF5E739007B394F /* DetectorResult.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DetectorResult.cpp; sourceTree = "<group>"; }; 855A65EA0DF5E739007B394F /* DetectorResult.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DetectorResult.cpp; sourceTree = "<group>"; };
855A65EB0DF5E739007B394F /* DetectorResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetectorResult.h; sourceTree = "<group>"; }; 855A65EB0DF5E739007B394F /* DetectorResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetectorResult.h; sourceTree = "<group>"; };
855A65EC0DF5E739007B394F /* GridSampler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GridSampler.cpp; sourceTree = "<group>"; }; 855A65EC0DF5E739007B394F /* GridSampler.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp; fileEncoding = 4; path = GridSampler.cpp; sourceTree = "<group>"; };
855A65ED0DF5E739007B394F /* GridSampler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GridSampler.h; sourceTree = "<group>"; }; 855A65ED0DF5E739007B394F /* GridSampler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GridSampler.h; sourceTree = "<group>"; };
855A65EE0DF5E739007B394F /* IllegalArgumentException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IllegalArgumentException.cpp; sourceTree = "<group>"; }; 855A65EE0DF5E739007B394F /* IllegalArgumentException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IllegalArgumentException.cpp; sourceTree = "<group>"; };
855A65EF0DF5E739007B394F /* IllegalArgumentException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IllegalArgumentException.h; sourceTree = "<group>"; }; 855A65EF0DF5E739007B394F /* IllegalArgumentException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IllegalArgumentException.h; sourceTree = "<group>"; };
@ -893,6 +893,7 @@
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_THUMB_SUPPORT = NO;
PREBINDING = NO; PREBINDING = NO;
PRODUCT_NAME = zxingcore; PRODUCT_NAME = zxingcore;
}; };