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; 18 19 import android.accounts.Account; 20 import android.provider.ContactsContract.CommonDataKinds.Email; 21 import android.provider.ContactsContract.CommonDataKinds.Im; 22 import android.provider.ContactsContract.CommonDataKinds.Organization; 23 import android.provider.ContactsContract.CommonDataKinds.Phone; 24 import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; 25 26 import com.android.contacts.model.RawContactModifier; 27 28 /** 29 * This class contains utility functions for determining the precedence of 30 * different types associated with contact data items. 31 * 32 * @deprecated use {@link RawContactModifier#getTypePrecedence} instead, since this 33 * list isn't {@link Account} based. 34 */ 35 @Deprecated 36 public final class TypePrecedence { 37 38 public static final String MIME_TYPE_VIDEO_CHAT = "vnd.android.cursor.item/video-chat-address"; 39 40 /* This utility class has cannot be instantiated.*/ 41 private TypePrecedence() {} 42 43 //TODO These may need to be tweaked. 44 private static final int[] TYPE_PRECEDENCE_PHONES = { 45 Phone.TYPE_CUSTOM, 46 Phone.TYPE_MAIN, 47 Phone.TYPE_MOBILE, 48 Phone.TYPE_HOME, 49 Phone.TYPE_WORK, 50 Phone.TYPE_OTHER, 51 Phone.TYPE_FAX_HOME, 52 Phone.TYPE_FAX_WORK, 53 Phone.TYPE_PAGER}; 54 55 private static final int[] TYPE_PRECEDENCE_EMAIL = { 56 Email.TYPE_CUSTOM, 57 Email.TYPE_HOME, 58 Email.TYPE_WORK, 59 Email.TYPE_OTHER}; 60 61 private static final int[] TYPE_PRECEDENCE_POSTAL = { 62 StructuredPostal.TYPE_CUSTOM, 63 StructuredPostal.TYPE_HOME, 64 StructuredPostal.TYPE_WORK, 65 StructuredPostal.TYPE_OTHER}; 66 67 private static final int[] TYPE_PRECEDENCE_IM = { 68 Im.TYPE_CUSTOM, 69 Im.TYPE_HOME, 70 Im.TYPE_WORK, 71 Im.TYPE_OTHER}; 72 73 private static final int[] TYPE_PRECEDENCE_ORG = { 74 Organization.TYPE_CUSTOM, 75 Organization.TYPE_WORK, 76 Organization.TYPE_OTHER}; 77 78 /** 79 * Returns the precedence (1 being the highest) of a type in the context of it's mimetype. 80 * 81 * @param mimetype The mimetype of the data with which the type is associated. 82 * @param type The integer type as defined in {@Link ContactsContract#CommonDataKinds}. 83 * @return The integer precedence, where 1 is the highest. 84 */ 85 @Deprecated 86 public static int getTypePrecedence(String mimetype, int type) { 87 int[] typePrecedence = getTypePrecedenceList(mimetype); 88 if (typePrecedence == null) { 89 return -1; 90 } 91 92 for (int i = 0; i < typePrecedence.length; i++) { 93 if (typePrecedence[i] == type) { 94 return i; 95 } 96 } 97 return typePrecedence.length; 98 } 99 100 @Deprecated 101 private static int[] getTypePrecedenceList(String mimetype) { 102 if (mimetype.equals(Phone.CONTENT_ITEM_TYPE)) { 103 return TYPE_PRECEDENCE_PHONES; 104 } else if (mimetype.equals(Email.CONTENT_ITEM_TYPE)) { 105 return TYPE_PRECEDENCE_EMAIL; 106 } else if (mimetype.equals(StructuredPostal.CONTENT_ITEM_TYPE)) { 107 return TYPE_PRECEDENCE_POSTAL; 108 } else if (mimetype.equals(Im.CONTENT_ITEM_TYPE)) { 109 return TYPE_PRECEDENCE_IM; 110 } else if (mimetype.equals(MIME_TYPE_VIDEO_CHAT)) { 111 return TYPE_PRECEDENCE_IM; 112 } else if (mimetype.equals(Organization.CONTENT_ITEM_TYPE)) { 113 return TYPE_PRECEDENCE_ORG; 114 } else { 115 return null; 116 } 117 } 118 119 120 } 121