Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 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 | |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 19 | import android.accounts.Account; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 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; |
Jeff Sharkey | c6ad3ab | 2009-07-21 19:30:15 -0700 | [diff] [blame] | 24 | import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 25 | |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 26 | import com.android.contacts.model.RawContactModifier; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 27 | |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 28 | /** |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 29 | * This class contains utility functions for determining the precedence of |
| 30 | * different types associated with contact data items. |
| 31 | * |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 32 | * @deprecated use {@link RawContactModifier#getTypePrecedence} instead, since this |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 33 | * list isn't {@link Account} based. |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 34 | */ |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 35 | @Deprecated |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 36 | public final class TypePrecedence { |
| 37 | |
Chiao Cheng | d9eab4d | 2012-11-14 18:24:25 -0800 | [diff] [blame] | 38 | public static final String MIME_TYPE_VIDEO_CHAT = "vnd.android.cursor.item/video-chat-address"; |
| 39 | |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 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, |
Daniel Lehmann | 0563058 | 2011-03-28 17:50:58 -0700 | [diff] [blame] | 46 | Phone.TYPE_MAIN, |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 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 = { |
Jeff Sharkey | c6ad3ab | 2009-07-21 19:30:15 -0700 | [diff] [blame] | 62 | StructuredPostal.TYPE_CUSTOM, |
| 63 | StructuredPostal.TYPE_HOME, |
| 64 | StructuredPostal.TYPE_WORK, |
| 65 | StructuredPostal.TYPE_OTHER}; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 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, |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 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 | */ |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 85 | @Deprecated |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 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 | |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 100 | @Deprecated |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 101 | private static int[] getTypePrecedenceList(String mimetype) { |
| 102 | if (mimetype.equals(Phone.CONTENT_ITEM_TYPE)) { |
| 103 | return TYPE_PRECEDENCE_PHONES; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 104 | } else if (mimetype.equals(Email.CONTENT_ITEM_TYPE)) { |
| 105 | return TYPE_PRECEDENCE_EMAIL; |
Jeff Sharkey | c6ad3ab | 2009-07-21 19:30:15 -0700 | [diff] [blame] | 106 | } else if (mimetype.equals(StructuredPostal.CONTENT_ITEM_TYPE)) { |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 107 | return TYPE_PRECEDENCE_POSTAL; |
| 108 | } else if (mimetype.equals(Im.CONTENT_ITEM_TYPE)) { |
| 109 | return TYPE_PRECEDENCE_IM; |
Chiao Cheng | d9eab4d | 2012-11-14 18:24:25 -0800 | [diff] [blame] | 110 | } else if (mimetype.equals(MIME_TYPE_VIDEO_CHAT)) { |
Dmitri Plotnikov | cccf627 | 2011-01-05 13:25:42 -0800 | [diff] [blame] | 111 | return TYPE_PRECEDENCE_IM; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 112 | } else if (mimetype.equals(Organization.CONTENT_ITEM_TYPE)) { |
| 113 | return TYPE_PRECEDENCE_ORG; |
| 114 | } else { |
| 115 | return null; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | |
| 120 | } |