Skip to content

Commit fd4c654

Browse files
author
gomercin
committed
0 parents  commit fd4c654

34 files changed

+3508
-0
lines changed

Classes/Common.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
enum subViews {
2+
enumMenuView = 0,
3+
enumSMSView,
4+
enumNotesView,
5+
enumFileView,
6+
enumAboutView,
7+
enumTextPage,
8+
enumSMSSubPage,
9+
enumMailView,
10+
enumMailSubPage,
11+
enumContactsView
12+
};

Classes/ContactsView.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#import <UIKit/UIKit.h>
2+
#import <UIKit/UISimpleTableCell.h>
3+
#import <UIKit/UITableColumn.h>
4+
#import "Common.h"
5+
6+
@interface ContactsView : UITable
7+
{
8+
NSMutableArray *ContactsList;
9+
NSMutableArray *contactNames;
10+
UITableColumn *colContactName;
11+
12+
UIView * SuperView;
13+
UIImageView *contactsIcon;
14+
15+
bool contactsAreLoaded;
16+
}
17+
- (id)initWithFrame:(struct CGRect)rect;
18+
- (void)reloadData;
19+
- (int)numberOfRowsInTable:(UITable *)_table;
20+
- (UITableCell *)table:(UITable *)table
21+
cellForRow:(int)row
22+
column:(UITableColumn *)col;
23+
- (void)dealloc;
24+
- (void)tableRowSelected:(NSNotification *)notification;
25+
- (void) setSuperView: (UIView *) sv;
26+
@end

Classes/ContactsView.h.kas

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#import <UIKit/UIKit.h>
2+
#import <UIKit/UISimpleTableCell.h>
3+
#import <UIKit/UITableColumn.h>
4+
#import "Common.h"
5+
6+
@interface ContactsView : UITable
7+
{
8+
NSMutableArray *ContactsList;
9+
NSMutableArray *contactNames;
10+
UITableColumn *colContactName;
11+
12+
NSMutableArray *gContactsList;
13+
NSMutableArray *gcontactNames;
14+
15+
16+
UIView * SuperView;
17+
UIImageView *contactsIcon;
18+
19+
bool contactsAreLoaded;
20+
}
21+
- (id)initWithFrame:(struct CGRect)rect;
22+
- (void)reloadData;
23+
- (int)numberOfRowsInTable:(UITable *)_table;
24+
- (UITableCell *)table:(UITable *)table
25+
cellForRow:(int)row
26+
column:(UITableColumn *)col;
27+
- (void)dealloc;
28+
- (void)tableRowSelected:(NSNotification *)notification;
29+
- (void) setSuperView: (UIView *) sv;
30+
@end

