Add image picker during contact edition

This commit is contained in:
Yann Diorcet 2012-08-16 10:18:40 +02:00
parent c786f60d81
commit ce208db0d2
9 changed files with 234 additions and 6 deletions

View file

@ -0,0 +1,35 @@
/* ContactDetailsImagePickerController.h
*
* Copyright (C) 2012 Belledonne Comunications, Grenoble, France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "UICompositeViewController.h"
@protocol ContactDetailsImagePickerDelegate <NSObject>
- (void)changeContactImage:(UIImage*)image;
@end
@interface ContactDetailsImagePickerController : UIImagePickerController <UICompositeViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
@private
id<ContactDetailsImagePickerDelegate> imagePickerDelegate;
}
@property (nonatomic, retain) id<ContactDetailsImagePickerDelegate> imagePickerDelegate;
@end

View file

@ -0,0 +1,81 @@
/* ContactDetailsImagePickerController.m
*
* Copyright (C) 2012 Belledonne Comunications, Grenoble, France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "ContactDetailsImagePickerController.h"
#import "PhoneMainView.h"
@implementation ContactDetailsImagePickerController
@synthesize imagePickerDelegate;
#pragma mark - UICompositeViewDelegate Functions
static UICompositeViewDescription *compositeDescription = nil;
+ (UICompositeViewDescription *)compositeViewDescription {
if(compositeDescription == nil) {
compositeDescription = [[UICompositeViewDescription alloc] init:@"ContactDetailsImage"
content:@"ContactDetailsImagePickerController"
stateBar:nil
stateBarEnabled:false
tabBar:@"UIMainBar"
tabBarEnabled:true
fullscreen:false
landscapeMode:[LinphoneManager runningOnIpad]
portraitMode:true];
}
return compositeDescription;
}
#pragma mark - ViewController Functions
- (void)viewDidLoad {
[super viewDidLoad];
[self setDelegate:self];
}
#pragma mark -
- (void)dismiss {
if([[[PhoneMainView instance] currentView] equal:[ContactDetailsImagePickerController compositeViewDescription]]) {
[[PhoneMainView instance] popCurrentView];
}
}
#pragma mark - UIImagePickerControllerDelegate Functions
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if(image == nil) {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
if(image != nil) {
[imagePickerDelegate changeContactImage:image];
}
[self dismiss];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismiss];
}
@end

View file

@ -64,7 +64,7 @@ static UICompositeViewDescription *compositeDescription = nil;
tabBar:@"UIMainBar"
tabBarEnabled:true
fullscreen:false
landscapeMode:true
landscapeMode:[LinphoneManager runningOnIpad]
portraitMode:true];
}
return compositeDescription;
@ -79,6 +79,7 @@ static UICompositeViewDescription *compositeDescription = nil;
}
}
#pragma mark - Property Functions
- (void)setDataList:(NSDictionary *)adatalist {

View file

@ -490,7 +490,7 @@ static const int contactSections[ContactSections_MAX] = {ContactSections_None, C
} else {
// Go to Chat room view
[[PhoneMainView instance] popToView:[ChatViewController compositeViewDescription]];
ChatRoomViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[ChatRoomViewController compositeViewDescription] push:TRUE], ChatRoomViewController);
ChatRoomViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[ChatRoomViewController compositeViewDescription]], ChatRoomViewController);
if(controller != nil) {
[controller setRemoteAddress:dest];
}

View file

@ -20,9 +20,10 @@
#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import "ContactDetailsImagePickerController.h"
#import "ContactDetailsDelegate.h"
@interface UIContactDetailsHeader : UIViewController<UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate> {
@interface UIContactDetailsHeader : UIViewController<UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, ContactDetailsImagePickerDelegate> {
UILabel *addressLabel;
UIImageView *avatarImage;
UIView *normalView;
@ -45,7 +46,9 @@
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) IBOutlet id<ContactDetailsDelegate> contactDetailsDelegate;
@property(nonatomic,getter=isEditing) BOOL editing;
@property(nonatomic,getter=isEditing) BOOL editing;
- (IBAction)onAvatarClick:(id)event;
+ (CGFloat)height:(BOOL)editing;

View file

@ -22,6 +22,7 @@
#import "UIEditableTableViewCell.h"
#import "FastAddressBook.h"
#import "UILinphone.h"
#import "PhoneMainView.h"
@implementation UIContactDetailsHeader
@ -231,6 +232,40 @@
}
#pragma mark - Action Functions
- (IBAction)onAvatarClick:(id)event {
if(self.isEditing) {
ContactDetailsImagePickerController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[ContactDetailsImagePickerController compositeViewDescription] push:TRUE], ContactDetailsImagePickerController);
if(controller != nil) {
[controller setAllowsEditing:TRUE];
[controller setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[controller setImagePickerDelegate:self];
}
}
}
#pragma mark - ContactDetailsImagePickerDelegate Functions
- (void)changeContactImage:(UIImage*)image {
NSError* error = NULL;
if(!ABPersonRemoveImageData(contact, (CFErrorRef*)error)) {
[LinphoneLogger log:LinphoneLoggerLog format:@"Can't add entry: %@", [error localizedDescription]];
}
NSData *dataRef = UIImagePNGRepresentation(image);
CFDataRef cfdata = CFDataCreate(NULL,[dataRef bytes], [dataRef length]);
if(!ABPersonSetImageData(contact, cfdata, (CFErrorRef*)error)) {
[LinphoneLogger log:LinphoneLoggerLog format:@"Can't add entry: %@", [error localizedDescription]];
}
CFRelease(cfdata);
[self update];
}
#pragma mark - UITableViewDelegate Functions
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

View file

@ -12,6 +12,7 @@
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBProxyObject</string>
<string>IBUIButton</string>
<string>IBUIImageView</string>
<string>IBUILabel</string>
<string>IBUITableView</string>
@ -58,7 +59,7 @@
<string key="NSFrame">{{20, 6}, {65, 65}}</string>
<reference key="NSSuperview" ref="1033790597"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="959860357"/>
<reference key="NSNextKeyView" ref="854571707"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
@ -67,6 +68,40 @@
<string key="NSResourceName">avatar_unknown_small.png</string>
</object>
</object>
<object class="IBUIButton" id="854571707">
<reference key="NSNextResponder" ref="1033790597"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 6}, {65, 65}}</string>
<reference key="NSSuperview" ref="1033790597"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="959860357"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<object class="NSColor" key="IBUIHighlightedTitleColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
<object class="NSColor" key="IBUINormalTitleColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes>
</object>
<object class="NSColor" key="IBUINormalTitleShadowColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MC41AA</bytes>
</object>
<object class="IBUIFontDescription" key="IBUIFontDescription">
<int key="type">2</int>
<double key="pointSize">15</double>
</object>
<object class="NSFont" key="IBUIFont">
<string key="NSName">Helvetica-Bold</string>
<double key="NSSize">15</double>
<int key="NSfFlags">16</int>
</object>
</object>
<object class="IBUIView" id="959860357">
<reference key="NSNextResponder" ref="1033790597"/>
<int key="NSvFlags">290</int>
@ -277,6 +312,15 @@ AAgACAAIAAEAAQABAAE</bytes>
</object>
<int key="connectionID">19</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">onAvatarClick:</string>
<reference key="source" ref="854571707"/>
<reference key="destination" ref="372490531"/>
<int key="IBEventType">7</int>
</object>
<int key="connectionID">23</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@ -305,6 +349,7 @@ AAgACAAIAAEAAQABAAE</bytes>
<reference ref="906825234"/>
<reference ref="959860357"/>
<reference ref="451441616"/>
<reference ref="854571707"/>
</array>
<reference key="parent" ref="0"/>
</object>
@ -349,6 +394,12 @@ AAgACAAIAAEAAQABAAE</bytes>
<reference key="object" ref="579848711"/>
<reference key="parent" ref="451441616"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">22</int>
<reference key="object" ref="854571707"/>
<reference key="parent" ref="1033790597"/>
<string key="objectName">avatarButton</string>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
@ -359,6 +410,7 @@ AAgACAAIAAEAAQABAAE</bytes>
<string key="12.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="13.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="15.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="22.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="7.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@ -368,13 +420,24 @@ AAgACAAIAAEAAQABAAE</bytes>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">21</int>
<int key="maxID">23</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">UIContactDetailsHeader</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="actions">
<string key="NS.key.0">onImageClick:</string>
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<string key="NS.key.0">onImageClick:</string>
<object class="IBActionInfo" key="NS.object.0">
<string key="name">onImageClick:</string>
<string key="candidateClassName">id</string>
</object>
</object>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="addressLabel">UILabel</string>
<string key="avatarImage">UIImageView</string>

View file

@ -29,6 +29,8 @@
#import "DialerViewController.h"
#import "ContactsViewController.h"
#import "ContactDetailsViewController.h"
#import "ContactDetailsLabelViewController.h"
#import "ContactDetailsImagePickerController.h"
#import "HistoryViewController.h"
#import "HistoryDetailsViewController.h"
#import "InCallViewController.h"

View file

@ -674,6 +674,8 @@
D378906515AC373B00BD776C /* ContactDetailsLabelViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378906315AC373B00BD776C /* ContactDetailsLabelViewController.m */; };
D378906615AC373B00BD776C /* ContactDetailsLabelViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378906315AC373B00BD776C /* ContactDetailsLabelViewController.m */; };
D378906715AC373B00BD776C /* ContactDetailsLabelViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D378906415AC373B00BD776C /* ContactDetailsLabelViewController.xib */; };
D378AB2A15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378AB2915DCDB490098505D /* ContactDetailsImagePickerController.m */; };
D378AB2B15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378AB2915DCDB490098505D /* ContactDetailsImagePickerController.m */; };
D37B96B715A1A6F20005CCD2 /* call_state_delete_default.png in Resources */ = {isa = PBXBuildFile; fileRef = D37B96B515A1A6F20005CCD2 /* call_state_delete_default.png */; };
D37B96B915A1A6F20005CCD2 /* call_state_delete_over.png in Resources */ = {isa = PBXBuildFile; fileRef = D37B96B615A1A6F20005CCD2 /* call_state_delete_over.png */; };
D37C638E15AAD251009D0BAC /* contact_number_over.png in Resources */ = {isa = PBXBuildFile; fileRef = D37C638C15AAD251009D0BAC /* contact_number_over.png */; };
@ -1674,6 +1676,8 @@
D378906215AC373B00BD776C /* ContactDetailsLabelViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactDetailsLabelViewController.h; sourceTree = "<group>"; };
D378906315AC373B00BD776C /* ContactDetailsLabelViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactDetailsLabelViewController.m; sourceTree = "<group>"; };
D378906415AC373B00BD776C /* ContactDetailsLabelViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ContactDetailsLabelViewController.xib; sourceTree = "<group>"; };
D378AB2815DCDB480098505D /* ContactDetailsImagePickerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactDetailsImagePickerController.h; sourceTree = "<group>"; };
D378AB2915DCDB490098505D /* ContactDetailsImagePickerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactDetailsImagePickerController.m; sourceTree = "<group>"; };
D37B96B515A1A6F20005CCD2 /* call_state_delete_default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = call_state_delete_default.png; path = Resources/call_state_delete_default.png; sourceTree = "<group>"; };
D37B96B615A1A6F20005CCD2 /* call_state_delete_over.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = call_state_delete_over.png; path = Resources/call_state_delete_over.png; sourceTree = "<group>"; };
D37C638C15AAD251009D0BAC /* contact_number_over.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = contact_number_over.png; path = Resources/contact_number_over.png; sourceTree = "<group>"; };
@ -2152,6 +2156,8 @@
22E0A81F111C44E100B04932 /* ConsoleViewController.m */,
22E0A81E111C44E100B04932 /* ConsoleViewController.xib */,
D30BBD1215D3EFEB000F93DD /* ContactDetailsDelegate.h */,
D378AB2815DCDB480098505D /* ContactDetailsImagePickerController.h */,
D378AB2915DCDB490098505D /* ContactDetailsImagePickerController.m */,
D378906215AC373B00BD776C /* ContactDetailsLabelViewController.h */,
D378906315AC373B00BD776C /* ContactDetailsLabelViewController.m */,
D378906415AC373B00BD776C /* ContactDetailsLabelViewController.xib */,
@ -4312,6 +4318,7 @@
D380800215C2894A005BE9BC /* IASKTextField.m in Sources */,
D380800515C28A7A005BE9BC /* UILinphone.m in Sources */,
D380801315C299D0005BE9BC /* ColorSpaceUtilites.m in Sources */,
D378AB2A15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -4401,6 +4408,7 @@
D380800315C2894A005BE9BC /* IASKTextField.m in Sources */,
D380800615C28A7A005BE9BC /* UILinphone.m in Sources */,
D380801415C299D0005BE9BC /* ColorSpaceUtilites.m in Sources */,
D378AB2B15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};