Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-15577] Exposed hideScreenShotOnAppResume on Ti.App module #4847

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions apidoc/Titanium/App/App.yml
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ properties:
permission: read-only
exclude-platforms: [blackberry]

- name hideScreenShotOnAppResume
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to forceSplashAsSnapshot

summary: Shows the application's splash screen on app resume.
description: |
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
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)setHideScreenShotOnAppResume:(id)args
{
ENSURE_SINGLE_ARG(args, NSNumber)
[self replaceValue:args forKey:@"hideScreenShotOnAppResume" notification:NO];
BOOL flag = [TiUtils boolValue:args def:YES];
Copy link
Contributor

Choose a reason for hiding this comment

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

def:NO

[[TiApp app] setHideScreenShotOnAppResume: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 hideScreenShotOnAppResume;
Copy link
Contributor

Choose a reason for hiding this comment

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

rename this as well to match method in App Module

@property (nonatomic) BOOL appInBackground;
/**
Returns application's primary window.

Expand Down
31 changes: 30 additions & 1 deletion iphone/Classes/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,33 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application
[self boot];
}

-(UIImageView*)splashScreenImage
{
if(splashScreenImage == nil) {
UIDeviceOrientation imageOrientation;
UIUserInterfaceIdiom imageIdiom;

splashScreenImage = [[UIImageView alloc] init];
[splashScreenImage setBackgroundColor:[UIColor yellowColor]];
[splashScreenImage setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
[splashScreenImage setContentMode:UIViewContentModeScaleToFill];
[controller rotateDefaultImageViewToOrientation:[[UIApplication sharedApplication] statusBarOrientation]
withImageView:splashScreenImage];

// UIImage *img = [controller defaultImageForOrientation:[[UIApplication sharedApplication] statusBarOrientation] resultingOrientation:imageOrientation idiom:imageIdiom];
// [splashScreenImage setImage:img];
[splashScreenImage setFrame:[window 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
// bump out the dictionary as-is
remoteNotification = [[NSMutableDictionary alloc] initWithDictionary:dict];
NSDictionary* aps = [dict objectForKey:@"aps"];
for (id key in aps)
for (id key in aps)
{
if ([dict objectForKey:key] != nil) {
DebugLog(@"[WARN] Conflicting keys in push APS dictionary and notification dictionary `%@`, not copying to toplevel from APS", key);
Expand Down Expand Up @@ -439,6 +459,10 @@ - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application

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

// suspend any image loading
Expand Down Expand Up @@ -495,6 +519,9 @@ -(void)applicationDidEnterBackground:(UIApplication *)application

-(void)applicationWillEnterForeground:(UIApplication *)application
{
[[self splashScreenImage] removeFromSuperview];
RELEASE_TO_NIL(splashScreenImage);

[sessionId release];
sessionId = [[TiUtils createUUID] retain];

Expand Down Expand Up @@ -625,6 +652,7 @@ - (void)dealloc
RELEASE_TO_NIL(xhrBridge);
#endif
RELEASE_TO_NIL(loadView);
RELEASE_TO_NIL(splashScreenImage)
RELEASE_TO_NIL(window);
RELEASE_TO_NIL(launchOptions);
RELEASE_TO_NIL(controller);
Expand Down Expand Up @@ -693,6 +721,7 @@ -(void)endBackgrounding

[self checkBackgroundServices];
RELEASE_TO_NIL(runningServices);
[self setAppInBackground:NO];
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this to applicationWillEnterForeground

}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
Expand Down
2 changes: 2 additions & 0 deletions iphone/Classes/TiRootViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@
-(void)shutdownUi:(id)arg;
#endif

-(void)rotateDefaultImageViewToOrientation: (UIInterfaceOrientation )newOrientation withImageView:(UIImageView*)theImageView;
Copy link
Contributor

Choose a reason for hiding this comment

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

rename method to rotateImageViewToOrientation



@end
38 changes: 30 additions & 8 deletions iphone/Classes/TiRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ -(void)loadView
rootView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self updateBackground];
if (defaultImageView != nil) {
[self rotateDefaultImageViewToOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
[self rotateDefaultImageViewToOrientation:[[UIApplication sharedApplication] statusBarOrientation] withImageView:defaultImageView];
[rootView addSubview:defaultImageView];
}
[rootView becomeFirstResponder];
Expand Down Expand Up @@ -294,9 +294,9 @@ - (UIImage*)defaultImageForOrientation:(UIDeviceOrientation) orientation resulti
return [UIImage imageNamed:@"Default.png"];
}

-(void)rotateDefaultImageViewToOrientation: (UIInterfaceOrientation )newOrientation;
-(void)rotateDefaultImageViewToOrientation: (UIInterfaceOrientation )newOrientation withImageView:(UIImageView*)theImageView;
{
if (defaultImageView == nil)
if (theImageView == nil)
{
return;
}
Expand Down Expand Up @@ -352,7 +352,29 @@ -(void)rotateDefaultImageViewToOrientation: (UIInterfaceOrientation )newOrientat
contentMode = UIViewContentModeCenter;
}
}
}
} else {
if([[TiApp app] appInBackground]) {
// Rotate image, we're in background!
UIImageOrientation newImgOrientation;
switch (newOrientation) {
case UIDeviceOrientationLandscapeLeft:
newImgOrientation = UIImageOrientationRight;
break;
case UIDeviceOrientationLandscapeRight:
newImgOrientation = UIImageOrientationLeft;
break;
default:
newImgOrientation = UIImageOrientationDown;
break;
}
defaultImage = [UIImage imageWithCGImage:[defaultImage CGImage] scale:imageScale orientation: newImgOrientation ];
if (imageScale > 1.5) {
contentMode = UIViewContentModeCenter;
}
} else {
// DO NOT rotate image, we're NOT in background!;
}
}

if(imageSize.width == newFrame.size.width)
{
Expand All @@ -363,9 +385,9 @@ -(void)rotateDefaultImageViewToOrientation: (UIInterfaceOrientation )newOrientat
newFrame.size.height += overheight;
}
}
[defaultImageView setContentMode:contentMode];
[defaultImageView setImage:defaultImage];
[defaultImageView setFrame:newFrame];
[theImageView setContentMode:contentMode];
[theImageView setImage:defaultImage];
[theImageView setFrame:newFrame];
}

#pragma mark - Keyboard Control
Expand Down Expand Up @@ -1319,7 +1341,7 @@ -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInter
[thisWindow willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
[self updateOrientationHistory:toInterfaceOrientation];
[self rotateDefaultImageViewToOrientation:toInterfaceOrientation];
[self rotateDefaultImageViewToOrientation:toInterfaceOrientation withImageView:defaultImageView];
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
Expand Down