/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: Tim Marston
  • Date: 2013-06-22 19:31:44 UTC
  • Revision ID: tim@ed.am-20130622193144-0lo7w92qagow0kmu
minor style tweaks

Show diffs side-by-side

added added

removed removed

4
4
 * Copyright (C) 2011 to 2012 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of the Export Contacts program (hereafter referred
7
 
 * to as "this program"). For more information, see
 
7
 * to as "this program").  For more information, see
8
8
 * http://ed.am/dev/android/export-contacts
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
48
48
        public int getNumContacts()
49
49
        {
50
50
                // get number of aggregate contacts
51
 
                Cursor cursor = _activity.managedQuery(
 
51
                Cursor cur = _activity.getContentResolver().query(
52
52
                        ContactsContract.Contacts.CONTENT_URI,
53
53
                        new String[] {
54
54
                                ContactsContract.Contacts._ID,
55
55
                        }, null, null, null );
56
 
                return cursor.getCount();
 
56
                int ret = cur.getCount();
 
57
                cur.close();
 
58
                return ret;
57
59
        }
58
60
 
59
61
        private int convertBackendTypeToType( Class< ? > cls, int type )
107
109
                if( _cur == null )
108
110
                {
109
111
                        // get all aggregate contacts
110
 
                        _cur = _activity.managedQuery(
 
112
                        _cur = _activity.getContentResolver().query(
111
113
                                ContactsContract.Contacts.CONTENT_URI,
112
114
                                new String[] {
113
115
                                        ContactsContract.Contacts._ID,
116
118
                }
117
119
 
118
120
                // if there are no more aggregate contacts, abort
119
 
                if( _cur == null || !_cur.moveToNext() ) {
 
121
                if( _cur == null ) return false;
 
122
                if( !_cur.moveToNext() ) {
 
123
                        _cur.close();
120
124
                        _cur = null;
121
125
                        return false;
122
126
                }
140
144
                                ContactsContract.Data.DATA4,
141
145
                        },
142
146
                        ContactsContract.Data.CONTACT_ID + " = ? AND " +
143
 
                                ContactsContract.Data.DELETED + " = 0 AND " +
 
147
// column DELTED not found!?
 
148
//                              ContactsContract.Data.DELETED + " = 0 AND " +
144
149
                                ContactsContract.Data.MIMETYPE + " IN ( ?, ?, ?, ?, ? )",
145
150
                        new String[] {
146
151
                                String.valueOf( id ),
170
175
                        // add email addresses
171
176
                        else if( type.equals( CommonDataKinds.Email.CONTENT_ITEM_TYPE ) )
172
177
                                contact.addEmail( contact.new EmailDetail(
173
 
                                        convertBackendTypeToType( CommonDataKinds.Phone.class,
 
178
                                        convertBackendTypeToType( CommonDataKinds.Email.class,
174
179
                                                cur.getInt( cur.getColumnIndex(
175
180
                                                        CommonDataKinds.Email.TYPE ) ) ),
176
181
                                        cur.getString( cur.getColumnIndex(
179
184
                        // add postal addresses
180
185
                        else if( type.equals( CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE ) )
181
186
                                contact.addAddress( contact.new AddressDetail(
182
 
                                        convertBackendTypeToType( CommonDataKinds.Phone.class,
 
187
                                        convertBackendTypeToType( CommonDataKinds.StructuredPostal.class,
183
188
                                                cur.getInt( cur.getColumnIndex(
184
189
                                                        CommonDataKinds.StructuredPostal.TYPE ) ) ),
185
190
                                        cur.getString( cur.getColumnIndex(
198
203
                                contact.addNote( cur.getString( cur.getColumnIndex(
199
204
                                        CommonDataKinds.Note.NOTE ) ) );
200
205
                }
 
206
                cur.close();
201
207
 
202
208
                return true;
203
209
        }