mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
UI: work on rounded images and avatar update
This commit is contained in:
parent
d7f18cab84
commit
c5624d6711
6 changed files with 57 additions and 26 deletions
|
|
@ -302,6 +302,11 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
#pragma mark - Image picker delegate
|
||||
|
||||
- (void)imagePickerDelegateImage:(UIImage *)image info:(NSDictionary *)info {
|
||||
// Dismiss popover on iPad
|
||||
if (LinphoneManager.runningOnIpad) {
|
||||
[VIEW(ImagePickerView).popoverController dismissPopoverAnimated:TRUE];
|
||||
}
|
||||
|
||||
FastAddressBook *fab = [LinphoneManager instance].fastAddressBook;
|
||||
CFErrorRef error = NULL;
|
||||
if (!ABPersonRemoveImageData(_contact, (CFErrorRef *)&error)) {
|
||||
|
|
|
|||
|
|
@ -169,10 +169,10 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
|
||||
+ (void)SelectImageFromDevice:(id<ImagePickerDelegate>)delegate
|
||||
atPosition:(UIView *)ipadPopoverView
|
||||
inView:(UIView *_Nonnull)ipadView {
|
||||
inView:(UIView *)ipadView {
|
||||
void (^block)(UIImagePickerControllerSourceType) = ^(UIImagePickerControllerSourceType type) {
|
||||
ImagePickerView *view = VIEW(ImagePickerView);
|
||||
if (!LinphoneManager.runningOnIpad) {
|
||||
if (!(LinphoneManager.runningOnIpad && ipadView && ipadPopoverView)) {
|
||||
[PhoneMainView.instance changeCurrentView:view.compositeViewDescription push:TRUE];
|
||||
}
|
||||
view.sourceType = type;
|
||||
|
|
@ -186,16 +186,14 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
view.allowsEditing = NO;
|
||||
view.imagePickerDelegate = delegate;
|
||||
|
||||
if (LinphoneManager.runningOnIpad) {
|
||||
if (LinphoneManager.runningOnIpad && ipadView && ipadPopoverView) {
|
||||
UIView *iterview = ipadPopoverView;
|
||||
CGRect ipadPopoverPosition = iterview.frame;
|
||||
do {
|
||||
// [_avatarImage.superview convertRect:_avatarImage.frame toView:self.view];
|
||||
// CGRect rect = [_messageView convertRect:[_pictureButton frame] toView:self.view];
|
||||
ipadPopoverPosition =
|
||||
[iterview.superview convertRect:ipadPopoverPosition toView:iterview.superview.superview];
|
||||
iterview = iterview.superview;
|
||||
} while (iterview.superview.superview != ipadView);
|
||||
} while (iterview && iterview.superview != ipadView);
|
||||
[view.popoverController presentPopoverFromRect:ipadPopoverPosition
|
||||
inView:ipadView
|
||||
permittedArrowDirections:UIPopoverArrowDirectionAny
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ INIT_WITH_COMMON {
|
|||
name:@"UIDeviceOrientationDidChangeNotification"
|
||||
object:nil];
|
||||
|
||||
// self.layer.borderWidth = 1;
|
||||
// self.layer.borderColor = [UIColor redColor].CGColor;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
@ -51,20 +53,20 @@ INIT_WITH_COMMON {
|
|||
- (void)setBordered:(BOOL)bordered {
|
||||
borderView.hidden = !bordered;
|
||||
if (bordered) {
|
||||
CGRect frame = borderView.frame;
|
||||
frame.size.height = frame.size.height = MIN(self.layer.frame.size.height, self.layer.frame.size.width);
|
||||
frame.origin.x += (borderView.frame.size.width - frame.size.width) / 2;
|
||||
frame.origin.y += (borderView.frame.size.height - frame.size.height) / 2;
|
||||
CGRect frame = self.frame;
|
||||
frame.size.height = frame.size.width = MIN(self.layer.frame.size.height, self.layer.frame.size.width);
|
||||
frame.origin.x = (self.frame.size.width - frame.size.width) / 2;
|
||||
frame.origin.y = (self.frame.size.height - frame.size.height) / 2;
|
||||
borderView.frame = frame;
|
||||
borderView.layer.borderWidth = 10;
|
||||
borderView.layer.borderColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"color_A.png"]].CGColor;
|
||||
self.layer.borderWidth = 10;
|
||||
// [borderView.layer setCornerRadius:frame.size.height / 2];
|
||||
self.layer.borderColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"color_A.png"]].CGColor;
|
||||
} else {
|
||||
borderView.layer.borderWidth = 0;
|
||||
self.layer.borderWidth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setRoundRadius {
|
||||
return;
|
||||
CALayer *imageLayer = self.layer;
|
||||
|
||||
CGFloat height = imageLayer.frame.size.height;
|
||||
|
|
|
|||
|
|
@ -64,8 +64,9 @@
|
|||
|
||||
- (IBAction)onAvatarClick:(id)sender {
|
||||
// hide ourself because we are on top of image picker
|
||||
// [PhoneMainView.instance.mainViewController hideSideMenu:YES];
|
||||
|
||||
if (!LinphoneManager.runningOnIpad) {
|
||||
[PhoneMainView.instance.mainViewController hideSideMenu:YES];
|
||||
}
|
||||
[ImagePickerView SelectImageFromDevice:self atPosition:_avatarImage inView:self.view];
|
||||
}
|
||||
|
||||
|
|
@ -77,9 +78,16 @@
|
|||
#pragma mark - Image picker delegate
|
||||
|
||||
- (void)imagePickerDelegateImage:(UIImage *)image info:(NSDictionary *)info {
|
||||
// Dismiss popover on iPad
|
||||
if (LinphoneManager.runningOnIpad) {
|
||||
[VIEW(ImagePickerView).popoverController dismissPopoverAnimated:TRUE];
|
||||
} else {
|
||||
[PhoneMainView.instance.mainViewController hideSideMenu:NO];
|
||||
}
|
||||
|
||||
NSURL *url = [info valueForKey:UIImagePickerControllerReferenceURL];
|
||||
[LinphoneManager.instance lpConfigSetString:url.absoluteString forKey:@"avatar"];
|
||||
[PhoneMainView.instance.mainViewController hideSideMenu:NO];
|
||||
_avatarImage.image = [LinphoneUtils selfAvatar];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -352,10 +352,12 @@ void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info, void
|
|||
LOGI(@"Remove contact %p: Success!", contact);
|
||||
}
|
||||
contact = NULL;
|
||||
|
||||
// Save address book
|
||||
error = NULL;
|
||||
ABAddressBookSave(addressBook, (CFErrorRef *)&error);
|
||||
|
||||
[self reload];
|
||||
|
||||
if (error != NULL) {
|
||||
LOGE(@"Save AddressBook: Fail(%@)", [(__bridge NSError *)error localizedDescription]);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -455,8 +455,6 @@ void linphone_iphone_log_handler(int lev, const char *fmt, va_list args) {
|
|||
@implementation UIImage (squareCrop)
|
||||
|
||||
- (UIImage *)squareCrop {
|
||||
UIImage *ret = nil;
|
||||
|
||||
// This calculates the crop area.
|
||||
|
||||
float originalWidth = self.size.width;
|
||||
|
|
@ -467,20 +465,38 @@ void linphone_iphone_log_handler(int lev, const char *fmt, va_list args) {
|
|||
float posX = (originalWidth - edge) / 2.0f;
|
||||
float posY = (originalHeight - edge) / 2.0f;
|
||||
|
||||
CGRect cropSquare = CGRectMake(posX, posY, edge, edge);
|
||||
|
||||
CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], cropSquare);
|
||||
ret = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation];
|
||||
CGRect rect = CGRectMake(posX, posY, edge, edge);
|
||||
|
||||
// Create bitmap image from original image data,
|
||||
// using rectangle to specify desired crop area
|
||||
CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], rect);
|
||||
UIImage *img = [UIImage imageWithCGImage:imageRef];
|
||||
CGImageRelease(imageRef);
|
||||
|
||||
return ret;
|
||||
return img; /*
|
||||
UIImage *ret = nil;
|
||||
|
||||
|
||||
|
||||
CGRect cropSquare = CGRectMake(posX, posY, edge, edge);
|
||||
|
||||
// CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], cropSquare);
|
||||
// ret = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation];
|
||||
//
|
||||
// CGImageRelease(imageRef);
|
||||
|
||||
CGImageRef imageRef = CGImageCreateWithImageInRect(self.CGImage, cropSquare);
|
||||
ret = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation];
|
||||
CGImageRelease(imageRef);
|
||||
|
||||
|
||||
return ret;*/
|
||||
}
|
||||
|
||||
- (UIImage *)scaleToSize:(CGSize)size squared:(BOOL)squared {
|
||||
UIImage *scaledImage = self;
|
||||
if (squared) {
|
||||
scaledImage = [self squareCrop];
|
||||
// scaledImage = [self squareCrop];
|
||||
size.width = size.height = MAX(size.width, size.height);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue