1/*
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
17package com.android.contacts.common.model.account;
18
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;
25import android.util.Log;
26
27import com.android.contacts.common.R;
28import com.android.contacts.common.model.dataitem.DataKind;
29import com.android.contacts.common.util.CommonDateUtils;
30import com.google.common.collect.Lists;
31
32import java.util.List;
33
34public class GoogleAccountType extends BaseAccountType {
35    private static final String TAG = "GoogleAccountType";
36
37    public static final String ACCOUNT_TYPE = "com.google";
38
39    private static final List<String> mExtensionPackages =
40            Lists.newArrayList("com.google.android.apps.plus");
41
42    public GoogleAccountType(Context context, String authenticatorPackageName) {
43        this.accountType = ACCOUNT_TYPE;
44        this.resourcePackageName = null;
45        this.syncAdapterPackageName = authenticatorPackageName;
46
47        try {
48            addDataKindStructuredName(context);
49            addDataKindDisplayName(context);
50            addDataKindPhoneticName(context);
51            addDataKindNickname(context);
52            addDataKindPhone(context);
53            addDataKindEmail(context);
54            addDataKindStructuredPostal(context);
55            addDataKindIm(context);
56            addDataKindOrganization(context);
57            addDataKindPhoto(context);
58            addDataKindNote(context);
59            addDataKindWebsite(context);
60            addDataKindSipAddress(context);
61            addDataKindGroupMembership(context);
62            addDataKindRelation(context);
63            addDataKindEvent(context);
64
65            mIsInitialized = true;
66        } catch (DefinitionException e) {
67            Log.e(TAG, "Problem building account type", e);
68        }
69    }
70
71    @Override
72    public List<String> getExtensionPackageNames() {
73        return mExtensionPackages;
74    }
75
76    @Override
77    protected DataKind addDataKindPhone(Context context) throws DefinitionException {
78        final DataKind kind = super.addDataKindPhone(context);
79
80        kind.typeColumn = Phone.TYPE;
81        kind.typeList = Lists.newArrayList();
82        kind.typeList.add(buildPhoneType(Phone.TYPE_MOBILE));
83        kind.typeList.add(buildPhoneType(Phone.TYPE_WORK));
84        kind.typeList.add(buildPhoneType(Phone.TYPE_HOME));
85        kind.typeList.add(buildPhoneType(Phone.TYPE_MAIN));
86        kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_WORK).setSecondary(true));
87        kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_HOME).setSecondary(true));
88        kind.typeList.add(buildPhoneType(Phone.TYPE_PAGER).setSecondary(true));
89        kind.typeList.add(buildPhoneType(Phone.TYPE_OTHER));
90        kind.typeList.add(buildPhoneType(Phone.TYPE_CUSTOM).setSecondary(true)
91                .setCustomColumn(Phone.LABEL));
92
93        kind.fieldList = Lists.newArrayList();
94        kind.fieldList.add(new EditField(Phone.NUMBER, R.string.phoneLabelsGroup, FLAGS_PHONE));
95
96        return kind;
97    }
98
99    @Override
100    protected DataKind addDataKindEmail(Context context) throws DefinitionException {
101        final DataKind kind = super.addDataKindEmail(context);
102
103        kind.typeColumn = Email.TYPE;
104        kind.typeList = Lists.newArrayList();
105        kind.typeList.add(buildEmailType(Email.TYPE_HOME));
106        kind.typeList.add(buildEmailType(Email.TYPE_WORK));
107        kind.typeList.add(buildEmailType(Email.TYPE_OTHER));
108        kind.typeList.add(buildEmailType(Email.TYPE_CUSTOM).setSecondary(true).setCustomColumn(
109                Email.LABEL));
110
111        kind.fieldList = Lists.newArrayList();
112        kind.fieldList.add(new EditField(Email.DATA, R.string.emailLabelsGroup, FLAGS_EMAIL));
113
114        return kind;
115    }
116
117    private DataKind addDataKindRelation(Context context) throws DefinitionException {
118        DataKind kind = addKind(new DataKind(Relation.CONTENT_ITEM_TYPE,
119                R.string.relationLabelsGroup, 160, true));
120        kind.actionHeader = new RelationActionInflater();
121        kind.actionBody = new SimpleInflater(Relation.NAME);
122
123        kind.typeColumn = Relation.TYPE;
124        kind.typeList = Lists.newArrayList();
125        kind.typeList.add(buildRelationType(Relation.TYPE_ASSISTANT));
126        kind.typeList.add(buildRelationType(Relation.TYPE_BROTHER));
127        kind.typeList.add(buildRelationType(Relation.TYPE_CHILD));
128        kind.typeList.add(buildRelationType(Relation.TYPE_DOMESTIC_PARTNER));
129        kind.typeList.add(buildRelationType(Relation.TYPE_FATHER));
130        kind.typeList.add(buildRelationType(Relation.TYPE_FRIEND));
131        kind.typeList.add(buildRelationType(Relation.TYPE_MANAGER));
132        kind.typeList.add(buildRelationType(Relation.TYPE_MOTHER));
133        kind.typeList.add(buildRelationType(Relation.TYPE_PARENT));
134        kind.typeList.add(buildRelationType(Relation.TYPE_PARTNER));
135        kind.typeList.add(buildRelationType(Relation.TYPE_REFERRED_BY));
136        kind.typeList.add(buildRelationType(Relation.TYPE_RELATIVE));
137        kind.typeList.add(buildRelationType(Relation.TYPE_SISTER));
138        kind.typeList.add(buildRelationType(Relation.TYPE_SPOUSE));
139        kind.typeList.add(buildRelationType(Relation.TYPE_CUSTOM).setSecondary(true)
140                .setCustomColumn(Relation.LABEL));
141
142        kind.defaultValues = new ContentValues();
143        kind.defaultValues.put(Relation.TYPE, Relation.TYPE_SPOUSE);
144
145        kind.fieldList = Lists.newArrayList();
146        kind.fieldList.add(new EditField(Relation.DATA, R.string.relationLabelsGroup,
147                FLAGS_RELATION));
148
149        return kind;
150    }
151
152    private DataKind addDataKindEvent(Context context) throws DefinitionException {
153        DataKind kind = addKind(new DataKind(Event.CONTENT_ITEM_TYPE,
154                    R.string.eventLabelsGroup, 150, true));
155        kind.actionHeader = new EventActionInflater();
156        kind.actionBody = new SimpleInflater(Event.START_DATE);
157
158        kind.typeColumn = Event.TYPE;
159        kind.typeList = Lists.newArrayList();
160        kind.dateFormatWithoutYear = CommonDateUtils.NO_YEAR_DATE_FORMAT;
161        kind.dateFormatWithYear = CommonDateUtils.FULL_DATE_FORMAT;
162        kind.typeList.add(buildEventType(Event.TYPE_BIRTHDAY, true).setSpecificMax(1));
163        kind.typeList.add(buildEventType(Event.TYPE_ANNIVERSARY, false));
164        kind.typeList.add(buildEventType(Event.TYPE_OTHER, false));
165        kind.typeList.add(buildEventType(Event.TYPE_CUSTOM, false).setSecondary(true)
166                .setCustomColumn(Event.LABEL));
167
168        kind.defaultValues = new ContentValues();
169        kind.defaultValues.put(Event.TYPE, Event.TYPE_BIRTHDAY);
170
171        kind.fieldList = Lists.newArrayList();
172        kind.fieldList.add(new EditField(Event.DATA, R.string.eventLabelsGroup, FLAGS_EVENT));
173
174        return kind;
175    }
176
177    @Override
178    public boolean isGroupMembershipEditable() {
179        return true;
180    }
181
182    @Override
183    public boolean areContactsWritable() {
184        return true;
185    }
186
187    @Override
188    public String getViewContactNotifyServiceClassName() {
189        return "com.google.android.syncadapters.contacts." +
190                "SyncHighResPhotoIntentService";
191    }
192
193    @Override
194    public String getViewContactNotifyServicePackageName() {
195        return "com.google.android.syncadapters.contacts";
196    }
197}
198