summaryrefslogtreecommitdiffstats
path: root/src/com/android/dialer/calllog/CallTypeHelper.java
blob: 3603ce6c375615a86e3edc1f92e83c7f69a798e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.dialer.calllog;

import android.content.res.Resources;
import android.provider.CallLog.Calls;

import com.android.dialer.R;

/**
 * Helper class to perform operations related to call types.
 */
public class CallTypeHelper {
    /** Name used to identify incoming calls. */
    private final CharSequence mIncomingName;
    /** Name used to identify outgoing calls. */
    private final CharSequence mOutgoingName;
    /** Name used to identify missed calls. */
    private final CharSequence mMissedName;
    /** Name used to identify incoming video calls. */
    private final CharSequence mIncomingVideoName;
    /** Name used to identify outgoing video calls. */
    private final CharSequence mOutgoingVideoName;
    /** Name used to identify missed video calls. */
    private final CharSequence mMissedVideoName;
    /** Name used to identify voicemail calls. */
    private final CharSequence mVoicemailName;
    /** Name used to identify blacklisted calls */
    private final CharSequence mBlacklistedName;
    /** Color used to identify new missed calls. */
    private final int mNewMissedColor;
    /** Color used to identify new voicemail calls. */
    private final int mNewVoicemailColor;

    public CallTypeHelper(Resources resources) {
        // Cache these values so that we do not need to look them up each time.
        mIncomingName = resources.getString(R.string.type_incoming);
        mOutgoingName = resources.getString(R.string.type_outgoing);
        mMissedName = resources.getString(R.string.type_missed);
        mIncomingVideoName = resources.getString(R.string.type_incoming_video);
        mOutgoingVideoName = resources.getString(R.string.type_outgoing_video);
        mMissedVideoName = resources.getString(R.string.type_missed_video);
        mVoicemailName = resources.getString(R.string.type_voicemail);
        mBlacklistedName = resources.getText(R.string.type_blacklist);
        mNewMissedColor = resources.getColor(R.color.call_log_missed_call_highlight_color);
        mNewVoicemailColor = resources.getColor(R.color.call_log_voicemail_highlight_color);
    }

    /** Returns the text used to represent the given call type. */
    public CharSequence getCallTypeText(int callType, boolean isVideoCall) {
        switch (callType) {
            case Calls.INCOMING_TYPE:
                if (isVideoCall) {
                    return mIncomingVideoName;
                } else {
                    return mIncomingName;
                }

            case Calls.OUTGOING_TYPE:
                if (isVideoCall) {
                    return mOutgoingVideoName;
                } else {
                    return mOutgoingName;
                }

            case Calls.MISSED_TYPE:
                if (isVideoCall) {
                    return mMissedVideoName;
                } else {
                    return mMissedName;
                }

            case Calls.VOICEMAIL_TYPE:
                return mVoicemailName;

            case Calls.BLACKLIST_TYPE:
                return mBlacklistedName;

            default:
                return mMissedName;
        }
    }

    /** Returns the color used to highlight the given call type, null if not highlight is needed. */
    public Integer getHighlightedColor(int callType) {
        switch (callType) {
            case Calls.INCOMING_TYPE:
                // New incoming calls are not highlighted.
                return null;

            case Calls.OUTGOING_TYPE:
                // New outgoing calls are not highlighted.
                return null;

            case Calls.MISSED_TYPE:
                return mNewMissedColor;

            case Calls.VOICEMAIL_TYPE:
                return mNewVoicemailColor;

            default:
                // Don't highlight calls of unknown types. They are treated as missed calls by
                // the rest of the UI, but since they will never be marked as read by
                // {@link CallLogQueryHandler}, just don't ever highlight them anyway.
                return null;
        }
    }

    public static boolean isMissedCallType(int callType) {
        return (callType != Calls.INCOMING_TYPE && callType != Calls.OUTGOING_TYPE &&
                callType != Calls.VOICEMAIL_TYPE);
    }
}