Fix chat view:

Keyboard after screen rotation
Bubbles rotation strange effect
This commit is contained in:
Yann Diorcet 2012-08-13 13:26:20 +02:00
parent 2dffddd07b
commit 23d3e03bac
10 changed files with 78 additions and 47 deletions

View file

@ -363,7 +363,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
[tokenString appendFormat:@"%02X", (unsigned int)tokenBuffer[i]]; [tokenString appendFormat:@"%02X", (unsigned int)tokenBuffer[i]];
} }
// NSLocalizedString(@"IC_MSG", nil); // Fake // NSLocalizedString(@"IC_MSG", nil); // Fake
NSString *params = [NSString stringWithFormat:@"APN-TOK=%@;APN-MSG=IC_MSG;APN-SND=oldphone-mono-30s.caf", tokenString]; NSString *params = [NSString stringWithFormat:@"APN-TOK=%@;APN-MSG=IM_MSG;APN-CAL=IC_MSG;APN-SND=oldphone-mono-30s.caf", tokenString];
linphone_proxy_config_set_contact_parameters(proxyCfg, [params UTF8String]); linphone_proxy_config_set_contact_parameters(proxyCfg, [params UTF8String]);
} }

View file

@ -99,25 +99,33 @@
// Message // Message
[chatContentLabel setText:[chat message]]; [chatContentLabel setText:[chat message]];
}
- (void)layoutSubviews {
[super layoutSubviews];
// //
// Adapt size // Adapt size
// //
CGRect displayNameFrame = [addressLabel frame]; CGRect displayNameFrame = [addressLabel frame];
CGRect chatContentFrame = [chatContentLabel frame]; CGRect chatContentFrame = [chatContentLabel frame];
chatContentFrame.origin.x -= displayNameFrame.size.width;
// Compute firstName size // Compute firstName size
CGSize contraints; CGSize displayNameSize = [[addressLabel text] sizeWithFont:[addressLabel font]];
contraints.height = [addressLabel frame].size.height; CGSize chatContentSize = [[chatContentLabel text] sizeWithFont:[chatContentLabel font]];
contraints.width = ([chatContentLabel frame].size.width + [chatContentLabel frame].origin.x) - [addressLabel frame].origin.x; float sum = displayNameSize.width + 5 + chatContentSize.width;
CGSize firstNameSize = [[addressLabel text] sizeWithFont:[addressLabel font] constrainedToSize: contraints]; float limit = self.bounds.size.width - 5 - displayNameFrame.origin.x;
displayNameFrame.size.width = firstNameSize.width; if(sum >limit) {
displayNameSize.width *= limit/sum;
chatContentSize.width *= limit/sum;
}
displayNameFrame.size.width = displayNameSize.width;
chatContentFrame.size.width = chatContentSize.width;
// Compute lastName size & position // Compute lastName size & position
chatContentFrame.origin.x += displayNameFrame.size.width; chatContentFrame.origin.x = displayNameFrame.origin.x + displayNameFrame.size.width;
chatContentFrame.size.width = (contraints.width + [addressLabel frame].origin.x) - chatContentFrame.origin.x; if(displayNameFrame.size.width)
chatContentFrame.origin.x += 5;
[addressLabel setFrame: displayNameFrame]; [addressLabel setFrame: displayNameFrame];
[chatContentLabel setFrame: chatContentFrame]; [chatContentLabel setFrame: chatContentFrame];

View file

@ -23,7 +23,7 @@
@interface UIChatRoomCell : UITableViewCell { @interface UIChatRoomCell : UITableViewCell {
UIImageView *backgroundImage; UIImageView *backgroundImage;
UIView *contentView; UIView *innerView;
UIView *messageView; UIView *messageView;
UILabel *messageLabel; UILabel *messageLabel;
UIButton *deleteButton; UIButton *deleteButton;
@ -33,7 +33,7 @@
} }
@property (nonatomic, retain) ChatModel *chat; @property (nonatomic, retain) ChatModel *chat;
@property (nonatomic, retain) IBOutlet UIView *contentView; @property (nonatomic, retain) IBOutlet UIView *innerView;
@property (nonatomic, retain) IBOutlet UIView *messageView; @property (nonatomic, retain) IBOutlet UIView *messageView;
@property (nonatomic, retain) IBOutlet UIImageView* backgroundImage; @property (nonatomic, retain) IBOutlet UIImageView* backgroundImage;
@property (nonatomic, retain) IBOutlet UILabel *messageLabel; @property (nonatomic, retain) IBOutlet UILabel *messageLabel;

View file

@ -24,7 +24,7 @@
@implementation UIChatRoomCell @implementation UIChatRoomCell
@synthesize contentView; @synthesize innerView;
@synthesize messageView; @synthesize messageView;
@synthesize backgroundImage; @synthesize backgroundImage;
@synthesize messageLabel; @synthesize messageLabel;
@ -47,14 +47,14 @@ static UIFont *CELL_FONT = nil;
[[NSBundle mainBundle] loadNibNamed:@"UIChatRoomCell" [[NSBundle mainBundle] loadNibNamed:@"UIChatRoomCell"
owner:self owner:self
options:nil]; options:nil];
[self addSubview:contentView]; [self addSubview:innerView];
} }
return self; return self;
} }
- (void)dealloc { - (void)dealloc {
[backgroundImage release]; [backgroundImage release];
[contentView release]; [innerView release];
[messageView release]; [messageView release];
[messageLabel release]; [messageLabel release];
[deleteButton release]; [deleteButton release];
@ -143,20 +143,20 @@ static UIFont *CELL_FONT = nil;
- (void)layoutSubviews { - (void)layoutSubviews {
[super layoutSubviews]; [super layoutSubviews];
if(chat != nil) { if(chat != nil) {
// Resize Content // Resize inner
CGRect contentFrame = [contentView frame]; CGRect innerFrame;
contentFrame.size = [UIChatRoomCell viewSize:[chat message] width:[self frame].size.width]; innerFrame.size = [UIChatRoomCell viewSize:[chat message] width:[self frame].size.width];
if([[chat direction] intValue]) { // Inverted if([[chat direction] intValue]) { // Inverted
contentFrame.origin.x = 0.0f; innerFrame.origin.x = 0.0f;
contentFrame.origin.y = 0.0f; innerFrame.origin.y = 0.0f;
} else { } else {
contentFrame.origin.x = [self frame].size.width - contentFrame.size.width; innerFrame.origin.x = [self frame].size.width - innerFrame.size.width;
contentFrame.origin.y = 0.0f; innerFrame.origin.y = 0.0f;
} }
[contentView setFrame:contentFrame]; [innerView setFrame:innerFrame];
CGRect messageFrame = [messageView frame]; CGRect messageFrame = [messageView frame];
messageFrame.origin.y = ([contentView frame].size.height - messageFrame.size.height)/2; messageFrame.origin.y = ([innerView frame].size.height - messageFrame.size.height)/2;
if([[chat direction] intValue]) { // Inverted if([[chat direction] intValue]) { // Inverted
[backgroundImage setImage:[TUNinePatchCache imageOfSize:[backgroundImage bounds].size [backgroundImage setImage:[TUNinePatchCache imageOfSize:[backgroundImage bounds].size
forNinePatchNamed:@"chat_bubble_incoming"]]; forNinePatchNamed:@"chat_bubble_incoming"]];

View file

@ -35,7 +35,7 @@
</object> </object>
<object class="IBUIView" id="579600281"> <object class="IBUIView" id="579600281">
<reference key="NSNextResponder"/> <reference key="NSNextResponder"/>
<int key="NSvFlags">301</int> <int key="NSvFlags">256</int>
<array class="NSMutableArray" key="NSSubviews"> <array class="NSMutableArray" key="NSSubviews">
<object class="IBUIImageView" id="340144998"> <object class="IBUIImageView" id="340144998">
<reference key="NSNextResponder" ref="579600281"/> <reference key="NSNextResponder" ref="579600281"/>
@ -227,14 +227,6 @@
</object> </object>
<int key="connectionID">13</int> <int key="connectionID">13</int>
</object> </object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">contentView</string>
<reference key="source" ref="841351856"/>
<reference key="destination" ref="579600281"/>
</object>
<int key="connectionID">14</int>
</object>
<object class="IBConnectionRecord"> <object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection"> <object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">messageLabel</string> <string key="label">messageLabel</string>
@ -267,6 +259,14 @@
</object> </object>
<int key="connectionID">24</int> <int key="connectionID">24</int>
</object> </object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">innerView</string>
<reference key="source" ref="841351856"/>
<reference key="destination" ref="579600281"/>
</object>
<int key="connectionID">25</int>
</object>
<object class="IBConnectionRecord"> <object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection"> <object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">onDeleteClick:</string> <string key="label">onDeleteClick:</string>
@ -304,7 +304,7 @@
<reference ref="456806949"/> <reference ref="456806949"/>
</array> </array>
<reference key="parent" ref="0"/> <reference key="parent" ref="0"/>
<string key="objectName">contentView</string> <string key="objectName">innerView</string>
</object> </object>
<object class="IBObjectRecord"> <object class="IBObjectRecord">
<int key="objectID">7</int> <int key="objectID">7</int>
@ -375,7 +375,7 @@
<nil key="activeLocalization"/> <nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/> <dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/> <nil key="sourceID"/>
<int key="maxID">24</int> <int key="maxID">25</int>
</object> </object>
<object class="IBClassDescriber" key="IBDocument.Classes"> <object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions"> <array class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -395,9 +395,9 @@
</object> </object>
<dictionary class="NSMutableDictionary" key="outlets"> <dictionary class="NSMutableDictionary" key="outlets">
<string key="backgroundImage">UIImageView</string> <string key="backgroundImage">UIImageView</string>
<string key="contentView">UIView</string>
<string key="dateLabel">UILabel</string> <string key="dateLabel">UILabel</string>
<string key="deleteButton">UIButton</string> <string key="deleteButton">UIButton</string>
<string key="innerView">UIView</string>
<string key="messageLabel">UILabel</string> <string key="messageLabel">UILabel</string>
<string key="messageView">UIView</string> <string key="messageView">UIView</string>
</dictionary> </dictionary>
@ -406,10 +406,6 @@
<string key="name">backgroundImage</string> <string key="name">backgroundImage</string>
<string key="candidateClassName">UIImageView</string> <string key="candidateClassName">UIImageView</string>
</object> </object>
<object class="IBToOneOutletInfo" key="contentView">
<string key="name">contentView</string>
<string key="candidateClassName">UIView</string>
</object>
<object class="IBToOneOutletInfo" key="dateLabel"> <object class="IBToOneOutletInfo" key="dateLabel">
<string key="name">dateLabel</string> <string key="name">dateLabel</string>
<string key="candidateClassName">UILabel</string> <string key="candidateClassName">UILabel</string>
@ -418,6 +414,10 @@
<string key="name">deleteButton</string> <string key="name">deleteButton</string>
<string key="candidateClassName">UIButton</string> <string key="candidateClassName">UIButton</string>
</object> </object>
<object class="IBToOneOutletInfo" key="innerView">
<string key="name">innerView</string>
<string key="candidateClassName">UIView</string>
</object>
<object class="IBToOneOutletInfo" key="messageLabel"> <object class="IBToOneOutletInfo" key="messageLabel">
<string key="name">messageLabel</string> <string key="name">messageLabel</string>
<string key="candidateClassName">UILabel</string> <string key="candidateClassName">UILabel</string>

View file

@ -251,7 +251,7 @@
// Update rotation // Update rotation
UIInterfaceOrientation correctOrientation = [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]]; UIInterfaceOrientation correctOrientation = [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]];
if(currentOrientation != correctOrientation) { if(currentOrientation != correctOrientation) {
[PhoneMainView forceOrientation:correctOrientation animated:currentOrientation!=UIDeviceOrientationUnknown]; [PhoneMainView setOrientation:correctOrientation animated:currentOrientation!=UIDeviceOrientationUnknown];
} }
} }
@ -439,7 +439,7 @@
// Update rotation // Update rotation
UIInterfaceOrientation correctOrientation = [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]]; UIInterfaceOrientation correctOrientation = [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]];
if(currentOrientation != correctOrientation) { if(currentOrientation != correctOrientation) {
[PhoneMainView forceOrientation:correctOrientation animated:currentOrientation!=UIDeviceOrientationUnknown]; [PhoneMainView setOrientation:correctOrientation animated:currentOrientation!=UIDeviceOrientationUnknown];
} else { } else {
[self updateInterfaceOrientation:correctOrientation]; [self updateInterfaceOrientation:correctOrientation];
} }

