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