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]];
}
// 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]);
}

View file

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

View file

@ -23,7 +23,7 @@
@interface UIChatRoomCell : UITableViewCell {
UIImageView *backgroundImage;
UIView *contentView;
UIView *innerView;
UIView *messageView;
UILabel *messageLabel;
UIButton *deleteButton;
@ -33,7 +33,7 @@
}
@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 UIImageView* backgroundImage;
@property (nonatomic, retain) IBOutlet UILabel *messageLabel;

View file

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

View file

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

View file

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

View file

@ -111,7 +111,7 @@
// Compute firstName size
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 limit = self.bounds.size.width - 5 - firstNameFrame.origin.x;
if(sum >limit) {

View file

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

View file

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