Use LinphoneManager singleton

Fix Rotation issues
This commit is contained in:
Yann Diorcet 2012-07-24 11:52:09 +02:00
parent 88144bc4b1
commit 6d9f40a9a1
6 changed files with 87 additions and 58 deletions

View file

@ -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];

View file

@ -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 {

View file

@ -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;
}

View file

@ -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

View file

@ -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

View file

@ -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];