Classes/ContactsView.m

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#import "ContactsView.h"
2+
#import <sqlite3.h>
3+
#import <AddressBook/AddressBook.h>
4+
5+
@implementation ContactsView
6+
7+
- (id)initWithFrame:(struct CGRect)rect {
8+
if ((self == [ super initWithFrame: rect ]) != nil) {
9+
10+
colContactName = [ [ UITableColumn alloc ]
11+
initWithTitle: @"ContactsPreview"
12+
identifier:@"contactspreview"
13+
width: rect.size.width
14+
];
15+
[ self addTableColumn: colContactName ];
16+
17+
[ self setSeparatorStyle: 1 ];
18+
[ self setDelegate: self ];
19+
[ self setDataSource: self ];
20+
[ self setRowHeight: 48 ];
21+
22+
ContactsList = [ [ NSMutableArray alloc] init ];
23+
contactNames = [ [ NSMutableArray alloc] init ];
24+
25+
contactsAreLoaded = NO;
26+
}
27+
28+
return self;
29+
}
30+
31+
- (void) reloadData {
32+
//[ ContactsList removeAllObjects ];
33+
// [ contactNames removeAllObjects ];
34+
35+
if (contactsAreLoaded == YES) return;
36+
37+
contactsAreLoaded = YES;
38+
// NSMutableArray *list = [[NSMutableArray alloc] init];
39+
40+
ABAddressBookRef addressBook = ABAddressBookCreate();
41+
42+
NSArray *addresses = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);
43+
int addressesCount = [addresses count];
44+
45+
for (int i = 0; i < addressesCount; i++) {
46+
ABRecordRef record = [addresses objectAtIndex:i];
47+
48+
NSString *tableEntry = @"";
49+
NSString *fullInfo = @"";
50+
51+
//Get name
52+
NSMutableString *contactName = (NSMutableString *)ABRecordCopyCompositeName(record);
53+
if (contactName != nil)
54+
{
55+
contactName = [NSString stringWithFormat: @"%@", contactName];
56+
tableEntry = contactName;
57+
fullInfo = [fullInfo stringByAppendingString: [NSString stringWithFormat: @"%@ ", contactName]];
58+
}
59+
60+
//Get phone numbers
61+
ABMultiValueRef phoneNumbers =(NSString*)ABRecordCopyValue(record,kABPersonPhoneProperty);
62+
NSString* mobile=@"";
63+
for(int j=0;j<ABMultiValueGetCount(phoneNumbers);j++)
64+
{
65+
mobile=(NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers,j);
66+
fullInfo = [fullInfo stringByAppendingString: [NSString stringWithFormat: @"%@ ", mobile]];
67+
68+
if ([tableEntry isEqualToString:@""] == YES)
69+
tableEntry = mobile;
70+
}
71+
72+
//Get eMail addresses
73+
ABMultiValueRef emailAddresses =(NSString*)ABRecordCopyValue(record,kABPersonEmailProperty);
74+
for(int j=0;j<ABMultiValueGetCount(emailAddresses);j++)
75+
{
76+
NSString* email=@"";
77+
email=(NSString*)ABMultiValueCopyValueAtIndex(emailAddresses,j);
78+
fullInfo = [fullInfo stringByAppendingString: [NSString stringWithFormat: @"%@ ", email]];
79+
80+
if ([tableEntry isEqualToString:@""] == YES)
81+
tableEntry = email;
82+
}
83+
84+
//Get Street Addresses
85+
ABMutableMultiValueRef multiValue = ABRecordCopyValue(record, kABPersonAddressProperty);
86+
for(CFIndex k=0;k<ABMultiValueGetCount(multiValue);k++)
87+
{
88+
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multiValue, k);
89+
CFStringRef street = CFDictionaryGetValue(dict, kABPersonAddressStreetKey);
90+
CFStringRef city = CFDictionaryGetValue(dict, kABPersonAddressCityKey);
91+
CFStringRef country = CFDictionaryGetValue(dict, kABPersonAddressCountryKey);
92+
CFRelease(dict);
93+
94+
if (street == nil) street = @"";
95+
if (city == nil) city = @"";
96+
if (country == nil) country = @"";
97+
98+
NSString *address = [NSString stringWithFormat:@"%@ %@ %@",street,city,country];
99+
100+
fullInfo = [fullInfo stringByAppendingString: [NSString stringWithFormat: @"%@ ", address]];
101+
102+
if ([tableEntry isEqualToString:@""] == YES)
103+
tableEntry = address;
104+
}
105+
106+
[contactNames addObject: tableEntry];
107+
[ContactsList addObject: fullInfo];
108+
}
109+
110+
[ super reloadData ];
111+
}
112+
113+
- (int)numberOfRowsInTable:(UITable *)_table {
114+
return [ ContactsList count ];
115+
}
116+
117+
- (UITableCell *)table:(UITable *)table
118+
cellForRow:(int)row
119+
column:(UITableColumn *)col
120+
{
121+
UIImageAndTextTableCell *cell = [ [ UIImageAndTextTableCell alloc ] init ];
122+
//[ cell setTable: self ];
123+
124+
contactsIcon = [[ UIImage imageAtPath:@"/Applications/MobileAddressBook.app/icon.png" ]
125+
_imageScaledToSize:CGSizeMake(40.0f, 40.0f) interpolationQuality:1];
126+
[cell setImage: contactsIcon ];
127+
128+
[ cell setTitle: [ contactNames objectAtIndex: row ] ];
129+
130+
return [ cell autorelease ];
131+
}
132+
133+
- (void)tableRowSelected:(NSNotification *)notification {
134+
135+
NSString *selectedText = [ ContactsList objectAtIndex: [ self selectedRow ] ];
136+
137+
[SuperView setTextToEdit: selectedText];
138+
[SuperView flipTo: enumTextPage];
139+
}
140+
141+
- (void)dealloc {
142+
[ colContactName release ];
143+
[ ContactsList release ];
144+
[ contactNames release ];
145+
[ SuperView release ];
146+
[ contactsIcon release ];
147+
[ super dealloc ];
148+
}
149+
150+
- (void) setSuperView: (UIView *) sv
151+
{
152+
SuperView = sv;
153+
}
154+
@end

