blob: 8a2e520906d1d85715d8c0906e2e7793d7e88267 [file] [log] [blame]
Chiao Cheng94b10b52012-08-17 16:59:12 -07001/*
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
17package com.android.dialer;
18
Victor Chang240523d2015-12-17 09:14:15 +000019import com.android.contacts.common.ContactsUtils.UserType;
Brandon Maxwell36aeec92015-10-23 12:01:00 -070020import com.android.contacts.common.preference.ContactsPreferences;
Brad Ebingera46ed832016-03-30 18:24:42 -070021import com.android.contacts.common.util.ContactDisplayUtils;
Andrew Lee49efd912015-05-19 12:17:26 -070022import com.android.dialer.calllog.PhoneNumberDisplayUtil;
Yorke Lee8cd94232014-07-23 14:05:31 -070023
Andrew Lee49efd912015-05-19 12:17:26 -070024import android.content.Context;
Brad Ebingera46ed832016-03-30 18:24:42 -070025import android.content.res.Resources;
Chiao Cheng94b10b52012-08-17 16:59:12 -070026import android.net.Uri;
27import android.provider.CallLog.Calls;
Brad Ebingera46ed832016-03-30 18:24:42 -070028import android.support.annotation.Nullable;
Nancy Chene80d6222014-10-08 20:17:55 -070029import android.telecom.PhoneAccountHandle;
Brandon Maxwell36aeec92015-10-23 12:01:00 -070030import android.text.TextUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070031
32/**
33 * The details of a phone call to be shown in the UI.
34 */
35public class PhoneCallDetails {
Andrew Leeedb22da2015-06-09 18:22:14 -070036 // The number of the other party involved in the call.
37 public CharSequence number;
Hall Liu35e44d42015-10-14 15:19:06 -070038 // Post-dial digits associated with the outgoing call.
39 public String postDialDigits;
Brad Ebingera46ed832016-03-30 18:24:42 -070040 // The secondary line number the call was received via.
41 public String viaNumber;
Andrew Leeedb22da2015-06-09 18:22:14 -070042 // 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 Cheng94b10b52012-08-17 16:59:12 -070051 /**
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 Leeedb22da2015-06-09 18:22:14 -070056 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 Maxwell36aeec92015-10-23 12:01:00 -070063 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 Leeedb22da2015-06-09 18:22:14 -070071 // 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 Lee2f05af32015-06-09 15:59:47 -070077
Chiao Cheng94b10b52012-08-17 16:59:12 -070078 /**
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 Leeedb22da2015-06-09 18:22:14 -070084 public Uri photoUri;
85
86 // The source type of the contact associated with this call.
87 public int sourceType;
88
Andrew Lee2f05af32015-06-09 15:59:47 -070089 // The object id type of the contact associated with this call.
90 public String objectId;
91
Andrew Leeedb22da2015-06-09 18:22:14 -070092 // 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 Chen03aaf382015-06-11 20:06:26 -0700104 // The display string for the number.
Andrew Leeedb22da2015-06-09 18:22:14 -0700105 public String displayNumber;
Nancy Chen03aaf382015-06-11 20:06:26 -0700106
107 // Whether the contact number is a voicemail number.
Andrew Leeedb22da2015-06-09 18:22:14 -0700108 public boolean isVoicemail;
Nancy Chene80d6222014-10-08 20:17:55 -0700109
Victor Chang240523d2015-12-17 09:14:15 +0000110 /** The {@link UserType} of the contact */
111 public @UserType long contactUserType;
112
Nancy Chen87ba4892014-06-11 17:56:07 -0700113 /**
Nancy Chen03aaf382015-06-11 20:06:26 -0700114 * 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
Qi Wang4bbb9c82016-03-31 11:11:01 -0700119 // If this call is a spam number.
120 public boolean isSpam = false;
121
Nancy Chen03aaf382015-06-11 20:06:26 -0700122 /**
Andrew Leeedb22da2015-06-09 18:22:14 -0700123 * Constructor with required fields for the details of a call with a number associated with a
124 * contact.
Nancy Chen19702632014-07-25 13:23:16 -0700125 */
Andrew Leeedb22da2015-06-09 18:22:14 -0700126 public PhoneCallDetails(
127 Context context,
128 CharSequence number,
129 int numberPresentation,
130 CharSequence formattedNumber,
Hall Liu35e44d42015-10-14 15:19:06 -0700131 CharSequence postDialDigits,
Andrew Lee49efd912015-05-19 12:17:26 -0700132 boolean isVoicemail) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700133 this.number = number;
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700134 this.numberPresentation = numberPresentation;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700135 this.formattedNumber = formattedNumber;
Andrew Lee49efd912015-05-19 12:17:26 -0700136 this.isVoicemail = isVoicemail;
Hall Liu35e44d42015-10-14 15:19:06 -0700137 this.postDialDigits = postDialDigits.toString();
Andrew Lee49efd912015-05-19 12:17:26 -0700138 this.displayNumber = PhoneNumberDisplayUtil.getDisplayNumber(
139 context,
Andrew Lee49efd912015-05-19 12:17:26 -0700140 this.number,
141 this.numberPresentation,
142 this.formattedNumber,
Hall Liu35e44d42015-10-14 15:19:06 -0700143 this.postDialDigits,
Andrew Lee49efd912015-05-19 12:17:26 -0700144 this.isVoicemail).toString();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700145 }
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700146
147 /**
148 * Returns the preferred name for the call details as specified by the
149 * {@link #nameDisplayOrder}
150 *
151 * @return the preferred name
152 */
153 public CharSequence getPreferredName() {
154 if (nameDisplayOrder == ContactsPreferences.DISPLAY_ORDER_PRIMARY
155 || TextUtils.isEmpty(nameAlternative)) {
156 return namePrimary;
157 }
158 return nameAlternative;
159 }
Brad Ebingera46ed832016-03-30 18:24:42 -0700160
161 /**
162 * Construct the "on {accountLabel} via {viaNumber}" accessibility description for the account
163 * list item, depending on the existence of the accountLabel and viaNumber.
164 * @param viaNumber The number that this call is being placed via.
165 * @param accountLabel The {@link PhoneAccount} label that this call is being placed with.
166 * @return The description of the account that this call has been placed on.
167 */
168 public static CharSequence createAccountLabelDescription(Resources resources,
169 @Nullable String viaNumber, @Nullable CharSequence accountLabel) {
170
171 if((!TextUtils.isEmpty(viaNumber)) && !TextUtils.isEmpty(accountLabel)) {
172 String msg = resources.getString(R.string.description_via_number_phone_account,
173 accountLabel, viaNumber);
174 CharSequence accountNumberLabel = ContactDisplayUtils.getTelephoneTtsSpannable(msg,
175 viaNumber);
176 return (accountNumberLabel == null) ? msg : accountNumberLabel;
177 } else if (!TextUtils.isEmpty(viaNumber)) {
178 CharSequence viaNumberLabel = ContactDisplayUtils.getTtsSpannedPhoneNumber(resources,
179 R.string.description_via_number, viaNumber);
180 return (viaNumberLabel == null) ? viaNumber : viaNumberLabel;
181 } else if (!TextUtils.isEmpty(accountLabel)) {
182 return TextUtils.expandTemplate(
183 resources.getString(R.string.description_phone_account), accountLabel);
184 }
185 return "";
186 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700187}