Skip to content

Commit

Permalink
Added ability to have Portrait/Landscape launch images along with a D…
Browse files Browse the repository at this point in the history
…efault one
  • Loading branch information
codeboyer committed Apr 28, 2011
1 parent 96c40ca commit c73fd00
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
1 change: 0 additions & 1 deletion PhoneGapLib/Classes/PhoneGapDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
IBOutlet UIWebView *webView;
IBOutlet PhoneGapViewController *viewController;

IBOutlet UIImageView *imageView;
IBOutlet UIActivityIndicatorView *activityView;

NSURLConnection *conn; // added by urbian
Expand Down
20 changes: 8 additions & 12 deletions PhoneGapLib/Classes/PhoneGapDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NSNumber *useLocation = [settings objectForKey:@"UseLocation"];
NSString *topActivityIndicator = [settings objectForKey:@"TopActivityIndicator"];


// The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait)
[[UIApplication sharedApplication] setStatusBarOrientation:[[supportedOrientations objectAtIndex:0] intValue]];

// Set the supported orientations for rotation. If number of items in the array is > 1, autorotate is supported
viewController.supportedOrientations = supportedOrientations;


CGRect screenBounds = [ [ UIScreen mainScreen ] bounds ];
self.window = [ [ [ UIWindow alloc ] initWithFrame:screenBounds ] autorelease ];

Expand Down Expand Up @@ -259,12 +254,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
* imageView - is the Default loading screen, it stay up until the app and UIWebView (WebKit) has completly loaded.
* You can change this image by swapping out the Default.png file within the resource folder.
*/
UIImage* image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]];
imageView = [[UIImageView alloc] initWithImage:image];
[image release];

UIImageView* imageView = [[UIImageView alloc] init];
imageView.tag = 1;
[window addSubview:imageView];
viewController.launchImage = imageView;
[viewController setDisplayLaunchImage:UIInterfaceOrientationPortrait];
[viewController.view addSubview:imageView];
[viewController.view bringSubviewToFront:imageView];
[imageView release];

/*
Expand Down Expand Up @@ -415,7 +410,9 @@ - (void)webViewDidFinishLoad:(UIWebView *)theWebView {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
activityView.hidden = YES;

imageView.hidden = YES;
viewController.launchImage.hidden = YES;
[viewController.launchImage removeFromSuperview];
viewController.launchImage = nil;

[window bringSubviewToFront:viewController.view];
webView = theWebView;
Expand Down Expand Up @@ -615,7 +612,6 @@ - (void)dealloc
{
[PluginResult releaseStatus];
[commandObjects release];
[imageView release];
[viewController release];
[activityView release];
[window release];
Expand Down
3 changes: 3 additions & 0 deletions PhoneGapLib/Classes/PhoneGapViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
@interface PhoneGapViewController : UIViewController {
IBOutlet UIWebView *webView;
NSArray* supportedOrientations;
UIImageView* launchImage;
}

@property (nonatomic, retain) NSArray* supportedOrientations;
@property (nonatomic, retain) UIWebView* webView;
@property (nonatomic, retain) UIImageView* launchImage;

- (void)setDisplayLaunchImage: (UIInterfaceOrientation)orientation;

@end
34 changes: 30 additions & 4 deletions PhoneGapLib/Classes/PhoneGapViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@implementation PhoneGapViewController

@synthesize supportedOrientations, webView;
@synthesize supportedOrientations, webView, launchImage;

- (id) init
{
Expand Down Expand Up @@ -69,17 +69,43 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfac
return NO;
}

- (void)setDisplayLaunchImage: (UIInterfaceOrientation)orientation
{
if(launchImage == nil)
return;

NSString* imageName = @"Default";
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if(UIInterfaceOrientationIsPortrait(orientation)){
imageName = @"Default-Portrait";
}else if(UIInterfaceOrientationIsLandscape(orientation)){
imageName = @"Default-Landscape";
}
}

UIImage* image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]];
[launchImage setImage:image];
[launchImage setFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
[image release];
}

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self setDisplayLaunchImage:toInterfaceOrientation];
}

/**
Called by UIKit when the device starts to rotate to a new orientation. This fires the \c setOrientation
method on the Orientation object in JavaScript. Look at the JavaScript documentation for more information.
*/
- (void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation
{
int i = 0;

switch (self.interfaceOrientation){
case UIInterfaceOrientationPortrait:
i = 0;
i = 0;
break;
case UIInterfaceOrientationPortraitUpsideDown:
i = 180;
Expand All @@ -91,7 +117,7 @@ - (void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterface
i = 90;
break;
}

NSString* jsCallback = [NSString stringWithFormat:@"window.__defineGetter__('orientation',function(){return %d;});window.onorientationchange();",i];
[webView stringByEvaluatingJavaScriptFromString:jsCallback];

Expand Down

1 comment on commit c73fd00

@RandyMcMillan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PhoneGapDelegate.h....? For xcode 4 template?

ifdef PHONEGAP_FRAMEWORK

import <PhoneGap/JSON.h>

else

import "JSON.h"

endif

Please sign in to comment.