GoogleAccountType.java revision 392ccec3b56e8074a5a028af28106134b39f64bc
1ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey/* 2ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * Copyright (C) 2009 The Android Open Source Project 3ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * 4ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * Licensed under the Apache License, Version 2.0 (the "License"); 5ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * you may not use this file except in compliance with the License. 6ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * You may obtain a copy of the License at 7ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * 8ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * http://www.apache.org/licenses/LICENSE-2.0 9ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * 10ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * Unless required by applicable law or agreed to in writing, software 11ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * distributed under the License is distributed on an "AS IS" BASIS, 12ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * See the License for the specific language governing permissions and 14ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey * limitations under the License. 15ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey */ 16ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 17ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkeypackage com.android.contacts.model; 18ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 19ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkeyimport com.android.contacts.R; 20392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmannimport com.android.contacts.util.DateUtils; 21392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmannimport com.android.contacts.views.editor.EventFieldEditorView; 22ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkeyimport com.google.android.collect.Lists; 23ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 240540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmannimport android.content.ContentValues; 25ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkeyimport android.content.Context; 26ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkeyimport android.provider.ContactsContract.CommonDataKinds.Email; 27392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Event; 28ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkeyimport android.provider.ContactsContract.CommonDataKinds.Phone; 290540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmannimport android.provider.ContactsContract.CommonDataKinds.Relation; 300540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmannimport android.view.inputmethod.EditorInfo; 31ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 3235769b804fbfd5a1fc0b2c36cd0a786d662c4334Daniel Lehmannpublic class GoogleAccountType extends FallbackAccountType { 33386dd954869544581f8825148ac41ed15d465ab2Costin Manolache public static final String ACCOUNT_TYPE = "com.google"; 340540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann protected static final int FLAGS_RELATION = EditorInfo.TYPE_CLASS_TEXT 350540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann | EditorInfo.TYPE_TEXT_FLAG_CAP_WORDS | EditorInfo.TYPE_TEXT_VARIATION_PERSON_NAME; 369f26ce5718f08fa96f2bc0cbdc27831c9942b06aFred Quintana 3735769b804fbfd5a1fc0b2c36cd0a786d662c4334Daniel Lehmann public GoogleAccountType(String resPackageName) { 38ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey this.accountType = ACCOUNT_TYPE; 39ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey this.resPackageName = null; 40ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey this.summaryResPackageName = resPackageName; 41ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey } 42ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 43ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey @Override 44ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey protected void inflate(Context context, int inflateLevel) { 450540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann super.inflate(context, inflateLevel); 46ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 470540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann inflateRelation(context, inflateLevel); 48392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann inflateEvent(context, inflateLevel); 49ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey } 50ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 51ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey @Override 5232904f58ea5b9a675554a50b9c85db47a54f397aDmitri Plotnikov protected DataKind inflatePhone(Context context, int inflateLevel) { 5335769b804fbfd5a1fc0b2c36cd0a786d662c4334Daniel Lehmann final DataKind kind = super.inflatePhone(context, BaseAccountType.LEVEL_MIMETYPES); 54ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 5535769b804fbfd5a1fc0b2c36cd0a786d662c4334Daniel Lehmann if (inflateLevel >= BaseAccountType.LEVEL_CONSTRAINTS) { 56ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeColumn = Phone.TYPE; 57ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList = Lists.newArrayList(); 58ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildPhoneType(Phone.TYPE_HOME)); 59ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildPhoneType(Phone.TYPE_MOBILE)); 60ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildPhoneType(Phone.TYPE_WORK)); 61ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_WORK).setSecondary(true)); 62ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildPhoneType(Phone.TYPE_FAX_HOME).setSecondary(true)); 63ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildPhoneType(Phone.TYPE_PAGER).setSecondary(true)); 64ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildPhoneType(Phone.TYPE_OTHER)); 65ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildPhoneType(Phone.TYPE_CUSTOM).setSecondary(true).setCustomColumn( 66ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey Phone.LABEL)); 67ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 68ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.fieldList = Lists.newArrayList(); 69ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.fieldList.add(new EditField(Phone.NUMBER, R.string.phoneLabelsGroup, FLAGS_PHONE)); 70ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey } 71ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 72ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey return kind; 73ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey } 74ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 75ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey @Override 7632904f58ea5b9a675554a50b9c85db47a54f397aDmitri Plotnikov protected DataKind inflateEmail(Context context, int inflateLevel) { 7735769b804fbfd5a1fc0b2c36cd0a786d662c4334Daniel Lehmann final DataKind kind = super.inflateEmail(context, BaseAccountType.LEVEL_MIMETYPES); 78ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 7935769b804fbfd5a1fc0b2c36cd0a786d662c4334Daniel Lehmann if (inflateLevel >= BaseAccountType.LEVEL_CONSTRAINTS) { 80ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeColumn = Email.TYPE; 81ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList = Lists.newArrayList(); 82ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildEmailType(Email.TYPE_HOME)); 83ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildEmailType(Email.TYPE_WORK)); 84ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildEmailType(Email.TYPE_OTHER)); 85ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.typeList.add(buildEmailType(Email.TYPE_CUSTOM).setSecondary(true).setCustomColumn( 86ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey Email.LABEL)); 87ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 88ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.fieldList = Lists.newArrayList(); 89ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey kind.fieldList.add(new EditField(Email.DATA, R.string.emailLabelsGroup, FLAGS_EMAIL)); 90ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey } 91ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 92ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey return kind; 93ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey } 94ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey 95392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann private DataKind inflateRelation(Context context, int inflateLevel) { 960540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann DataKind kind = getKindForMimetype(Relation.CONTENT_ITEM_TYPE); 970540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann if (kind == null) { 980540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind = addKind(new DataKind(Relation.CONTENT_ITEM_TYPE, 990540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann R.string.relationLabelsGroup, -1, 160, true)); 1000540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.actionHeader = new RelationActionInflater(); 1010540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.actionBody = new SimpleInflater(Relation.NAME); 1020540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann 1030540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeColumn = Relation.TYPE; 1040540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList = Lists.newArrayList(); 1050540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_ASSISTANT)); 1060540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_BROTHER)); 1070540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_CHILD)); 1080540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_DOMESTIC_PARTNER)); 1090540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_FATHER)); 1100540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_FRIEND)); 1110540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_MANAGER)); 1120540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_MOTHER)); 1130540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_PARENT)); 1140540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_PARTNER)); 1150540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_REFERRED_BY)); 1160540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_RELATIVE)); 1170540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_SISTER)); 1180540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_SPOUSE)); 1190540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.typeList.add(buildRelationType(Relation.TYPE_CUSTOM).setSecondary(true) 1200540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann .setCustomColumn(Relation.LABEL)); 1210540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann 1220540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.defaultValues = new ContentValues(); 1230540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.defaultValues.put(Relation.TYPE, Relation.TYPE_SPOUSE); 1240540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann 1250540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.fieldList = Lists.newArrayList(); 1260540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann kind.fieldList.add(new EditField(Relation.DATA, R.string.relationLabelsGroup, 1270540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann FLAGS_RELATION)); 1280540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann } 1290540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann 1300540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann return kind; 1310540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann } 1320540f8b74a44f5d1da519cc54e598d75f0e572ddDaniel Lehmann 133392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann private DataKind inflateEvent(Context context, int inflateLevel) { 134392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann DataKind kind = getKindForMimetype(Event.CONTENT_ITEM_TYPE); 135392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann if (kind == null) { 136392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind = addKind(new DataKind(Event.CONTENT_ITEM_TYPE, 137392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann R.string.eventLabelsGroup, -1, 150, true)); 138392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.actionHeader = new EventActionInflater(); 139392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.actionBody = new SimpleInflater(Event.START_DATE); 140392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.editorClass = EventFieldEditorView.class; 141392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann 142392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.typeColumn = Event.TYPE; 143392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.typeList = Lists.newArrayList(); 144392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.dateFormatWithoutYear = DateUtils.NO_YEAR_DATE_FORMAT; 145392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.dateFormatWithYear = DateUtils.FULL_DATE_FORMAT; 146392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.typeList.add(buildEventType(Event.TYPE_BIRTHDAY, true).setSpecificMax(1)); 147392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.typeList.add(buildEventType(Event.TYPE_ANNIVERSARY, false)); 148392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.typeList.add(buildEventType(Event.TYPE_OTHER, false)); 149392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.typeList.add(buildEventType(Event.TYPE_CUSTOM, false).setSecondary(true) 150392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann .setCustomColumn(Event.LABEL)); 151392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann 152392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.defaultValues = new ContentValues(); 153392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.defaultValues.put(Event.TYPE, Event.TYPE_BIRTHDAY); 154392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann 155392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.fieldList = Lists.newArrayList(); 156392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann kind.fieldList.add(new EditField(Event.DATA, R.string.eventLabelsGroup, FLAGS_EVENT)); 157392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann } 158392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann 159392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann return kind; 160392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann } 161392ccec3b56e8074a5a028af28106134b39f64bcDaniel Lehmann 162ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey @Override 1635297c6af41f3fd2f08cff5b84105af4efd1ab79fJeff Hamilton public int getHeaderColor(Context context) { 1641fb6275a57318261cb6dba511954cb754cd17fa2Jeff Hamilton return 0xff89c2c2; 1655297c6af41f3fd2f08cff5b84105af4efd1ab79fJeff Hamilton } 1665297c6af41f3fd2f08cff5b84105af4efd1ab79fJeff Hamilton 1675297c6af41f3fd2f08cff5b84105af4efd1ab79fJeff Hamilton @Override 1685297c6af41f3fd2f08cff5b84105af4efd1ab79fJeff Hamilton public int getSideBarColor(Context context) { 1691fb6275a57318261cb6dba511954cb754cd17fa2Jeff Hamilton return 0xff5bb4b4; 1705297c6af41f3fd2f08cff5b84105af4efd1ab79fJeff Hamilton } 171ab066931efd4b6408b5f57026b421eb4a7934a39Jeff Sharkey} 172