From be9509f7c3319ca7ba673b01362e6c2057f16143 Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Thu, 9 Aug 2012 14:35:28 +0200 Subject: [PATCH] Improve animation between views Improve Start/Foreground/Background --- Classes/LinphoneAppDelegate.h | 6 -- Classes/LinphoneAppDelegate.m | 97 +++++-------------- Classes/LinphoneManager.h | 2 +- Classes/LinphoneManager.m | 8 +- Classes/LinphoneUI/UICallBar.m | 2 + .../LinphoneUI/UICompositeViewController.m | 16 +-- Classes/LinphoneUI/UIMainBar.m | 20 ++-- Classes/PhoneMainView.m | 23 ++++- 8 files changed, 74 insertions(+), 100 deletions(-) diff --git a/Classes/LinphoneAppDelegate.h b/Classes/LinphoneAppDelegate.h index a17a464fd..bc83e5280 100644 --- a/Classes/LinphoneAppDelegate.h +++ b/Classes/LinphoneAppDelegate.h @@ -33,12 +33,6 @@ BOOL started; } -- (void)loadDefaultSettings:(NSDictionary *) appDefaults; -- (void)setupUI; -- (void)setupGSMInteraction; - -- (void)startApplication; - @property (nonatomic, retain) IBOutlet UIWindow *window; @property (assign) BOOL started; diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 4e731bc61..c6ef17ab8 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -100,11 +100,7 @@ int __aeabi_idiv(int a, int b) { linphone_call_enable_camera(call, false); } -} -- (void)applicationDidEnterBackground:(UIApplication *)application { - if ([[LinphoneManager instance] settingsStore]!=Nil) - [[[LinphoneManager instance] settingsStore] synchronize]; - if (![[LinphoneManager instance] enterBackgroundMode]) { + if (![[LinphoneManager instance] resignActive]) { // destroying eventHandler if app cannot go in background. // Otherwise if a GSM call happen and Linphone is resumed, // the handler will be called before LinphoneCore is built. @@ -113,29 +109,14 @@ int __aeabi_idiv(int a, int b) { [callCenter release]; callCenter = nil; } -} -- (void)applicationDidBecomeActive:(UIApplication *)application { - if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] - && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground - && (![[NSUserDefaults standardUserDefaults] boolForKey:@"start_at_boot_preference"] || - ![[NSUserDefaults standardUserDefaults] boolForKey:@"backgroundmode_preference"])) { - // autoboot disabled, doing nothing - return; - } +} + +- (void)applicationDidBecomeActive:(UIApplication *)application { [self startApplication]; [[LinphoneManager instance] becomeActive]; - if (callCenter == nil) { - callCenter = [[CTCallCenter alloc] init]; - callCenter.callEventHandler = ^(CTCall* call) { - // post on main thread - [self performSelectorOnMainThread:@selector(handleGSMCallInteration:) - withObject:callCenter - waitUntilDone:YES]; - }; - } // check call state at startup [self handleGSMCallInteration:callCenter]; @@ -156,31 +137,6 @@ int __aeabi_idiv(int a, int b) { } } -- (void)loadDefaultSettings:(NSDictionary *) appDefaults { - for(NSString* key in appDefaults){ - [LinphoneLogger log:LinphoneLoggerLog format:@"Overload %@ to in app settings.", key]; - [[[LinphoneManager instance] settingsStore] setObject:[appDefaults objectForKey:key] forKey:key]; - } - [[[LinphoneManager instance] settingsStore] synchronize]; -} - -- (void)setupUI { - [[PhoneMainView instance] startUp]; - if ([[LinphoneManager instance].settingsStore boolForKey:@"enable_first_login_view_preference"] == true) { - // Change to fist login view - [[PhoneMainView instance] changeCurrentView: [FirstLoginViewController compositeViewDescription]]; - } else { - // Change to default view - const MSList *list = linphone_core_get_proxy_config_list([LinphoneManager getLc]); - if(list != NULL) { - [[PhoneMainView instance] changeCurrentView: [DialerViewController compositeViewDescription]]; - } else { - [[PhoneMainView instance] changeCurrentView: [WizardViewController compositeViewDescription]]; - } - } - [UIDevice currentDevice].batteryMonitoringEnabled = YES; -} - - (void)setupGSMInteraction { if (callCenter == nil) { callCenter = [[CTCallCenter alloc] init]; @@ -193,36 +149,34 @@ int __aeabi_idiv(int a, int b) { } } -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ - NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys: nil]; - // Put your default NSUserDefaults settings in the dictionary above. +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound]; - if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] - && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground + if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] + && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground && (![[NSUserDefaults standardUserDefaults] boolForKey:@"start_at_boot_preference"] || ![[NSUserDefaults standardUserDefaults] boolForKey:@"backgroundmode_preference"])) { - // autoboot disabled, doing nothing - } else { - [self startApplication]; - [self loadDefaultSettings: appDefaults]; - } - + // autoboot disabled, doing nothing + return YES; + } + + [self startApplication]; + return YES; } - (void)startApplication { - if(started) - return; - - started = TRUE; - - [[LinphoneManager instance] startLibLinphone]; - - [self setupUI]; - - [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound]; - + // Restart Linphone Core if needed + if(![LinphoneManager isLcReady]) { + [[LinphoneManager instance] startLibLinphone]; + } [self setupGSMInteraction]; + + // Only execute one time at application start + if(!started) { + started = TRUE; + [[PhoneMainView instance] startUp]; + } } @@ -230,7 +184,7 @@ int __aeabi_idiv(int a, int b) { } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { - //NSLog(@"%@", userInfo); + [LinphoneLogger log:LinphoneLoggerDebug format:@"PushNotification: Receive %@", userInfo]; } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { @@ -257,7 +211,6 @@ int __aeabi_idiv(int a, int b) { - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { [LinphoneLogger log:LinphoneLoggerDebug format:@"PushNotification: Token %@", deviceToken]; - //NSLog(@"%@", deviceToken); [[LinphoneManager instance] setPushNotificationToken:deviceToken]; } diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index b2b3dcabd..7e3adc7ef 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -86,7 +86,7 @@ typedef struct _LinphoneCallAppData { - (void)startLibLinphone; - (void)destroyLibLinphone; -- (BOOL)enterBackgroundMode; +- (BOOL)resignActive; - (void)becomeActive; - (void)kickOffNetworkConnection; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index d2a7408f0..98cc5bad0 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -636,7 +636,7 @@ static LinphoneCoreVTable linphonec_vtable = { if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { //go directly to bg mode - [self enterBackgroundMode]; + [self resignActive]; } } @@ -657,6 +657,12 @@ static LinphoneCoreVTable linphonec_vtable = { } } +- (BOOL)resignActive { + if ([[LinphoneManager instance] settingsStore] != Nil) + [[[LinphoneManager instance] settingsStore] synchronize]; + return [self enterBackgroundMode]; +} + - (BOOL)enterBackgroundMode { LinphoneProxyConfig* proxyCfg; linphone_core_get_default_proxy(theLinphoneCore, &proxyCfg); diff --git a/Classes/LinphoneUI/UICallBar.m b/Classes/LinphoneUI/UICallBar.m index 3751dcdba..2a7ae4deb 100644 --- a/Classes/LinphoneUI/UICallBar.m +++ b/Classes/LinphoneUI/UICallBar.m @@ -197,6 +197,8 @@ setImage:[UIImage imageNamed:@"dialer_alt_back_over_landscape.png"] forState:(UIControlStateHighlighted | UIControlStateSelected)]; + [optionsView setHidden:TRUE]; + [padView setHidden:TRUE]; [super viewDidLoad]; } diff --git a/Classes/LinphoneUI/UICompositeViewController.m b/Classes/LinphoneUI/UICompositeViewController.m index a27966eea..5483b3b71 100644 --- a/Classes/LinphoneUI/UICompositeViewController.m +++ b/Classes/LinphoneUI/UICompositeViewController.m @@ -356,13 +356,17 @@ // Animate only with a previous screen if(oldViewDescription != nil && viewTransition != nil) { - [contentView.layer addAnimation:viewTransition forKey:@"Transition"]; - if((oldViewDescription.stateBarEnabled == true && currentViewDescription.stateBarEnabled == false) || - (oldViewDescription.stateBarEnabled == false && currentViewDescription.stateBarEnabled == true)) { - [stateBarView.layer addAnimation:viewTransition forKey:@"Transition"]; + [contentView.layer removeAnimationForKey:@"transition"]; + [contentView.layer addAnimation:viewTransition forKey:@"transition"]; + if(oldViewDescription.stateBar != currentViewDescription.stateBar || + [stateBarView.layer animationForKey:@"transition"] != nil) { + [stateBarView.layer removeAnimationForKey:@"transition"]; + [stateBarView.layer addAnimation:viewTransition forKey:@"transition"]; } - if(oldViewDescription.tabBar != currentViewDescription.tabBar) { - [tabBarView.layer addAnimation:viewTransition forKey:@"Transition"]; + if(oldViewDescription.tabBar != currentViewDescription.tabBar || + [tabBarView.layer animationForKey:@"transition"] != nil) { + [tabBarView.layer removeAnimationForKey:@"transition"]; + [tabBarView.layer addAnimation:viewTransition forKey:@"transition"]; } } diff --git a/Classes/LinphoneUI/UIMainBar.m b/Classes/LinphoneUI/UIMainBar.m index 631d465cd..2f12c029e 100644 --- a/Classes/LinphoneUI/UIMainBar.m +++ b/Classes/LinphoneUI/UIMainBar.m @@ -187,19 +187,19 @@ if([chatNotificationView isHidden]) { [chatNotificationView setHidden:FALSE]; if(appear) { - [self appearAnimation:@"Appear" target:chatNotificationView completion:^(BOOL finished){ - [self startBounceAnimation:@"Bounce" target:chatNotificationView]; + [self appearAnimation:@"appear" target:chatNotificationView completion:^(BOOL finished){ + [self startBounceAnimation:@"bounce" target:chatNotificationView]; }]; } else { - [self startBounceAnimation:@"Bounce" target:chatNotificationView]; + [self startBounceAnimation:@"bounce" target:chatNotificationView]; } } [chatNotificationLabel setText:[NSString stringWithFormat:@"%i", unreadMessage]]; } else { if(![chatNotificationView isHidden]) { - [self stopBounceAnimation:@"Bounce" target:chatNotificationView]; + [self stopBounceAnimation:@"bounce" target:chatNotificationView]; if(appear) { - [self disappearAnimation:@"Disappear" target:chatNotificationView completion:^(BOOL finished){ + [self disappearAnimation:@"disappear" target:chatNotificationView completion:^(BOOL finished){ [chatNotificationView setHidden:TRUE]; }]; } else { @@ -214,19 +214,19 @@ if([historyNotificationView isHidden]) { [historyNotificationView setHidden:FALSE]; if(appear) { - [self appearAnimation:@"Appear" target:historyNotificationView completion:^(BOOL finished){ - [self startBounceAnimation:@"Bounce" target:historyNotificationView]; + [self appearAnimation:@"appear" target:historyNotificationView completion:^(BOOL finished){ + [self startBounceAnimation:@"bounce" target:historyNotificationView]; }]; } else { - [self startBounceAnimation:@"Bounce" target:historyNotificationView]; + [self startBounceAnimation:@"bounce" target:historyNotificationView]; } } [historyNotificationLabel setText:[NSString stringWithFormat:@"%i", missedCall]]; } else { if(![historyNotificationView isHidden]) { - [self stopBounceAnimation:@"Bounce" target:historyNotificationView]; + [self stopBounceAnimation:@"bounce" target:historyNotificationView]; if(appear) { - [self disappearAnimation:@"Disappear" target:historyNotificationView completion:^(BOOL finished){ + [self disappearAnimation:@"disappear" target:historyNotificationView completion:^(BOOL finished){ }]; } else { diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index cc510e626..c40c8aa1a 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -116,6 +116,7 @@ static PhoneMainView* phoneMainViewInstance=nil; selector:@selector(batteryLevelChanged:) name:UIDeviceBatteryLevelDidChangeNotification object:nil]; + [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; } - (void)viewWillDisappear:(BOOL)animated { @@ -138,6 +139,7 @@ static PhoneMainView* phoneMainViewInstance=nil; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceBatteryLevelDidChangeNotification object:nil]; + [[UIDevice currentDevice] setBatteryMonitoringEnabled:NO]; } - (void)viewDidAppear:(BOOL)animated { @@ -351,7 +353,20 @@ static PhoneMainView* phoneMainViewInstance=nil; #pragma mark - -- (void)startUp { +- (void)startUp { + if ([[LinphoneManager instance].settingsStore boolForKey:@"enable_first_login_view_preference"] == true) { + // Change to fist login view + [self changeCurrentView: [FirstLoginViewController compositeViewDescription]]; + } else { + // Change to default view + const MSList *list = linphone_core_get_proxy_config_list([LinphoneManager getLc]); + if(list != NULL) { + [self changeCurrentView: [DialerViewController compositeViewDescription]]; + } else { + [self changeCurrentView: [WizardViewController compositeViewDescription]]; + } + } + [self updateApplicationBadgeNumber]; // Update Badge at startup } @@ -420,15 +435,15 @@ static PhoneMainView* phoneMainViewInstance=nil; return phoneMainViewInstance; } -- (void) showTabBar:(BOOL) show { +- (void) showTabBar:(BOOL)show { [mainViewController setToolBarHidden:!show]; } -- (void) showStateBar:(BOOL) show { +- (void) showStateBar:(BOOL)show { [mainViewController setStateBarHidden:!show]; } -- (void)fullScreen:(BOOL) enabled { +- (void)fullScreen:(BOOL)enabled { [mainViewController setFullScreen:enabled]; }