Skip to content

Commit

Permalink
Implemented two-finger swipe navigation proof of concept, better navi…
Browse files Browse the repository at this point in the history
…gation in general.
  • Loading branch information
Workstation authored and Workstation committed Mar 11, 2012
1 parent 0c61c44 commit aa9fd1a
Show file tree
Hide file tree
Showing 215 changed files with 5,557 additions and 1,532 deletions.
6 changes: 5 additions & 1 deletion Humalog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
840BBB21150AF0BF00B681A7 /* plato.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = plato.pdf; sourceTree = "<group>"; };
840BBB24150AFAA900B681A7 /* AnnotationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnnotationView.h; sourceTree = "<group>"; };
840BBB25150AFAA900B681A7 /* AnnotationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnnotationView.m; sourceTree = "<group>"; };
840BBB2A150C675D00B681A7 /* ContentDisplayDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; name = ContentDisplayDelegate.h; path = Protocols/ContentDisplayDelegate.h; sourceTree = "<group>"; };
840BBB2A150C675D00B681A7 /* ContentDisplayDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ContentDisplayDelegate.h; path = Protocols/ContentDisplayDelegate.h; sourceTree = "<group>"; };
840BBB3A150C945F00B681A7 /* ToolControlDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ToolControlDelegate.h; path = Protocols/ToolControlDelegate.h; sourceTree = "<group>"; };
840BBB3C150C9EA900B681A7 /* ContentNotificationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ContentNotificationDelegate.h; path = Protocols/ContentNotificationDelegate.h; sourceTree = "<group>"; };
84C9DF8515009F6700E16B3B /* Humalog.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Humalog.app; sourceTree = BUILT_PRODUCTS_DIR; };
84C9DF8915009F6700E16B3B /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
84C9DF8B15009F6700E16B3B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -189,6 +191,8 @@
840BBB131509E39700B681A7 /* ContentControlProtocol.h */,
840BBB181509EB6000B681A7 /* NavigationControlDelegate.h */,
840BBB2A150C675D00B681A7 /* ContentDisplayDelegate.h */,
840BBB3A150C945F00B681A7 /* ToolControlDelegate.h */,
840BBB3C150C9EA900B681A7 /* ContentNotificationDelegate.h */,
);
name = Protocols;
sourceTree = "<group>";
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEWorkspaceUserSettings_HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges</key>
<true/>
<key>IDEWorkspaceUserSettings_SnapshotAutomaticallyBeforeSignificantChanges</key>
<false/>
</dict>
</plist>
5 changes: 2 additions & 3 deletions Humalog/Controllers/MasterController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
#import <UIKit/UIKit.h>
#import "NavigationControlDelegate.h"
#import "ContentDisplayDelegate.h"
#import "ToolControlDelegate.h"

@interface MasterController : UIViewController<NavigationControlDelegate, ContentDisplayDelegate> {
int currentContentScreen;
}
@interface MasterController : UIViewController<NavigationControlDelegate, ToolControlDelegate, ContentDisplayDelegate, UIGestureRecognizerDelegate>

@end
149 changes: 114 additions & 35 deletions Humalog/Controllers/MasterController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
#import "MenubarView.h"
#import "AnnotationView.h"

#define FADE_DURATION 0.5
#define FADE_DURATION 0.25

// Private
@interface MasterController() {
ContentProvider *contentProvider;
UIView<ContentControlProtocol> *contentView;
ToolbarView *toolbarView;
MenubarView *menubarView;
AnnotationView *annotationView;
int currentContentScreen;
}
- (void)discardToolbar;
- (void)fadeOut;
- (void)fadeOutToAction:(void(^)(void))action;
- (void)fadeIn;
- (void)loadContent;
@end
Expand Down Expand Up @@ -61,11 +63,11 @@ - (void)loadView
{
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; //[[UIScreen mainScreen] bounds]];
// Initialization code
self.view.backgroundColor = [UIColor whiteColor];
self.view.backgroundColor = [UIColor purpleColor];

// Subviews
toolbarView = [[ToolbarView alloc] init];
MenubarView *menubarView = [[MenubarView alloc] init];
menubarView = [[MenubarView alloc] init];
contentView = [contentProvider viewForDocumentAtIndex:currentContentScreen];

menubarView.frame = CGRectMake(0, self.view.frame.size.height - menubarView.image.size.height,
Expand All @@ -80,7 +82,8 @@ - (void)loadView
[self.view addSubview:annotationView];

// Delegation
toolbarView.navigationDelegate = self;
toolbarView.navigationDelegate = self;
toolbarView.toolControlDelegate = self;

// Gestures & view for toolbar
UIView *gestureView = [[UIView alloc] initWithFrame:toolbarView.frame];
Expand All @@ -96,40 +99,43 @@ - (void)loadView

[self.view addSubview:gestureView];

// Navigation gestures
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeLeft setNumberOfTouchesRequired:2];
[contentView addGestureRecognizer:swipeLeft];
swipeLeft.delegate = self;

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[swipeRight setNumberOfTouchesRequired:2];
[contentView addGestureRecognizer:swipeRight];
swipeRight.delegate = self;

// Hide content views until content is loaded
contentView.alpha = 0.0;
annotationView.alpha = 0.0;
}

- (void)fadeOut
- (void)fadeOutToAction:(void(^)(void))action
{
[UIView animateWithDuration:FADE_DURATION
animations:^{
contentView.alpha = 0.0;
contentView.alpha = 0.0;
annotationView.alpha = 0.0;
}
completion:^(BOOL finished) {
action();
}];
}

- (void)fadeIn
{
[UIView animateWithDuration:FADE_DURATION
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
contentView.alpha = 1.0;
}
completion:^(BOOL finished) {

}];

[UIView animateWithDuration:FADE_DURATION
delay:FADE_DURATION / 2.0
options:0
animations:^{
contentView.alpha = 1.0;
annotationView.alpha = 1.0;
}
completion:^(BOOL finished) {


}];
}

Expand Down Expand Up @@ -159,6 +165,8 @@ - (void)discardToolbar
[toolbarView performSelector:@selector(hide) withObject:nil afterDelay:0.25];
}

// Document navigation

- (void)saveAnnotations
{
NSDictionary *annotations = [NSDictionary dictionaryWithObjectsAndKeys:
Expand All @@ -177,15 +185,55 @@ - (void)loadAnnotations

- (void)loadContent
{
[self fadeOut];
[self loadAnnotations];
contentView = [contentProvider viewForDocumentAtIndex:currentContentScreen];
[self fadeOutToAction:^{
[self loadAnnotations];
contentView = [contentProvider viewForDocumentAtIndex:currentContentScreen];
}];
}

// Delegation
- (void)loadPreviousDocument
{
[self saveAnnotations];
currentContentScreen = MAX(--currentContentScreen, [contentProvider first]);
[self loadContent];
}

- (void)loadNextDocument
{
[self saveAnnotations];
currentContentScreen = MIN(++currentContentScreen, [contentProvider count]);
[self loadContent];
}

- (void)loadFirstDocument
{
[self saveAnnotations];
currentContentScreen = [contentProvider first];
[self loadContent];
}

- (void)loadLastDocument
{
[self saveAnnotations];
currentContentScreen = [contentProvider count];
[self loadContent];
}

// Delegation
- (void)contentViewDidFinishLoad
{
[toolbarView contentChanged];
[menubarView contentChanged];

if (currentContentScreen == [contentProvider first]) {
[toolbarView contentStarted];
[menubarView contentStarted];
}
else if (currentContentScreen == [contentProvider count]) {
[toolbarView contentFinished];
[menubarView contentFinished];
}

[self fadeIn];
[self discardToolbar];
}
Expand All @@ -204,32 +252,63 @@ - (void)swipeDown:(UISwipeGestureRecognizer *)recognizer
[toolbarView show];
}

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

- (void)swipeLeft:(UISwipeGestureRecognizer *)recognizer
{
[self loadNextDocument];
}

- (void)swipeRight:(UISwipeGestureRecognizer *)recognizer
{
[self loadPreviousDocument];
}

- (void)tap:(UISwipeGestureRecognizer *)recognizer
{
CGPoint point = [recognizer locationInView:self.view];
if (CGRectContainsPoint(CGRectMake(0, 0, toolbarView.frame.size.width, toolbarView.frame.size.height), point))
[toolbarView toggle];
}

- (void)menubarViewDidPressApertura
{
[self loadFirstDocument];
}

- (void)menubarViewDidPressCierre
{
[self loadLastDocument];
}

- (void)menubarViewDidPressEstudios
{
NSLog(@"Estudios");
}

- (void)menubarViewDidPressIPP
{
NSLog(@"IPP");
}

- (void)toolbarViewDidPressBack
{
[self saveAnnotations];
currentContentScreen = MAX(--currentContentScreen, [contentProvider first]);
[self loadContent];
[self loadPreviousDocument];
}

- (void)toolbarViewDidPressForward
{
[self saveAnnotations];
currentContentScreen = MIN(++currentContentScreen, [contentProvider count]);
[self loadContent];
[self loadNextDocument];
}

- (void)toolbarViewDidPressPlay
{
[self fadeOut];
[contentView playAction];
[self discardToolbar];
[self fadeOutToAction:^{
[contentView playAction];
[self discardToolbar];
}];
}

- (void)toolbarViewDidSelectPen
Expand Down
2 changes: 1 addition & 1 deletion Humalog/Helpers/ContentProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Humalog
//
// Created by Workstation on 3/9/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
// Copyright (c) 2012 Astra Zeneca. All rights reserved.
//

#import <Foundation/Foundation.h>
Expand Down
30 changes: 18 additions & 12 deletions Humalog/Helpers/ContentProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Humalog
//
// Created by Workstation on 3/9/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
// Copyright (c) 2012 Astra Zeneca. All rights reserved.
//

#import "ContentProvider.h"
Expand Down Expand Up @@ -34,26 +34,32 @@ - (int)first

- (int)count
{
return 11;
return 13;
}

- (UIView<ContentControlProtocol> *)viewForDocumentAtIndex:(int)index
{
NSString *slideName = [@"slide" stringByAppendingString:[[NSNumber numberWithInt:index] stringValue]];
NSString *path = [[NSBundle mainBundle] pathForResource:slideName ofType:@"html" inDirectory:[@"slides/" stringByAppendingString:slideName]];

if (index == 1)
path = [[NSBundle mainBundle] pathForResource:@"plato" ofType:@"pdf"];
[[WebContentView sharedInstance] setScalesPageToFit:NO];
[[WebContentView sharedInstance] scrollView].scrollEnabled = NO;

if (path) {
NSURL *url = [NSURL URLWithString: [path lastPathComponent]
relativeToURL: [NSURL fileURLWithPath: [path stringByDeletingLastPathComponent]
isDirectory: YES]];

[[WebContentView sharedInstance] loadRequest:[NSURLRequest requestWithURL:url]];
return [WebContentView sharedInstance];
if (index == [self count]) {
path = [[NSBundle mainBundle] pathForResource:@"plato" ofType:@"pdf"];
[[WebContentView sharedInstance] setScalesPageToFit:YES];
[[WebContentView sharedInstance] scrollView].scrollEnabled = YES;
}
return nil;

if (!path)
return nil;

NSURL *url = [NSURL URLWithString: [path lastPathComponent]
relativeToURL: [NSURL fileURLWithPath: [path stringByDeletingLastPathComponent]
isDirectory: YES]];

[[WebContentView sharedInstance] loadRequest:[NSURLRequest requestWithURL:url]];
return [WebContentView sharedInstance];
}

- (NSDictionary *)annotationsForDocumentAtIndex:(int)index
Expand Down
2 changes: 1 addition & 1 deletion Humalog/Helpers/GridLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ + (id)gridWithFrame:(CGRect)frame numRows:(int)numRows numCols:(int)numCols
{
NSMutableArray *output = [[NSMutableArray alloc] init];
for (int i = 0; i < numRows; ++i) {
for (int j = 0; j < numCols; j++) {
for (int j = 0; j < numCols; ++j) {
float x = CGRectGetMinX(frame) + (j + 0.5) * (CGRectGetMaxX(frame) - CGRectGetMinX(frame)) / numCols;
float y = CGRectGetMinY(frame) + (i + 0.5) * (CGRectGetMaxY(frame) - CGRectGetMinY(frame)) / numRows;
[output addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]];
Expand Down
2 changes: 1 addition & 1 deletion Humalog/Protocols/ContentControlProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Humalog
//
// Created by Workstation on 3/9/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
// Copyright (c) 2012 Astra Zeneca. All rights reserved.
//

#import <Foundation/Foundation.h>
Expand Down
4 changes: 2 additions & 2 deletions Humalog/Protocols/ContentDisplayDelegate.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// ContentControlDelegate.h
// ContentDisplayDelegate.h
// Humalog
//
// Created by Workstation on 3/10/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
// Copyright (c) 2012 Astra Zeneca. All rights reserved.
//

#import <Foundation/Foundation.h>
Expand Down
15 changes: 15 additions & 0 deletions Humalog/Protocols/ContentNotificationDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ContentNotificationDelegate.h
// Humalog
//
// Created by Workstation on 3/11/12.
// Copyright (c) 2012 Astra Zeneca. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol ContentNotificationDelegate <NSObject>
- (void)contentStarted;
- (void)contentFinished;
- (void)contentChanged;
@end
Loading

0 comments on commit aa9fd1a

Please sign in to comment.