Classes/ContactsView.m.kas

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#import "ContactsView.h"
2+
#import <sqlite3.h>
3+
#import <AddressBook/AddressBook.h>
4+
5+
@implementation ContactsView
6+
7+
- (id)initWithFrame:(struct CGRect)rect {
8+
if ((self == [ super initWithFrame: rect ]) != nil) {
9+
10+
colContactName = [ [ UITableColumn alloc ]
11+
initWithTitle: @"ContactsPreview"
12+
identifier:@"contactspreview"
13+
width: rect.size.width
14+
];
15+
[ self addTableColumn: colContactName ];
16+
17+
[ self setSeparatorStyle: 1 ];
18+
[ self setDelegate: self ];
19+
[ self setDataSource: self ];
20+
[ self setRowHeight: 48 ];
21+
22+
ContactsList = [ [ NSMutableArray alloc] init ];
23+
contactNames = [ [ NSMutableArray alloc] init ];
24+
25+
gContactsList = [ [ NSMutableArray alloc] init ];
26+
gcontactNames = [ [ NSMutableArray alloc] init ];
27+
28+
contactsAreLoaded = NO;
29+
}
30+
31+
return self;
32+
}
33+
34+
- (void) reloadData {
35+
//[ ContactsList removeAllObjects ];
36+
// [ contactNames removeAllObjects ];
37+
38+
if (contactsAreLoaded == YES) return;
39+
40+
contactsAreLoaded = YES;
41+
42+
// NSMutableArray *list = [[NSMutableArray alloc] init];
43+
44+
ABAddressBookRef addressBook = ABAddressBookCreate();
45+
46+
NSArray *addresses = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);
47+
48+
[SuperView gomerLOG:@"0"];
49+
50+
int addressesCount = [addresses count];
51+
52+
for (int i = 0; i < addressesCount; i++) {
53+
ABRecordRef record = [addresses objectAtIndex:i];
54+
55+
NSString *tableEntry = @"";
56+
NSString *fullInfo = @"";
57+
58+
//Get name
59+
NSMutableString *contactName = (NSMutableString *)ABRecordCopyCompositeName(record);
60+
if (contactName != nil)
61+
{
62+
contactName = [NSString stringWithFormat: @"%@", contactName];
63+
tableEntry = contactName;
64+
fullInfo = [fullInfo stringByAppendingString: [NSString stringWithFormat: @"%@ ", contactName]];
65+
}
66+
67+
//Get phone numbers
68+
ABMultiValueRef phoneNumbers =(NSString*)ABRecordCopyValue(record,kABPersonPhoneProperty);
69+
NSString* mobile=@"";
70+
for(int j=0;j<ABMultiValueGetCount(phoneNumbers);j++)
71+
{
72+
mobile=(NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers,j);
73+
fullInfo = [fullInfo stringByAppendingString: [NSString stringWithFormat: @"%@ ", mobile]];
74+
75+
if ([tableEntry isEqualToString:@""] == YES)
76+
tableEntry = mobile;
77+
}
78+
79+
//Get eMail addresses
80+
ABMultiValueRef emailAddresses =(NSString*)ABRecordCopyValue(record,kABPersonEmailProperty);
81+
for(int j=0;j<ABMultiValueGetCount(emailAddresses);j++)
82+
{
83+
NSString* email=@"";
84+
email=(NSString*)ABMultiValueCopyValueAtIndex(emailAddresses,j);
85+
fullInfo = [fullInfo stringByAppendingString: [NSString stringWithFormat: @"%@ ", email]];
86+
87+
if ([tableEntry isEqualToString:@""] == YES)
88+
tableEntry = email;
89+
}
90+
91+
//Get Street Addresses
92+
ABMutableMultiValueRef multiValue = ABRecordCopyValue(record, kABPersonAddressProperty);
93+
for(CFIndex k=0;k<ABMultiValueGetCount(multiValue);k++)
94+
{
95+
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multiValue, k);
96+
CFStringRef street = CFDictionaryGetValue(dict, kABPersonAddressStreetKey);
97+
CFStringRef city = CFDictionaryGetValue(dict, kABPersonAddressCityKey);
98+
CFStringRef country = CFDictionaryGetValue(dict, kABPersonAddressCountryKey);
99+
CFRelease(dict);
100+
101+
if (street == nil) street = @"";
102+
if (city == nil) city = @"";
103+
if (country == nil) country = @"";
104+
105+
NSString *address = [NSString stringWithFormat:@"%@ %@ %@",street,city,country];
106+
107+
fullInfo = [fullInfo stringByAppendingString: [NSString stringWithFormat: @"%@ ", address]];
108+
109+
if ([tableEntry isEqualToString:@""] == YES)
110+
tableEntry = address;
111+
}
112+
113+
[gcontactNames addObject: tableEntry];
114+
[gContactsList addObject: fullInfo];
115+
}
116+
117+
[SuperView gomerLOG:@"1"];
118+
contactNames = [NSMutableArray arrayWithArray:(NSMutableArray*)[gcontactNames sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];
119+
[SuperView gomerLOG:@"2"];
120+
ContactsList = [NSMutableArray arrayWithArray:(NSMutableArray*)[gContactsList sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];
121+
[SuperView gomerLOG:@"3"];
122+
123+
[ super reloadData ];
124+
}
125+
126+
- (int)numberOfRowsInTable:(UITable *)_table {
127+
return [ ContactsList count ];
128+
}
129+
130+
- (UITableCell *)table:(UITable *)table
131+
cellForRow:(int)row
132+
column:(UITableColumn *)col
133+
{
134+
UIImageAndTextTableCell *cell = [ [ UIImageAndTextTableCell alloc ] init ];
135+
//[ cell setTable: self ];
136+
137+
contactsIcon = [[ UIImage imageAtPath:@"/Applications/MobileAddressBook.app/icon.png" ]
138+
_imageScaledToSize:CGSizeMake(40.0f, 40.0f) interpolationQuality:1];
139+
[cell setImage: contactsIcon ];
140+
141+
//[ cell setTitle: [ contactNames objectAtIndex: row ] ];
142+
[ cell setTitle: [ contactNames objectAtIndex: 0 ] ];
143+
144+
return [ cell autorelease ];
145+
}
146+
147+
- (void)tableRowSelected:(NSNotification *)notification {
148+
149+
NSString *selectedText = [ ContactsList objectAtIndex: [ self selectedRow ] ];
150+
151+
[SuperView setTextToEdit: selectedText];
152+
[SuperView flipTo: enumTextPage];
153+
}
154+
155+
- (void)dealloc {
156+
[ colContactName release ];
157+
[ ContactsList release ];
158+
[ contactNames release ];
159+
[ SuperView release ];
160+
[ contactsIcon release ];
161+
[ super dealloc ];
162+
}
163+
164+
- (void) setSuperView: (UIView *) sv
165+
{
166+
SuperView = sv;
167+
}
168+
@end

0 commit comments

Comments
 (0)