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