blob: efb4400521d2aae0d2b17a6215aa398fafc38ab0 [file] [log] [blame]
Brian Attwell684318f2015-02-25 12:39:28 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.contacts.common.model.account;
18
19import com.google.common.collect.Lists;
20
21import com.android.contacts.common.R;
22import com.android.contacts.common.model.dataitem.DataKind;
23import com.android.contacts.common.util.CommonDateUtils;
Walter Jang3a0b4832016-10-12 11:02:54 -070024import com.android.contactsbind.FeedbackHelper;
Brian Attwell684318f2015-02-25 12:39:28 -080025
26import android.content.ContentValues;
27import android.content.Context;
28import android.provider.ContactsContract.CommonDataKinds.Email;
29import android.provider.ContactsContract.CommonDataKinds.Event;
30import android.provider.ContactsContract.CommonDataKinds.Phone;
31import android.provider.ContactsContract.CommonDataKinds.Relation;
32import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
33import android.util.Log;
34
35import java.util.Locale;
36
37/**
38 * A writable account type that can be used to support samsung contacts. This may not perfectly
39 * match Samsung's latest intended account schema.
40 *
41 * This is only used to partially support Samsung accounts. The DataKind labels & fields are
42 * setup to support the values used by Samsung. But, not everything in the Samsung account type is
43 * supported. The Samsung account type includes a "Message Type" mimetype that we have no intention
44 * of showing inside the Contact editor. Similarly, we don't handle the "Ringtone" mimetype here
45 * since managing ringtones is handled in a different flow.
46 */
47public class SamsungAccountType extends BaseAccountType {
48 private static final String TAG = "KnownExternalAccountType";
49 private static final String ACCOUNT_TYPE_SAMSUNG = "com.osp.app.signin";
50
51 public SamsungAccountType(Context context, String authenticatorPackageName, String type) {
52 this.accountType = type;
53 this.resourcePackageName = null;
54 this.syncAdapterPackageName = authenticatorPackageName;
55
56 try {
57 addDataKindStructuredName(context);
Gary Mai7a6daea2016-10-10 15:41:48 -070058 addDataKindName(context);
Brian Attwell684318f2015-02-25 12:39:28 -080059 addDataKindPhoneticName(context);
60 addDataKindNickname(context);
61 addDataKindPhone(context);
62 addDataKindEmail(context);
63 addDataKindStructuredPostal(context);
64 addDataKindIm(context);
65 addDataKindOrganization(context);
66 addDataKindPhoto(context);
67 addDataKindNote(context);
68 addDataKindWebsite(context);
69 addDataKindGroupMembership(context);
70 addDataKindRelation(context);
71 addDataKindEvent(context);
72
73 mIsInitialized = true;
74 } catch (DefinitionException e) {
Walter Jang3a0b4832016-10-12 11:02:54 -070075 FeedbackHelper.sendFeedback(context, TAG, "Failed to build samsung account type", e);
Brian Attwell684318f2015-02-25 12:39:28 -080076 }
77 }
78
79 /**
80 * Returns {@code TRUE} if this is samsung's account type and Samsung hasn't bothered to
81 * define a contacts.xml to provide a more accurate definition than ours.
82 */
83 public static boolean isSamsungAccountType(Context context, String type,
84 String packageName) {
85 return ACCOUNT_TYPE_SAMSUNG.equals(type)
86 && !ExternalAccountType.hasContactsXml(context, packageName);
87 }
88
89 @Override
90 protected DataKind addDataKindStructuredPostal(Context context) throws DefinitionException {
91 final DataKind kind = super.addDataKindStructuredPostal(context);
92
93 final boolean useJapaneseOrder =
94 Locale.JAPANESE.getLanguage().equals(Locale.getDefault().getLanguage());
95 kind.typeColumn = StructuredPostal.TYPE;
96 kind.typeList = Lists.newArrayList();
97 kind.typeList.add(buildPostalType(StructuredPostal.TYPE_WORK).setSpecificMax(1));
98 kind.typeList.add(buildPostalType(StructuredPostal.TYPE_HOME).setSpecificMax(1));
99 kind.typeList.add(buildPostalType(StructuredPostal.TYPE_OTHER).setSpecificMax(1));
100
101 kind.fieldList = Lists.newArrayList();
102 if (useJapaneseOrder) {
103 kind.fieldList.add(new EditField(StructuredPostal.COUNTRY,
104 R.string.postal_country, FLAGS_POSTAL).setOptional(true));
105 kind.fieldList.add(new EditField(StructuredPostal.POSTCODE,
106 R.string.postal_postcode, FLAGS_POSTAL));
107 kind.fieldList.add(new EditField(StructuredPostal.REGION,
108 R.string.postal_region, FLAGS_POSTAL));
109 kind.fieldList.add(new EditField(StructuredPostal.CITY,
110 R.string.postal_city,FLAGS_POSTAL));
111 kind.fieldList.add(new EditField(StructuredPostal.STREET,
112 R.string.postal_street, FLAGS_POSTAL));
113 } else {
114 kind.fieldList.add(new EditField(StructuredPostal.STREET,
115 R.string.postal_street, FLAGS_POSTAL));
116 kind.fieldList.add(new EditField(StructuredPostal.CITY,
117 R.string.postal_city,FLAGS_POSTAL));
118 kind.fieldList.add(new EditField(StructuredPostal.REGION,
119 R.string.postal_region, FLAGS_POSTAL));
120 kind.fieldList.add(new EditField(StructuredPostal.POSTCODE,
121 R.string.postal_postcode, FLAGS_POSTAL));
122 kind.fieldList.add(new EditField(StructuredPostal.COUNTRY,
123 R.string.postal_country, FLAGS_POSTAL).setOptional(true));
124 }
125
126 return kind;
127 }
128
129 @Override
130 protected DataKind addDataKindPhone(Context context) throws DefinitionException {
131 final DataKind kind = super.addDataKindPhone(context);
132
133 kind.typeColumn = Phone.TYPE;
134 kind.typeList = Lists.newArrayList();
135 kind.typeList.add(buildPhoneType(Phone.TYPE_MOBILE));
136 kind.typeList.add(buildPhoneType(Phone.TYPE_HOME));
137 kind.typeList.add(buildPhoneType(Phone.TYPE_WORK));
138 kind.typeList.add(buildPhoneType(Phone.TYPE_MAIN));
139 kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_WORK).setSecondary(true));
140 kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_HOME).setSecondary(true));
141 kind.typeList.add(buildPhoneType(Phone.TYPE_PAGER).setSecondary(true));
142 kind.typeList.add(buildPhoneType(Phone.TYPE_RADIO).setSecondary(true));
143 kind.typeList.add(buildPhoneType(Phone.TYPE_OTHER));
144 kind.typeList.add(buildPhoneType(Phone.TYPE_CUSTOM).setSecondary(true)
145 .setCustomColumn(Phone.LABEL));
146
147 kind.fieldList = Lists.newArrayList();
148 kind.fieldList.add(new EditField(Phone.NUMBER, R.string.phoneLabelsGroup, FLAGS_PHONE));
149
150 return kind;
151 }
152
153 @Override
154 protected DataKind addDataKindEmail(Context context) throws DefinitionException {
155 final DataKind kind = super.addDataKindEmail(context);
156
157 kind.typeColumn = Email.TYPE;
158 kind.typeList = Lists.newArrayList();
159 kind.typeList.add(buildEmailType(Email.TYPE_HOME));
160 kind.typeList.add(buildEmailType(Email.TYPE_WORK));
161 kind.typeList.add(buildEmailType(Email.TYPE_OTHER));
162 kind.typeList.add(buildEmailType(Email.TYPE_CUSTOM).setSecondary(true).setCustomColumn(
163 Email.LABEL));
164
165 kind.fieldList = Lists.newArrayList();
166 kind.fieldList.add(new EditField(Email.DATA, R.string.emailLabelsGroup, FLAGS_EMAIL));
167
168 return kind;
169 }
170
171 private DataKind addDataKindRelation(Context context) throws DefinitionException {
172 DataKind kind = addKind(new DataKind(Relation.CONTENT_ITEM_TYPE,
173 R.string.relationLabelsGroup, 160, true));
174 kind.actionHeader = new RelationActionInflater();
175 kind.actionBody = new SimpleInflater(Relation.NAME);
176
177 kind.typeColumn = Relation.TYPE;
178 kind.typeList = Lists.newArrayList();
179 kind.typeList.add(buildRelationType(Relation.TYPE_ASSISTANT));
180 kind.typeList.add(buildRelationType(Relation.TYPE_BROTHER));
181 kind.typeList.add(buildRelationType(Relation.TYPE_CHILD));
182 kind.typeList.add(buildRelationType(Relation.TYPE_DOMESTIC_PARTNER));
183 kind.typeList.add(buildRelationType(Relation.TYPE_FATHER));
184 kind.typeList.add(buildRelationType(Relation.TYPE_FRIEND));
185 kind.typeList.add(buildRelationType(Relation.TYPE_MANAGER));
186 kind.typeList.add(buildRelationType(Relation.TYPE_MOTHER));
187 kind.typeList.add(buildRelationType(Relation.TYPE_PARENT));
188 kind.typeList.add(buildRelationType(Relation.TYPE_PARTNER));
189 kind.typeList.add(buildRelationType(Relation.TYPE_REFERRED_BY));
190 kind.typeList.add(buildRelationType(Relation.TYPE_RELATIVE));
191 kind.typeList.add(buildRelationType(Relation.TYPE_SISTER));
192 kind.typeList.add(buildRelationType(Relation.TYPE_SPOUSE));
193 kind.typeList.add(buildRelationType(Relation.TYPE_CUSTOM).setSecondary(true)
194 .setCustomColumn(Relation.LABEL));
195
196 kind.defaultValues = new ContentValues();
197 kind.defaultValues.put(Relation.TYPE, Relation.TYPE_SPOUSE);
198
199 kind.fieldList = Lists.newArrayList();
200 kind.fieldList.add(new EditField(Relation.DATA, R.string.relationLabelsGroup,
201 FLAGS_RELATION));
202
203 return kind;
204 }
205
206 private DataKind addDataKindEvent(Context context) throws DefinitionException {
207 DataKind kind = addKind(new DataKind(Event.CONTENT_ITEM_TYPE,
208 R.string.eventLabelsGroup, 150, true));
209 kind.actionHeader = new EventActionInflater();
210 kind.actionBody = new SimpleInflater(Event.START_DATE);
211
212 kind.typeColumn = Event.TYPE;
213 kind.typeList = Lists.newArrayList();
214 kind.dateFormatWithoutYear = CommonDateUtils.NO_YEAR_DATE_FORMAT;
215 kind.dateFormatWithYear = CommonDateUtils.FULL_DATE_FORMAT;
216 kind.typeList.add(buildEventType(Event.TYPE_BIRTHDAY, true).setSpecificMax(1));
217 kind.typeList.add(buildEventType(Event.TYPE_ANNIVERSARY, false));
218 kind.typeList.add(buildEventType(Event.TYPE_OTHER, false));
219 kind.typeList.add(buildEventType(Event.TYPE_CUSTOM, false).setSecondary(true)
220 .setCustomColumn(Event.LABEL));
221
222 kind.defaultValues = new ContentValues();
223 kind.defaultValues.put(Event.TYPE, Event.TYPE_BIRTHDAY);
224
225 kind.fieldList = Lists.newArrayList();
226 kind.fieldList.add(new EditField(Event.DATA, R.string.eventLabelsGroup, FLAGS_EVENT));
227
228 return kind;
229 }
230
231 @Override
232 public boolean isGroupMembershipEditable() {
233 return true;
234 }
235
236 @Override
237 public boolean areContactsWritable() {
238 return true;
239 }
240}