diff --git a/.gitignore b/.gitignore index 901ff480..af7a5ee1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,58 @@ +############################################## +# .gitignore for Xcode 5 Project # +# https://gist.github.com/bartjacobs/8334797 # +############################################## + +# Temporary Files OS X + .DS_Store -project.xcworkspace +*.swp +*.lock +profile + + +# Temporary Files Xcode + +*~.nib + + +# Xcode Build Files + +DerivedData/ +build/ + + +# Xcode Private Settings + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 + + +# Whitelist Defaults + +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + + +# Xcode 5 Personal Settings + xcuserdata + + +# Xcode 5 Deprecated Classes + +*.moved-aside + + +# Xcode 5 Version Control + +*.xccheckout + + +# Cocoapods + +Pods/ diff --git a/Reader.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Reader.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..9bb4f589 --- /dev/null +++ b/Reader.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Sources/ReaderConstants.h b/Sources/ReaderConstants.h index a4440ad9..d0e058c6 100644 --- a/Sources/ReaderConstants.h +++ b/Sources/ReaderConstants.h @@ -29,14 +29,14 @@ #import -#define READER_BOOKMARKS TRUE +#define READER_BOOKMARKS FALSE #define READER_ENABLE_MAIL TRUE #define READER_ENABLE_PRINT TRUE -#define READER_ENABLE_THUMBS TRUE +#define READER_ENABLE_THUMBS FALSE #define READER_ENABLE_PREVIEW TRUE #define READER_DISABLE_RETINA FALSE #define READER_DISABLE_IDLE FALSE #define READER_SHOW_SHADOWS TRUE -#define READER_STANDALONE FALSE +#define READER_STANDALONE TRUE extern NSString *const kReaderCopyrightNotice; diff --git a/Sources/ReaderDocument.h b/Sources/ReaderDocument.h index 98768de3..69914ce0 100644 --- a/Sources/ReaderDocument.h +++ b/Sources/ReaderDocument.h @@ -35,6 +35,7 @@ @property (nonatomic, strong, readwrite) NSNumber *pageNumber; @property (nonatomic, strong, readonly) NSMutableIndexSet *bookmarks; @property (nonatomic, strong, readonly) NSString *fileName; +@property (nonatomic, copy) NSString *title; @property (nonatomic, strong, readonly) NSString *password; @property (nonatomic, strong, readonly) NSURL *fileURL; diff --git a/Sources/ReaderDocument.m b/Sources/ReaderDocument.m index 4a1f841e..62f16476 100644 --- a/Sources/ReaderDocument.m +++ b/Sources/ReaderDocument.m @@ -48,6 +48,8 @@ @implementation ReaderDocument NSString *_password; NSURL *_fileURL; + + NSString *_title; } #pragma mark Properties @@ -60,6 +62,7 @@ @implementation ReaderDocument @synthesize bookmarks = _bookmarks; @synthesize lastOpen = _lastOpen; @synthesize password = _password; +@synthesize title = _title; @dynamic fileName, fileURL; #pragma mark ReaderDocument class methods diff --git a/Sources/ReaderMainPagebar.m b/Sources/ReaderMainPagebar.m index 47b756b8..beea590a 100644 --- a/Sources/ReaderMainPagebar.m +++ b/Sources/ReaderMainPagebar.m @@ -145,17 +145,23 @@ - (id)initWithFrame:(CGRect)frame document:(ReaderDocument *)object self.contentMode = UIViewContentModeRedraw; self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; self.backgroundColor = [UIColor clearColor]; - - CAGradientLayer *layer = (CAGradientLayer *)self.layer; - UIColor *liteColor = [UIColor colorWithWhite:0.82f alpha:0.8f]; - UIColor *darkColor = [UIColor colorWithWhite:0.32f alpha:0.8f]; - layer.colors = [NSArray arrayWithObjects:(id)liteColor.CGColor, (id)darkColor.CGColor, nil]; - - CGRect shadowRect = self.bounds; shadowRect.size.height = 4.0f; shadowRect.origin.y -= shadowRect.size.height; - - ReaderPagebarShadow *shadowView = [[ReaderPagebarShadow alloc] initWithFrame:shadowRect]; - - [self addSubview:shadowView]; // Add the shadow to the view + + UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.f, 0.f, frame.size.width, frame.size.height)]; + toolbar.tintColor = [UIColor lightGrayColor]; + toolbar.translucent = YES; + toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + [self addSubview:toolbar]; + +// CAGradientLayer *layer = (CAGradientLayer *)self.layer; +// UIColor *liteColor = [UIColor colorWithWhite:0.82f alpha:0.8f]; +// UIColor *darkColor = [UIColor colorWithWhite:0.32f alpha:0.8f]; +// layer.colors = [NSArray arrayWithObjects:(id)liteColor.CGColor, (id)darkColor.CGColor, nil]; +// +// CGRect shadowRect = self.bounds; shadowRect.size.height = 4.0f; shadowRect.origin.y -= shadowRect.size.height; +// +// ReaderPagebarShadow *shadowView = [[ReaderPagebarShadow alloc] initWithFrame:shadowRect]; +// +// [self addSubview:shadowView]; // Add the shadow to the view CGFloat numberY = (0.0f - (PAGE_NUMBER_HEIGHT + PAGE_NUMBER_SPACE)); CGFloat numberX = ((self.bounds.size.width - PAGE_NUMBER_WIDTH) / 2.0f); diff --git a/Sources/ReaderMainToolbar.h b/Sources/ReaderMainToolbar.h index 3f61ac07..ab2d96e2 100644 --- a/Sources/ReaderMainToolbar.h +++ b/Sources/ReaderMainToolbar.h @@ -25,8 +25,6 @@ #import -#import "UIXToolbarView.h" - @class ReaderMainToolbar; @class ReaderDocument; @@ -42,7 +40,7 @@ @end -@interface ReaderMainToolbar : UIXToolbarView +@interface ReaderMainToolbar : UIView @property (nonatomic, weak, readwrite) id delegate; diff --git a/Sources/ReaderMainToolbar.m b/Sources/ReaderMainToolbar.m index 119a3685..2f682292 100644 --- a/Sources/ReaderMainToolbar.m +++ b/Sources/ReaderMainToolbar.m @@ -37,21 +37,6 @@ @implementation ReaderMainToolbar UIImage *markImageY; } -#pragma mark Constants - -#define BUTTON_X 8.0f -#define BUTTON_Y 8.0f -#define BUTTON_SPACE 8.0f -#define BUTTON_HEIGHT 30.0f - -#define DONE_BUTTON_WIDTH 56.0f -#define THUMBS_BUTTON_WIDTH 40.0f -#define PRINT_BUTTON_WIDTH 40.0f -#define EMAIL_BUTTON_WIDTH 40.0f -#define MARK_BUTTON_WIDTH 40.0f - -#define TITLE_HEIGHT 28.0f - #pragma mark Properties @synthesize delegate; @@ -67,85 +52,51 @@ - (id)initWithFrame:(CGRect)frame document:(ReaderDocument *)object { assert(object != nil); // Must have a valid ReaderDocument + BOOL isIOS7 = [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f; + + if(isIOS7) { + frame.size.height += 20.f; + } + if ((self = [super initWithFrame:frame])) { - CGFloat viewWidth = self.bounds.size.width; - - UIImage *imageH = [UIImage imageNamed:@"Reader-Button-H"]; - UIImage *imageN = [UIImage imageNamed:@"Reader-Button-N"]; - - UIImage *buttonH = [imageH stretchableImageWithLeftCapWidth:5 topCapHeight:0]; - UIImage *buttonN = [imageN stretchableImageWithLeftCapWidth:5 topCapHeight:0]; - - CGFloat titleX = BUTTON_X; CGFloat titleWidth = (viewWidth - (titleX + titleX)); - - CGFloat leftButtonX = BUTTON_X; // Left button start X position + self.autoresizingMask = UIViewAutoresizingFlexibleWidth; + + UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:frame]; + navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; + if(isIOS7) { + navigationBar.tintColor = [UIColor darkGrayColor]; + } + else { + navigationBar.tintColor = [UIColor lightGrayColor]; + } + navigationBar.translucent = YES; + [self addSubview:navigationBar]; + + UINavigationItem *navigationItem = [[UINavigationItem alloc] init]; + NSMutableArray *navigationBarItems = [NSMutableArray array]; #if (READER_STANDALONE == FALSE) // Option - UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; - - doneButton.frame = CGRectMake(leftButtonX, BUTTON_Y, DONE_BUTTON_WIDTH, BUTTON_HEIGHT); - [doneButton setTitle:NSLocalizedString(@"Done", @"button") forState:UIControlStateNormal]; - [doneButton setTitleColor:[UIColor colorWithWhite:0.0f alpha:1.0f] forState:UIControlStateNormal]; - [doneButton setTitleColor:[UIColor colorWithWhite:1.0f alpha:1.0f] forState:UIControlStateHighlighted]; - [doneButton addTarget:self action:@selector(doneButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; - [doneButton setBackgroundImage:buttonH forState:UIControlStateHighlighted]; - [doneButton setBackgroundImage:buttonN forState:UIControlStateNormal]; - doneButton.titleLabel.font = [UIFont systemFontOfSize:14.0f]; - doneButton.autoresizingMask = UIViewAutoresizingNone; - doneButton.exclusiveTouch = YES; - - [self addSubview:doneButton]; leftButtonX += (DONE_BUTTON_WIDTH + BUTTON_SPACE); - - titleX += (DONE_BUTTON_WIDTH + BUTTON_SPACE); titleWidth -= (DONE_BUTTON_WIDTH + BUTTON_SPACE); + UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"button") style:UIBarButtonItemStyleDone target:self action:@selector(doneButtonTapped:)]; + [navigationBarItems addObject:doneButton]; #endif // end of READER_STANDALONE Option #if (READER_ENABLE_THUMBS == TRUE) // Option - UIButton *thumbsButton = [UIButton buttonWithType:UIButtonTypeCustom]; - - thumbsButton.frame = CGRectMake(leftButtonX, BUTTON_Y, THUMBS_BUTTON_WIDTH, BUTTON_HEIGHT); - [thumbsButton setImage:[UIImage imageNamed:@"Reader-Thumbs"] forState:UIControlStateNormal]; - [thumbsButton addTarget:self action:@selector(thumbsButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; - [thumbsButton setBackgroundImage:buttonH forState:UIControlStateHighlighted]; - [thumbsButton setBackgroundImage:buttonN forState:UIControlStateNormal]; - thumbsButton.autoresizingMask = UIViewAutoresizingNone; - thumbsButton.exclusiveTouch = YES; - - [self addSubview:thumbsButton]; //leftButtonX += (THUMBS_BUTTON_WIDTH + BUTTON_SPACE); - - titleX += (THUMBS_BUTTON_WIDTH + BUTTON_SPACE); titleWidth -= (THUMBS_BUTTON_WIDTH + BUTTON_SPACE); + UIBarButtonItem *thumbsButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Reader-Thumbs"] style:UIBarButtonItemStylePlain target:self action:@selector(thumbsButtonTapped:)]; + [navigationBarItems addObject:thumbsButton]; #endif // end of READER_ENABLE_THUMBS Option -#if (READER_BOOKMARKS == TRUE || READER_ENABLE_MAIL == TRUE || READER_ENABLE_PRINT == TRUE) - - CGFloat rightButtonX = viewWidth; // Right button start X position - -#endif // end of READER_BOOKMARKS || READER_ENABLE_MAIL || READER_ENABLE_PRINT Options + [navigationItem setLeftBarButtonItems:navigationBarItems]; + navigationBarItems = [NSMutableArray array]; #if (READER_BOOKMARKS == TRUE) // Option - rightButtonX -= (MARK_BUTTON_WIDTH + BUTTON_SPACE); - - UIButton *flagButton = [UIButton buttonWithType:UIButtonTypeCustom]; - - flagButton.frame = CGRectMake(rightButtonX, BUTTON_Y, MARK_BUTTON_WIDTH, BUTTON_HEIGHT); - //[flagButton setImage:[UIImage imageNamed:@"Reader-Mark-N"] forState:UIControlStateNormal]; - [flagButton addTarget:self action:@selector(markButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; - [flagButton setBackgroundImage:buttonH forState:UIControlStateHighlighted]; - [flagButton setBackgroundImage:buttonN forState:UIControlStateNormal]; - flagButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; - flagButton.exclusiveTouch = YES; - - [self addSubview:flagButton]; titleWidth -= (MARK_BUTTON_WIDTH + BUTTON_SPACE); - - markButton = flagButton; markButton.enabled = NO; markButton.tag = NSIntegerMin; - - markImageN = [UIImage imageNamed:@"Reader-Mark-N"]; // N image - markImageY = [UIImage imageNamed:@"Reader-Mark-Y"]; // Y image + UIBarButtonItem *flagButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Reader-Mark-N"] style:UIBarButtonItemStylePlain target:self action:@selector(markButtonTapped:)]; + [navigationBarItems addObject:flagButton]; #endif // end of READER_BOOKMARKS Option @@ -157,20 +108,9 @@ - (id)initWithFrame:(CGRect)frame document:(ReaderDocument *)object if (fileSize < (unsigned long long)15728640) // Check attachment size limit (15MB) { - rightButtonX -= (EMAIL_BUTTON_WIDTH + BUTTON_SPACE); - - UIButton *emailButton = [UIButton buttonWithType:UIButtonTypeCustom]; - - emailButton.frame = CGRectMake(rightButtonX, BUTTON_Y, EMAIL_BUTTON_WIDTH, BUTTON_HEIGHT); - [emailButton setImage:[UIImage imageNamed:@"Reader-Email"] forState:UIControlStateNormal]; - [emailButton addTarget:self action:@selector(emailButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; - [emailButton setBackgroundImage:buttonH forState:UIControlStateHighlighted]; - [emailButton setBackgroundImage:buttonN forState:UIControlStateNormal]; - emailButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; - emailButton.exclusiveTouch = YES; - - [self addSubview:emailButton]; titleWidth -= (EMAIL_BUTTON_WIDTH + BUTTON_SPACE); - } + UIBarButtonItem *emailButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Reader-Email"] style:UIBarButtonItemStylePlain target:self action:@selector(emailButtonTapped:)]; + [navigationBarItems addObject:emailButton]; + } } #endif // end of READER_ENABLE_MAIL Option @@ -183,44 +123,21 @@ - (id)initWithFrame:(CGRect)frame document:(ReaderDocument *)object if ((printInteractionController != nil) && [printInteractionController isPrintingAvailable]) { - rightButtonX -= (PRINT_BUTTON_WIDTH + BUTTON_SPACE); - - UIButton *printButton = [UIButton buttonWithType:UIButtonTypeCustom]; - - printButton.frame = CGRectMake(rightButtonX, BUTTON_Y, PRINT_BUTTON_WIDTH, BUTTON_HEIGHT); - [printButton setImage:[UIImage imageNamed:@"Reader-Print"] forState:UIControlStateNormal]; - [printButton addTarget:self action:@selector(printButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; - [printButton setBackgroundImage:buttonH forState:UIControlStateHighlighted]; - [printButton setBackgroundImage:buttonN forState:UIControlStateNormal]; - printButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; - printButton.exclusiveTouch = YES; - - [self addSubview:printButton]; titleWidth -= (PRINT_BUTTON_WIDTH + BUTTON_SPACE); + UIBarButtonItem *printButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Reader-Print"] style:UIBarButtonItemStylePlain target:self action:@selector(printButtonTapped:)]; + [navigationBarItems addObject:printButton]; } } #endif // end of READER_ENABLE_PRINT Option - + + [navigationItem setRightBarButtonItems:navigationBarItems]; + if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { - CGRect titleRect = CGRectMake(titleX, BUTTON_Y, titleWidth, TITLE_HEIGHT); - - UILabel *titleLabel = [[UILabel alloc] initWithFrame:titleRect]; - - titleLabel.textAlignment = NSTextAlignmentCenter; - titleLabel.font = [UIFont systemFontOfSize:19.0f]; - titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; - titleLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters; - titleLabel.textColor = [UIColor colorWithWhite:0.0f alpha:1.0f]; - titleLabel.shadowColor = [UIColor colorWithWhite:0.65f alpha:1.0f]; - titleLabel.backgroundColor = [UIColor clearColor]; - titleLabel.shadowOffset = CGSizeMake(0.0f, 1.0f); - titleLabel.adjustsFontSizeToFitWidth = YES; - titleLabel.minimumScaleFactor = 0.75f; - titleLabel.text = [object.fileName stringByDeletingPathExtension]; - - [self addSubview:titleLabel]; + navigationItem.title = (object.title.length > 0 ? object.title : [object.fileName stringByDeletingPathExtension]); } + + [navigationBar setItems:@[navigationItem]]; } return self; diff --git a/Sources/ReaderViewController.h b/Sources/ReaderViewController.h index 11da1073..1c8aa92a 100644 --- a/Sources/ReaderViewController.h +++ b/Sources/ReaderViewController.h @@ -41,6 +41,12 @@ @property (nonatomic, weak, readwrite) id delegate; +#pragma mark - +#pragma mark Initialization - (id)initWithReaderDocument:(ReaderDocument *)object; +#pragma mark - +#pragma mark Convenience Methods +- (void)showDocumentPage:(NSInteger)page; + @end diff --git a/Sources/ReaderViewController.m b/Sources/ReaderViewController.m index 3ea1e029..2ab7c1b7 100644 --- a/Sources/ReaderViewController.m +++ b/Sources/ReaderViewController.m @@ -845,7 +845,7 @@ - (void)tappedInToolbar:(ReaderMainToolbar *)toolbar emailButton:(UIButton *)but if (fileSize < (unsigned long long)15728640) // Check attachment size limit (15MB) { - NSURL *fileURL = document.fileURL; NSString *fileName = document.fileName; // Document + NSURL *fileURL = document.fileURL; NSString *fileName = [document.title stringByAppendingPathExtension:@"pdf"]; // Document NSData *attachment = [NSData dataWithContentsOfURL:fileURL options:(NSDataReadingMapped|NSDataReadingUncached) error:nil]; @@ -855,7 +855,7 @@ - (void)tappedInToolbar:(ReaderMainToolbar *)toolbar emailButton:(UIButton *)but [mailComposer addAttachmentData:attachment mimeType:@"application/pdf" fileName:fileName]; - [mailComposer setSubject:fileName]; // Use the document file name for the subject + [mailComposer setSubject:document.title]; // Use the document file name for the subject mailComposer.modalTransitionStyle = UIModalTransitionStyleCoverVertical; mailComposer.modalPresentationStyle = UIModalPresentationFormSheet; diff --git a/Sources/_ReaderMainToolbar.h b/Sources/_ReaderMainToolbar.h new file mode 100644 index 00000000..9ca51a67 --- /dev/null +++ b/Sources/_ReaderMainToolbar.h @@ -0,0 +1,56 @@ +// +// ReaderMainToolbar.h +// Reader v2.6.0 +// +// Created by Julius Oklamcak on 2011-07-01. +// Copyright © 2011-2013 Julius Oklamcak. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to +// do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +#import + +#import "UIXToolbarView.h" + +@class ReaderMainToolbar; +@class ReaderDocument; + +@protocol ReaderMainToolbarDelegate + +@required // Delegate protocols + +- (void)tappedInToolbar:(ReaderMainToolbar *)toolbar doneButton:(UIButton *)button; +- (void)tappedInToolbar:(ReaderMainToolbar *)toolbar thumbsButton:(UIButton *)button; +- (void)tappedInToolbar:(ReaderMainToolbar *)toolbar printButton:(UIButton *)button; +- (void)tappedInToolbar:(ReaderMainToolbar *)toolbar emailButton:(UIButton *)button; +- (void)tappedInToolbar:(ReaderMainToolbar *)toolbar markButton:(UIButton *)button; + +@end + +@interface ReaderMainToolbar : UIXToolbarView + +@property (nonatomic, unsafe_unretained, readwrite) id delegate; + +- (id)initWithFrame:(CGRect)frame document:(ReaderDocument *)object; + +- (void)setBookmarkState:(BOOL)state; + +- (void)hideToolbar; +- (void)showToolbar; + +@end diff --git a/Sources/_ReaderMainToolbar.m b/Sources/_ReaderMainToolbar.m new file mode 100644 index 00000000..cc62b193 --- /dev/null +++ b/Sources/_ReaderMainToolbar.m @@ -0,0 +1,331 @@ +// +// ReaderMainToolbar.m +// Reader v2.6.2 +// +// Created by Julius Oklamcak on 2011-07-01. +// Copyright © 2011-2013 Julius Oklamcak. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to +// do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +#import "ReaderConstants.h" +#import "ReaderMainToolbar.h" +#import "ReaderDocument.h" + +#import + +@implementation ReaderMainToolbar +{ + UIButton *markButton; + + UIImage *markImageN; + UIImage *markImageY; +} + +#pragma mark Constants + +#define BUTTON_X 8.0f +#define BUTTON_Y 8.0f +#define BUTTON_SPACE 8.0f +#define BUTTON_HEIGHT 30.0f + +#define DONE_BUTTON_WIDTH 56.0f +#define THUMBS_BUTTON_WIDTH 40.0f +#define PRINT_BUTTON_WIDTH 40.0f +#define EMAIL_BUTTON_WIDTH 40.0f +#define MARK_BUTTON_WIDTH 40.0f + +#define TITLE_HEIGHT 28.0f + +#pragma mark Properties + +@synthesize delegate; + +#pragma mark ReaderMainToolbar instance methods + +- (id)initWithFrame:(CGRect)frame +{ + return [self initWithFrame:frame document:nil]; +} + +- (id)initWithFrame:(CGRect)frame document:(ReaderDocument *)object +{ + assert(object != nil); // Must have a valid ReaderDocument + + if ((self = [super initWithFrame:frame])) + { + CGFloat viewWidth = self.bounds.size.width; + + UIImage *imageH = [UIImage imageNamed:@"Reader-Button-H"]; + UIImage *imageN = [UIImage imageNamed:@"Reader-Button-N"]; + + UIImage *buttonH = [imageH stretchableImageWithLeftCapWidth:5 topCapHeight:0]; + UIImage *buttonN = [imageN stretchableImageWithLeftCapWidth:5 topCapHeight:0]; + + CGFloat titleX = BUTTON_X; CGFloat titleWidth = (viewWidth - (titleX + titleX)); + + CGFloat leftButtonX = BUTTON_X; // Left button start X position + +#if (READER_STANDALONE == FALSE) // Option + + UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; + + doneButton.frame = CGRectMake(leftButtonX, BUTTON_Y, DONE_BUTTON_WIDTH, BUTTON_HEIGHT); + [doneButton setTitle:NSLocalizedString(@"Done", @"button") forState:UIControlStateNormal]; + [doneButton setTitleColor:[UIColor colorWithWhite:0.0f alpha:1.0f] forState:UIControlStateNormal]; + [doneButton setTitleColor:[UIColor colorWithWhite:1.0f alpha:1.0f] forState:UIControlStateHighlighted]; + [doneButton addTarget:self action:@selector(doneButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; + [doneButton setBackgroundImage:buttonH forState:UIControlStateHighlighted]; + [doneButton setBackgroundImage:buttonN forState:UIControlStateNormal]; + doneButton.titleLabel.font = [UIFont systemFontOfSize:14.0f]; + doneButton.autoresizingMask = UIViewAutoresizingNone; + doneButton.exclusiveTouch = YES; + + [self addSubview:doneButton]; leftButtonX += (DONE_BUTTON_WIDTH + BUTTON_SPACE); + + titleX += (DONE_BUTTON_WIDTH + BUTTON_SPACE); titleWidth -= (DONE_BUTTON_WIDTH + BUTTON_SPACE); + +#endif // end of READER_STANDALONE Option + +#if (READER_ENABLE_THUMBS == TRUE) // Option + + UIButton *thumbsButton = [UIButton buttonWithType:UIButtonTypeCustom]; + + thumbsButton.frame = CGRectMake(leftButtonX, BUTTON_Y, THUMBS_BUTTON_WIDTH, BUTTON_HEIGHT); + [thumbsButton setImage:[UIImage imageNamed:@"Reader-Thumbs"] forState:UIControlStateNormal]; + [thumbsButton addTarget:self action:@selector(thumbsButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; + [thumbsButton setBackgroundImage:buttonH forState:UIControlStateHighlighted]; + [thumbsButton setBackgroundImage:buttonN forState:UIControlStateNormal]; + thumbsButton.autoresizingMask = UIViewAutoresizingNone; + thumbsButton.exclusiveTouch = YES; + + [self addSubview:thumbsButton]; //leftButtonX += (THUMBS_BUTTON_WIDTH + BUTTON_SPACE); + + titleX += (THUMBS_BUTTON_WIDTH + BUTTON_SPACE); titleWidth -= (THUMBS_BUTTON_WIDTH + BUTTON_SPACE); + +#endif // end of READER_ENABLE_THUMBS Option + +#if (READER_BOOKMARKS == TRUE || READER_ENABLE_MAIL == TRUE || READER_ENABLE_PRINT == TRUE) + + CGFloat rightButtonX = viewWidth; // Right button start X position + +#endif // end of READER_BOOKMARKS || READER_ENABLE_MAIL || READER_ENABLE_PRINT Options + +#if (READER_BOOKMARKS == TRUE) // Option + + rightButtonX -= (MARK_BUTTON_WIDTH + BUTTON_SPACE); + + UIButton *flagButton = [UIButton buttonWithType:UIButtonTypeCustom]; + + flagButton.frame = CGRectMake(rightButtonX, BUTTON_Y, MARK_BUTTON_WIDTH, BUTTON_HEIGHT); + //[flagButton setImage:[UIImage imageNamed:@"Reader-Mark-N"] forState:UIControlStateNormal]; + [flagButton addTarget:self action:@selector(markButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; + [flagButton setBackgroundImage:buttonH forState:UIControlStateHighlighted]; + [flagButton setBackgroundImage:buttonN forState:UIControlStateNormal]; + flagButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; + flagButton.exclusiveTouch = YES; + + [self addSubview:flagButton]; titleWidth -= (MARK_BUTTON_WIDTH + BUTTON_SPACE); + + markButton = flagButton; markButton.enabled = NO; markButton.tag = NSIntegerMin; + + markImageN = [UIImage imageNamed:@"Reader-Mark-N"]; // N image + markImageY = [UIImage imageNamed:@"Reader-Mark-Y"]; // Y image + +#endif // end of READER_BOOKMARKS Option + +#if (READER_ENABLE_MAIL == TRUE) // Option + + if ([MFMailComposeViewController canSendMail] == YES) // Can email + { + unsigned long long fileSize = [object.fileSize unsignedLongLongValue]; + + if (fileSize < (unsigned long long)15728640) // Check attachment size limit (15MB) + { + rightButtonX -= (EMAIL_BUTTON_WIDTH + BUTTON_SPACE); + + UIButton *emailButton = [UIButton buttonWithType:UIButtonTypeCustom]; + + emailButton.frame = CGRectMake(rightButtonX, BUTTON_Y, EMAIL_BUTTON_WIDTH, BUTTON_HEIGHT); + [emailButton setImage:[UIImage imageNamed:@"Reader-Email"] forState:UIControlStateNormal]; + [emailButton addTarget:self action:@selector(emailButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; + [emailButton setBackgroundImage:buttonH forState:UIControlStateHighlighted]; + [emailButton setBackgroundImage:buttonN forState:UIControlStateNormal]; + emailButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; + emailButton.exclusiveTouch = YES; + + [self addSubview:emailButton]; titleWidth -= (EMAIL_BUTTON_WIDTH + BUTTON_SPACE); + } + } + +#endif // end of READER_ENABLE_MAIL Option + +#if (READER_ENABLE_PRINT == TRUE) // Option + + if (object.password == nil) // We can only print documents without passwords + { + Class printInteractionController = NSClassFromString(@"UIPrintInteractionController"); + + if ((printInteractionController != nil) && [printInteractionController isPrintingAvailable]) + { + rightButtonX -= (PRINT_BUTTON_WIDTH + BUTTON_SPACE); + + UIButton *printButton = [UIButton buttonWithType:UIButtonTypeCustom]; + + printButton.frame = CGRectMake(rightButtonX, BUTTON_Y, PRINT_BUTTON_WIDTH, BUTTON_HEIGHT); + [printButton setImage:[UIImage imageNamed:@"Reader-Print"] forState:UIControlStateNormal]; + [printButton addTarget:self action:@selector(printButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; + [printButton setBackgroundImage:buttonH forState:UIControlStateHighlighted]; + [printButton setBackgroundImage:buttonN forState:UIControlStateNormal]; + printButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; + printButton.exclusiveTouch = YES; + + [self addSubview:printButton]; titleWidth -= (PRINT_BUTTON_WIDTH + BUTTON_SPACE); + } + } + +#endif // end of READER_ENABLE_PRINT Option + + if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) + { + CGRect titleRect = CGRectMake(titleX, BUTTON_Y, titleWidth, TITLE_HEIGHT); + + UILabel *titleLabel = [[UILabel alloc] initWithFrame:titleRect]; + + titleLabel.textAlignment = UITextAlignmentCenter; + titleLabel.font = [UIFont systemFontOfSize:19.0f]; + titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; + titleLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters; + titleLabel.textColor = [UIColor colorWithWhite:0.0f alpha:1.0f]; + titleLabel.shadowColor = [UIColor colorWithWhite:0.65f alpha:1.0f]; + titleLabel.backgroundColor = [UIColor clearColor]; + titleLabel.shadowOffset = CGSizeMake(0.0f, 1.0f); + titleLabel.adjustsFontSizeToFitWidth = YES; + titleLabel.minimumFontSize = 14.0f; + titleLabel.text = titleLabel.text = (object.title.length > 0 ? object.title : [object.fileName stringByDeletingPathExtension]); + + [self addSubview:titleLabel]; + } + } + + return self; +} + +- (void)setBookmarkState:(BOOL)state +{ +#if (READER_BOOKMARKS == TRUE) // Option + + if (state != markButton.tag) // Only if different state + { + if (self.hidden == NO) // Only if toolbar is visible + { + UIImage *image = (state ? markImageY : markImageN); + + [markButton setImage:image forState:UIControlStateNormal]; + } + + markButton.tag = state; // Update bookmarked state tag + } + + if (markButton.enabled == NO) markButton.enabled = YES; + +#endif // end of READER_BOOKMARKS Option +} + +- (void)updateBookmarkImage +{ +#if (READER_BOOKMARKS == TRUE) // Option + + if (markButton.tag != NSIntegerMin) // Valid tag + { + BOOL state = markButton.tag; // Bookmarked state + + UIImage *image = (state ? markImageY : markImageN); + + [markButton setImage:image forState:UIControlStateNormal]; + } + + if (markButton.enabled == NO) markButton.enabled = YES; + +#endif // end of READER_BOOKMARKS Option +} + +- (void)hideToolbar +{ + if (self.hidden == NO) + { + [UIView animateWithDuration:0.25 delay:0.0 + options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction + animations:^(void) + { + self.alpha = 0.0f; + } + completion:^(BOOL finished) + { + self.hidden = YES; + } + ]; + } +} + +- (void)showToolbar +{ + if (self.hidden == YES) + { + [self updateBookmarkImage]; // First + + [UIView animateWithDuration:0.25 delay:0.0 + options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction + animations:^(void) + { + self.hidden = NO; + self.alpha = 1.0f; + } + completion:NULL + ]; + } +} + +#pragma mark UIButton action methods + +- (void)doneButtonTapped:(UIButton *)button +{ + [delegate tappedInToolbar:self doneButton:button]; +} + +- (void)thumbsButtonTapped:(UIButton *)button +{ + [delegate tappedInToolbar:self thumbsButton:button]; +} + +- (void)printButtonTapped:(UIButton *)button +{ + [delegate tappedInToolbar:self printButton:button]; +} + +- (void)emailButtonTapped:(UIButton *)button +{ + [delegate tappedInToolbar:self emailButton:button]; +} + +- (void)markButtonTapped:(UIButton *)button +{ + [delegate tappedInToolbar:self markButton:button]; +} + +@end