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