Improve animation between views

Improve Start/Foreground/Background
This commit is contained in:
Yann Diorcet 2012-08-09 14:35:28 +02:00
parent 25dcdee588
commit be9509f7c3
8 changed files with 74 additions and 100 deletions

View file

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

View file

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

View file

@ -86,7 +86,7 @@ typedef struct _LinphoneCallAppData {
- (void)startLibLinphone;
- (void)destroyLibLinphone;
- (BOOL)enterBackgroundMode;
- (BOOL)resignActive;
- (void)becomeActive;
- (void)kickOffNetworkConnection;

View file

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

View file

@ -197,6 +197,8 @@
setImage:[UIImage imageNamed:@"dialer_alt_back_over_landscape.png"]
forState:(UIControlStateHighlighted | UIControlStateSelected)];
[optionsView setHidden:TRUE];
[padView setHidden:TRUE];
[super viewDidLoad];
}

View file

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

View file

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

View file

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