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