mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
scan archive UI improvements, phase 3
git-svn-id: https://zxing.googlecode.com/svn/trunk@471 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
ad66af0ce1
commit
8cffdc4b70
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<MonochromeBitmapSource> 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> result(reader.decode(grayImage));
|
||||
NSLog(@"gray image decoed");
|
||||
#ifdef DEBUG
|
||||
NSLog(@"gray image decoded");
|
||||
#endif
|
||||
|
||||
Ref<String> 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]) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -113,7 +113,10 @@
|
|||
|
||||
|
||||
- (void)populateActions {
|
||||
#ifdef DEBUG
|
||||
NSLog(@"creating action to open URL '%@'", self.urlString);
|
||||
#endif
|
||||
|
||||
[actions addObject:[self createAction]];
|
||||
}
|
||||
|
||||
|
|
|
@ -64,8 +64,6 @@
|
|||
}
|
||||
#undef N_SOURCE_TYPES
|
||||
}
|
||||
|
||||
NSLog(@"current locale is %@", [NSLocale currentLocale]);
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<data>
|
||||
<int key="IBDocument.SystemTarget">512</int>
|
||||
<string key="IBDocument.SystemVersion">9D34</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">667</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">670</string>
|
||||
<string key="IBDocument.AppKitVersion">949.33</string>
|
||||
<string key="IBDocument.HIToolboxVersion">352.00</string>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
|
@ -406,56 +406,6 @@
|
|||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">DecodingController</string>
|
||||
<string key="superclassName">UIViewController</string>
|
||||
<object class="NSMutableDictionary" key="actions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSMutableArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>performResultAction:</string>
|
||||
<string>pickAndDecode:</string>
|
||||
<string>showArchive:</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>id</string>
|
||||
<string>id</string>
|
||||
<string>id</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="outlets">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSMutableArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>actionBarItem</string>
|
||||
<string>archiveBarItem</string>
|
||||
<string>cameraBarItem</string>
|
||||
<string>imageView</string>
|
||||
<string>libraryBarItem</string>
|
||||
<string>messageView</string>
|
||||
<string>resultView</string>
|
||||
<string>savedPhotosBarItem</string>
|
||||
<string>toolbar</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>UIBarItem</string>
|
||||
<string>UIBarItem</string>
|
||||
<string>UIBarItem</string>
|
||||
<string>UIImageView</string>
|
||||
<string>UIBarItem</string>
|
||||
<string>UITextView</string>
|
||||
<string>UIView</string>
|
||||
<string>UIBarItem</string>
|
||||
<string>UIToolbar</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">Classes/DecodingController.h</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">DecodingController</string>
|
||||
<string key="superclassName">UIViewController</string>
|
||||
|
@ -467,7 +417,7 @@
|
|||
</object>
|
||||
</object>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
<string key="IBDocument.LastKnownRelativeProjectPath">ZXing.xcodeproj</string>
|
||||
<string key="IBDocument.LastKnownRelativeProjectPath">../ZXing.xcodeproj</string>
|
||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
||||
</data>
|
||||
</archive>
|
||||
|
|
Loading…
Reference in a new issue