blob: 53b8343019abebbe73117bcac9943c8e1197047c [file] [log] [blame]
Evan Millar54a5c9f2009-06-23 17:41:09 -07001/*
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
Jeff Sharkey49d17b32009-09-07 02:14:21 -070019import android.accounts.Account;
Evan Millar54a5c9f2009-06-23 17:41:09 -070020import android.provider.ContactsContract.CommonDataKinds.Email;
21import android.provider.ContactsContract.CommonDataKinds.Im;
22import android.provider.ContactsContract.CommonDataKinds.Organization;
23import android.provider.ContactsContract.CommonDataKinds.Phone;
Jeff Sharkeyc6ad3ab2009-07-21 19:30:15 -070024import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
Evan Millar54a5c9f2009-06-23 17:41:09 -070025
Gary Mai69c182a2016-12-05 13:07:03 -080026import com.android.contacts.model.RawContactModifier;
Chiao Chenge0b2f1e2012-06-12 13:07:56 -070027
Evan Millar54a5c9f2009-06-23 17:41:09 -070028/**
Jeff Sharkey49d17b32009-09-07 02:14:21 -070029 * This class contains utility functions for determining the precedence of
30 * different types associated with contact data items.
31 *
Maurice Chu851222a2012-06-21 11:43:08 -070032 * @deprecated use {@link RawContactModifier#getTypePrecedence} instead, since this
Jeff Sharkey49d17b32009-09-07 02:14:21 -070033 * list isn't {@link Account} based.
Evan Millar54a5c9f2009-06-23 17:41:09 -070034 */
Jeff Sharkey49d17b32009-09-07 02:14:21 -070035@Deprecated
Evan Millar54a5c9f2009-06-23 17:41:09 -070036public final class TypePrecedence {
37
Chiao Chengd9eab4d2012-11-14 18:24:25 -080038 public static final String MIME_TYPE_VIDEO_CHAT = "vnd.android.cursor.item/video-chat-address";
39
Evan Millar54a5c9f2009-06-23 17:41:09 -070040 /* 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 Lehmann05630582011-03-28 17:50:58 -070046 Phone.TYPE_MAIN,
Evan Millar54a5c9f2009-06-23 17:41:09 -070047 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 Sharkeyc6ad3ab2009-07-21 19:30:15 -070062 StructuredPostal.TYPE_CUSTOM,
63 StructuredPostal.TYPE_HOME,
64 StructuredPostal.TYPE_WORK,
65 StructuredPostal.TYPE_OTHER};
Evan Millar54a5c9f2009-06-23 17:41:09 -070066
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 Millar54a5c9f2009-06-23 17:41:09 -070076 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 Sharkey49d17b32009-09-07 02:14:21 -070085 @Deprecated
Evan Millar54a5c9f2009-06-23 17:41:09 -070086 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 Sharkey49d17b32009-09-07 02:14:21 -0700100 @Deprecated
Evan Millar54a5c9f2009-06-23 17:41:09 -0700101 private static int[] getTypePrecedenceList(String mimetype) {
102 if (mimetype.equals(Phone.CONTENT_ITEM_TYPE)) {
103 return TYPE_PRECEDENCE_PHONES;
Evan Millar54a5c9f2009-06-23 17:41:09 -0700104 } else if (mimetype.equals(Email.CONTENT_ITEM_TYPE)) {
105 return TYPE_PRECEDENCE_EMAIL;
Jeff Sharkeyc6ad3ab2009-07-21 19:30:15 -0700106 } else if (mimetype.equals(StructuredPostal.CONTENT_ITEM_TYPE)) {
Evan Millar54a5c9f2009-06-23 17:41:09 -0700107 return TYPE_PRECEDENCE_POSTAL;
108 } else if (mimetype.equals(Im.CONTENT_ITEM_TYPE)) {
109 return TYPE_PRECEDENCE_IM;
Chiao Chengd9eab4d2012-11-14 18:24:25 -0800110 } else if (mimetype.equals(MIME_TYPE_VIDEO_CHAT)) {
Dmitri Plotnikovcccf6272011-01-05 13:25:42 -0800111 return TYPE_PRECEDENCE_IM;
Evan Millar54a5c9f2009-06-23 17:41:09 -0700112 } else if (mimetype.equals(Organization.CONTENT_ITEM_TYPE)) {
113 return TYPE_PRECEDENCE_ORG;
114 } else {
115 return null;
116 }
117 }
118
119
120}