Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 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 | |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 17 | package com.android.contacts.model.account; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 18 | |
| 19 | import android.content.ContentValues; |
| 20 | import android.content.Context; |
| 21 | import android.provider.ContactsContract.CommonDataKinds.Email; |
| 22 | import android.provider.ContactsContract.CommonDataKinds.Event; |
| 23 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 24 | import android.provider.ContactsContract.CommonDataKinds.Relation; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 25 | |
Arthur Wang | 3f6a244 | 2016-12-05 14:51:59 -0800 | [diff] [blame] | 26 | import com.android.contacts.R; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 27 | import com.android.contacts.model.dataitem.DataKind; |
| 28 | import com.android.contacts.util.CommonDateUtils; |
Walter Jang | 3a0b483 | 2016-10-12 11:02:54 -0700 | [diff] [blame] | 29 | import com.android.contactsbind.FeedbackHelper; |
| 30 | |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 31 | import com.google.common.collect.Lists; |
| 32 | |
| 33 | import java.util.List; |
| 34 | |
| 35 | public class GoogleAccountType extends BaseAccountType { |
| 36 | private static final String TAG = "GoogleAccountType"; |
| 37 | |
Yorke Lee | 0c2d073 | 2014-06-20 16:16:19 -0700 | [diff] [blame] | 38 | /** |
| 39 | * The package name that we should load contacts.xml from and rely on to handle |
Brian Attwell | e5ac8b1 | 2014-12-10 14:40:40 -0800 | [diff] [blame] | 40 | * G+ account actions. Even though this points to gms, in some cases gms will still hand |
| 41 | * off responsibility to the G+ app. |
Yorke Lee | 0c2d073 | 2014-06-20 16:16:19 -0700 | [diff] [blame] | 42 | */ |
Brian Attwell | e5ac8b1 | 2014-12-10 14:40:40 -0800 | [diff] [blame] | 43 | public static final String PLUS_EXTENSION_PACKAGE_NAME = "com.google.android.gms"; |
Yorke Lee | 0c2d073 | 2014-06-20 16:16:19 -0700 | [diff] [blame] | 44 | |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 45 | public static final String ACCOUNT_TYPE = "com.google"; |
| 46 | |
| 47 | private static final List<String> mExtensionPackages = |
Yorke Lee | 0c2d073 | 2014-06-20 16:16:19 -0700 | [diff] [blame] | 48 | Lists.newArrayList(PLUS_EXTENSION_PACKAGE_NAME); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 49 | |
| 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 Mai | 7a6daea | 2016-10-10 15:41:48 -0700 | [diff] [blame] | 57 | addDataKindName(context); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 58 | 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); |
yaolu | 1bd8826 | 2016-08-18 10:29:12 -0700 | [diff] [blame] | 72 | addDataKindCustomField(context); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 73 | |
| 74 | mIsInitialized = true; |
| 75 | } catch (DefinitionException e) { |
Walter Jang | 3a0b483 | 2016-10-12 11:02:54 -0700 | [diff] [blame] | 76 | FeedbackHelper.sendFeedback(context, TAG, "Failed to build google account type", e); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 77 | } |
| 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 Attwell | 913e18a | 2014-10-30 11:16:05 -0700 | [diff] [blame] | 128 | R.string.relationLabelsGroup, Weight.RELATIONSHIP, true)); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 129 | 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 Attwell | 913e18a | 2014-10-30 11:16:05 -0700 | [diff] [blame] | 163 | R.string.eventLabelsGroup, Weight.EVENT, true)); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 164 | 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 Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 206 | } |