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.Context; 20 import android.content.res.Resources; 21 import android.net.Uri; 22 import android.provider.CallLog; 23 import android.provider.CallLog.Calls; 24 import android.support.annotation.Nullable; 25 import android.telecom.PhoneAccountHandle; 26 import android.text.TextUtils; 27 import com.android.contacts.common.ContactsUtils.UserType; 28 import com.android.contacts.common.preference.ContactsPreferences; 29 import com.android.contacts.common.util.ContactDisplayUtils; 30 import com.android.dialer.logging.ContactSource; 31 import com.android.dialer.phonenumbercache.ContactInfo; 32 33 /** The details of a phone call to be shown in the UI. */ 34 public class PhoneCallDetails { 35 36 // The number of the other party involved in the call. 37 public CharSequence number; 38 // Post-dial digits associated with the outgoing call. 39 public String postDialDigits; 40 // The secondary line number the call was received via. 41 public String viaNumber; 42 // The number presenting rules set by the network, e.g., {@link Calls#PRESENTATION_ALLOWED} 43 public int numberPresentation; 44 // The country corresponding with the phone number. 45 public String countryIso; 46 // The geocoded location for the phone number. 47 public String geocode; 48 49 /** 50 * The type of calls, as defined in the call log table, e.g., {@link Calls#INCOMING_TYPE}. 51 * 52 * <p>There might be multiple types if this represents a set of entries grouped together. 53 */ 54 public int[] callTypes; 55 56 // The date of the call, in milliseconds since the epoch. 57 public long date; 58 // The duration of the call in milliseconds, or 0 for missed calls. 59 public long duration; 60 // The name of the contact, or the empty string. 61 public CharSequence namePrimary; 62 // The alternative name of the contact, e.g. last name first, or the empty string 63 public CharSequence nameAlternative; 64 /** 65 * The user's preference on name display order, last name first or first time first. {@see 66 * ContactsPreferences} 67 */ 68 public int nameDisplayOrder; 69 // The type of phone, e.g., {@link Phone#TYPE_HOME}, 0 if not available. 70 public int numberType; 71 // The custom label associated with the phone number in the contact, or the empty string. 72 public CharSequence numberLabel; 73 // The URI of the contact associated with this phone call. 74 public Uri contactUri; 75 76 /** 77 * The photo URI of the picture of the contact that is associated with this phone call or null if 78 * there is none. 79 * 80 * <p>This is meant to store the high-res photo only. 81 */ 82 public Uri photoUri; 83 84 // The source type of the contact associated with this call. 85 public ContactSource.Type sourceType; 86 87 // The object id type of the contact associated with this call. 88 public String objectId; 89 90 // The unique identifier for the account associated with the call. 91 public PhoneAccountHandle accountHandle; 92 93 // Features applicable to this call. 94 public int features; 95 96 // Total data usage for this call. 97 public Long dataUsage; 98 99 // Voicemail transcription 100 public String transcription; 101 102 // The display string for the number. 103 public String displayNumber; 104 105 // Whether the contact number is a voicemail number. 106 public boolean isVoicemail; 107 108 /** The {@link UserType} of the contact */ 109 public @UserType long contactUserType; 110 111 /** 112 * If this is a voicemail, whether the message is read. For other types of calls, this defaults to 113 * {@code true}. 114 */ 115 public boolean isRead = true; 116 117 // If this call is a spam number. 118 public boolean isSpam = false; 119 120 // If this call is a blocked number. 121 public boolean isBlocked = false; 122 123 // Call location and date text. 124 public CharSequence callLocationAndDate; 125 126 // Call description. 127 public CharSequence callDescription; 128 public String accountComponentName; 129 public String accountId; 130 public ContactInfo cachedContactInfo; 131 public int voicemailId; 132 public int previousGroup; 133 134 /** 135 * Constructor with required fields for the details of a call with a number associated with a 136 * contact. 137 */ PhoneCallDetails( CharSequence number, int numberPresentation, CharSequence postDialDigits)138 public PhoneCallDetails( 139 CharSequence number, int numberPresentation, CharSequence postDialDigits) { 140 this.number = number; 141 this.numberPresentation = numberPresentation; 142 this.postDialDigits = postDialDigits.toString(); 143 } 144 /** 145 * Construct the "on {accountLabel} via {viaNumber}" accessibility description for the account 146 * list item, depending on the existence of the accountLabel and viaNumber. 147 * 148 * @param viaNumber The number that this call is being placed via. 149 * @param accountLabel The {@link PhoneAccount} label that this call is being placed with. 150 * @return The description of the account that this call has been placed on. 151 */ createAccountLabelDescription( Resources resources, @Nullable String viaNumber, @Nullable CharSequence accountLabel)152 public static CharSequence createAccountLabelDescription( 153 Resources resources, @Nullable String viaNumber, @Nullable CharSequence accountLabel) { 154 155 if ((!TextUtils.isEmpty(viaNumber)) && !TextUtils.isEmpty(accountLabel)) { 156 String msg = 157 resources.getString( 158 R.string.description_via_number_phone_account, accountLabel, viaNumber); 159 CharSequence accountNumberLabel = 160 ContactDisplayUtils.getTelephoneTtsSpannable(msg, viaNumber); 161 return (accountNumberLabel == null) ? msg : accountNumberLabel; 162 } else if (!TextUtils.isEmpty(viaNumber)) { 163 CharSequence viaNumberLabel = 164 ContactDisplayUtils.getTtsSpannedPhoneNumber( 165 resources, R.string.description_via_number, viaNumber); 166 return (viaNumberLabel == null) ? viaNumber : viaNumberLabel; 167 } else if (!TextUtils.isEmpty(accountLabel)) { 168 return TextUtils.expandTemplate( 169 resources.getString(R.string.description_phone_account), accountLabel); 170 } 171 return ""; 172 } 173 174 /** 175 * Returns the preferred name for the call details as specified by the {@link #nameDisplayOrder} 176 * 177 * @return the preferred name 178 */ getPreferredName()179 public CharSequence getPreferredName() { 180 if (nameDisplayOrder == ContactsPreferences.DISPLAY_ORDER_PRIMARY 181 || TextUtils.isEmpty(nameAlternative)) { 182 return namePrimary; 183 } 184 return nameAlternative; 185 } 186 updateDisplayNumber( Context context, CharSequence formattedNumber, boolean isVoicemail)187 public void updateDisplayNumber( 188 Context context, CharSequence formattedNumber, boolean isVoicemail) { 189 displayNumber = 190 PhoneNumberDisplayUtil.getDisplayNumber( 191 context, number, numberPresentation, formattedNumber, postDialDigits, isVoicemail) 192 .toString(); 193 } 194 hasIncomingCalls()195 public boolean hasIncomingCalls() { 196 for (int i = 0; i < callTypes.length; i++) { 197 if (callTypes[i] == CallLog.Calls.INCOMING_TYPE 198 || callTypes[i] == CallLog.Calls.MISSED_TYPE 199 || callTypes[i] == CallLog.Calls.VOICEMAIL_TYPE 200 || callTypes[i] == CallLog.Calls.REJECTED_TYPE 201 || callTypes[i] == CallLog.Calls.BLOCKED_TYPE) { 202 return true; 203 } 204 } 205 return false; 206 } 207 } 208