Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B4382983C for ; Fri, 13 Jan 2012 15:59:49 +0000 (UTC) Received: (qmail 76037 invoked by uid 500); 13 Jan 2012 15:59:49 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 75997 invoked by uid 500); 13 Jan 2012 15:59:49 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 75988 invoked by uid 99); 13 Jan 2012 15:59:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jan 2012 15:59:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.114] (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jan 2012 15:59:47 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id D14EF557E5; Fri, 13 Jan 2012 15:59:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: becka11y@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [9/50] git commit: Added splash screen code to PGViewController (not working properly yet) Message-Id: <20120113155906.D14EF557E5@tyr.zones.apache.org> Date: Fri, 13 Jan 2012 15:59:06 +0000 (UTC) Added splash screen code to PGViewController (not working properly yet) Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/0fcc80da Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/0fcc80da Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/0fcc80da Branch: refs/heads/master Commit: 0fcc80da7906d32bedb0cbc4cfbbfd43eb231d23 Parents: d36c60e Author: shazron Authored: Mon Jan 9 15:56:44 2012 -0800 Committer: shazron Committed: Mon Jan 9 15:56:44 2012 -0800 ---------------------------------------------------------------------- PhoneGapLib/Classes/PGSplashScreen.m | 7 +- PhoneGapLib/Classes/PGViewController.h | 3 + PhoneGapLib/Classes/PGViewController.m | 181 +++++++++++++++++++++++++-- PhoneGapLib/Classes/PhoneGapDelegate.h | 2 - PhoneGapLib/Classes/PhoneGapDelegate.m | 154 +---------------------- 5 files changed, 179 insertions(+), 168 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/0fcc80da/PhoneGapLib/Classes/PGSplashScreen.m ---------------------------------------------------------------------- diff --git a/PhoneGapLib/Classes/PGSplashScreen.m b/PhoneGapLib/Classes/PGSplashScreen.m index d70d870..8bff7ce 100644 --- a/PhoneGapLib/Classes/PGSplashScreen.m +++ b/PhoneGapLib/Classes/PGSplashScreen.m @@ -8,6 +8,7 @@ #import "PGSplashScreen.h" #import "PhoneGapDelegate.h" +#import "PGViewController.h" @implementation PGSplashScreen @@ -15,12 +16,12 @@ - (void) __show:(BOOL)show { PhoneGapDelegate* delegate = [super appDelegate]; - if (!delegate.imageView) { + if (!delegate.viewController.imageView) { return; } - delegate.imageView.hidden = !show; - delegate.activityView.hidden = !show; + delegate.viewController.imageView.hidden = !show; + delegate.viewController.activityView.hidden = !show; } - (void) show:(NSArray*)arguments withDict:(NSMutableDictionary*)options http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/0fcc80da/PhoneGapLib/Classes/PGViewController.h ---------------------------------------------------------------------- diff --git a/PhoneGapLib/Classes/PGViewController.h b/PhoneGapLib/Classes/PGViewController.h index 4be165d..396fda9 100644 --- a/PhoneGapLib/Classes/PGViewController.h +++ b/PhoneGapLib/Classes/PGViewController.h @@ -26,6 +26,9 @@ @property (nonatomic, readonly, copy) NSString* sessionKey; @property (nonatomic, readonly, assign) BOOL loadFromString; +@property (nonatomic, readwrite, assign) BOOL useSplashScreen; +@property (nonatomic, readonly, retain) IBOutlet UIActivityIndicatorView* activityView; +@property (nonatomic, readonly, retain) UIImageView *imageView; + (NSDictionary*) getBundlePlist:(NSString*)plistName; + (NSString*) wwwFolderName; http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/0fcc80da/PhoneGapLib/Classes/PGViewController.m ---------------------------------------------------------------------- diff --git a/PhoneGapLib/Classes/PGViewController.m b/PhoneGapLib/Classes/PGViewController.m index e9f07cf..9606bb3 100644 --- a/PhoneGapLib/Classes/PGViewController.m +++ b/PhoneGapLib/Classes/PGViewController.m @@ -12,6 +12,7 @@ #define SYMBOL_TO_NSSTRING_HELPER(x) @#x #define SYMBOL_TO_NSSTRING(x) SYMBOL_TO_NSSTRING_HELPER(x) +#define degreesToRadian(x) (M_PI * (x) / 180.0) @interface PGViewController () @@ -23,6 +24,10 @@ @property (nonatomic, readwrite, copy) NSString* sessionKey; @property (nonatomic, readwrite, assign) BOOL loadFromString; +@property (nonatomic, readwrite, retain) IBOutlet UIActivityIndicatorView* activityView; +@property (nonatomic, readwrite, retain) UIImageView* imageView; + + @end @@ -31,7 +36,18 @@ @synthesize webView, supportedOrientations; @synthesize pluginObjects, pluginsMap, whitelist; @synthesize settings, sessionKey, loadFromString; +@synthesize imageView, activityView, useSplashScreen; +- (id) init +{ + self = [super init]; + if (self != nil) { + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedOrientationChange) name:UIDeviceOrientationDidChangeNotification + object:nil]; + } + return self; +} // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void) viewDidLoad @@ -278,17 +294,17 @@ /* * Hide the Top Activity THROBBER in the Battery Bar */ -// [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; -// -// id autoHideSplashScreenValue = [self.settings objectForKey:@"AutoHideSplashScreen"]; -// // if value is missing, default to yes -// if (autoHideSplashScreenValue == nil || [autoHideSplashScreenValue boolValue]) { -// self.imageView.hidden = YES; -// self.activityView.hidden = YES; -// [self.window bringSubviewToFront:self.viewController.view]; -// } -// -// [self.viewController didRotateFromInterfaceOrientation:(UIInterfaceOrientation)[[UIDevice currentDevice] orientation]]; + [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; + + id autoHideSplashScreenValue = [self.settings objectForKey:@"AutoHideSplashScreen"]; + // if value is missing, default to yes + if (autoHideSplashScreenValue == nil || [autoHideSplashScreenValue boolValue]) { + self.imageView.hidden = YES; + self.activityView.hidden = YES; + [self.view bringSubviewToFront:self.webView]; + } + + [self didRotateFromInterfaceOrientation:(UIInterfaceOrientation)[[UIDevice currentDevice] orientation]]; } - (void) webView:(UIWebView*)webView didFailLoadWithError:(NSError*)error @@ -407,6 +423,33 @@ return @"index.html"; } ++ (BOOL) isIPad +{ +#ifdef UI_USER_INTERFACE_IDIOM + return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); +#else + return NO; +#endif +} + ++ (NSString*) resolveImageResource:(NSString*)resource +{ + NSString* systemVersion = [[UIDevice currentDevice] systemVersion]; + BOOL isLessThaniOS4 = ([systemVersion compare:@"4.0" options:NSNumericSearch] == NSOrderedAscending); + + // the iPad image (nor retina) differentiation code was not in 3.x, and we have to explicitly set the path + if (isLessThaniOS4) + { + if ([[self class] isIPad]) { + return [NSString stringWithFormat:@"%@~ipad.png", resource]; + } else { + return [NSString stringWithFormat:@"%@.png", resource]; + } + } + + return resource; +} + + (NSString*) pathForResource:(NSString*)resourcepath { NSBundle * mainBundle = [NSBundle mainBundle]; @@ -431,6 +474,122 @@ return basePath; } +- (void) showSplashScreen +{ + NSString* launchImageFile = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UILaunchImageFile"]; + if (launchImageFile == nil) { // fallback if no launch image was specified + launchImageFile = @"Default"; + } + + NSString* orientedLaunchImageFile = nil; + CGAffineTransform startupImageTransform = CGAffineTransformIdentity; + UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; + CGRect screenBounds = [[UIScreen mainScreen] bounds]; + UIInterfaceOrientation statusBarOrientation = [UIApplication sharedApplication].statusBarOrientation; + BOOL isIPad = [[self class] isIPad]; + UIImage* launchImage = nil; + + if (isIPad) + { + if (!UIDeviceOrientationIsValidInterfaceOrientation(deviceOrientation)) { + deviceOrientation = (UIDeviceOrientation)statusBarOrientation; + } + + switch (deviceOrientation) + { + case UIDeviceOrientationLandscapeLeft: // this is where the home button is on the right (yeah, I know, confusing) + { + orientedLaunchImageFile = [NSString stringWithFormat:@"%@-Landscape", launchImageFile]; + startupImageTransform = CGAffineTransformMakeRotation(degreesToRadian(90)); + } + break; + case UIDeviceOrientationLandscapeRight: // this is where the home button is on the left (yeah, I know, confusing) + { + orientedLaunchImageFile = [NSString stringWithFormat:@"%@-Landscape", launchImageFile]; + startupImageTransform = CGAffineTransformMakeRotation(degreesToRadian(-90)); + } + break; + case UIDeviceOrientationPortraitUpsideDown: + { + orientedLaunchImageFile = [NSString stringWithFormat:@"%@-Portrait", launchImageFile]; + startupImageTransform = CGAffineTransformMakeRotation(degreesToRadian(180)); + } + break; + case UIDeviceOrientationPortrait: + default: + { + orientedLaunchImageFile = [NSString stringWithFormat:@"%@-Portrait", launchImageFile]; + startupImageTransform = CGAffineTransformIdentity; + } + break; + } + + launchImage = [UIImage imageNamed:[[self class] resolveImageResource:orientedLaunchImageFile]]; + } + else // not iPad + { + orientedLaunchImageFile = @"Default"; + launchImage = [UIImage imageNamed:[[self class] resolveImageResource:orientedLaunchImageFile]]; + } + + if (launchImage == nil) { + NSLog(@"WARNING: Splash-screen image '%@' was not found. Orientation: %d, iPad: %d", orientedLaunchImageFile, deviceOrientation, isIPad); + } + + self.imageView = [[[UIImageView alloc] initWithImage:launchImage] autorelease]; + self.imageView.tag = 1; + self.imageView.center = CGPointMake((screenBounds.size.width / 2), (screenBounds.size.height / 2)); + + self.imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth & UIViewAutoresizingFlexibleHeight & UIViewAutoresizingFlexibleLeftMargin & UIViewAutoresizingFlexibleRightMargin); + [self.imageView setTransform:startupImageTransform]; + [self.view addSubview:self.imageView]; + + + /* + * The Activity View is the top spinning throbber in the status/battery bar. We init it with the default Grey Style. + * + * whiteLarge = UIActivityIndicatorViewStyleWhiteLarge + * white = UIActivityIndicatorViewStyleWhite + * gray = UIActivityIndicatorViewStyleGray + * + */ + NSString* topActivityIndicator = [self.settings objectForKey:@"TopActivityIndicator"]; + UIActivityIndicatorViewStyle topActivityIndicatorStyle = UIActivityIndicatorViewStyleGray; + + if ([topActivityIndicator isEqualToString:@"whiteLarge"]) { + topActivityIndicatorStyle = UIActivityIndicatorViewStyleWhiteLarge; + } else if ([topActivityIndicator isEqualToString:@"white"]) { + topActivityIndicatorStyle = UIActivityIndicatorViewStyleWhite; + } else if ([topActivityIndicator isEqualToString:@"gray"]) { + topActivityIndicatorStyle = UIActivityIndicatorViewStyleGray; + } + + self.activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:topActivityIndicatorStyle] autorelease]; + self.activityView.tag = 2; + + id showSplashScreenSpinnerValue = [self.settings objectForKey:@"ShowSplashScreenSpinner"]; + // backwards compatibility - if key is missing, default to true + if (showSplashScreenSpinnerValue == nil || [showSplashScreenSpinnerValue boolValue]) { + [self.view addSubview:self.activityView]; + } + + self.activityView.center = self.view.center; + [self.activityView startAnimating]; + + [self.view layoutSubviews]; +} + +BOOL gSplashScreenShown = NO; +- (void) receivedOrientationChange +{ + if (self.imageView == nil) { + gSplashScreenShown = YES; + if (self.useSplashScreen) { + [self showSplashScreen]; + } + } +} + #pragma mark PhoneGapCommands /** http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/0fcc80da/PhoneGapLib/Classes/PhoneGapDelegate.h ---------------------------------------------------------------------- diff --git a/PhoneGapLib/Classes/PhoneGapDelegate.h b/PhoneGapLib/Classes/PhoneGapDelegate.h index 194bd37..e5c31c8 100644 --- a/PhoneGapLib/Classes/PhoneGapDelegate.h +++ b/PhoneGapLib/Classes/PhoneGapDelegate.h @@ -17,8 +17,6 @@ @property (nonatomic, readwrite, retain) IBOutlet UIWindow* window; @property (nonatomic, readonly, retain) IBOutlet PGViewController* viewController; -@property (nonatomic, readonly, retain) IBOutlet UIActivityIndicatorView* activityView; -@property (nonatomic, readonly, retain) UIImageView *imageView; - (void)applicationDidEnterBackground:(UIApplication *)application; - (void)applicationWillEnterForeground:(UIApplication *)application; http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/0fcc80da/PhoneGapLib/Classes/PhoneGapDelegate.m ---------------------------------------------------------------------- diff --git a/PhoneGapLib/Classes/PhoneGapDelegate.m b/PhoneGapLib/Classes/PhoneGapDelegate.m index 6e7c163..b3f7e94 100644 --- a/PhoneGapLib/Classes/PhoneGapDelegate.m +++ b/PhoneGapLib/Classes/PhoneGapDelegate.m @@ -21,23 +21,19 @@ #import "PGViewController.h" #import "PGPlugin.h" -#define degreesToRadian(x) (M_PI * (x) / 180.0) - // class extension @interface PhoneGapDelegate () // readwrite access for self @property (nonatomic, readwrite, retain) IBOutlet PGViewController* viewController; -@property (nonatomic, readwrite, retain) IBOutlet UIActivityIndicatorView* activityView; -@property (nonatomic, readwrite, retain) UIImageView* imageView; @end @implementation PhoneGapDelegate -@synthesize window, viewController, imageView, activityView; +@synthesize window, viewController; - (id) init { @@ -47,156 +43,11 @@ NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; - [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedOrientationChange) name:UIDeviceOrientationDidChangeNotification - object:nil]; - [PGURLProtocol registerPGHttpURLProtocol]; } return self; } -+ (BOOL) isIPad -{ -#ifdef UI_USER_INTERFACE_IDIOM - return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); -#else - return NO; -#endif -} - -+ (NSString*) resolveImageResource:(NSString*)resource -{ - NSString* systemVersion = [[UIDevice currentDevice] systemVersion]; - BOOL isLessThaniOS4 = ([systemVersion compare:@"4.0" options:NSNumericSearch] == NSOrderedAscending); - - // the iPad image (nor retina) differentiation code was not in 3.x, and we have to explicitly set the path - if (isLessThaniOS4) - { - if ([[self class] isIPad]) { - return [NSString stringWithFormat:@"%@~ipad.png", resource]; - } else { - return [NSString stringWithFormat:@"%@.png", resource]; - } - } - - return resource; -} - -- (void) showSplashScreen -{ - NSString* launchImageFile = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UILaunchImageFile"]; - if (launchImageFile == nil) { // fallback if no launch image was specified - launchImageFile = @"Default"; - } - - NSString* orientedLaunchImageFile = nil; - CGAffineTransform startupImageTransform = CGAffineTransformIdentity; - UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; - CGRect screenBounds = [[UIScreen mainScreen] bounds]; - UIInterfaceOrientation statusBarOrientation = [UIApplication sharedApplication].statusBarOrientation; - BOOL isIPad = [[self class] isIPad]; - UIImage* launchImage = nil; - - if (isIPad) - { - if (!UIDeviceOrientationIsValidInterfaceOrientation(deviceOrientation)) { - deviceOrientation = (UIDeviceOrientation)statusBarOrientation; - } - - switch (deviceOrientation) - { - case UIDeviceOrientationLandscapeLeft: // this is where the home button is on the right (yeah, I know, confusing) - { - orientedLaunchImageFile = [NSString stringWithFormat:@"%@-Landscape", launchImageFile]; - startupImageTransform = CGAffineTransformMakeRotation(degreesToRadian(90)); - } - break; - case UIDeviceOrientationLandscapeRight: // this is where the home button is on the left (yeah, I know, confusing) - { - orientedLaunchImageFile = [NSString stringWithFormat:@"%@-Landscape", launchImageFile]; - startupImageTransform = CGAffineTransformMakeRotation(degreesToRadian(-90)); - } - break; - case UIDeviceOrientationPortraitUpsideDown: - { - orientedLaunchImageFile = [NSString stringWithFormat:@"%@-Portrait", launchImageFile]; - startupImageTransform = CGAffineTransformMakeRotation(degreesToRadian(180)); - } - break; - case UIDeviceOrientationPortrait: - default: - { - orientedLaunchImageFile = [NSString stringWithFormat:@"%@-Portrait", launchImageFile]; - startupImageTransform = CGAffineTransformIdentity; - } - break; - } - - launchImage = [UIImage imageNamed:[[self class] resolveImageResource:orientedLaunchImageFile]]; - } - else // not iPad - { - orientedLaunchImageFile = @"Default"; - launchImage = [UIImage imageNamed:[[self class] resolveImageResource:orientedLaunchImageFile]]; - } - - if (launchImage == nil) { - NSLog(@"WARNING: Splash-screen image '%@' was not found. Orientation: %d, iPad: %d", orientedLaunchImageFile, deviceOrientation, isIPad); - } - - self.imageView = [[[UIImageView alloc] initWithImage:launchImage] autorelease]; - self.imageView.tag = 1; - self.imageView.center = CGPointMake((screenBounds.size.width / 2), (screenBounds.size.height / 2)); - - self.imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth & UIViewAutoresizingFlexibleHeight & UIViewAutoresizingFlexibleLeftMargin & UIViewAutoresizingFlexibleRightMargin); - [self.imageView setTransform:startupImageTransform]; - [self.window addSubview:self.imageView]; - - - /* - * The Activity View is the top spinning throbber in the status/battery bar. We init it with the default Grey Style. - * - * whiteLarge = UIActivityIndicatorViewStyleWhiteLarge - * white = UIActivityIndicatorViewStyleWhite - * gray = UIActivityIndicatorViewStyleGray - * - */ - NSString *topActivityIndicator = [self.viewController.settings objectForKey:@"TopActivityIndicator"]; - UIActivityIndicatorViewStyle topActivityIndicatorStyle = UIActivityIndicatorViewStyleGray; - - if ([topActivityIndicator isEqualToString:@"whiteLarge"]) { - topActivityIndicatorStyle = UIActivityIndicatorViewStyleWhiteLarge; - } else if ([topActivityIndicator isEqualToString:@"white"]) { - topActivityIndicatorStyle = UIActivityIndicatorViewStyleWhite; - } else if ([topActivityIndicator isEqualToString:@"gray"]) { - topActivityIndicatorStyle = UIActivityIndicatorViewStyleGray; - } - - self.activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:topActivityIndicatorStyle] autorelease]; - self.activityView.tag = 2; - - id showSplashScreenSpinnerValue = [self.viewController.settings objectForKey:@"ShowSplashScreenSpinner"]; - // backwards compatibility - if key is missing, default to true - if (showSplashScreenSpinnerValue == nil || [showSplashScreenSpinnerValue boolValue]) { - [self.window addSubview:self.activityView]; - } - - self.activityView.center = self.viewController.view.center; - [self.activityView startAnimating]; - - [self.window layoutSubviews]; -} - -BOOL gSplashScreenShown = NO; -- (void) receivedOrientationChange -{ - if (self.imageView == nil) { - gSplashScreenShown = YES; - //[self showSplashScreen]; - } -} - /** * This is main kick off after the app inits, the views and Settings are setup here. */ @@ -209,6 +60,7 @@ BOOL gSplashScreenShown = NO; CGRect viewBounds = [[UIScreen mainScreen] applicationFrame]; viewBounds.origin = screenBounds.origin; self.viewController = [[[PGViewController alloc] init] autorelease]; + self.viewController.useSplashScreen = YES; self.viewController.view.bounds = viewBounds; // check whether the current orientation is supported: if it is, keep it, rather than forcing a rotation @@ -351,9 +203,7 @@ BOOL gSplashScreenShown = NO; { [PluginResult releaseStatus]; self.viewController = nil; - self.activityView = nil; self.window = nil; - self.imageView = nil; [super dealloc]; }