diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index a14d4c1da..3f23e2296 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -186,10 +186,6 @@ int __aeabi_idiv(int a, int b) { } - (void)startApplication { - /* explicitely instanciate LinphoneManager */ - LinphoneManager* lm = [[LinphoneManager alloc] init]; - assert(lm == [LinphoneManager instance]); - [[LinphoneManager instance] startLibLinphone]; [self setupUI]; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 1cce9fbc8..e3c33e0d1 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -139,6 +139,10 @@ struct codec_name_pref_table codec_pref_table[]={ } + (LinphoneManager*)instance { + if(theLinphoneManager == nil) { + theLinphoneManager = [LinphoneManager alloc]; + [theLinphoneManager init]; + } return theLinphoneManager; } @@ -146,11 +150,9 @@ struct codec_name_pref_table codec_pref_table[]={ #pragma mark - Lifecycle Functions - (id)init { - assert (!theLinphoneManager); if ((self = [super init])) { fastAddressBook = [[FastAddressBook alloc] init]; database = NULL; - theLinphoneManager = self; settingsStore = nil; self.defaultExpires = 600; [self openDatabase]; @@ -161,6 +163,7 @@ struct codec_name_pref_table codec_pref_table[]={ - (void)dealloc { [fastAddressBook release]; [self closeDatabase]; + [settingsStore release]; [super dealloc]; } @@ -642,11 +645,6 @@ static LinphoneCoreVTable linphonec_vtable = { proxyReachability=nil; } - - if(settingsStore != nil) { - [settingsStore release]; - } - } - (BOOL)enterBackgroundMode { diff --git a/Classes/LinphoneUI/UICompositeViewController.m b/Classes/LinphoneUI/UICompositeViewController.m index dbb85c155..ea275ea23 100644 --- a/Classes/LinphoneUI/UICompositeViewController.m +++ b/Classes/LinphoneUI/UICompositeViewController.m @@ -174,31 +174,39 @@ - (void)orientationChanged:(NSNotification *)notification { currentOrientation = [[UIDevice currentDevice] orientation]; - } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { - UIDeviceOrientation correctOrientation = [self getCorrectInterfaceOrientation:currentOrientation]; - [UIView beginAnimations:@"Rotation" context:nil]; - [UIView setAnimationDuration:duration]; - [self applySubLayoutsForInterfaceOrientation:correctOrientation]; + UIDeviceOrientation correctOrientation = [self getCorrectInterfaceOrientation:toInterfaceOrientation]; + [super willRotateToInterfaceOrientation:correctOrientation duration:duration]; + [contentViewController willRotateToInterfaceOrientation:correctOrientation duration:duration]; + [tabBarViewController willRotateToInterfaceOrientation:correctOrientation duration:duration]; + [stateBarViewController willRotateToInterfaceOrientation:correctOrientation duration:duration]; [self update:nil tabBar:nil fullscreen:nil]; - [UIView commitAnimations]; +} + +- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { + UIDeviceOrientation correctOrientation = [self getCorrectInterfaceOrientation:toInterfaceOrientation]; + [super willAnimateRotationToInterfaceOrientation:correctOrientation duration:duration]; + [contentViewController willAnimateRotationToInterfaceOrientation:correctOrientation duration:duration]; + [tabBarViewController willAnimateRotationToInterfaceOrientation:correctOrientation duration:duration]; + [stateBarViewController willAnimateRotationToInterfaceOrientation:correctOrientation duration:duration]; +} + +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { + [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; + [contentViewController didRotateFromInterfaceOrientation:fromInterfaceOrientation]; + [tabBarViewController didRotateFromInterfaceOrientation:fromInterfaceOrientation]; + [stateBarViewController didRotateFromInterfaceOrientation:fromInterfaceOrientation]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(currentViewDescription != nil) { - if (interfaceOrientation == UIInterfaceOrientationPortrait || - interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { - if ([currentViewDescription portraitMode]) { - return YES; - } + if (UIInterfaceOrientationIsPortrait(interfaceOrientation) && [currentViewDescription portraitMode]) { + return YES; } - if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || - interfaceOrientation == UIInterfaceOrientationLandscapeRight) { - if ([currentViewDescription landscapeMode]) { - return YES; - } + if (UIInterfaceOrientationIsLandscape(interfaceOrientation) && [currentViewDescription landscapeMode]) { + return YES; } return NO; } @@ -265,28 +273,24 @@ return UIInterfaceOrientationPortrait; } -- (void)applySubLayoutsForInterfaceOrientation:(UIInterfaceOrientation)newOrientation { - [self applyLayoutForInterfaceOrientation:newOrientation]; - [contentViewController willRotateToInterfaceOrientation:newOrientation duration:0]; - [contentViewController willAnimateRotationToInterfaceOrientation:newOrientation duration:0]; - if ([contentViewController isKindOfClass:[TPMultiLayoutViewController class]]) { - [(TPMultiLayoutViewController*)contentViewController applyLayoutForInterfaceOrientation:newOrientation]; - } - [contentViewController didRotateFromInterfaceOrientation: newOrientation]; +- (void)updateInterfaceOrientation:(UIInterfaceOrientation)correctOrientation { + UIInterfaceOrientation orientation; - [tabBarViewController willRotateToInterfaceOrientation:newOrientation duration:0]; - [tabBarViewController willAnimateRotationToInterfaceOrientation:newOrientation duration:0]; - if ([tabBarViewController isKindOfClass:[TPMultiLayoutViewController class]]) { - [(TPMultiLayoutViewController*)tabBarViewController applyLayoutForInterfaceOrientation:newOrientation]; - } - [tabBarViewController didRotateFromInterfaceOrientation: newOrientation]; + orientation = self.interfaceOrientation; + [super willRotateToInterfaceOrientation:correctOrientation duration:0]; + [super didRotateFromInterfaceOrientation:orientation]; - [stateBarViewController willRotateToInterfaceOrientation:newOrientation duration:0]; - [stateBarViewController willAnimateRotationToInterfaceOrientation:newOrientation duration:0]; - if ([stateBarViewController isKindOfClass:[TPMultiLayoutViewController class]]) { - [(TPMultiLayoutViewController*)stateBarViewController applyLayoutForInterfaceOrientation:newOrientation]; - } - [stateBarViewController didRotateFromInterfaceOrientation: newOrientation]; + orientation = contentViewController.interfaceOrientation; + [contentViewController willRotateToInterfaceOrientation:correctOrientation duration:0]; + [contentViewController didRotateFromInterfaceOrientation:orientation]; + + orientation = tabBarViewController.interfaceOrientation; + [tabBarViewController willRotateToInterfaceOrientation:correctOrientation duration:0]; + [contentViewController didRotateFromInterfaceOrientation:orientation]; + + orientation = stateBarViewController.interfaceOrientation; + [stateBarViewController willRotateToInterfaceOrientation:correctOrientation duration:0]; + [stateBarViewController didRotateFromInterfaceOrientation:orientation]; } #define IPHONE_STATUSBAR_HEIGHT 20 @@ -326,12 +330,17 @@ // Update rotation UIDeviceOrientation correctOrientation = [self getCorrectInterfaceOrientation:currentOrientation]; - UIDeviceOrientation screenOrientation = [[UIApplication sharedApplication] statusBarOrientation]; - if(screenOrientation != correctOrientation) { - // Force the screen in correct rotation + if([UIApplication sharedApplication].statusBarOrientation != correctOrientation) { + [[NSNotificationCenter defaultCenter] removeObserver:self + name:UIDeviceOrientationDidChangeNotification + object:nil]; [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)correctOrientation]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(orientationChanged:) + name:UIDeviceOrientationDidChangeNotification + object:nil]; } - [self applySubLayoutsForInterfaceOrientation:correctOrientation]; + [self updateInterfaceOrientation:correctOrientation]; } else { oldViewDescription = (currentViewDescription != nil)? [currentViewDescription copy]: nil; } diff --git a/Classes/LinphoneUI/UIStateBar.m b/Classes/LinphoneUI/UIStateBar.m index da0d611c3..45914a3b9 100644 --- a/Classes/LinphoneUI/UIStateBar.m +++ b/Classes/LinphoneUI/UIStateBar.m @@ -242,4 +242,23 @@ NSTimer *callSecurityTimer; } } + +#pragma mark - TPMultiLayoutViewController Functions + +- (NSDictionary*)attributesForView:(UIView*)view { + NSMutableDictionary *attributes = [NSMutableDictionary dictionary]; + + [attributes setObject:[NSValue valueWithCGRect:view.frame] forKey:@"frame"]; + [attributes setObject:[NSValue valueWithCGRect:view.bounds] forKey:@"bounds"]; + [attributes setObject:[NSNumber numberWithInteger:view.autoresizingMask] forKey:@"autoresizingMask"]; + + return attributes; +} + +- (void)applyAttributes:(NSDictionary*)attributes toView:(UIView*)view { + view.frame = [[attributes objectForKey:@"frame"] CGRectValue]; + view.bounds = [[attributes objectForKey:@"bounds"] CGRectValue]; + view.autoresizingMask = [[attributes objectForKey:@"autoresizingMask"] integerValue]; +} + @end diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index bb467a11a..143a32343 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -171,6 +171,16 @@ static PhoneMainView* phoneMainViewInstance=nil; [mainViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; } +- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { + [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; + [mainViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; +} + +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { + [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; + [mainViewController didRotateFromInterfaceOrientation:fromInterfaceOrientation]; +} + #pragma mark - Event Functions diff --git a/Classes/Utils/TPMultiLayoutViewController/TPMultiLayoutViewController.m b/Classes/Utils/TPMultiLayoutViewController/TPMultiLayoutViewController.m index 76fccb14c..f57fdf46d 100755 --- a/Classes/Utils/TPMultiLayoutViewController/TPMultiLayoutViewController.m +++ b/Classes/Utils/TPMultiLayoutViewController/TPMultiLayoutViewController.m @@ -55,16 +55,12 @@ [super dealloc]; } -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { - return TRUE; -} - --(void)viewWillAppear:(BOOL)animated { +- (void)viewWillAppear:(BOOL)animated { // Display correct layout for orientation - if ( (UIInterfaceOrientationIsPortrait(self.interfaceOrientation) && !viewIsCurrentlyPortrait) || + /*if ( (UIInterfaceOrientationIsPortrait(self.interfaceOrientation) && !viewIsCurrentlyPortrait) || (UIInterfaceOrientationIsLandscape(self.interfaceOrientation) && viewIsCurrentlyPortrait) ) { [self applyLayoutForInterfaceOrientation:self.interfaceOrientation]; - } + }*/ [super viewWillAppear:animated]; } @@ -77,6 +73,7 @@ } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { + [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; if ( (UIInterfaceOrientationIsPortrait(toInterfaceOrientation) && !viewIsCurrentlyPortrait) || (UIInterfaceOrientationIsLandscape(toInterfaceOrientation) && viewIsCurrentlyPortrait) ) { [self applyLayoutForInterfaceOrientation:toInterfaceOrientation];