blob: c7aac7639ee4733810964ee28b83b66406e27e97 [file] [log] [blame]
Chiao Chenge88fcd32012-11-13 18:38:05 -08001/*
2 * Copyright (C) 2009 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
Gary Mai69c182a2016-12-05 13:07:03 -080017package com.android.contacts.model.account;
Chiao Chenge88fcd32012-11-13 18:38:05 -080018
19import android.content.ContentValues;
20import android.content.Context;
21import android.provider.ContactsContract.CommonDataKinds.Email;
22import android.provider.ContactsContract.CommonDataKinds.Event;
23import android.provider.ContactsContract.CommonDataKinds.Phone;
24import android.provider.ContactsContract.CommonDataKinds.Relation;
Chiao Chenge88fcd32012-11-13 18:38:05 -080025
Arthur Wang3f6a2442016-12-05 14:51:59 -080026import com.android.contacts.R;
Gary Mai69c182a2016-12-05 13:07:03 -080027import com.android.contacts.model.dataitem.DataKind;
28import com.android.contacts.util.CommonDateUtils;
Walter Jang3a0b4832016-10-12 11:02:54 -070029import com.android.contactsbind.FeedbackHelper;
30
Chiao Chenge88fcd32012-11-13 18:38:05 -080031import com.google.common.collect.Lists;
32
33import java.util.List;
34
35public class GoogleAccountType extends BaseAccountType {
36 private static final String TAG = "GoogleAccountType";
37
Yorke Lee0c2d0732014-06-20 16:16:19 -070038 /**
39 * The package name that we should load contacts.xml from and rely on to handle
Brian Attwelle5ac8b12014-12-10 14:40:40 -080040 * G+ account actions. Even though this points to gms, in some cases gms will still hand
41 * off responsibility to the G+ app.
Yorke Lee0c2d0732014-06-20 16:16:19 -070042 */
Brian Attwelle5ac8b12014-12-10 14:40:40 -080043 public static final String PLUS_EXTENSION_PACKAGE_NAME = "com.google.android.gms";
Yorke Lee0c2d0732014-06-20 16:16:19 -070044
Chiao Chenge88fcd32012-11-13 18:38:05 -080045 public static final String ACCOUNT_TYPE = "com.google";
46
47 private static final List<String> mExtensionPackages =
Yorke Lee0c2d0732014-06-20 16:16:19 -070048 Lists.newArrayList(PLUS_EXTENSION_PACKAGE_NAME);
Chiao Chenge88fcd32012-11-13 18:38:05 -080049
50 public GoogleAccountType(Context context, String authenticatorPackageName) {
51 this.accountType = ACCOUNT_TYPE;
52 this.resourcePackageName = null;
53 this.syncAdapterPackageName = authenticatorPackageName;
54
55 try {
56 addDataKindStructuredName(context);
Gary Mai7a6daea2016-10-10 15:41:48 -070057 addDataKindName(context);
Chiao Chenge88fcd32012-11-13 18:38:05 -080058 addDataKindPhoneticName(context);
59 addDataKindNickname(context);
60 addDataKindPhone(context);
61 addDataKindEmail(context);
62 addDataKindStructuredPostal(context);
63 addDataKindIm(context);
64 addDataKindOrganization(context);
65 addDataKindPhoto(context);
66 addDataKindNote(context);
67 addDataKindWebsite(context);
68 addDataKindSipAddress(context);
69 addDataKindGroupMembership(context);
70 addDataKindRelation(context);
71 addDataKindEvent(context);
yaolu1bd88262016-08-18 10:29:12 -070072 addDataKindCustomField(context);
Chiao Chenge88fcd32012-11-13 18:38:05 -080073
74 mIsInitialized = true;
75 } catch (DefinitionException e) {
Walter Jang3a0b4832016-10-12 11:02:54 -070076 FeedbackHelper.sendFeedback(context, TAG, "Failed to build google account type", e);
Chiao Chenge88fcd32012-11-13 18:38:05 -080077 }
78 }
79
80 @Override
81 public List<String> getExtensionPackageNames() {
82 return mExtensionPackages;
83 }
84
85 @Override
86 protected DataKind addDataKindPhone(Context context) throws DefinitionException {
87 final DataKind kind = super.addDataKindPhone(context);
88
89 kind.typeColumn = Phone.TYPE;
90 kind.typeList = Lists.newArrayList();
91 kind.typeList.add(buildPhoneType(Phone.TYPE_MOBILE));
92 kind.typeList.add(buildPhoneType(Phone.TYPE_WORK));
93 kind.typeList.add(buildPhoneType(Phone.TYPE_HOME));
94 kind.typeList.add(buildPhoneType(Phone.TYPE_MAIN));
95 kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_WORK).setSecondary(true));
96 kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_HOME).setSecondary(true));
97 kind.typeList.add(buildPhoneType(Phone.TYPE_PAGER).setSecondary(true));
98 kind.typeList.add(buildPhoneType(Phone.TYPE_OTHER));
99 kind.typeList.add(buildPhoneType(Phone.TYPE_CUSTOM).setSecondary(true)
100 .setCustomColumn(Phone.LABEL));
101
102 kind.fieldList = Lists.newArrayList();
103 kind.fieldList.add(new EditField(Phone.NUMBER, R.string.phoneLabelsGroup, FLAGS_PHONE));
104
105 return kind;
106 }
107
108 @Override
109 protected DataKind addDataKindEmail(Context context) throws DefinitionException {
110 final DataKind kind = super.addDataKindEmail(context);
111
112 kind.typeColumn = Email.TYPE;
113 kind.typeList = Lists.newArrayList();
114 kind.typeList.add(buildEmailType(Email.TYPE_HOME));
115 kind.typeList.add(buildEmailType(Email.TYPE_WORK));
116 kind.typeList.add(buildEmailType(Email.TYPE_OTHER));
117 kind.typeList.add(buildEmailType(Email.TYPE_CUSTOM).setSecondary(true).setCustomColumn(
118 Email.LABEL));
119
120 kind.fieldList = Lists.newArrayList();
121 kind.fieldList.add(new EditField(Email.DATA, R.string.emailLabelsGroup, FLAGS_EMAIL));
122
123 return kind;
124 }
125
126 private DataKind addDataKindRelation(Context context) throws DefinitionException {
127 DataKind kind = addKind(new DataKind(Relation.CONTENT_ITEM_TYPE,
Brian Attwell913e18a2014-10-30 11:16:05 -0700128 R.string.relationLabelsGroup, Weight.RELATIONSHIP, true));
Chiao Chenge88fcd32012-11-13 18:38:05 -0800129 kind.actionHeader = new RelationActionInflater();
130 kind.actionBody = new SimpleInflater(Relation.NAME);
131
132 kind.typeColumn = Relation.TYPE;
133 kind.typeList = Lists.newArrayList();
134 kind.typeList.add(buildRelationType(Relation.TYPE_ASSISTANT));
135 kind.typeList.add(buildRelationType(Relation.TYPE_BROTHER));
136 kind.typeList.add(buildRelationType(Relation.TYPE_CHILD));
137 kind.typeList.add(buildRelationType(Relation.TYPE_DOMESTIC_PARTNER));
138 kind.typeList.add(buildRelationType(Relation.TYPE_FATHER));
139 kind.typeList.add(buildRelationType(Relation.TYPE_FRIEND));
140 kind.typeList.add(buildRelationType(Relation.TYPE_MANAGER));
141 kind.typeList.add(buildRelationType(Relation.TYPE_MOTHER));
142 kind.typeList.add(buildRelationType(Relation.TYPE_PARENT));
143 kind.typeList.add(buildRelationType(Relation.TYPE_PARTNER));
144 kind.typeList.add(buildRelationType(Relation.TYPE_REFERRED_BY));
145 kind.typeList.add(buildRelationType(Relation.TYPE_RELATIVE));
146 kind.typeList.add(buildRelationType(Relation.TYPE_SISTER));
147 kind.typeList.add(buildRelationType(Relation.TYPE_SPOUSE));
148 kind.typeList.add(buildRelationType(Relation.TYPE_CUSTOM).setSecondary(true)
149 .setCustomColumn(Relation.LABEL));
150
151 kind.defaultValues = new ContentValues();
152 kind.defaultValues.put(Relation.TYPE, Relation.TYPE_SPOUSE);
153
154 kind.fieldList = Lists.newArrayList();
155 kind.fieldList.add(new EditField(Relation.DATA, R.string.relationLabelsGroup,
156 FLAGS_RELATION));
157
158 return kind;
159 }
160
161 private DataKind addDataKindEvent(Context context) throws DefinitionException {
162 DataKind kind = addKind(new DataKind(Event.CONTENT_ITEM_TYPE,
Brian Attwell913e18a2014-10-30 11:16:05 -0700163 R.string.eventLabelsGroup, Weight.EVENT, true));
Chiao Chenge88fcd32012-11-13 18:38:05 -0800164 kind.actionHeader = new EventActionInflater();
165 kind.actionBody = new SimpleInflater(Event.START_DATE);
166
167 kind.typeColumn = Event.TYPE;
168 kind.typeList = Lists.newArrayList();
169 kind.dateFormatWithoutYear = CommonDateUtils.NO_YEAR_DATE_FORMAT;
170 kind.dateFormatWithYear = CommonDateUtils.FULL_DATE_FORMAT;
171 kind.typeList.add(buildEventType(Event.TYPE_BIRTHDAY, true).setSpecificMax(1));
172 kind.typeList.add(buildEventType(Event.TYPE_ANNIVERSARY, false));
173 kind.typeList.add(buildEventType(Event.TYPE_OTHER, false));
174 kind.typeList.add(buildEventType(Event.TYPE_CUSTOM, false).setSecondary(true)
175 .setCustomColumn(Event.LABEL));
176
177 kind.defaultValues = new ContentValues();
178 kind.defaultValues.put(Event.TYPE, Event.TYPE_BIRTHDAY);
179
180 kind.fieldList = Lists.newArrayList();
181 kind.fieldList.add(new EditField(Event.DATA, R.string.eventLabelsGroup, FLAGS_EVENT));
182
183 return kind;
184 }
185
186 @Override
187 public boolean isGroupMembershipEditable() {
188 return true;
189 }
190
191 @Override
192 public boolean areContactsWritable() {
193 return true;
194 }
195
196 @Override
197 public String getViewContactNotifyServiceClassName() {
198 return "com.google.android.syncadapters.contacts." +
199 "SyncHighResPhotoIntentService";
200 }
201
202 @Override
203 public String getViewContactNotifyServicePackageName() {
204 return "com.google.android.syncadapters.contacts";
205 }
Chiao Chenge88fcd32012-11-13 18:38:05 -0800206}