Skip to content

Commit

Permalink
Merge branch 'appc_master' into timob-4829
Browse files Browse the repository at this point in the history
  • Loading branch information
billdawson committed Sep 15, 2011
2 parents 9d144be + 6ae6a01 commit 58ca4b0
Show file tree
Hide file tree
Showing 12 changed files with 396 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ protected boolean findRef(Object o)
}
return false;
}

@Override
public boolean add(WeakReference<T> o)
{
if (synchronizedList != null) {
synchronized (synchronizedList) {
return super.add(o);
}
}
return super.add(o);
}

@Override
public boolean contains(Object o)
Expand Down
14 changes: 3 additions & 11 deletions iphone/Classes/TiApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ TI_INLINE void waitForMemoryPanicCleared() //WARNING: This must never be run o
{
UIWindow *window;
UIImageView *loadView;
BOOL splashAttached;
BOOL loaded;
BOOL handledModal;

Expand All @@ -44,7 +43,7 @@ TI_INLINE void waitForMemoryPanicCleared() //WARNING: This must never be run o

int networkActivityCount; //We now can use atomic increment/decrement instead. This value is 0 upon initialization anyways.

UIViewController<TiRootController> *controller;
TiRootViewController *controller;
NSString *userAgent;
NSString *remoteDeviceUUID;

Expand All @@ -53,31 +52,24 @@ TI_INLINE void waitForMemoryPanicCleared() //WARNING: This must never be run o

NSString *sessionId;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
UIBackgroundTaskIdentifier bgTask;
NSMutableArray *backgroundServices;
NSMutableArray *runningServices;
UILocalNotification *localNotification;
#endif
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, assign) id remoteNotificationDelegate;
@property (nonatomic, readonly) NSDictionary* remoteNotification;
@property (nonatomic, retain) UIViewController<TiRootController>* controller;
@property (nonatomic, retain) TiRootViewController* controller;
@property (nonatomic, readonly) TiContextGroupRef contextGroup;
+(TiApp*)app;
//Convenience method
+(UIViewController<TiRootController>*)controller;
+(TiRootViewController*)controller;
+(TiContextGroupRef)contextGroup;

-(void)attachXHRBridgeIfRequired;

-(BOOL)isSplashVisible;
-(void)hideSplash:(id)event;
-(UIView*)splash;
-(void)loadSplash;
-(UIView*)attachSplash;
-(NSDictionary*)launchOptions;
-(NSString*)remoteDeviceUUID;

Expand Down
123 changes: 4 additions & 119 deletions iphone/Classes/TiApp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ + (TiApp*)app
return sharedApp;
}

+(UIViewController<TiRootController>*)controller;
+(TiRootViewController*)controller;
{
return [sharedApp controller];
}
Expand Down Expand Up @@ -157,118 +157,6 @@ -(NSDictionary*)launchOptions
return launchOptions;
}

- (UIImage*)loadAppropriateSplash
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

UIImage* image = nil;

if([TiUtils isIPad])
{
// Specific orientation check
switch (orientation) {
case UIDeviceOrientationPortrait:
image = [UIImage imageNamed:@"Default-Portrait.png"];
break;
case UIDeviceOrientationPortraitUpsideDown:
image = [UIImage imageNamed:@"Default-PortraitUpsideDown.png"];
break;
case UIDeviceOrientationLandscapeLeft:
image = [UIImage imageNamed:@"Default-LandscapeLeft.png"];
break;
case UIDeviceOrientationLandscapeRight:
image = [UIImage imageNamed:@"Default-LandscapeRight.png"];
break;
}
if (image != nil) {
return image;
}

// Generic orientation check
if (UIDeviceOrientationIsPortrait(orientation)) {
image = [UIImage imageNamed:@"Default-Portrait.png"];
}
else if (UIDeviceOrientationIsLandscape(orientation)) {
image = [UIImage imageNamed:@"Default-Landscape.png"];
}

if (image != nil) {
return image;
}
}

// Default
return [UIImage imageNamed:@"Default.png"];
}

- (UIView*)attachSplash
{
UIView * controllerView = [controller view];

RELEASE_TO_NIL(loadView);

CGRect destRect;

if([TiUtils isIPad]) //iPad, 1024*748 or 748*1004, under the status bar.
{
destRect = [controllerView bounds];
}
else //iPhone: 320*480, placing behind the statusBar.
{
destRect = [controllerView convertRect:[[UIScreen mainScreen] bounds] fromView:nil];
destRect.origin.y -= [[UIApplication sharedApplication] statusBarFrame].size.height;
}

loadView = [[UIImageView alloc] initWithFrame:destRect];
[loadView setContentMode:UIViewContentModeScaleAspectFill];
loadView.image = [self loadAppropriateSplash];
[controller.view addSubview:loadView];
splashAttached = YES;
return loadView;
}

