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