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.Im; |
| 24 | import android.provider.ContactsContract.CommonDataKinds.Nickname; |
| 25 | import android.provider.ContactsContract.CommonDataKinds.Note; |
| 26 | import android.provider.ContactsContract.CommonDataKinds.Organization; |
| 27 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 28 | import android.provider.ContactsContract.CommonDataKinds.Photo; |
| 29 | import android.provider.ContactsContract.CommonDataKinds.StructuredName; |
| 30 | import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; |
| 31 | import android.provider.ContactsContract.CommonDataKinds.Website; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 32 | |
Arthur Wang | 3f6a244 | 2016-12-05 14:51:59 -0800 | [diff] [blame] | 33 | import com.android.contacts.R; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 34 | import com.android.contacts.model.dataitem.DataKind; |
| 35 | import com.android.contacts.util.CommonDateUtils; |
Walter Jang | 3a0b483 | 2016-10-12 11:02:54 -0700 | [diff] [blame] | 36 | import com.android.contactsbind.FeedbackHelper; |
| 37 | |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 38 | import com.google.common.collect.Lists; |
| 39 | |
| 40 | import java.util.Locale; |
| 41 | |
| 42 | public class ExchangeAccountType extends BaseAccountType { |
| 43 | private static final String TAG = "ExchangeAccountType"; |
| 44 | |
Brian Attwell | 419fed1 | 2014-09-04 14:58:09 -0700 | [diff] [blame] | 45 | private static final String ACCOUNT_TYPE_AOSP = "com.android.exchange"; |
| 46 | private static final String ACCOUNT_TYPE_GOOGLE_1 = "com.google.android.exchange"; |
| 47 | private static final String ACCOUNT_TYPE_GOOGLE_2 = "com.google.android.gm.exchange"; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 48 | |
| 49 | public ExchangeAccountType(Context context, String authenticatorPackageName, String type) { |
| 50 | this.accountType = type; |
| 51 | this.resourcePackageName = null; |
| 52 | this.syncAdapterPackageName = authenticatorPackageName; |
| 53 | |
| 54 | try { |
| 55 | addDataKindStructuredName(context); |
Gary Mai | 7a6daea | 2016-10-10 15:41:48 -0700 | [diff] [blame] | 56 | addDataKindName(context); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 57 | addDataKindPhoneticName(context); |
| 58 | addDataKindNickname(context); |
| 59 | addDataKindPhone(context); |
| 60 | addDataKindEmail(context); |
| 61 | addDataKindStructuredPostal(context); |
| 62 | addDataKindIm(context); |
| 63 | addDataKindOrganization(context); |
| 64 | addDataKindPhoto(context); |
| 65 | addDataKindNote(context); |
| 66 | addDataKindEvent(context); |
| 67 | addDataKindWebsite(context); |
| 68 | addDataKindGroupMembership(context); |
| 69 | |
| 70 | mIsInitialized = true; |
| 71 | } catch (DefinitionException e) { |
Walter Jang | 3a0b483 | 2016-10-12 11:02:54 -0700 | [diff] [blame] | 72 | // TODO: Change this to fail fast if there are no feedback reports |
| 73 | FeedbackHelper.sendFeedback(context, TAG, "Failed to build exchange account type", e); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | public static boolean isExchangeType(String type) { |
Brian Attwell | 419fed1 | 2014-09-04 14:58:09 -0700 | [diff] [blame] | 78 | return ACCOUNT_TYPE_AOSP.equals(type) || ACCOUNT_TYPE_GOOGLE_1.equals(type) |
| 79 | || ACCOUNT_TYPE_GOOGLE_2.equals(type); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | protected DataKind addDataKindStructuredName(Context context) throws DefinitionException { |
| 84 | DataKind kind = addKind(new DataKind(StructuredName.CONTENT_ITEM_TYPE, |
Brian Attwell | 913e18a | 2014-10-30 11:16:05 -0700 | [diff] [blame] | 85 | R.string.nameLabelsGroup, Weight.NONE, true)); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 86 | kind.actionHeader = new SimpleInflater(R.string.nameLabelsGroup); |
| 87 | kind.actionBody = new SimpleInflater(Nickname.NAME); |
| 88 | |
| 89 | kind.typeOverallMax = 1; |
| 90 | |
| 91 | kind.fieldList = Lists.newArrayList(); |
| 92 | kind.fieldList.add(new EditField(StructuredName.PREFIX, R.string.name_prefix, |
| 93 | FLAGS_PERSON_NAME).setOptional(true)); |
| 94 | kind.fieldList.add(new EditField(StructuredName.FAMILY_NAME, |
| 95 | R.string.name_family, FLAGS_PERSON_NAME)); |
| 96 | kind.fieldList.add(new EditField(StructuredName.MIDDLE_NAME, |
| 97 | R.string.name_middle, FLAGS_PERSON_NAME)); |
| 98 | kind.fieldList.add(new EditField(StructuredName.GIVEN_NAME, |
| 99 | R.string.name_given, FLAGS_PERSON_NAME)); |
| 100 | kind.fieldList.add(new EditField(StructuredName.SUFFIX, |
| 101 | R.string.name_suffix, FLAGS_PERSON_NAME)); |
| 102 | |
| 103 | kind.fieldList.add(new EditField(StructuredName.PHONETIC_FAMILY_NAME, |
| 104 | R.string.name_phonetic_family, FLAGS_PHONETIC)); |
| 105 | kind.fieldList.add(new EditField(StructuredName.PHONETIC_GIVEN_NAME, |
| 106 | R.string.name_phonetic_given, FLAGS_PHONETIC)); |
| 107 | |
| 108 | return kind; |
| 109 | } |
| 110 | |
| 111 | @Override |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 112 | protected DataKind addDataKindPhoneticName(Context context) throws DefinitionException { |
| 113 | DataKind kind = addKind(new DataKind(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME, |
Brian Attwell | 913e18a | 2014-10-30 11:16:05 -0700 | [diff] [blame] | 114 | R.string.name_phonetic, Weight.NONE, true)); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 115 | kind.actionHeader = new SimpleInflater(R.string.nameLabelsGroup); |
| 116 | kind.actionBody = new SimpleInflater(Nickname.NAME); |
| 117 | |
| 118 | kind.typeOverallMax = 1; |
| 119 | |
| 120 | kind.fieldList = Lists.newArrayList(); |
| 121 | kind.fieldList.add(new EditField(StructuredName.PHONETIC_FAMILY_NAME, |
| 122 | R.string.name_phonetic_family, FLAGS_PHONETIC)); |
| 123 | kind.fieldList.add(new EditField(StructuredName.PHONETIC_GIVEN_NAME, |
| 124 | R.string.name_phonetic_given, FLAGS_PHONETIC)); |
| 125 | |
| 126 | return kind; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | protected DataKind addDataKindNickname(Context context) throws DefinitionException { |
| 131 | final DataKind kind = super.addDataKindNickname(context); |
| 132 | |
| 133 | kind.typeOverallMax = 1; |
| 134 | |
| 135 | kind.fieldList = Lists.newArrayList(); |
| 136 | kind.fieldList.add(new EditField(Nickname.NAME, R.string.nicknameLabelsGroup, |
| 137 | FLAGS_PERSON_NAME)); |
| 138 | |
| 139 | return kind; |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | protected DataKind addDataKindPhone(Context context) throws DefinitionException { |
| 144 | final DataKind kind = super.addDataKindPhone(context); |
| 145 | |
| 146 | kind.typeColumn = Phone.TYPE; |
| 147 | kind.typeList = Lists.newArrayList(); |
| 148 | kind.typeList.add(buildPhoneType(Phone.TYPE_MOBILE).setSpecificMax(1)); |
| 149 | kind.typeList.add(buildPhoneType(Phone.TYPE_HOME).setSpecificMax(2)); |
| 150 | kind.typeList.add(buildPhoneType(Phone.TYPE_WORK).setSpecificMax(2)); |
| 151 | kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_WORK).setSecondary(true) |
| 152 | .setSpecificMax(1)); |
| 153 | kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_HOME).setSecondary(true) |
| 154 | .setSpecificMax(1)); |
| 155 | kind.typeList |
| 156 | .add(buildPhoneType(Phone.TYPE_PAGER).setSecondary(true).setSpecificMax(1)); |
| 157 | kind.typeList.add(buildPhoneType(Phone.TYPE_CAR).setSecondary(true).setSpecificMax(1)); |
| 158 | kind.typeList.add(buildPhoneType(Phone.TYPE_COMPANY_MAIN).setSecondary(true) |
| 159 | .setSpecificMax(1)); |
| 160 | kind.typeList.add(buildPhoneType(Phone.TYPE_MMS).setSecondary(true).setSpecificMax(1)); |
| 161 | kind.typeList |
| 162 | .add(buildPhoneType(Phone.TYPE_RADIO).setSecondary(true).setSpecificMax(1)); |
| 163 | kind.typeList.add(buildPhoneType(Phone.TYPE_ASSISTANT).setSecondary(true) |
| 164 | .setSpecificMax(1)); |
| 165 | |
| 166 | kind.fieldList = Lists.newArrayList(); |
| 167 | kind.fieldList.add(new EditField(Phone.NUMBER, R.string.phoneLabelsGroup, FLAGS_PHONE)); |
| 168 | |
| 169 | return kind; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | protected DataKind addDataKindEmail(Context context) throws DefinitionException { |
| 174 | final DataKind kind = super.addDataKindEmail(context); |
| 175 | |
| 176 | kind.typeOverallMax = 3; |
| 177 | |
| 178 | kind.fieldList = Lists.newArrayList(); |
| 179 | kind.fieldList.add(new EditField(Email.DATA, R.string.emailLabelsGroup, FLAGS_EMAIL)); |
| 180 | |
| 181 | return kind; |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | protected DataKind addDataKindStructuredPostal(Context context) throws DefinitionException { |
| 186 | final DataKind kind = super.addDataKindStructuredPostal(context); |
| 187 | |
| 188 | final boolean useJapaneseOrder = |
| 189 | Locale.JAPANESE.getLanguage().equals(Locale.getDefault().getLanguage()); |
| 190 | kind.typeColumn = StructuredPostal.TYPE; |
| 191 | kind.typeList = Lists.newArrayList(); |
| 192 | kind.typeList.add(buildPostalType(StructuredPostal.TYPE_WORK).setSpecificMax(1)); |
| 193 | kind.typeList.add(buildPostalType(StructuredPostal.TYPE_HOME).setSpecificMax(1)); |
| 194 | kind.typeList.add(buildPostalType(StructuredPostal.TYPE_OTHER).setSpecificMax(1)); |
| 195 | |
| 196 | kind.fieldList = Lists.newArrayList(); |
| 197 | if (useJapaneseOrder) { |
| 198 | kind.fieldList.add(new EditField(StructuredPostal.COUNTRY, |
| 199 | R.string.postal_country, FLAGS_POSTAL).setOptional(true)); |
| 200 | kind.fieldList.add(new EditField(StructuredPostal.POSTCODE, |
| 201 | R.string.postal_postcode, FLAGS_POSTAL)); |
| 202 | kind.fieldList.add(new EditField(StructuredPostal.REGION, |
| 203 | R.string.postal_region, FLAGS_POSTAL)); |
| 204 | kind.fieldList.add(new EditField(StructuredPostal.CITY, |
| 205 | R.string.postal_city,FLAGS_POSTAL)); |
| 206 | kind.fieldList.add(new EditField(StructuredPostal.STREET, |
| 207 | R.string.postal_street, FLAGS_POSTAL)); |
| 208 | } else { |
| 209 | kind.fieldList.add(new EditField(StructuredPostal.STREET, |
| 210 | R.string.postal_street, FLAGS_POSTAL)); |
| 211 | kind.fieldList.add(new EditField(StructuredPostal.CITY, |
| 212 | R.string.postal_city,FLAGS_POSTAL)); |
| 213 | kind.fieldList.add(new EditField(StructuredPostal.REGION, |
| 214 | R.string.postal_region, FLAGS_POSTAL)); |
| 215 | kind.fieldList.add(new EditField(StructuredPostal.POSTCODE, |
| 216 | R.string.postal_postcode, FLAGS_POSTAL)); |
| 217 | kind.fieldList.add(new EditField(StructuredPostal.COUNTRY, |
| 218 | R.string.postal_country, FLAGS_POSTAL).setOptional(true)); |
| 219 | } |
| 220 | |
| 221 | return kind; |
| 222 | } |
| 223 | |
| 224 | @Override |
| 225 | protected DataKind addDataKindIm(Context context) throws DefinitionException { |
| 226 | final DataKind kind = super.addDataKindIm(context); |
| 227 | |
| 228 | // Types are not supported for IM. There can be 3 IMs, but OWA only shows only the first |
| 229 | kind.typeOverallMax = 3; |
| 230 | |
| 231 | kind.defaultValues = new ContentValues(); |
| 232 | kind.defaultValues.put(Im.TYPE, Im.TYPE_OTHER); |
| 233 | |
| 234 | kind.fieldList = Lists.newArrayList(); |
| 235 | kind.fieldList.add(new EditField(Im.DATA, R.string.imLabelsGroup, FLAGS_EMAIL)); |
| 236 | |
| 237 | return kind; |
| 238 | } |
| 239 | |
| 240 | @Override |
| 241 | protected DataKind addDataKindOrganization(Context context) throws DefinitionException { |
| 242 | final DataKind kind = super.addDataKindOrganization(context); |
| 243 | |
| 244 | kind.typeOverallMax = 1; |
| 245 | |
| 246 | kind.fieldList = Lists.newArrayList(); |
| 247 | kind.fieldList.add(new EditField(Organization.COMPANY, R.string.ghostData_company, |
| 248 | FLAGS_GENERIC_NAME)); |
| 249 | kind.fieldList.add(new EditField(Organization.TITLE, R.string.ghostData_title, |
| 250 | FLAGS_GENERIC_NAME)); |
| 251 | |
| 252 | return kind; |
| 253 | } |
| 254 | |
| 255 | @Override |
| 256 | protected DataKind addDataKindPhoto(Context context) throws DefinitionException { |
| 257 | final DataKind kind = super.addDataKindPhoto(context); |
| 258 | |
| 259 | kind.typeOverallMax = 1; |
| 260 | |
| 261 | kind.fieldList = Lists.newArrayList(); |
| 262 | kind.fieldList.add(new EditField(Photo.PHOTO, -1, -1)); |
| 263 | |
| 264 | return kind; |
| 265 | } |
| 266 | |
| 267 | @Override |
| 268 | protected DataKind addDataKindNote(Context context) throws DefinitionException { |
| 269 | final DataKind kind = super.addDataKindNote(context); |
| 270 | |
| 271 | kind.fieldList = Lists.newArrayList(); |
| 272 | kind.fieldList.add(new EditField(Note.NOTE, R.string.label_notes, FLAGS_NOTE)); |
| 273 | |
| 274 | return kind; |
| 275 | } |
| 276 | |
| 277 | protected DataKind addDataKindEvent(Context context) throws DefinitionException { |
Chiao Cheng | 4eff3d8 | 2012-12-06 12:15:08 -0800 | [diff] [blame] | 278 | DataKind kind = addKind(new DataKind(Event.CONTENT_ITEM_TYPE, R.string.eventLabelsGroup, |
Brian Attwell | 913e18a | 2014-10-30 11:16:05 -0700 | [diff] [blame] | 279 | Weight.EVENT, true)); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 280 | kind.actionHeader = new EventActionInflater(); |
| 281 | kind.actionBody = new SimpleInflater(Event.START_DATE); |
| 282 | |
| 283 | kind.typeOverallMax = 1; |
| 284 | |
| 285 | kind.typeColumn = Event.TYPE; |
| 286 | kind.typeList = Lists.newArrayList(); |
| 287 | kind.typeList.add(buildEventType(Event.TYPE_BIRTHDAY, false).setSpecificMax(1)); |
| 288 | |
| 289 | kind.dateFormatWithYear = CommonDateUtils.DATE_AND_TIME_FORMAT; |
| 290 | |
| 291 | kind.fieldList = Lists.newArrayList(); |
| 292 | kind.fieldList.add(new EditField(Event.DATA, R.string.eventLabelsGroup, FLAGS_EVENT)); |
| 293 | |
| 294 | return kind; |
| 295 | } |
| 296 | |
| 297 | @Override |
| 298 | protected DataKind addDataKindWebsite(Context context) throws DefinitionException { |
| 299 | final DataKind kind = super.addDataKindWebsite(context); |
| 300 | |
| 301 | kind.typeOverallMax = 1; |
| 302 | |
| 303 | kind.fieldList = Lists.newArrayList(); |
| 304 | kind.fieldList.add(new EditField(Website.URL, R.string.websiteLabelsGroup, FLAGS_WEBSITE)); |
| 305 | |
| 306 | return kind; |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public boolean isGroupMembershipEditable() { |
| 311 | return true; |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public boolean areContactsWritable() { |
| 316 | return true; |
| 317 | } |
| 318 | } |