- (void)loadSplash
{
sharedApp = self;

// attach our main view controller... IF we haven't already loaded the main window.
if (!loaded) {
[self attachSplash];
}
if ([window respondsToSelector:@selector(setRootViewController:)]) {
[window setRootViewController:controller];
}
else
{
[window addSubview:[controller view]];
}
[window makeKeyAndVisible];
}

- (BOOL)isSplashVisible
{
return splashAttached;
}

-(UIView*)splash
{
return loadView;
}

- (void)hideSplash:(id)event
{
// this is called when the first window is loaded
// and should only be done once (obviously) - the
// caller is responsible for setting up the animation
// context before calling this and committing it afterwards
if (loadView!=nil && splashAttached)
{
splashAttached = NO;
loaded = YES;
[loadView removeFromSuperview];
RELEASE_TO_NIL(loadView);
}
}

-(void)initController
{
Expand All @@ -277,12 +165,9 @@ -(void)initController
// attach our main view controller
controller = [[TiRootViewController alloc] init];

// Force view load
controller.view.backgroundColor = [UIColor clearColor];

if (![TiUtils isiPhoneOS3_2OrGreater]) {
[self loadSplash];
}
// attach our main view controller... IF we haven't already loaded the main window.
[window setRootViewController:controller];
[window makeKeyAndVisible];
}

-(void)attachXHRBridgeIfRequired
Expand Down
2 changes: 2 additions & 0 deletions iphone/Classes/TiModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ -(void)contextShutdown:(id)sender
[self contextWasShutdown:context];
if(pageContext == context){
pageContext = nil;
pageKrollObject = nil;
}
//DO NOT run super shutdown here, as we want to change the behavior that TiProxy does.
}

-(void)setPageContext:(id<TiEvaluator>)evaluator
{
pageContext = evaluator; // don't retain
pageKrollObject = nil;
}

-(void)setHost:(TiHost*)host_
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ -(void)contextShutdown:(id)sender
//it's no longer referenced by any contexts at all.
[self _destroy];
pageContext = nil;
pageKrollObject = nil;
}
}

Expand Down
32 changes: 21 additions & 11 deletions iphone/Classes/TiRootViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,35 @@
#import "TiRootController.h"
#import "TiWindowProxy.h"

#define MAX_ORIENTATIONS 7

@interface TiRootViewController : UIViewController<UIApplicationDelegate,TiRootController,TiOrientationController> {
@private
NSMutableArray *windowViewControllers;

//Presentation: background image and color.
UIColor * backgroundColor;
UIImage * backgroundImage;

//View Controller stack:
/*
* Due to historical reasons, there are three arrays that track views/
* windows/viewcontrollers that are 'opened' on the rootViewController.
* For best results, this should be realigned with a traditional container-
* style view controller, perhaps even something proxy-agnostic in the
* future. TODO: Refactor viewController arrays.
*/
NSMutableArray *windowViewControllers;
NSMutableArray * viewControllerStack;
NSMutableArray * windowProxies;

//While no windows are onscreen, present default.png
UIImageView * defaultImageView;

//Orientation handling:
TiOrientationFlags allowedOrientations;
NSTimeInterval orientationRequestTimes[MAX_ORIENTATIONS];
UIInterfaceOrientation orientationHistory[4];

UIInterfaceOrientation lastOrientation;
UIInterfaceOrientation windowOrientation;

NSMutableArray * viewControllerStack;
BOOL isCurrentlyVisible;

//TiOrientationController variables.
NSMutableArray * windowProxies;

//Keyboard handling -- This can probably be done in a better way.
BOOL updatingAccessoryView;
Expand All @@ -46,6 +55,9 @@
CGFloat leaveDuration;
}

@property(nonatomic,readonly) UIImageView * defaultImageView;
-(void)dismissDefaultImageView;

@property(nonatomic,readwrite,retain) UIColor * backgroundColor;
@property(nonatomic,readwrite,retain) UIImage * backgroundImage;

Expand All @@ -65,6 +77,4 @@
- (void)openWindow:(TiWindowProxy *)window withObject:(id)args;
- (void)closeWindow:(TiWindowProxy *)window withObject:(id)args;

-(UIInterfaceOrientation)mostRecentlyAllowedOrientation;

@end
Loading

0 comments on commit 58ca4b0

Please sign in to comment.