1/*
2 * Copyright (C) 2011 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.dialer.calllog;
18
19import android.content.res.Resources;
20import android.provider.CallLog.Calls;
21
22import com.android.dialer.R;
23
24/**
25 * Helper class to perform operations related to call types.
26 */
27public class CallTypeHelper {
28    /** Name used to identify incoming calls. */
29    private final CharSequence mIncomingName;
30    /** Name used to identify outgoing calls. */
31    private final CharSequence mOutgoingName;
32    /** Name used to identify missed calls. */
33    private final CharSequence mMissedName;
34    /** Name used to identify incoming video calls. */
35    private final CharSequence mIncomingVideoName;
36    /** Name used to identify outgoing video calls. */
37    private final CharSequence mOutgoingVideoName;
38    /** Name used to identify missed video calls. */
39    private final CharSequence mMissedVideoName;
40    /** Name used to identify voicemail calls. */
41    private final CharSequence mVoicemailName;
42    /** Color used to identify new missed calls. */
43    private final int mNewMissedColor;
44    /** Color used to identify new voicemail calls. */
45    private final int mNewVoicemailColor;
46
47    public CallTypeHelper(Resources resources) {
48        // Cache these values so that we do not need to look them up each time.
49        mIncomingName = resources.getString(R.string.type_incoming);
50        mOutgoingName = resources.getString(R.string.type_outgoing);
51        mMissedName = resources.getString(R.string.type_missed);
52        mIncomingVideoName = resources.getString(R.string.type_incoming_video);
53        mOutgoingVideoName = resources.getString(R.string.type_outgoing_video);
54        mMissedVideoName = resources.getString(R.string.type_missed_video);
55        mVoicemailName = resources.getString(R.string.type_voicemail);
56        mNewMissedColor = resources.getColor(R.color.call_log_missed_call_highlight_color);
57        mNewVoicemailColor = resources.getColor(R.color.call_log_voicemail_highlight_color);
58    }
59
60    /** Returns the text used to represent the given call type. */
61    public CharSequence getCallTypeText(int callType, boolean isVideoCall) {
62        switch (callType) {
63            case Calls.INCOMING_TYPE:
64                if (isVideoCall) {
65                    return mIncomingVideoName;
66                } else {
67                    return mIncomingName;
68                }
69
70            case Calls.OUTGOING_TYPE:
71                if (isVideoCall) {
72                    return mOutgoingVideoName;
73                } else {
74                    return mOutgoingName;
75                }
76
77            case Calls.MISSED_TYPE:
78                if (isVideoCall) {
79                    return mMissedVideoName;
80                } else {
81                    return mMissedName;
82                }
83
84            case Calls.VOICEMAIL_TYPE:
85                return mVoicemailName;
86
87            default:
88                return mMissedName;
89        }
90    }
91
92    /** Returns the color used to highlight the given call type, null if not highlight is needed. */
93    public Integer getHighlightedColor(int callType) {
94        switch (callType) {
95            case Calls.INCOMING_TYPE:
96                // New incoming calls are not highlighted.
97                return null;
98
99            case Calls.OUTGOING_TYPE:
100                // New outgoing calls are not highlighted.
101                return null;
102
103            case Calls.MISSED_TYPE:
104                return mNewMissedColor;
105
106            case Calls.VOICEMAIL_TYPE:
107                return mNewVoicemailColor;
108
109            default:
110                // Don't highlight calls of unknown types. They are treated as missed calls by
111                // the rest of the UI, but since they will never be marked as read by
112                // {@link CallLogQueryHandler}, just don't ever highlight them anyway.
113                return null;
114        }
115    }
116
117    public static boolean isMissedCallType(int callType) {
118        return (callType != Calls.INCOMING_TYPE && callType != Calls.OUTGOING_TYPE &&
119                callType != Calls.VOICEMAIL_TYPE);
120    }
121}
122