/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/ContactsBackend.java

  • Committer: edam
  • Date: 2012-12-21 12:04:38 UTC
  • Revision ID: tim@ed.am-20121221120438-epjtxbsjvs07w6no
renamed ContactAccessor to Backend

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * ContactsContactAccessor.java
3
3
 *
4
 
 * Copyright (C) 2011 to 2012 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2011 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of the Export Contacts program (hereafter referred
7
7
 * to as "this program"). For more information, see
23
23
 
24
24
package am.ed.exportcontacts;
25
25
 
26
 
import am.ed.exportcontacts.Exporter.ContactData;
27
26
import android.app.Activity;
28
27
import android.database.Cursor;
29
28
import android.provider.Contacts;
30
29
 
31
 
@SuppressWarnings( "deprecation" )
32
 
public class ContactsBackend implements Backend
 
30
public class ContactsBackend implements ContactAccessor
33
31
{
34
32
        Activity _activity = null;
35
33
        Exporter _exporter = null;
52
50
                return cursor.getCount();
53
51
        }
54
52
 
55
 
        private int convertBackendTypeToType( Class< ? > cls, int type )
56
 
        {
57
 
                if( cls == Contacts.Phones.class )
58
 
                {
59
 
                        switch( type )
60
 
                        {
61
 
                        case Contacts.Phones.TYPE_MOBILE:
62
 
                                return ContactData.TYPE_MOBILE;
63
 
                        case Contacts.Phones.TYPE_FAX_HOME:
64
 
                                return ContactData.TYPE_FAX_HOME;
65
 
                        case Contacts.Phones.TYPE_FAX_WORK:
66
 
                                return ContactData.TYPE_FAX_WORK;
67
 
                        case Contacts.Phones.TYPE_PAGER:
68
 
                                return ContactData.TYPE_PAGER;
69
 
                        case Contacts.Phones.TYPE_WORK:
70
 
                                return ContactData.TYPE_WORK;
71
 
                        default:
72
 
                                return ContactData.TYPE_HOME;
73
 
                        }
74
 
                }
75
 
                else if( cls == Contacts.ContactMethods.class )
76
 
                {
77
 
                        switch( type )
78
 
                        {
79
 
                        case Contacts.Phones.TYPE_WORK:
80
 
                                return ContactData.TYPE_WORK;
81
 
                        default:
82
 
                                return ContactData.TYPE_HOME;
83
 
                        }
84
 
                }
85
 
 
86
 
                return ContactData.TYPE_HOME;
87
 
        }
88
 
 
89
53
        @Override
90
54
        public boolean getNextContact( Exporter.ContactData contact )
91
55
        {
97
61
                                new String[] {
98
62
                                        Contacts.People._ID,
99
63
                                        Contacts.People.NAME,
100
 
                                        Contacts.People.NOTES,
101
64
                                }, null, null, null );
102
65
                }
103
66
 
110
73
                // get this contact's id
111
74
                Long id = _cur.getLong( _cur.getColumnIndex( Contacts.People._ID ) );
112
75
 
113
 
                // set name
 
76
                // create contact
114
77
                contact.setName(
115
78
                        _cur.getString( _cur.getColumnIndex( Contacts.People.NAME ) ) );
116
79
 
117
 
                // add notes
118
 
                contact.addNote(
119
 
                        _cur.getString( _cur.getColumnIndex( Contacts.People.NOTES ) ) );
120
 
 
121
 
                // add the organisations
 
80
                // get the organisations
122
81
                Cursor cur = _activity.managedQuery( Contacts.Organizations.CONTENT_URI,
123
82
                        new String[] {
124
83
                                Contacts.Organizations.COMPANY,
135
94
                                        Contacts.Organizations.TITLE ) ) ) );
136
95
                cur.close();
137
96
 
138
 
                // add the phone numbers
 
97
                // get the phone numbers
139
98
                cur = _activity.managedQuery( Contacts.Phones.CONTENT_URI,
140
99
                        new String[] {
141
100
                                Contacts.Phones.NUMBER,
146
105
                                Contacts.Phones.PERSON_ID + " ASC" );
147
106
                while( cur.moveToNext() )
148
107
                        contact.addNumber( contact.new NumberDetail(
149
 
                                convertBackendTypeToType( Contacts.Phones.class,
150
 
                                        cur.getInt( cur.getColumnIndex( Contacts.Phones.TYPE ) ) ),
 
108
                                cur.getInt( cur.getColumnIndex(
 
109
                                        Contacts.Phones.TYPE ) ),
151
110
                                cur.getString( cur.getColumnIndex(
152
111
                                        Contacts.Phones.NUMBER ) ) ) );
153
112
                cur.close();
154
113
 
155
 
                // add the email and postal addresses
 
114
                // get the email and postal addresses
156
115
                cur = _activity.managedQuery( Contacts.ContactMethods.CONTENT_URI,
157
116
                        new String[] {
158
117
                                Contacts.ContactMethods.KIND,
173
132
                                Contacts.ContactMethods.KIND ) );
174
133
                        if( kind == Contacts.KIND_EMAIL )
175
134
                                contact.addEmail( contact.new EmailDetail(
176
 
                                        convertBackendTypeToType( Contacts.ContactMethods.class,
177
 
                                                cur.getInt( cur.getColumnIndex(
178
 
                                                        Contacts.ContactMethods.TYPE ) ) ),
 
135
                                        cur.getInt( cur.getColumnIndex(
 
136
                                                Contacts.ContactMethods.TYPE ) ),
179
137
                                        cur.getString( cur.getColumnIndex(
180
138
                                                Contacts.ContactMethods.DATA ) ) ) );
181
139
                        else
182
140
                                contact.addAddress( contact.new AddressDetail(
183
 
                                        convertBackendTypeToType( Contacts.ContactMethods.class,
184
 
                                                cur.getInt( cur.getColumnIndex(
185
 
                                                        Contacts.ContactMethods.TYPE ) ) ),
 
141
                                        cur.getInt( cur.getColumnIndex(
 
142
                                                Contacts.ContactMethods.TYPE ) ),
186
143
                                        cur.getString( cur.getColumnIndex(
187
144
                                                Contacts.ContactMethods.DATA ) ) ) );
188
145
                }