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 
17 package com.android.dialer.calllogutils;
18 
19 import android.content.res.Resources;
20 import android.provider.CallLog.Calls;
21 import com.android.dialer.duo.Duo;
22 
23 /** Helper class to perform operations related to call types. */
24 public class CallTypeHelper {
25 
26   /** Name used to identify incoming calls. */
27   private final CharSequence incomingName;
28   /** Name used to identify incoming calls which were transferred to another device. */
29   private final CharSequence incomingPulledName;
30   /** Name used to identify outgoing calls. */
31   private final CharSequence outgoingName;
32   /** Name used to identify outgoing calls which were transferred to another device. */
33   private final CharSequence outgoingPulledName;
34   /** Name used to identify missed calls. */
35   private final CharSequence missedName;
36   /** Name used to identify incoming video calls. */
37   private final CharSequence incomingVideoName;
38   /** Name used to identify incoming video calls which were transferred to another device. */
39   private final CharSequence incomingVideoPulledName;
40   /** Name used to identify outgoing video calls. */
41   private final CharSequence outgoingVideoName;
42   /** Name used to identify outgoing video calls which were transferred to another device. */
43   private final CharSequence outgoingVideoPulledName;
44   /** Name used to identify missed video calls. */
45   private final CharSequence missedVideoName;
46   /** Name used to identify voicemail calls. */
47   private final CharSequence voicemailName;
48   /** Name used to identify rejected calls. */
49   private final CharSequence rejectedName;
50   /** Name used to identify blocked calls. */
51   private final CharSequence blockedName;
52   /** Name used to identify calls which were answered on another device. */
53   private final CharSequence answeredElsewhereName;
54   /** Name used to identify incoming Duo calls. */
55   private final CharSequence incomingDuoCall;
56   /** Name used to identify outgoing Duo calls. */
57   private final CharSequence outgoingDuoCall;
58 
CallTypeHelper(Resources resources, Duo duo)59   public CallTypeHelper(Resources resources, Duo duo) {
60     // Cache these values so that we do not need to look them up each time.
61     incomingName = resources.getString(R.string.type_incoming);
62     incomingPulledName = resources.getString(R.string.type_incoming_pulled);
63     outgoingName = resources.getString(R.string.type_outgoing);
64     outgoingPulledName = resources.getString(R.string.type_outgoing_pulled);
65     missedName = resources.getString(R.string.type_missed);
66     incomingVideoName = resources.getString(R.string.type_incoming_video);
67     incomingVideoPulledName = resources.getString(R.string.type_incoming_video_pulled);
68     outgoingVideoName = resources.getString(R.string.type_outgoing_video);
69     outgoingVideoPulledName = resources.getString(R.string.type_outgoing_video_pulled);
70     missedVideoName = resources.getString(R.string.type_missed_video);
71     voicemailName = resources.getString(R.string.type_voicemail);
72     rejectedName = resources.getString(R.string.type_rejected);
73     blockedName = resources.getString(R.string.type_blocked);
74     answeredElsewhereName = resources.getString(R.string.type_answered_elsewhere);
75 
76     if (duo.getIncomingCallTypeText() != -1) {
77       incomingDuoCall = resources.getString(duo.getIncomingCallTypeText());
78     } else {
79       incomingDuoCall = incomingVideoName;
80     }
81 
82     if (duo.getOutgoingCallTypeText() != -1) {
83       outgoingDuoCall = resources.getString(duo.getOutgoingCallTypeText());
84     } else {
85       outgoingDuoCall = outgoingVideoName;
86     }
87   }
88 
isMissedCallType(int callType)89   public static boolean isMissedCallType(int callType) {
90     return (callType != Calls.INCOMING_TYPE
91         && callType != Calls.OUTGOING_TYPE
92         && callType != Calls.VOICEMAIL_TYPE
93         && callType != Calls.ANSWERED_EXTERNALLY_TYPE);
94   }
95 
96   /** Returns the text used to represent the given call type. */
getCallTypeText( int callType, boolean isVideoCall, boolean isPulledCall, boolean isDuoCall)97   public CharSequence getCallTypeText(
98       int callType, boolean isVideoCall, boolean isPulledCall, boolean isDuoCall) {
99     switch (callType) {
100       case Calls.INCOMING_TYPE:
101         if (isVideoCall) {
102           if (isPulledCall) {
103             return incomingVideoPulledName;
104           } else {
105             if (isDuoCall) {
106               return incomingDuoCall;
107             }
108             return incomingVideoName;
109           }
110         } else {
111           if (isPulledCall) {
112             return incomingPulledName;
113           } else {
114             return incomingName;
115           }
116         }
117 
118       case Calls.OUTGOING_TYPE:
119         if (isVideoCall) {
120           if (isPulledCall) {
121             return outgoingVideoPulledName;
122           } else {
123             if (isDuoCall) {
124               return outgoingDuoCall;
125             }
126             return outgoingVideoName;
127           }
128         } else {
129           if (isPulledCall) {
130             return outgoingPulledName;
131           } else {
132             return outgoingName;
133           }
134         }
135 
136       case Calls.MISSED_TYPE:
137         if (isVideoCall) {
138           return missedVideoName;
139         } else {
140           return missedName;
141         }
142 
143       case Calls.VOICEMAIL_TYPE:
144         return voicemailName;
145 
146       case Calls.REJECTED_TYPE:
147         return rejectedName;
148 
149       case Calls.BLOCKED_TYPE:
150         return blockedName;
151 
152       case Calls.ANSWERED_EXTERNALLY_TYPE:
153         return answeredElsewhereName;
154 
155       default:
156         return missedName;
157     }
158   }
159 }
160