Home | History | Annotate | Download | only in model
      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.loaderapp.model;
     18 
     19 import com.android.loaderapp.R;
     20 import com.google.android.collect.Lists;
     21 
     22 import android.content.ContentValues;
     23 import android.content.Context;
     24 import android.provider.ContactsContract.CommonDataKinds.Email;
     25 import android.provider.ContactsContract.CommonDataKinds.Im;
     26 import android.provider.ContactsContract.CommonDataKinds.Nickname;
     27 import android.provider.ContactsContract.CommonDataKinds.Note;
     28 import android.provider.ContactsContract.CommonDataKinds.Organization;
     29 import android.provider.ContactsContract.CommonDataKinds.Phone;
     30 import android.provider.ContactsContract.CommonDataKinds.Photo;
     31 import android.provider.ContactsContract.CommonDataKinds.StructuredName;
     32 import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
     33 import android.provider.ContactsContract.CommonDataKinds.Website;
     34 
     35 import java.util.Locale;
     36 
     37 public class ExchangeSource extends FallbackSource {
     38 
     39     public static final String ACCOUNT_TYPE = "com.android.exchange";
     40 
     41     public ExchangeSource(String resPackageName) {
     42         this.accountType = ACCOUNT_TYPE;
     43         this.resPackageName = null;
     44         this.summaryResPackageName = resPackageName;
     45     }
     46 
     47     @Override
     48     protected void inflate(Context context, int inflateLevel) {
     49 
     50         inflateStructuredName(context, inflateLevel);
     51         inflateNickname(context, inflateLevel);
     52         inflatePhone(context, inflateLevel);
     53         inflateEmail(context, inflateLevel);
     54         inflateStructuredPostal(context, inflateLevel);
     55         inflateIm(context, inflateLevel);
     56         inflateOrganization(context, inflateLevel);
     57         inflatePhoto(context, inflateLevel);
     58         inflateNote(context, inflateLevel);
     59         inflateWebsite(context, inflateLevel);
     60 
     61         setInflatedLevel(inflateLevel);
     62     }
     63 
     64     @Override
     65     protected DataKind inflateStructuredName(Context context, int inflateLevel) {
     66         final DataKind kind = super.inflateStructuredName(context, ContactsSource.LEVEL_MIMETYPES);
     67 
     68         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
     69             final boolean useJapaneseOrder =
     70                 Locale.JAPANESE.getLanguage().equals(Locale.getDefault().getLanguage());
     71             kind.typeOverallMax = 1;
     72 
     73             kind.fieldList = Lists.newArrayList();
     74             kind.fieldList.add(new EditField(StructuredName.PREFIX, R.string.name_prefix,
     75                     FLAGS_PERSON_NAME).setOptional(true));
     76             if (useJapaneseOrder) {
     77                 kind.fieldList.add(new EditField(StructuredName.FAMILY_NAME,
     78                         R.string.name_family, FLAGS_PERSON_NAME));
     79                 kind.fieldList.add(new EditField(StructuredName.MIDDLE_NAME,
     80                         R.string.name_middle, FLAGS_PERSON_NAME).setOptional(true));
     81                 kind.fieldList.add(new EditField(StructuredName.GIVEN_NAME,
     82                         R.string.name_given, FLAGS_PERSON_NAME));
     83                 kind.fieldList.add(new EditField(StructuredName.SUFFIX,
     84                         R.string.name_suffix, FLAGS_PERSON_NAME).setOptional(true));
     85                 kind.fieldList.add(new EditField(StructuredName.PHONETIC_FAMILY_NAME,
     86                         R.string.name_phonetic_family, FLAGS_PHONETIC).setOptional(true));
     87                 kind.fieldList.add(new EditField(StructuredName.PHONETIC_GIVEN_NAME,
     88                         R.string.name_phonetic_given, FLAGS_PHONETIC).setOptional(true));
     89             } else {
     90                 kind.fieldList.add(new EditField(StructuredName.GIVEN_NAME,
     91                         R.string.name_given, FLAGS_PERSON_NAME));
     92                 kind.fieldList.add(new EditField(StructuredName.MIDDLE_NAME,
     93                         R.string.name_middle, 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.SUFFIX,
     97                         R.string.name_suffix, FLAGS_PERSON_NAME).setOptional(true));
     98                 kind.fieldList.add(new EditField(StructuredName.PHONETIC_GIVEN_NAME,
     99                         R.string.name_phonetic_given, FLAGS_PHONETIC).setOptional(true));
    100                 kind.fieldList.add(new EditField(StructuredName.PHONETIC_FAMILY_NAME,
    101                         R.string.name_phonetic_family, FLAGS_PHONETIC).setOptional(true));
    102             }
    103         }
    104 
    105         return kind;
    106     }
    107 
    108     @Override
    109     protected DataKind inflateNickname(Context context, int inflateLevel) {
    110         final DataKind kind = super.inflateNickname(context, ContactsSource.LEVEL_MIMETYPES);
    111 
    112         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
    113             kind.isList = false;
    114 
    115             kind.fieldList = Lists.newArrayList();
    116             kind.fieldList.add(new EditField(Nickname.NAME, R.string.nicknameLabelsGroup,
    117                     FLAGS_PERSON_NAME));
    118         }
    119 
    120         return kind;
    121     }
    122 
    123     @Override
    124     protected DataKind inflatePhone(Context context, int inflateLevel) {
    125         final DataKind kind = super.inflatePhone(context, ContactsSource.LEVEL_MIMETYPES);
    126 
    127         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
    128             kind.typeColumn = Phone.TYPE;
    129             kind.typeList = Lists.newArrayList();
    130             kind.typeList.add(buildPhoneType(Phone.TYPE_HOME).setSpecificMax(2));
    131             kind.typeList.add(buildPhoneType(Phone.TYPE_MOBILE).setSpecificMax(1));
    132             kind.typeList.add(buildPhoneType(Phone.TYPE_WORK).setSpecificMax(2));
    133             kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_WORK).setSecondary(true)
    134                     .setSpecificMax(1));
    135             kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_HOME).setSecondary(true)
    136                     .setSpecificMax(1));
    137             kind.typeList
    138                     .add(buildPhoneType(Phone.TYPE_PAGER).setSecondary(true).setSpecificMax(1));
    139             kind.typeList.add(buildPhoneType(Phone.TYPE_CAR).setSecondary(true).setSpecificMax(1));
    140             kind.typeList.add(buildPhoneType(Phone.TYPE_COMPANY_MAIN).setSecondary(true)
    141                     .setSpecificMax(1));
    142             kind.typeList.add(buildPhoneType(Phone.TYPE_MMS).setSecondary(true).setSpecificMax(1));
    143             kind.typeList
    144                     .add(buildPhoneType(Phone.TYPE_RADIO).setSecondary(true).setSpecificMax(1));
    145             kind.typeList.add(buildPhoneType(Phone.TYPE_ASSISTANT).setSecondary(true)
    146                     .setSpecificMax(1).setCustomColumn(Phone.LABEL));
    147 
    148             kind.fieldList = Lists.newArrayList();
    149             kind.fieldList.add(new EditField(Phone.NUMBER, R.string.phoneLabelsGroup, FLAGS_PHONE));
    150         }
    151 
    152         return kind;
    153     }
    154 
    155     @Override
    156     protected DataKind inflateEmail(Context context, int inflateLevel) {
    157         final DataKind kind = super.inflateEmail(context, ContactsSource.LEVEL_MIMETYPES);
    158 
    159         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
    160             kind.typeOverallMax = 3;
    161 
    162             kind.fieldList = Lists.newArrayList();
    163             kind.fieldList.add(new EditField(Email.DATA, R.string.emailLabelsGroup, FLAGS_EMAIL));
    164         }
    165 
    166         return kind;
    167     }
    168 
    169     @Override
    170     protected DataKind inflateStructuredPostal(Context context, int inflateLevel) {
    171         final DataKind kind = super.inflateStructuredPostal(context, ContactsSource.LEVEL_MIMETYPES);
    172 
    173         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
    174             final boolean useJapaneseOrder =
    175                 Locale.JAPANESE.getLanguage().equals(Locale.getDefault().getLanguage());
    176             kind.typeColumn = StructuredPostal.TYPE;
    177             kind.typeList = Lists.newArrayList();
    178             kind.typeList.add(buildPostalType(StructuredPostal.TYPE_WORK).setSpecificMax(1));
    179             kind.typeList.add(buildPostalType(StructuredPostal.TYPE_HOME).setSpecificMax(1));
    180             kind.typeList.add(buildPostalType(StructuredPostal.TYPE_OTHER).setSpecificMax(1));
    181 
    182             kind.fieldList = Lists.newArrayList();
    183             if (useJapaneseOrder) {
    184                 kind.fieldList.add(new EditField(StructuredPostal.COUNTRY,
    185                         R.string.postal_country, FLAGS_POSTAL).setOptional(true));
    186                 kind.fieldList.add(new EditField(StructuredPostal.POSTCODE,
    187                         R.string.postal_postcode, FLAGS_POSTAL));
    188                 kind.fieldList.add(new EditField(StructuredPostal.REGION,
    189                         R.string.postal_region, FLAGS_POSTAL));
    190                 kind.fieldList.add(new EditField(StructuredPostal.CITY,
    191                         R.string.postal_city,FLAGS_POSTAL));
    192                 kind.fieldList.add(new EditField(StructuredPostal.STREET,
    193                         R.string.postal_street, FLAGS_POSTAL));
    194             } else {
    195                 kind.fieldList.add(new EditField(StructuredPostal.STREET,
    196                         R.string.postal_street, FLAGS_POSTAL));
    197                 kind.fieldList.add(new EditField(StructuredPostal.CITY,
    198                         R.string.postal_city,FLAGS_POSTAL));
    199                 kind.fieldList.add(new EditField(StructuredPostal.REGION,
    200                         R.string.postal_region, FLAGS_POSTAL));
    201                 kind.fieldList.add(new EditField(StructuredPostal.POSTCODE,
    202                         R.string.postal_postcode, FLAGS_POSTAL));
    203                 kind.fieldList.add(new EditField(StructuredPostal.COUNTRY,
    204                         R.string.postal_country, FLAGS_POSTAL).setOptional(true));
    205             }
    206         }
    207 
    208         return kind;
    209     }
    210 
    211     @Override
    212     protected DataKind inflateIm(Context context, int inflateLevel) {
    213         final DataKind kind = super.inflateIm(context, ContactsSource.LEVEL_MIMETYPES);
    214 
    215         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
    216             kind.typeOverallMax = 3;
    217 
    218             // NOTE: even though a traditional "type" exists, for editing
    219             // purposes we're using the protocol to pick labels
    220 
    221             kind.defaultValues = new ContentValues();
    222             kind.defaultValues.put(Im.TYPE, Im.TYPE_OTHER);
    223 
    224             kind.typeColumn = Im.PROTOCOL;
    225             kind.typeList = Lists.newArrayList();
    226             kind.typeList.add(buildImType(Im.PROTOCOL_AIM));
    227             kind.typeList.add(buildImType(Im.PROTOCOL_MSN));
    228             kind.typeList.add(buildImType(Im.PROTOCOL_YAHOO));
    229             kind.typeList.add(buildImType(Im.PROTOCOL_SKYPE));
    230             kind.typeList.add(buildImType(Im.PROTOCOL_QQ));
    231             kind.typeList.add(buildImType(Im.PROTOCOL_GOOGLE_TALK));
    232             kind.typeList.add(buildImType(Im.PROTOCOL_ICQ));
    233             kind.typeList.add(buildImType(Im.PROTOCOL_JABBER));
    234             kind.typeList.add(buildImType(Im.PROTOCOL_CUSTOM).setSecondary(true).setCustomColumn(
    235                     Im.CUSTOM_PROTOCOL));
    236 
    237             kind.fieldList = Lists.newArrayList();
    238             kind.fieldList.add(new EditField(Im.DATA, R.string.imLabelsGroup, FLAGS_EMAIL));
    239         }
    240 
    241         return kind;
    242     }
    243 
    244     @Override
    245     protected DataKind inflateOrganization(Context context, int inflateLevel) {
    246         final DataKind kind = super.inflateOrganization(context, ContactsSource.LEVEL_MIMETYPES);
    247 
    248         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
    249             kind.isList = false;
    250             kind.typeColumn = Organization.TYPE;
    251             kind.typeList = Lists.newArrayList();
    252             kind.typeList.add(buildOrgType(Organization.TYPE_WORK).setSpecificMax(1));
    253             kind.typeList.add(buildOrgType(Organization.TYPE_OTHER).setSpecificMax(1));
    254             kind.typeList.add(buildOrgType(Organization.TYPE_CUSTOM).setSecondary(true)
    255                     .setSpecificMax(1));
    256 
    257             kind.fieldList = Lists.newArrayList();
    258             kind.fieldList.add(new EditField(Organization.COMPANY, R.string.ghostData_company,
    259                     FLAGS_GENERIC_NAME));
    260             kind.fieldList.add(new EditField(Organization.TITLE, R.string.ghostData_title,
    261                     FLAGS_GENERIC_NAME));
    262         }
    263 
    264         return kind;
    265     }
    266 
    267     @Override
    268     protected DataKind inflatePhoto(Context context, int inflateLevel) {
    269         final DataKind kind = super.inflatePhoto(context, ContactsSource.LEVEL_MIMETYPES);
    270 
    271         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
    272             kind.typeOverallMax = 1;
    273 
    274             kind.fieldList = Lists.newArrayList();
    275             kind.fieldList.add(new EditField(Photo.PHOTO, -1, -1));
    276         }
    277 
    278         return kind;
    279     }
    280 
    281     @Override
    282     protected DataKind inflateNote(Context context, int inflateLevel) {
    283         final DataKind kind = super.inflateNote(context, ContactsSource.LEVEL_MIMETYPES);
    284 
    285         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
    286             kind.fieldList = Lists.newArrayList();
    287             kind.fieldList.add(new EditField(Note.NOTE, R.string.label_notes, FLAGS_NOTE));
    288         }
    289 
    290         return kind;
    291     }
    292 
    293     @Override
    294     protected DataKind inflateWebsite(Context context, int inflateLevel) {
    295         final DataKind kind = super.inflateWebsite(context, ContactsSource.LEVEL_MIMETYPES);
    296 
    297         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
    298             kind.isList = false;
    299 
    300             kind.fieldList = Lists.newArrayList();
    301             kind.fieldList.add(new EditField(Website.URL, R.string.websiteLabelsGroup, FLAGS_WEBSITE));
    302         }
    303 
    304         return kind;
    305     }
    306 
    307     @Override
    308     public int getHeaderColor(Context context) {
    309         return 0xffd5ba96;
    310     }
    311 
    312     @Override
    313     public int getSideBarColor(Context context) {
    314         return 0xffb58e59;
    315     }
    316 }
    317