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