Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 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; |
| 18 | |
Victor Chang | 240523d | 2015-12-17 09:14:15 +0000 | [diff] [blame] | 19 | import com.android.contacts.common.ContactsUtils.UserType; |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 20 | import com.android.contacts.common.preference.ContactsPreferences; |
Brad Ebinger | a46ed83 | 2016-03-30 18:24:42 -0700 | [diff] [blame^] | 21 | import com.android.contacts.common.util.ContactDisplayUtils; |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 22 | import com.android.dialer.calllog.PhoneNumberDisplayUtil; |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 23 | |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 24 | import android.content.Context; |
Brad Ebinger | a46ed83 | 2016-03-30 18:24:42 -0700 | [diff] [blame^] | 25 | import android.content.res.Resources; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 26 | import android.net.Uri; |
| 27 | import android.provider.CallLog.Calls; |
Brad Ebinger | a46ed83 | 2016-03-30 18:24:42 -0700 | [diff] [blame^] | 28 | import android.support.annotation.Nullable; |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 29 | import android.telecom.PhoneAccountHandle; |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 30 | import android.text.TextUtils; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * The details of a phone call to be shown in the UI. |
| 34 | */ |
| 35 | public class PhoneCallDetails { |
Andrew Lee | edb22da | 2015-06-09 18:22:14 -0700 | [diff] [blame] | 36 | // The number of the other party involved in the call. |
| 37 | public CharSequence number; |
Hall Liu | 35e44d4 | 2015-10-14 15:19:06 -0700 | [diff] [blame] | 38 | // Post-dial digits associated with the outgoing call. |
| 39 | public String postDialDigits; |
Brad Ebinger | a46ed83 | 2016-03-30 18:24:42 -0700 | [diff] [blame^] | 40 | // The secondary line number the call was received via. |
| 41 | public String viaNumber; |
Andrew Lee | edb22da | 2015-06-09 18:22:14 -0700 | [diff] [blame] | 42 | // The number presenting rules set by the network, e.g., {@link Calls#PRESENTATION_ALLOWED} |
| 43 | public int numberPresentation; |
| 44 | // The formatted version of {@link #number}. |
| 45 | public CharSequence formattedNumber; |
| 46 | // The country corresponding with the phone number. |
| 47 | public String countryIso; |
| 48 | // The geocoded location for the phone number. |
| 49 | public String geocode; |
| 50 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 51 | /** |
| 52 | * The type of calls, as defined in the call log table, e.g., {@link Calls#INCOMING_TYPE}. |
| 53 | * <p> |
| 54 | * There might be multiple types if this represents a set of entries grouped together. |
| 55 | */ |
Andrew Lee | edb22da | 2015-06-09 18:22:14 -0700 | [diff] [blame] | 56 | public int[] callTypes; |
| 57 | |
| 58 | // The date of the call, in milliseconds since the epoch. |
| 59 | public long date; |
| 60 | // The duration of the call in milliseconds, or 0 for missed calls. |
| 61 | public long duration; |
| 62 | // The name of the contact, or the empty string. |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 63 | public CharSequence namePrimary; |
| 64 | // The alternative name of the contact, e.g. last name first, or the empty string |
| 65 | public CharSequence nameAlternative; |
| 66 | /** |
| 67 | * The user's preference on name display order, last name first or first time first. |
| 68 | * {@see ContactsPreferences} |
| 69 | */ |
| 70 | public int nameDisplayOrder; |
Andrew Lee | edb22da | 2015-06-09 18:22:14 -0700 | [diff] [blame] | 71 | // The type of phone, e.g., {@link Phone#TYPE_HOME}, 0 if not available. |
| 72 | public int numberType; |
| 73 | // The custom label associated with the phone number in the contact, or the empty string. |
| 74 | public CharSequence numberLabel; |
| 75 | // The URI of the contact associated with this phone call. |
| 76 | public Uri contactUri; |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 77 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 78 | /** |
| 79 | * The photo URI of the picture of the contact that is associated with this phone call or |
| 80 | * null if there is none. |
| 81 | * <p> |
| 82 | * This is meant to store the high-res photo only. |
| 83 | */ |
Andrew Lee | edb22da | 2015-06-09 18:22:14 -0700 | [diff] [blame] | 84 | public Uri photoUri; |
| 85 | |
| 86 | // The source type of the contact associated with this call. |
| 87 | public int sourceType; |
| 88 | |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 89 | // The object id type of the contact associated with this call. |
| 90 | public String objectId; |
| 91 | |
Andrew Lee | edb22da | 2015-06-09 18:22:14 -0700 | [diff] [blame] | 92 | // The unique identifier for the account associated with the call. |
| 93 | public PhoneAccountHandle accountHandle; |
| 94 | |
| 95 | // Features applicable to this call. |
| 96 | public int features; |
| 97 | |
| 98 | // Total data usage for this call. |
| 99 | public Long dataUsage; |
| 100 | |
| 101 | // Voicemail transcription |
| 102 | public String transcription; |
| 103 | |
Nancy Chen | 03aaf38 | 2015-06-11 20:06:26 -0700 | [diff] [blame] | 104 | // The display string for the number. |
Andrew Lee | edb22da | 2015-06-09 18:22:14 -0700 | [diff] [blame] | 105 | public String displayNumber; |
Nancy Chen | 03aaf38 | 2015-06-11 20:06:26 -0700 | [diff] [blame] | 106 | |
| 107 | // Whether the contact number is a voicemail number. |
Andrew Lee | edb22da | 2015-06-09 18:22:14 -0700 | [diff] [blame] | 108 | public boolean isVoicemail; |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 109 | |
Victor Chang | 240523d | 2015-12-17 09:14:15 +0000 | [diff] [blame] | 110 | /** The {@link UserType} of the contact */ |
| 111 | public @UserType long contactUserType; |
| 112 | |
Nancy Chen | 87ba489 | 2014-06-11 17:56:07 -0700 | [diff] [blame] | 113 | /** |
Nancy Chen | 03aaf38 | 2015-06-11 20:06:26 -0700 | [diff] [blame] | 114 | * If this is a voicemail, whether the message is read. For other types of calls, this defaults |
| 115 | * to {@code true}. |
| 116 | */ |
| 117 | public boolean isRead = true; |
| 118 | |
| 119 | /** |
Andrew Lee | edb22da | 2015-06-09 18:22:14 -0700 | [diff] [blame] | 120 | * Constructor with required fields for the details of a call with a number associated with a |
| 121 | * contact. |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 122 | */ |
Andrew Lee | edb22da | 2015-06-09 18:22:14 -0700 | [diff] [blame] | 123 | public PhoneCallDetails( |
| 124 | Context context, |
| 125 | CharSequence number, |
| 126 | int numberPresentation, |
| 127 | CharSequence formattedNumber, |
Hall Liu | 35e44d4 | 2015-10-14 15:19:06 -0700 | [diff] [blame] | 128 | CharSequence postDialDigits, |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 129 | boolean isVoicemail) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 130 | this.number = number; |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 131 | this.numberPresentation = numberPresentation; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 132 | this.formattedNumber = formattedNumber; |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 133 | this.isVoicemail = isVoicemail; |
Hall Liu | 35e44d4 | 2015-10-14 15:19:06 -0700 | [diff] [blame] | 134 | this.postDialDigits = postDialDigits.toString(); |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 135 | this.displayNumber = PhoneNumberDisplayUtil.getDisplayNumber( |
| 136 | context, |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 137 | this.number, |
| 138 | this.numberPresentation, |
| 139 | this.formattedNumber, |
Hall Liu | 35e44d4 | 2015-10-14 15:19:06 -0700 | [diff] [blame] | 140 | this.postDialDigits, |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 141 | this.isVoicemail).toString(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 142 | } |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 143 | |
| 144 | /** |
| 145 | * Returns the preferred name for the call details as specified by the |
| 146 | * {@link #nameDisplayOrder} |
| 147 | * |
| 148 | * @return the preferred name |
| 149 | */ |
| 150 | public CharSequence getPreferredName() { |
| 151 | if (nameDisplayOrder == ContactsPreferences.DISPLAY_ORDER_PRIMARY |
| 152 | || TextUtils.isEmpty(nameAlternative)) { |
| 153 | return namePrimary; |
| 154 | } |
| 155 | return nameAlternative; |
| 156 | } |
Brad Ebinger | a46ed83 | 2016-03-30 18:24:42 -0700 | [diff] [blame^] | 157 | |
| 158 | /** |
| 159 | * Construct the "on {accountLabel} via {viaNumber}" accessibility description for the account |
| 160 | * list item, depending on the existence of the accountLabel and viaNumber. |
| 161 | * @param viaNumber The number that this call is being placed via. |
| 162 | * @param accountLabel The {@link PhoneAccount} label that this call is being placed with. |
| 163 | * @return The description of the account that this call has been placed on. |
| 164 | */ |
| 165 | public static CharSequence createAccountLabelDescription(Resources resources, |
| 166 | @Nullable String viaNumber, @Nullable CharSequence accountLabel) { |
| 167 | |
| 168 | if((!TextUtils.isEmpty(viaNumber)) && !TextUtils.isEmpty(accountLabel)) { |
| 169 | String msg = resources.getString(R.string.description_via_number_phone_account, |
| 170 | accountLabel, viaNumber); |
| 171 | CharSequence accountNumberLabel = ContactDisplayUtils.getTelephoneTtsSpannable(msg, |
| 172 | viaNumber); |
| 173 | return (accountNumberLabel == null) ? msg : accountNumberLabel; |
| 174 | } else if (!TextUtils.isEmpty(viaNumber)) { |
| 175 | CharSequence viaNumberLabel = ContactDisplayUtils.getTtsSpannedPhoneNumber(resources, |
| 176 | R.string.description_via_number, viaNumber); |
| 177 | return (viaNumberLabel == null) ? viaNumber : viaNumberLabel; |
| 178 | } else if (!TextUtils.isEmpty(accountLabel)) { |
| 179 | return TextUtils.expandTemplate( |
| 180 | resources.getString(R.string.description_phone_account), accountLabel); |
| 181 | } |
| 182 | return ""; |
| 183 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 184 | } |