diff --git a/Classes/HistoryListTableView.m b/Classes/HistoryListTableView.m index ebc661cbf..3eff79234 100644 --- a/Classes/HistoryListTableView.m +++ b/Classes/HistoryListTableView.m @@ -167,39 +167,6 @@ } } -+ (UIImage *)resizeImage:(UIImage *)image -{ - float actualHeight = image.size.height; - float actualWidth = image.size.width; - float maxHeight = 200.0; - float maxWidth = 200.0; - float imgRatio = actualWidth/actualHeight; - float maxRatio = maxWidth/maxHeight; - float compressionQuality = 1; - if (actualHeight > maxHeight || actualWidth > maxWidth) - { - if(imgRatio < maxRatio) { - imgRatio = maxHeight / actualHeight; - actualWidth = imgRatio * actualWidth; - actualHeight = maxHeight; - } else if(imgRatio > maxRatio) { - imgRatio = maxWidth / actualWidth; - actualHeight = imgRatio * actualHeight; - actualWidth = maxWidth; - } else { - actualHeight = maxHeight; - actualWidth = maxWidth; - } - } - CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight); - UIGraphicsBeginImageContext(rect.size); - [image drawInRect:rect]; - UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); - NSData *imageData = UIImageJPEGRepresentation(img, compressionQuality); - UIGraphicsEndImageContext(); - return [UIImage imageWithData:imageData]; -} - + (void) saveDataToUserDefaults { const bctbx_list_t *logs = linphone_core_get_call_logs(LC); NSUserDefaults *mySharedDefaults = [[NSUserDefaults alloc] initWithSuiteName: @"group.belledonne-communications.linphone.widget"]; @@ -215,7 +182,7 @@ //FastAddressBook *fab = [LinphoneManager instance].fastAddressBook; Contact * contact = [FastAddressBook getContactWithAddress:linphone_call_log_get_remote_address(log)]; if (contact && contact.avatar) { - UIImage *image = [self resizeImage:contact.avatar]; + UIImage *image = [UIImage resizeImage:contact.avatar withMaxWidth:200 andMaxHeight:200]; NSData *imageData = UIImageJPEGRepresentation(image, 0); [images setObject:imageData forKey:[[NSString stringWithUTF8String:linphone_address_as_string_uri_only(linphone_call_log_get_remote_address(log))] substringFromIndex:4]]; diff --git a/Classes/Utils/Utils.h b/Classes/Utils/Utils.h index 97e1bacad..ced7d6937 100644 --- a/Classes/Utils/Utils.h +++ b/Classes/Utils/Utils.h @@ -68,6 +68,7 @@ typedef enum { - (UIImage *)squareCrop; - (UIImage *)scaleToSize:(CGSize)size squared:(BOOL)squared; ++ (UIImage *)resizeImage:(UIImage *)image withMaxWidth:(float)maxWidth andMaxHeight:(float)maxHeight; @end diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index bebbd9fbb..42002b4fc 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -644,6 +644,36 @@ return scaledImage; } ++ (UIImage *)resizeImage:(UIImage *)image withMaxWidth:(float)maxWidth andMaxHeight:(float)maxHeight { + float actualHeight = image.size.height; + float actualWidth = image.size.width; + float imgRatio = actualWidth / actualHeight; + float maxRatio = maxWidth / maxHeight; + float compressionQuality = 1; + if (actualHeight > maxHeight || actualWidth > maxWidth) + { + if (imgRatio < maxRatio) { + imgRatio = maxHeight / actualHeight; + actualWidth = imgRatio * actualWidth; + actualHeight = maxHeight; + } else if (imgRatio > maxRatio) { + imgRatio = maxWidth / actualWidth; + actualHeight = imgRatio * actualHeight; + actualWidth = maxWidth; + } else { + actualHeight = maxHeight; + actualWidth = maxWidth; + } + } + CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight); + UIGraphicsBeginImageContext(rect.size); + [image drawInRect:rect]; + UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); + NSData *imageData = UIImageJPEGRepresentation(img, compressionQuality); + UIGraphicsEndImageContext(); + return [UIImage imageWithData:imageData]; +} + @end @implementation UIColor (LightAndDark) diff --git a/latestCallsWidget/TodayViewController.h b/latestCallsWidget/TodayViewController.h index bcd86a702..d058197bd 100644 --- a/latestCallsWidget/TodayViewController.h +++ b/latestCallsWidget/TodayViewController.h @@ -14,7 +14,6 @@ @property (strong, nonatomic) NSMutableDictionary *imgs; @property (strong, nonatomic) NSMutableArray *sortedDates; @property (strong, nonatomic) NSMutableArray *logIds; -@property (nonatomic) BOOL updateNeeded; - (IBAction)firstButtonTapped; - (IBAction)secondButtonTapped; diff --git a/latestCallsWidget/TodayViewController.m b/latestCallsWidget/TodayViewController.m index d2262d0a1..0ff9f3dce 100644 --- a/latestCallsWidget/TodayViewController.m +++ b/latestCallsWidget/TodayViewController.m @@ -131,7 +131,6 @@ _sortedDates = [NSMutableArray array]; _contactsToDisplay = [NSMutableArray array]; _imgs = [NSMutableDictionary dictionary]; - _updateNeeded = YES; } - (void)didReceiveMemoryWarning {