OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / packages / apps / Contacts / src / com / android / contacts / TypePrecedence.java
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 com.android.contacts.model.EntityModifier;
20 import com.android.contacts.util.Constants;
21
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;
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 EntityModifier#getTypePrecedence} instead, since this
34  *             list isn't {@link Account} based.
35  */
36 @Deprecated
37 public 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_MOBILE,
46             Phone.TYPE_HOME,
47             Phone.TYPE_WORK,
48             Phone.TYPE_OTHER,
49             Phone.TYPE_FAX_HOME,
50             Phone.TYPE_FAX_WORK,
51             Phone.TYPE_PAGER};
52
53     private static final int[] TYPE_PRECEDENCE_EMAIL = {
54             Email.TYPE_CUSTOM,
55             Email.TYPE_HOME,
56             Email.TYPE_WORK,
57             Email.TYPE_OTHER};
58
59     private static final int[] TYPE_PRECEDENCE_POSTAL = {
60             StructuredPostal.TYPE_CUSTOM,
61             StructuredPostal.TYPE_HOME,
62             StructuredPostal.TYPE_WORK,
63             StructuredPostal.TYPE_OTHER};
64
65     private static final int[] TYPE_PRECEDENCE_IM = {
66             Im.TYPE_CUSTOM,
67             Im.TYPE_HOME,
68             Im.TYPE_WORK,
69             Im.TYPE_OTHER};
70
71     private static final int[] TYPE_PRECEDENCE_ORG = {
72             Organization.TYPE_CUSTOM,
73             Organization.TYPE_WORK,
74             Organization.TYPE_OTHER};
75
76     /**
77      * Returns the precedence (1 being the highest) of a type in the context of it's mimetype.
78      *
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.
82      */
83     @Deprecated
84     public static int getTypePrecedence(String mimetype, int type) {
85         int[] typePrecedence = getTypePrecedenceList(mimetype);
86         if (typePrecedence == null) {
87             return -1;
88         }
89
90         for (int i = 0; i < typePrecedence.length; i++) {
91             if (typePrecedence[i] == type) {
92                 return i;
93             }
94         }
95         return typePrecedence.length;
96     }
97
98     @Deprecated
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;
112         } else {
113             return null;
114         }
115     }
116
117
118 }