1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.xwalk.core.extension.api.contacts;
7 import android.provider.ContactsContract.CommonDataKinds.Email;
8 import android.provider.ContactsContract.CommonDataKinds.Event;
9 import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
10 import android.provider.ContactsContract.CommonDataKinds.Im;
11 import android.provider.ContactsContract.CommonDataKinds.Nickname;
12 import android.provider.ContactsContract.CommonDataKinds.Note;
13 import android.provider.ContactsContract.CommonDataKinds.Organization;
14 import android.provider.ContactsContract.CommonDataKinds.Phone;
15 import android.provider.ContactsContract.CommonDataKinds.Photo;
16 import android.provider.ContactsContract.CommonDataKinds.StructuredName;
17 import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
18 import android.provider.ContactsContract.CommonDataKinds.Website;
19 import android.provider.ContactsContract.Data;
20 import android.util.Pair;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.List;
29 * This class contains most constant variables that required by other Contacts classes.
31 public class ContactConstants {
32 public static final String CUSTOM_MIMETYPE_LASTUPDATED =
33 "vnd.android.cursor.item/contact_custom_lastupdated";
34 public static final String CUSTOM_MIMETYPE_GENDER =
35 "vnd.android.cursor.item/contact_custom_gender";
37 // This map is for fields in ContactFindOptions dictionary.
38 // e.g. When to find "givenName=John", we actually need to find "John" in "givenNames".
39 public static final Map<String, String> findFieldMap = createStringMap(new String[]{
40 "familyName", "familyNames",
41 "givenName", "givenNames",
42 "middleName", "middleNames",
43 "additionalName", "additionalNames",
44 "honorificPrefix", "honorificPrefixes",
45 "honorificSuffix", "honorificSuffixes",
46 "nickName", "nickNames",
50 "phoneNumber", "phoneNumbers",
51 "organization", "organizations",
52 "jobTitle", "jobTitles",
54 // TODO(hdq): Should birthday and anniversary be distinguished?
57 // This map is for contact fields between spec and Android's native API.
58 public static final Map<String, Pair<String, String>> contactDataMap = createTripleMap(new String[]{
59 "id", Data.CONTACT_ID, null,
60 "displayName", StructuredName.DISPLAY_NAME, StructuredName.CONTENT_ITEM_TYPE,
61 "familyNames", StructuredName.FAMILY_NAME, StructuredName.CONTENT_ITEM_TYPE,
62 "givenNames", StructuredName.GIVEN_NAME, StructuredName.CONTENT_ITEM_TYPE,
63 "middleNames", StructuredName.MIDDLE_NAME, StructuredName.CONTENT_ITEM_TYPE,
64 "additionalNames", StructuredName.MIDDLE_NAME, StructuredName.CONTENT_ITEM_TYPE,
65 "honorificPrefixes", StructuredName.PREFIX, StructuredName.CONTENT_ITEM_TYPE,
66 "honorificSuffixes", StructuredName.SUFFIX, StructuredName.CONTENT_ITEM_TYPE,
67 "nickNames", Nickname.NAME, Nickname.CONTENT_ITEM_TYPE,
68 "categories", GroupMembership.GROUP_ROW_ID, GroupMembership.CONTENT_ITEM_TYPE,
69 "gender", Data.DATA1, CUSTOM_MIMETYPE_GENDER,
70 "lastUpdated", Data.DATA1, CUSTOM_MIMETYPE_LASTUPDATED,
71 "birthday", Data.DATA1, Event.CONTENT_ITEM_TYPE,
72 "anniversary", Data.DATA1, Event.CONTENT_ITEM_TYPE,
73 "emails", Email.DATA, Email.CONTENT_ITEM_TYPE,
74 "photos", Photo.PHOTO, Photo.CONTENT_ITEM_TYPE,
75 "urls", Website.URL, Website.CONTENT_ITEM_TYPE,
76 "phoneNumbers", Phone.NUMBER, Phone.CONTENT_ITEM_TYPE,
77 "addresses", null, StructuredPostal.CONTENT_ITEM_TYPE,
78 "streetAddress", StructuredPostal.STREET, StructuredPostal.CONTENT_ITEM_TYPE,
79 "locality", StructuredPostal.NEIGHBORHOOD, StructuredPostal.CONTENT_ITEM_TYPE,
80 "region", StructuredPostal.REGION, StructuredPostal.CONTENT_ITEM_TYPE,
81 "postalCode", StructuredPostal.POSTCODE, StructuredPostal.CONTENT_ITEM_TYPE,
82 "countryName", StructuredPostal.COUNTRY, StructuredPostal.CONTENT_ITEM_TYPE,
83 "organizations", Organization.COMPANY, Organization.CONTENT_ITEM_TYPE,
84 "jobTitles", Organization.TITLE, Organization.CONTENT_ITEM_TYPE,
85 "notes", Note.NOTE, Note.CONTENT_ITEM_TYPE,
86 "impp", Im.DATA, Im.CONTENT_ITEM_TYPE
89 // Helper to create a triple map from a String array.
90 private static Map<String, Pair<String, String>> createTripleMap(String[] triplets) {
91 Map<String, Pair<String, String>> result = new HashMap<String, Pair<String, String>>();
92 for (int i = 0; i < triplets.length; i += 3) {
93 result.put(triplets[i], new Pair<String, String>(triplets[i + 1], triplets[i + 2]));
95 return Collections.unmodifiableMap(result);
98 // Helper to create a duality map from a String array.
99 private static Map<String, String> createStringMap(String[] pairs) {
100 Map<String, String> result = new HashMap<String, String>();
101 for (int i = 0; i < pairs.length; i += 2) {
102 result.put(pairs[i], pairs[i + 1]);
104 return Collections.unmodifiableMap(result);
107 // Helper to create a duality map from a String array with first element is always "data".
108 private static Map<String, String> createDataMap(String name) {
109 return createStringMap(new String[]{"data", name});
112 // Helper to create a duality map from a String array with second element is always "value".
113 private static Map<String, String> createValueMap(String name) {
114 return createStringMap(new String[]{name, "value"});
117 // For data map without type, should use `createDataMap()`
118 public static final Map<String, String> photoDataMap = createDataMap(Photo.PHOTO);
119 public static final Map<String, String> companyDataMap = createDataMap(Organization.COMPANY);
120 public static final Map<String, String> jobtitleDataMap = createDataMap(Organization.TITLE);
121 public static final Map<String, String> noteDataMap = createDataMap(Note.NOTE);
123 // For data map with type, should use `createValueMap()`
124 public static final Map<String, String> emailDataMap = createValueMap(Email.DATA);
125 public static final Map<String, String> websiteDataMap = createValueMap(Website.DATA);
126 public static final Map<String, String> phoneDataMap = createValueMap(Phone.DATA);
127 public static final Map<String, String> imDataMap = createValueMap(Im.DATA);
129 public static final Map<String, String> addressDataMap = createStringMap(new String[]{
130 StructuredPostal.STREET, "streetAddress",
131 StructuredPostal.NEIGHBORHOOD, "locality",
132 StructuredPostal.REGION, "region",
133 StructuredPostal.POSTCODE, "postalCode",
134 StructuredPostal.COUNTRY, "countryName"
137 @SuppressWarnings("serial")
138 public static final Map<String, String> emailTypeMap = new HashMap<String, String>() {{
139 put("type", Email.TYPE);
140 put("isPrimary", Email.IS_PRIMARY);
141 put("isSuperPrimary", Email.IS_SUPER_PRIMARY);
144 @SuppressWarnings("serial")
145 public static final Map<String, String> websiteTypeMap = new HashMap<String, String>() {{
146 put("type", Website.TYPE);
147 put("isPrimary", Website.IS_PRIMARY);
148 put("isSuperPrimary", Website.IS_SUPER_PRIMARY);
151 @SuppressWarnings("serial")
152 public static final Map<String, String> addressTypeMap = new HashMap<String, String>() {{
153 put("type", StructuredPostal.TYPE);
154 put("isPrimary", StructuredPostal.IS_PRIMARY);
155 put("isSuperPrimary", StructuredPostal.IS_SUPER_PRIMARY);
158 @SuppressWarnings("serial")
159 public static final Map<String, String> phoneTypeMap = new HashMap<String, String>() {{
160 put("type", Phone.TYPE);
161 put("isPrimary", Phone.IS_PRIMARY);
162 put("isSuperPrimary", Phone.IS_SUPER_PRIMARY);
165 @SuppressWarnings("serial")
166 public static final Map<String, String> imTypeMap = new HashMap<String, String>() {{
167 put("type", Im.TYPE);
168 put("isPrimary", Im.IS_PRIMARY);
169 put("isSuperPrimary", Im.IS_SUPER_PRIMARY);
172 @SuppressWarnings("serial")
173 public static final Map<String, Integer> emailTypeValuesMap = new HashMap<String, Integer>() {{
174 put("work", Email.TYPE_WORK);
175 put("home", Email.TYPE_HOME);
176 put("mobile", Email.TYPE_MOBILE);
179 @SuppressWarnings("serial")
180 public static final Map<String, Integer> websiteTypeValuesMap = new HashMap<String, Integer>() {{
181 put("blog", Website.TYPE_BLOG);
182 put("ftp", Website.TYPE_FTP);
183 put("home", Website.TYPE_HOME);
184 put("homepage", Website.TYPE_HOMEPAGE);
185 put("other", Website.TYPE_OTHER);
186 put("profile", Website.TYPE_PROFILE);
187 put("work", Website.TYPE_WORK);
190 @SuppressWarnings("serial")
191 public static final Map<String, Integer> addressTypeValuesMap = new HashMap<String, Integer>() {{
192 put("work", StructuredPostal.TYPE_WORK);
193 put("home", StructuredPostal.TYPE_HOME);
194 put("other", StructuredPostal.TYPE_OTHER);
197 @SuppressWarnings("serial")
198 public static final Map<String, Integer> phoneTypeValuesMap = new HashMap<String, Integer>() {{
199 put("home", Phone.TYPE_HOME);
200 put("mobile", Phone.TYPE_MOBILE);
201 put("work", Phone.TYPE_WORK);
202 put("fax_work", Phone.TYPE_FAX_WORK);
203 put("fax_home", Phone.TYPE_FAX_HOME);
204 put("pager", Phone.TYPE_PAGER);
205 put("other", Phone.TYPE_OTHER);
206 put("callback", Phone.TYPE_CALLBACK);
207 put("car", Phone.TYPE_CAR);
208 put("company_main", Phone.TYPE_COMPANY_MAIN);
209 put("isdn", Phone.TYPE_ISDN);
210 put("main", Phone.TYPE_MAIN);
211 put("other_fax", Phone.TYPE_OTHER_FAX);
212 put("radio", Phone.TYPE_RADIO);
213 put("telex", Phone.TYPE_TELEX);
214 put("tty_tdd", Phone.TYPE_TTY_TDD);
215 put("mobile", Phone.TYPE_WORK_MOBILE);
216 put("work_pager", Phone.TYPE_WORK_PAGER);
217 put("assistant", Phone.TYPE_ASSISTANT);
218 put("mms", Phone.TYPE_MMS);
221 @SuppressWarnings("serial")
222 public static final Map<String, Integer> imTypeValuesMap = new HashMap<String, Integer>() {{
223 put("work", Im.TYPE_WORK);
224 put("home", Im.TYPE_HOME);
225 put("other", Im.TYPE_OTHER);
228 @SuppressWarnings("serial")
229 public static final Map<String, Integer> imProtocolMap = new HashMap<String, Integer>() {{
230 put("aim", Im.PROTOCOL_AIM);
231 put("msn", Im.PROTOCOL_MSN);
232 put("ymsgr", Im.PROTOCOL_YAHOO);
233 put("skype", Im.PROTOCOL_SKYPE);
234 put("qq", Im.PROTOCOL_QQ);
235 put("gtalk", Im.PROTOCOL_GOOGLE_TALK);
236 put("icq", Im.PROTOCOL_ICQ);
237 put("jabber", Im.PROTOCOL_JABBER);
238 put("netmeeting", Im.PROTOCOL_NETMEETING);
241 // Stores Spec<->Android mappings for a contact field.
242 public static class ContactMap {
244 public String mMimeType;
245 public Map<String, String> mDataMap;
246 public Map<String, String> mTypeMap;
247 public Map<String, Integer> mTypeValueMap;
248 public ContactMap(String n, Map<String, String> datas,
249 Map<String, String> types, Map<String, Integer> typeValues) {
251 mMimeType = contactDataMap.get(n).second;
254 mTypeValueMap = typeValues;
258 // Contains all maps that we can handle by a unique logic.
259 @SuppressWarnings("serial")
260 public static final List<ContactMap> contactMapList = new ArrayList<ContactMap>() {{
261 add(new ContactMap("emails", emailDataMap, emailTypeMap, emailTypeValuesMap));
262 add(new ContactMap("photos", photoDataMap, null, null));
263 add(new ContactMap("urls", websiteDataMap, websiteTypeMap, websiteTypeValuesMap));
264 add(new ContactMap("phoneNumbers", phoneDataMap, phoneTypeMap, phoneTypeValuesMap));
265 add(new ContactMap("addresses", addressDataMap, addressTypeMap, addressTypeValuesMap));
266 add(new ContactMap("organizations", companyDataMap, null, null));
267 add(new ContactMap("jobTitles", jobtitleDataMap, null, null));
268 add(new ContactMap("notes", noteDataMap, null, null));
269 add(new ContactMap("impp", imDataMap, imTypeMap, imTypeValuesMap));