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.model; 18 19 import com.android.contacts.R; 20 import com.android.contacts.util.DateUtils; 21 import com.google.android.collect.Lists; 22 23 import android.content.ContentValues; 24 import android.content.Context; 25 import android.provider.ContactsContract.CommonDataKinds.Email; 26 import android.provider.ContactsContract.CommonDataKinds.Event; 27 import android.provider.ContactsContract.CommonDataKinds.Phone; 28 import android.provider.ContactsContract.CommonDataKinds.Relation; 29 import android.view.inputmethod.EditorInfo; 30 31 import java.util.List; 32 33 public class GoogleAccountType extends BaseAccountType { 34 public static final String ACCOUNT_TYPE = "com.google"; 35 protected static final int FLAGS_RELATION = EditorInfo.TYPE_CLASS_TEXT 36 | EditorInfo.TYPE_TEXT_FLAG_CAP_WORDS | EditorInfo.TYPE_TEXT_VARIATION_PERSON_NAME; 37 38 private static final List<String> mExtensionPackages = 39 Lists.newArrayList("com.google.android.apps.plus"); 40 41 public GoogleAccountType(Context context, String resPackageName) { 42 this.accountType = ACCOUNT_TYPE; 43 this.resPackageName = null; 44 this.summaryResPackageName = resPackageName; 45 46 addDataKindStructuredName(context); 47 addDataKindDisplayName(context); 48 addDataKindPhoneticName(context); 49 addDataKindNickname(context); 50 addDataKindPhone(context); 51 addDataKindEmail(context); 52 addDataKindStructuredPostal(context); 53 addDataKindIm(context); 54 addDataKindOrganization(context); 55 addDataKindPhoto(context); 56 addDataKindNote(context); 57 addDataKindWebsite(context); 58 addDataKindSipAddress(context); 59 addDataKindGroupMembership(context); 60 addDataKindRelation(context); 61 addDataKindEvent(context); 62 } 63 64 @Override 65 public List<String> getExtensionPackageNames() { 66 return mExtensionPackages; 67 } 68 69 @Override 70 protected DataKind addDataKindPhone(Context context) { 71 final DataKind kind = super.addDataKindPhone(context); 72 73 kind.typeColumn = Phone.TYPE; 74 kind.typeList = Lists.newArrayList(); 75 kind.typeList.add(buildPhoneType(Phone.TYPE_MOBILE)); 76 kind.typeList.add(buildPhoneType(Phone.TYPE_WORK)); 77 kind.typeList.add(buildPhoneType(Phone.TYPE_HOME)); 78 kind.typeList.add(buildPhoneType(Phone.TYPE_MAIN)); 79 kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_WORK).setSecondary(true)); 80 kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_HOME).setSecondary(true)); 81 kind.typeList.add(buildPhoneType(Phone.TYPE_PAGER).setSecondary(true)); 82 kind.typeList.add(buildPhoneType(Phone.TYPE_OTHER)); 83 kind.typeList.add(buildPhoneType(Phone.TYPE_CUSTOM).setSecondary(true) 84 .setCustomColumn(Phone.LABEL)); 85 86 kind.fieldList = Lists.newArrayList(); 87 kind.fieldList.add(new EditField(Phone.NUMBER, R.string.phoneLabelsGroup, FLAGS_PHONE)); 88 89 return kind; 90 } 91 92 @Override 93 protected DataKind addDataKindEmail(Context context) { 94 final DataKind kind = super.addDataKindEmail(context); 95 96 kind.typeColumn = Email.TYPE; 97 kind.typeList = Lists.newArrayList(); 98 kind.typeList.add(buildEmailType(Email.TYPE_HOME)); 99 kind.typeList.add(buildEmailType(Email.TYPE_WORK)); 100 kind.typeList.add(buildEmailType(Email.TYPE_OTHER)); 101 kind.typeList.add(buildEmailType(Email.TYPE_CUSTOM).setSecondary(true).setCustomColumn( 102 Email.LABEL)); 103 104 kind.fieldList = Lists.newArrayList(); 105 kind.fieldList.add(new EditField(Email.DATA, R.string.emailLabelsGroup, FLAGS_EMAIL)); 106 107 return kind; 108 } 109 110 private DataKind addDataKindRelation(Context context) { 111 DataKind kind = addKind(new DataKind(Relation.CONTENT_ITEM_TYPE, 112 R.string.relationLabelsGroup, 160, true, R.layout.text_fields_editor_view)); 113 kind.actionHeader = new RelationActionInflater(); 114 kind.actionBody = new SimpleInflater(Relation.NAME); 115 116 kind.typeColumn = Relation.TYPE; 117 kind.typeList = Lists.newArrayList(); 118 kind.typeList.add(buildRelationType(Relation.TYPE_ASSISTANT)); 119 kind.typeList.add(buildRelationType(Relation.TYPE_BROTHER)); 120 kind.typeList.add(buildRelationType(Relation.TYPE_CHILD)); 121 kind.typeList.add(buildRelationType(Relation.TYPE_DOMESTIC_PARTNER)); 122 kind.typeList.add(buildRelationType(Relation.TYPE_FATHER)); 123 kind.typeList.add(buildRelationType(Relation.TYPE_FRIEND)); 124 kind.typeList.add(buildRelationType(Relation.TYPE_MANAGER)); 125 kind.typeList.add(buildRelationType(Relation.TYPE_MOTHER)); 126 kind.typeList.add(buildRelationType(Relation.TYPE_PARENT)); 127 kind.typeList.add(buildRelationType(Relation.TYPE_PARTNER)); 128 kind.typeList.add(buildRelationType(Relation.TYPE_REFERRED_BY)); 129 kind.typeList.add(buildRelationType(Relation.TYPE_RELATIVE)); 130 kind.typeList.add(buildRelationType(Relation.TYPE_SISTER)); 131 kind.typeList.add(buildRelationType(Relation.TYPE_SPOUSE)); 132 kind.typeList.add(buildRelationType(Relation.TYPE_CUSTOM).setSecondary(true) 133 .setCustomColumn(Relation.LABEL)); 134 135 kind.defaultValues = new ContentValues(); 136 kind.defaultValues.put(Relation.TYPE, Relation.TYPE_SPOUSE); 137 138 kind.fieldList = Lists.newArrayList(); 139 kind.fieldList.add(new EditField(Relation.DATA, R.string.relationLabelsGroup, 140 FLAGS_RELATION)); 141 142 return kind; 143 } 144 145 private DataKind addDataKindEvent(Context context) { 146 DataKind kind = addKind(new DataKind(Event.CONTENT_ITEM_TYPE, 147 R.string.eventLabelsGroup, 150, true, R.layout.event_field_editor_view)); 148 kind.actionHeader = new EventActionInflater(); 149 kind.actionBody = new SimpleInflater(Event.START_DATE); 150 151 kind.typeColumn = Event.TYPE; 152 kind.typeList = Lists.newArrayList(); 153 kind.dateFormatWithoutYear = DateUtils.NO_YEAR_DATE_FORMAT; 154 kind.dateFormatWithYear = DateUtils.FULL_DATE_FORMAT; 155 kind.typeList.add(buildEventType(Event.TYPE_BIRTHDAY, true).setSpecificMax(1)); 156 kind.typeList.add(buildEventType(Event.TYPE_ANNIVERSARY, false)); 157 kind.typeList.add(buildEventType(Event.TYPE_OTHER, false)); 158 kind.typeList.add(buildEventType(Event.TYPE_CUSTOM, false).setSecondary(true) 159 .setCustomColumn(Event.LABEL)); 160 161 kind.defaultValues = new ContentValues(); 162 kind.defaultValues.put(Event.TYPE, Event.TYPE_BIRTHDAY); 163 164 kind.fieldList = Lists.newArrayList(); 165 kind.fieldList.add(new EditField(Event.DATA, R.string.eventLabelsGroup, FLAGS_EVENT)); 166 167 return kind; 168 } 169 170 @Override 171 public int getHeaderColor(Context context) { 172 return 0xff89c2c2; 173 } 174 175 @Override 176 public int getSideBarColor(Context context) { 177 return 0xff5bb4b4; 178 } 179 180 @Override 181 public boolean isGroupMembershipEditable() { 182 return true; 183 } 184 185 @Override 186 public boolean areContactsWritable() { 187 return true; 188 } 189 } 190