Skip to content

Commit

Permalink
Merge pull request #4867 from pec1985/timob-15577-2
Browse files Browse the repository at this point in the history
[TIMOB-15577] iOS Force splash screen image as snapshot on app resume
  • Loading branch information
vishalduggal committed Oct 30, 2013
2 parents 3bf03a3 + c201739 commit 21b7305
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
12 changes: 11 additions & 1 deletion apidoc/Titanium/App/App.yml
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,16 @@ properties:
permission: read-only
exclude-platforms: [blackberry]

- name forceSplashAsSnapshot
summary: Shows the application's splash screen on app resume.
description: |
Note: This only works on device.
When the app goes to the background a screenshot of the current app state is taken. When
the app resumes that screenshot is shown for brief moment. To disable this behavior, set
this property to `true` and the default splash screen will show on app resume instead.
type: Boolean
platforms: [iphone, ipad]

- name: id
summary: Application ID, from `tiapp.xml`.
description: |
Expand Down Expand Up @@ -491,4 +501,4 @@ properties:
If set to `true`, this key indicates that the application was launched in response to an
incoming location event.
type: Boolean
default: false
default: false
8 changes: 8 additions & 0 deletions iphone/Classes/AppModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,14 @@ -(NSNumber*)keyboardVisible
return NUMBOOL([[[TiApp app] controller] keyboardVisible]);
}

-(void)setForceSplashAsSnapshot:(id)args
{
ENSURE_SINGLE_ARG(args, NSNumber)
[self replaceValue:args forKey:@"forceSplashAsSnapshot" notification:NO];
BOOL flag = [TiUtils boolValue:args def:NO];
[[TiApp app] setForceSplashAsSnapshot:flag];
}

#if defined(USE_TI_APPIOS)
-(id)iOS
{
Expand Down
3 changes: 3 additions & 0 deletions iphone/Classes/TiApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ TI_INLINE void waitForMemoryPanicCleared() //WARNING: This must never be run o
{
UIWindow *window;
UIImageView *loadView;
UIImageView *splashScreenImage;
BOOL loaded;

TiContextGroupRef contextGroup;
Expand Down Expand Up @@ -61,6 +62,8 @@ TI_INLINE void waitForMemoryPanicCleared() //WARNING: This must never be run o
NSDictionary *localNotification;
}

@property (nonatomic) BOOL forceSplashAsSnapshot;

/**
Returns application's primary window.
Expand Down
46 changes: 46 additions & 0 deletions iphone/Classes/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,44 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application
[self boot];
}

-(UIImageView*)splashScreenImage
{
if(splashScreenImage == nil) {
splashScreenImage = [[UIImageView alloc] init];
[splashScreenImage setBackgroundColor:[UIColor yellowColor]];
[splashScreenImage setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
[splashScreenImage setContentMode:UIViewContentModeScaleToFill];

UIDeviceOrientation imageOrientation;
UIUserInterfaceIdiom imageIdiom;

UIImage * defaultImage = [controller defaultImageForOrientation:
(UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation]
resultingOrientation:&imageOrientation idiom:&imageIdiom];
if([TiUtils isIPad]) {
CGAffineTransform transform;
switch ([[UIApplication sharedApplication] statusBarOrientation]) {
case UIInterfaceOrientationPortraitUpsideDown:
transform = CGAffineTransformMakeRotation(M_PI);
break;
case UIInterfaceOrientationLandscapeLeft:
transform = CGAffineTransformMakeRotation(-M_PI_2);
break;
case UIInterfaceOrientationLandscapeRight:
transform = CGAffineTransformMakeRotation(M_PI_2);
break;
default:
transform = CGAffineTransformIdentity;
break;
}
[splashScreenImage setTransform:transform];
}
[splashScreenImage setImage: defaultImage];
[splashScreenImage setFrame:[[UIScreen mainScreen] bounds]];
}
return splashScreenImage;
}

- (void)generateNotification:(NSDictionary*)dict
{
// Check and see if any keys from APS and the rest of the dictionary match; if they do, just
Expand Down Expand Up @@ -439,6 +477,9 @@ - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application

-(void)applicationWillResignActive:(UIApplication *)application
{
if([self forceSplashAsSnapshot]) {
[window addSubview:[self splashScreenImage]];
}
[[NSNotificationCenter defaultCenter] postNotificationName:kTiSuspendNotification object:self];

// suspend any image loading
Expand All @@ -453,6 +494,10 @@ -(void)applicationWillResignActive:(UIApplication *)application

- (void)applicationDidBecomeActive:(UIApplication *)application
{
if(splashScreenImage != nil) {
[[self splashScreenImage] removeFromSuperview];
RELEASE_TO_NIL(splashScreenImage);
}
// NOTE: Have to fire a separate but non-'resume' event here because there is SOME information
// (like new URL) that is not passed through as part of the normal foregrounding process.
[[NSNotificationCenter defaultCenter] postNotificationName:kTiResumedNotification object:self];
Expand Down Expand Up @@ -631,6 +676,7 @@ - (void)dealloc
RELEASE_TO_NIL(userAgent);
RELEASE_TO_NIL(remoteDeviceUUID);
RELEASE_TO_NIL(remoteNotification);
RELEASE_TO_NIL(splashScreenImage);
if ([self debugMode]) {
TiDebuggerStop();
}
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiRootViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#if defined(DEBUG) || defined(DEVELOPER)
-(void)shutdownUi:(id)arg;
#endif
- (UIImage*)defaultImageForOrientation:(UIDeviceOrientation) orientation resultingOrientation:(UIDeviceOrientation *)imageOrientation idiom:(UIUserInterfaceIdiom*) imageIdiom;


@end

0 comments on commit 21b7305

Please sign in to comment.