/android/export-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/export-contacts

« back to all changes in this revision

Viewing changes to src/am/ed/exportcontacts/ContactsContractBackend.java

  • Committer: edam
  • Date: 2012-12-21 13:28:27 UTC
  • Revision ID: tim@ed.am-20121221132827-u32vfk3ywktt7xa5
updated some copyright dates

Show diffs side-by-side

added added

removed removed

48
48
        public int getNumContacts()
49
49
        {
50
50
                // get number of aggregate contacts
51
 
                Cursor cur = _activity.getContentResolver().query(
 
51
                Cursor cursor = _activity.managedQuery(
52
52
                        ContactsContract.Contacts.CONTENT_URI,
53
53
                        new String[] {
54
54
                                ContactsContract.Contacts._ID,
55
55
                        }, null, null, null );
56
 
                int ret = cur.getCount();
57
 
                cur.close();
58
 
                return ret;
 
56
                return cursor.getCount();
59
57
        }
60
58
 
61
59
        private int convertBackendTypeToType( Class< ? > cls, int type )
109
107
                if( _cur == null )
110
108
                {
111
109
                        // get all aggregate contacts
112
 
                        _cur = _activity.getContentResolver().query(
 
110
                        _cur = _activity.managedQuery(
113
111
                                ContactsContract.Contacts.CONTENT_URI,
114
112
                                new String[] {
115
113
                                        ContactsContract.Contacts._ID,
118
116
                }
119
117
 
120
118
                // if there are no more aggregate contacts, abort
121
 
                if( _cur == null ) return false;
122
 
                if( !_cur.moveToNext() ) {
123
 
                        _cur.close();
 
119
                if( _cur == null || !_cur.moveToNext() ) {
124
120
                        _cur = null;
125
121
                        return false;
126
122
                }
144
140
                                ContactsContract.Data.DATA4,
145
141
                        },
146
142
                        ContactsContract.Data.CONTACT_ID + " = ? AND " +
147
 
// column DELTED not found!?
148
 
//                              ContactsContract.Data.DELETED + " = 0 AND " +
 
143
                                ContactsContract.Data.DELETED + " = 0 AND " +
149
144
                                ContactsContract.Data.MIMETYPE + " IN ( ?, ?, ?, ?, ? )",
150
145
                        new String[] {
151
146
                                String.valueOf( id ),
175
170
                        // add email addresses
176
171
                        else if( type.equals( CommonDataKinds.Email.CONTENT_ITEM_TYPE ) )
177
172
                                contact.addEmail( contact.new EmailDetail(
178
 
                                        convertBackendTypeToType( CommonDataKinds.Email.class,
 
173
                                        convertBackendTypeToType( CommonDataKinds.Phone.class,
179
174
                                                cur.getInt( cur.getColumnIndex(
180
175
                                                        CommonDataKinds.Email.TYPE ) ) ),
181
176
                                        cur.getString( cur.getColumnIndex(
184
179
                        // add postal addresses
185
180
                        else if( type.equals( CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE ) )
186
181
                                contact.addAddress( contact.new AddressDetail(
187
 
                                        convertBackendTypeToType( CommonDataKinds.StructuredPostal.class,
 
182
                                        convertBackendTypeToType( CommonDataKinds.Phone.class,
188
183
                                                cur.getInt( cur.getColumnIndex(
189
184
                                                        CommonDataKinds.StructuredPostal.TYPE ) ) ),
190
185
                                        cur.getString( cur.getColumnIndex(
203
198
                                contact.addNote( cur.getString( cur.getColumnIndex(
204
199
                                        CommonDataKinds.Note.NOTE ) ) );
205
200
                }
206
 
                cur.close();
207
201
 
208
202
                return true;
209
203
        }