2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.contacts;
19 import com.android.contacts.model.EntityModifier;
20 import com.android.contacts.util.Constants;
22 import android.accounts.Account;
23 import android.provider.ContactsContract.CommonDataKinds.Email;
24 import android.provider.ContactsContract.CommonDataKinds.Im;
25 import android.provider.ContactsContract.CommonDataKinds.Organization;
26 import android.provider.ContactsContract.CommonDataKinds.Phone;
27 import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
30 * This class contains utility functions for determining the precedence of
31 * different types associated with contact data items.
33 * @deprecated use {@link EntityModifier#getTypePrecedence} instead, since this
34 * list isn't {@link Account} based.
37 public final class TypePrecedence {
39 /* This utility class has cannot be instantiated.*/
40 private TypePrecedence() {}
42 //TODO These may need to be tweaked.
43 private static final int[] TYPE_PRECEDENCE_PHONES = {
53 private static final int[] TYPE_PRECEDENCE_EMAIL = {
59 private static final int[] TYPE_PRECEDENCE_POSTAL = {
60 StructuredPostal.TYPE_CUSTOM,
61 StructuredPostal.TYPE_HOME,
62 StructuredPostal.TYPE_WORK,
63 StructuredPostal.TYPE_OTHER};
65 private static final int[] TYPE_PRECEDENCE_IM = {
71 private static final int[] TYPE_PRECEDENCE_ORG = {
72 Organization.TYPE_CUSTOM,
73 Organization.TYPE_WORK,
74 Organization.TYPE_OTHER};
77 * Returns the precedence (1 being the highest) of a type in the context of it's mimetype.
79 * @param mimetype The mimetype of the data with which the type is associated.
80 * @param type The integer type as defined in {@Link ContactsContract#CommonDataKinds}.
81 * @return The integer precedence, where 1 is the highest.
84 public static int getTypePrecedence(String mimetype, int type) {
85 int[] typePrecedence = getTypePrecedenceList(mimetype);
86 if (typePrecedence == null) {
90 for (int i = 0; i < typePrecedence.length; i++) {
91 if (typePrecedence[i] == type) {
95 return typePrecedence.length;
99 private static int[] getTypePrecedenceList(String mimetype) {
100 if (mimetype.equals(Phone.CONTENT_ITEM_TYPE)) {
101 return TYPE_PRECEDENCE_PHONES;
102 } else if (mimetype.equals(Constants.MIME_SMS_ADDRESS)) {
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(Organization.CONTENT_ITEM_TYPE)) {
111 return TYPE_PRECEDENCE_ORG;