View file

@ -111,7 +111,7 @@
// Compute firstName size // Compute firstName size
CGSize firstNameSize = [[firstNameLabel text] sizeWithFont:[firstNameLabel font]]; CGSize firstNameSize = [[firstNameLabel text] sizeWithFont:[firstNameLabel font]];
CGSize lastNameSize = [[lastNameLabel text] sizeWithFont:[firstNameLabel font]]; CGSize lastNameSize = [[lastNameLabel text] sizeWithFont:[lastNameLabel font]];
float sum = firstNameSize.width + 5 + lastNameSize.width; float sum = firstNameSize.width + 5 + lastNameSize.width;
float limit = self.bounds.size.width - 5 - firstNameFrame.origin.x; float limit = self.bounds.size.width - 5 - firstNameFrame.origin.x;
if(sum >limit) { if(sum >limit) {

View file

@ -62,7 +62,7 @@
- (void)fullScreen:(BOOL)enabled; - (void)fullScreen:(BOOL)enabled;
- (void)startUp; - (void)startUp;
+ (void)forceOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated; + (void)setOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated;
+ (PhoneMainView*) instance; + (PhoneMainView*) instance;

View file

@ -169,11 +169,27 @@ static PhoneMainView* phoneMainViewInstance=nil;
return NO; return NO;
} }
+ (UIView*)findFirstResponder:(UIView*)view {
if (view.isFirstResponder) {
return view;
}
for (UIView *subView in view.subviews) {
UIView *ret = [PhoneMainView findFirstResponder:subView];
if (ret != nil)
return ret;
}
return nil;
}
/* /*
Will simulate a device rotation Will simulate a device rotation
*/ */
+ (void)forceOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated { + (void)setOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated {
UIView *firstResponder = nil;
for(UIWindow *window in [[UIApplication sharedApplication] windows]) { for(UIWindow *window in [[UIApplication sharedApplication] windows]) {
if([NSStringFromClass(window.class) isEqualToString:@"UITextEffectsWindow"]) {
continue;
}
UIView *view = window; UIView *view = window;
UIViewController *controller = nil; UIViewController *controller = nil;
CGRect frame = [view frame]; CGRect frame = [view frame];
@ -216,8 +232,15 @@ static PhoneMainView* phoneMainViewInstance=nil;
[UIView commitAnimations]; [UIView commitAnimations];
} }
[controller didRotateFromInterfaceOrientation:oldOrientation]; [controller didRotateFromInterfaceOrientation:oldOrientation];
if(firstResponder == nil) {
firstResponder = [PhoneMainView findFirstResponder:view];
}
} }
[[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:animated]; [[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:animated];
if(firstResponder) {
[firstResponder resignFirstResponder];
[firstResponder becomeFirstResponder];
}
} }
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
@ -246,8 +269,8 @@ static PhoneMainView* phoneMainViewInstance=nil;
ChatModel *chat = [[notif userInfo] objectForKey:@"chat"]; ChatModel *chat = [[notif userInfo] objectForKey:@"chat"];
if(chat != nil) { if(chat != nil) {
[self displayMessage:chat]; [self displayMessage:chat];
[self updateApplicationBadgeNumber];
} }
[self updateApplicationBadgeNumber];
} }
- (void)registrationUpdate:(NSNotification*)notif { - (void)registrationUpdate:(NSNotification*)notif {