blob: 81a1bed1544df77a0a5e278c649222a8fcb00dca [file] [log] [blame]
Bai Tao107736c2010-03-12 08:00:42 +08001/*
2 * Copyright (C) 2010 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.content.Context;
20import android.graphics.drawable.Drawable;
Dmitri Plotnikovdfe20252011-01-04 16:31:33 -080021import android.provider.ContactsContract.CommonDataKinds.Im;
Bai Tao107736c2010-03-12 08:00:42 +080022import android.provider.ContactsContract.StatusUpdates;
23
24/**
25 * Define the contact present show policy in Contacts
26 */
27public class ContactPresenceIconUtil {
28 /**
29 * Get the presence icon resource according the status.
Dmitri Plotnikovdfe20252011-01-04 16:31:33 -080030 *
Bai Tao107736c2010-03-12 08:00:42 +080031 * @return null means don't show the status icon.
32 */
33 public static Drawable getPresenceIcon (Context context, int status) {
34 // We don't show the offline status in Contacts
35 switch(status) {
36 case StatusUpdates.AVAILABLE:
37 case StatusUpdates.IDLE:
38 case StatusUpdates.AWAY:
39 case StatusUpdates.DO_NOT_DISTURB:
40 case StatusUpdates.INVISIBLE:
41 return context.getResources().getDrawable(
42 StatusUpdates.getPresenceIconResourceId(status));
43 case StatusUpdates.OFFLINE:
44 // The undefined status is treated as OFFLINE in getPresenceIconResourceId();
45 default:
46 return null;
47 }
48 }
Dmitri Plotnikovdfe20252011-01-04 16:31:33 -080049
50 public static Drawable getCapabilityIcon(Context context, int status, int chatCapability) {
51 int resourceId = 0;
52 if ((chatCapability & Im.CAPABILITY_HAS_CAMERA) != 0) {
53 switch(status) {
54 case StatusUpdates.AVAILABLE:
55 resourceId = android.R.drawable.presence_video_online;
56 break;
57 case StatusUpdates.IDLE:
58 case StatusUpdates.AWAY:
59 resourceId = android.R.drawable.presence_video_away;
60 break;
61 case StatusUpdates.DO_NOT_DISTURB:
62 resourceId = android.R.drawable.presence_video_busy;
63 break;
64 }
65 } else if ((chatCapability & Im.CAPABILITY_HAS_VOICE) != 0) {
66 switch(status) {
67 case StatusUpdates.AVAILABLE:
68 resourceId = android.R.drawable.presence_audio_online;
69 break;
70 case StatusUpdates.IDLE:
71 case StatusUpdates.AWAY:
72 resourceId = android.R.drawable.presence_audio_away;
73 break;
74 case StatusUpdates.DO_NOT_DISTURB:
75 resourceId = android.R.drawable.presence_audio_busy;
76 break;
77 }
78 }
79
80 if (resourceId != 0) {
81 return context.getResources().getDrawable(resourceId);
82 }
83
84 return null;
85 }
Bai Tao107736c2010-03-12 08:00:42 +080086}