mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
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:
parent
584564a594
commit
8c345b81e8
|
@ -76,10 +76,6 @@
|
|||
return [NSString stringWithString:result];
|
||||
}
|
||||
|
||||
- (NSString *)typeName {
|
||||
return @"DoCoMo MeCard";
|
||||
}
|
||||
|
||||
- (void)populateActions {
|
||||
[actions addObject:[AddContactAction actionWithName:self.name
|
||||
phoneNumbers:self.phoneNumbers
|
||||
|
@ -99,4 +95,8 @@
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
+ (NSString *)typeName {
|
||||
return @"MeCard";
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -26,10 +26,12 @@
|
|||
@interface ArchiveController : UITableViewController {
|
||||
NSMutableArray *scans;
|
||||
DecoderViewController *decoderViewController;
|
||||
NSDateFormatter *dateFormatter;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) NSMutableArray *scans;
|
||||
@property (nonatomic, retain) DecoderViewController *decoderViewController;
|
||||
@property (nonatomic, retain) NSDateFormatter *dateFormatter;
|
||||
|
||||
- (NSInteger)scanIndexForRow:(NSInteger)row;
|
||||
- initWithDecoderViewController:(DecoderViewController *)dc;
|
||||
|
|
|
@ -25,15 +25,26 @@
|
|||
#import "ParsedResult.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
|
||||
|
||||
@synthesize scans;
|
||||
@synthesize decoderViewController;
|
||||
@synthesize dateFormatter;
|
||||
|
||||
- initWithDecoderViewController:(DecoderViewController *)dc {
|
||||
if (self = [super initWithStyle:UITableViewStylePlain]) {
|
||||
self.decoderViewController = dc;
|
||||
self.scans = [NSMutableArray array];
|
||||
decoderViewController = [dc retain];
|
||||
scans = [[NSMutableArray alloc] init];
|
||||
dateFormatter = [[NSDateFormatter alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -46,19 +57,73 @@
|
|||
return [scans count];
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return IMAGE_VIEW_SIDE + 2 * VIEW_PADDING;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
static NSString *ScanIdentifier = @"ScanIdentifier";
|
||||
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ScanIdentifier];
|
||||
if (cell == nil) {
|
||||
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
|
||||
Scan *scan = [scans objectAtIndex:[self scanIndexForRow:indexPath.row]];
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -70,34 +135,34 @@
|
|||
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
||||
int index = [self scanIndexForRow:indexPath.row];
|
||||
Scan *scan = [self.scans objectAtIndex:index];
|
||||
// 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];
|
||||
// ... and remove the row from the table view.
|
||||
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
[tableView reloadData];
|
||||
// [tableView reloadData];
|
||||
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
||||
// no insertions!
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return YES;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[scans release];
|
||||
[decoderViewController release];
|
||||
[dateFormatter release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
|
|
@ -49,4 +49,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
+ (NSString *)typeName {
|
||||
return @"Bookmark";
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -300,8 +300,9 @@
|
|||
}
|
||||
|
||||
- (void)showScan:(Scan *)scan {
|
||||
[[self navigationController] popToViewController:self animated:YES];
|
||||
[self.imageView setImage:nil];
|
||||
[self presentResultForString:scan.text];
|
||||
[[self navigationController] popToViewController:self animated:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -72,8 +72,8 @@ bool LooksLikeAnEmailAddress(NSString *s) {
|
|||
return [NSString stringWithString:result];
|
||||
}
|
||||
|
||||
- (NSString *)typeName {
|
||||
return @"DoCoMo Email";
|
||||
+ (NSString *)typeName {
|
||||
return @"Email";
|
||||
}
|
||||
|
||||
- (NSArray *)actions {
|
||||
|
|
|
@ -44,12 +44,10 @@
|
|||
autorelease];
|
||||
}
|
||||
return nil;
|
||||
|
||||
|
||||
}
|
||||
|
||||
+ (NSString *)typeName {
|
||||
return @"Geographic Location";
|
||||
return @"GeoLoc";
|
||||
}
|
||||
|
||||
- (NSString *)stringForDisplay {
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
+ (NSString *)typeName;
|
||||
|
||||
- (NSString *)stringForDisplay;
|
||||
- (UIImage *)icon;
|
||||
- (NSArray *)actions;
|
||||
- (void)populateActions;
|
||||
|
||||
|
|
|
@ -30,9 +30,13 @@
|
|||
#import "BookmarkDoCoMoParsedResult.h"
|
||||
#import "GeoParsedResult.h"
|
||||
|
||||
#import "UIKit/UIStringDrawing.h"
|
||||
#import <math.h>
|
||||
|
||||
@implementation ParsedResult
|
||||
|
||||
static NSArray *parsedResultTypes = nil;
|
||||
static NSMutableDictionary *iconsByClass = nil;
|
||||
|
||||
+ (NSArray *)parsedResultTypes {
|
||||
if (parsedResultTypes == nil) {
|
||||
|
@ -63,13 +67,52 @@ static NSArray *parsedResultTypes = nil;
|
|||
}
|
||||
|
||||
+ (NSString *)typeName {
|
||||
return @"ABSTRACT";
|
||||
return NSStringFromClass(self);
|
||||
}
|
||||
|
||||
- (NSString *)stringForDisplay {
|
||||
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 {
|
||||
if (!actions) {
|
||||
actions = [[NSMutableArray alloc] init];
|
||||
|
|
|
@ -49,6 +49,12 @@
|
|||
return self.number;
|
||||
}
|
||||
|
||||
|
||||
+ (NSString *)typeName {
|
||||
return @"Tel";
|
||||
}
|
||||
|
||||
|
||||
- (NSArray *)actions {
|
||||
return [NSArray arrayWithObject:[CallAction actionWithNumber:self.number]];
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
}
|
||||
|
||||
+ (NSString *)typeName {
|
||||
return @"TEXT";
|
||||
return @"Text";
|
||||
}
|
||||
|
||||
- (NSString *)stringForDisplay {
|
||||
|
|
|
@ -106,6 +106,12 @@
|
|||
return self.urlString;
|
||||
}
|
||||
|
||||
|
||||
+ (NSString *)typeName {
|
||||
return @"URI";
|
||||
}
|
||||
|
||||
|
||||
- (void)populateActions {
|
||||
NSLog(@"creating action to open URL '%@'", self.urlString);
|
||||
[actions addObject:[self createAction]];
|
||||
|
|
|
@ -59,4 +59,9 @@
|
|||
}
|
||||
|
||||
|
||||
+ (NSString *)typeName {
|
||||
return @"UrlTo";
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
8514EAF70DF88F0500EE78D3 /* Counted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65E60DF5E739007B394F /* Counted.cpp */; };
|
||||
8514EAF80DF88F0500EE78D3 /* DecoderResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65E80DF5E739007B394F /* DecoderResult.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 */; };
|
||||
8514EAFC0DF88F0500EE78D3 /* PerspectiveTransform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 855A65F00DF5E739007B394F /* PerspectiveTransform.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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
|
@ -893,6 +893,7 @@
|
|||
COPY_PHASE_STRIP = NO;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_THUMB_SUPPORT = NO;
|
||||
PREBINDING = NO;
|
||||
PRODUCT_NAME = zxingcore;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue