Skip to content

Commit

Permalink
Landscape support (without the background loading image)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzph committed Oct 30, 2009
1 parent 86aea91 commit 23d316c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.DS_Store
40 changes: 40 additions & 0 deletions Twitter+OAuth/Libraries & Headers/jQueryInjectLandscape.txt
@@ -0,0 +1,40 @@
$('html').css({'-webkit-background-size':'360px'});
$('body').css({'font-size':'12px','background':'#9AE4E8'});
$('#header').width(430);
$('.signin-content').css({'padding' : '15px','width' : '430px'});
$('#twitainer').width(430);
$('#twitainer').css({'margin-left' : '8px'});
$('#login_form').width(30);
$('#content').width(430);
$('#content').css({'margin':'0px','float':'left'});
$('.tos').hide();
$('.newtos').css({'text-align':'left', 'border':'1px solid red','color':'#555555','font-size':'12px','line-height':'1.3','margin':'20px 15px 5px'});
$('.newtos p').css({'margin' : '8px'});
$('h2').hide();
$('.oauth-errors').after("<br/><div class='newtos'>" + $('.tos').html() + "</div>");
$("label:contains('Username or Email: ')").html("Username: ");
$(".app-icon").attr({align : "right"});
$(".app-icon").css({'margin': '20px 0px 0px 0px;', 'border': '0px solid black', 'padding' : '-20px 0 0 10px'});
$('#signin_form .text').width(155);
$('#signin_form .password').width(155);
$('h4').after("<br/>");
$('#signin_form').css({'padding-top': '0'});
$("h4").width(410);
$("h4").css('font-size', '12px');
$("h4").html($("h4").html().replace(/This application/, '<br/><br/>This application'));
$('.buttons').css({'margin-left' : '-17px' , 'width':'300'});
$('#deny').css({'-webkit-transform': 'scale(0.9)'});
$('#allow').css({'-webkit-transform': 'scale(0.9)'});
$('#oauth_pin').css({'-webkit-transform': 'scale(0.5)'});
$('.newtos').css({'border':'1px solid #A9BF74', 'background-color':'#E8FECD'});
$('.newtos p').css({'margin':'8px'});

// This rearranges the allow and deny buttons so that
// the allow button is the first of the two input[type=submit]
// This allows the "Go" button on the UIWebView's keyboard
// to trigger an allow, instead of a deny.
var deny = $( '#deny' );
var allow = $( '#allow' );
$('div.buttons').empty();
$('div.buttons').append( allow );
$('div.buttons').append( deny );
Expand Up @@ -30,16 +30,21 @@

id <SA_OAuthTwitterControllerDelegate> _delegate;
UIActivityIndicatorView *_activityIndicator;

UIInterfaceOrientation _orientation;
}


@property (nonatomic, readwrite, retain) SA_OAuthTwitterEngine *engine;
@property (nonatomic, readwrite, assign) id <SA_OAuthTwitterControllerDelegate> delegate;
@property (nonatomic, readonly) UINavigationBar *navigationBar;

@property (nonatomic) UIInterfaceOrientation orientation;

+ (SA_OAuthTwitterController *) controllerToEnterCredentialsWithTwitterEngine: (SA_OAuthTwitterEngine *) engine delegate: (id <SA_OAuthTwitterControllerDelegate>) delegate forOrientation:(UIInterfaceOrientation)theOrientation;
+ (SA_OAuthTwitterController *) controllerToEnterCredentialsWithTwitterEngine: (SA_OAuthTwitterEngine *) engine delegate: (id <SA_OAuthTwitterControllerDelegate>) delegate;
+ (BOOL) credentialEntryRequiredWithTwitterEngine: (SA_OAuthTwitterEngine *) engine;


- (id) initWithEngine: (SA_OAuthTwitterEngine *) engine;
- (id) initWithEngine: (SA_OAuthTwitterEngine *) engine andOrientation:(UIInterfaceOrientation)theOrientation;
@end
76 changes: 53 additions & 23 deletions Twitter+OAuth/SAOAuthTwitterEngine/SA_OAuthTwitterController.m
Expand Up @@ -24,7 +24,7 @@ - (void) setDetectsPhoneNumbers: (BOOL) detects;
@end

@implementation SA_OAuthTwitterController
@synthesize engine = _engine, delegate = _delegate, navigationBar = _navBar;
@synthesize engine = _engine, delegate = _delegate, navigationBar = _navBar, orientation = _orientation;


- (void) dealloc {
Expand All @@ -41,28 +41,37 @@ - (void) dealloc {
[super dealloc];
}

+ (SA_OAuthTwitterController *) controllerToEnterCredentialsWithTwitterEngine: (SA_OAuthTwitterEngine *) engine delegate: (id <SA_OAuthTwitterControllerDelegate>) delegate {
+ (SA_OAuthTwitterController *) controllerToEnterCredentialsWithTwitterEngine: (SA_OAuthTwitterEngine *) engine delegate: (id <SA_OAuthTwitterControllerDelegate>) delegate forOrientation:(UIInterfaceOrientation)theOrientation {
if (![self credentialEntryRequiredWithTwitterEngine: engine]) return nil; //not needed

SA_OAuthTwitterController *controller = [[[SA_OAuthTwitterController alloc] initWithEngine: engine] autorelease];

SA_OAuthTwitterController *controller = [[[SA_OAuthTwitterController alloc] initWithEngine:engine andOrientation:theOrientation] autorelease];
controller.delegate = delegate;
return controller;
}

+ (SA_OAuthTwitterController *) controllerToEnterCredentialsWithTwitterEngine: (SA_OAuthTwitterEngine *) engine delegate: (id <SA_OAuthTwitterControllerDelegate>) delegate {
return [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:engine delegate:delegate forOrientation:UIInterfaceOrientationPortrait];
}


+ (BOOL) credentialEntryRequiredWithTwitterEngine: (SA_OAuthTwitterEngine *) engine {
return ![engine isAuthorized];
}


- (id) initWithEngine: (SA_OAuthTwitterEngine *) engine {
- (id) initWithEngine: (SA_OAuthTwitterEngine *) engine andOrientation:(UIInterfaceOrientation)theOrientation {
if (self = [super init]) {
self.engine = engine;

self.orientation = theOrientation;

_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhite];
_activityIndicator.hidesWhenStopped = YES;

_webView = [[UIWebView alloc] initWithFrame: CGRectMake(0, 44, 320, 416)];
if ( UIInterfaceOrientationIsLandscape( self.orientation ) )
_webView = [[UIWebView alloc] initWithFrame: CGRectMake(0, 32, 480, 288)];
else
_webView = [[UIWebView alloc] initWithFrame: CGRectMake(0, 44, 320, 416)];

_webView.delegate = self;
_webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
if ([_webView respondsToSelector: @selector(setDetectsPhoneNumbers:)]) [(id) _webView setDetectsPhoneNumbers: NO];
Expand Down Expand Up @@ -99,47 +108,68 @@ - (void) cancel: (id) sender {
#pragma mark View Controller Stuff
- (void) loadView {
[super loadView];
self.view = [[[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 416)] autorelease];
_backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kGGTwitterLoadingBackgroundImage]];
_backgroundView.frame = CGRectMake(0, 44, 320, 416);

UIActivityIndicatorView* spinner = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
[spinner startAnimating];
spinner.frame = CGRectMake((320 / 2) - (spinner.bounds.size.width / 2),
(416 / 2) - (spinner.bounds.size.height / 2),
spinner.bounds.size.width,
spinner.bounds.size.height);
_backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kGGTwitterLoadingBackgroundImage]];
if ( UIInterfaceOrientationIsLandscape( self.orientation ) ) {
self.view = [[[UIView alloc] initWithFrame: CGRectMake(0, 0, 480, 288)] autorelease];
_backgroundView.frame = CGRectMake(0, 44, 480, 288);
spinner.frame = CGRectMake((480 / 2) - (spinner.bounds.size.width / 2),
(288 / 2) - (spinner.bounds.size.height / 2),
spinner.bounds.size.width,
spinner.bounds.size.height);

_navBar = [[[UINavigationBar alloc] initWithFrame: CGRectMake(0, 0, 480, 32)] autorelease];
}
else {
self.view = [[[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 416)] autorelease];
_backgroundView.frame = CGRectMake(0, 44, 320, 416);
spinner.frame = CGRectMake((320 / 2) - (spinner.bounds.size.width / 2),
(416 / 2) - (spinner.bounds.size.height / 2),
spinner.bounds.size.width,
spinner.bounds.size.height);

_navBar = [[[UINavigationBar alloc] initWithFrame: CGRectMake(0, 0, 320, 44)] autorelease];
}
[_backgroundView addSubview:spinner];

[self.view addSubview:_backgroundView];

if ( !UIInterfaceOrientationIsLandscape( self.orientation ) )
[self.view addSubview:_backgroundView];

[self.view addSubview: _webView];

_navBar = [[[UINavigationBar alloc] initWithFrame: CGRectMake(0, 0, 320, 44)] autorelease];
[self.view addSubview: _navBar];

UINavigationItem *navItem = [[[UINavigationItem alloc] initWithTitle: NSLocalizedString(@"Twitter Info", @"Twitter Info")] autorelease];
navItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCancel target: self action: @selector(cancel:)] autorelease];

[_navBar pushNavigationItem: navItem animated: NO];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == self.orientation);
}

//=============================================================================================================================
#pragma mark Webview Delegate stuff
- (void) webViewDidFinishLoad: (UIWebView *) webView {
NSError *error;
NSString *path = [[NSBundle mainBundle] pathForResource: @"jQueryInject" ofType: @"txt"];
NSString *path = [[NSBundle mainBundle]
pathForResource:
UIInterfaceOrientationIsLandscape( self.orientation ) ? @"jQueryInjectLandscape" : @"jQueryInject"
ofType:@"txt"];

NSString *dataSource = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];

if (dataSource == nil) {
NSLog(@"An error occured while processing the jQueryInject file");
}

[_webView stringByEvaluatingJavaScriptFromString:dataSource]; //This line injects the jQuery to make it look better

NSString *authPin = [[_webView stringByEvaluatingJavaScriptFromString: @"document.getElementById('oauth_pin').innerHTML"] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];

if (authPin.length == 0) authPin = [[_webView stringByEvaluatingJavaScriptFromString: @"document.getElementById('oauth_pin').getElementsByTagName('a')[0].innerHTML"] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];

[_activityIndicator stopAnimating];
Expand Down

0 comments on commit 23d316c

Please sign in to comment.