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 
19 import com.android.contacts.common.ContactsUtils.UserType;
20 import com.android.contacts.common.preference.ContactsPreferences;
21 import com.android.contacts.common.util.ContactDisplayUtils;
22 import com.android.dialer.calllog.PhoneNumberDisplayUtil;
23 
24 import android.content.Context;
25 import android.content.res.Resources;
26 import android.net.Uri;
27 import android.provider.CallLog.Calls;
28 import android.support.annotation.Nullable;
29 import android.telecom.PhoneAccountHandle;
30 import android.text.TextUtils;
31 
32 /**
33  * The details of a phone call to be shown in the UI.
34  */
35 public class PhoneCallDetails {
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 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 
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      */
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.
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;
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;
77 
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      */
84     public Uri photoUri;
85 
86     // The source type of the contact associated with this call.
87     public int sourceType;
88 
89     // The object id type of the contact associated with this call.
90     public String objectId;
91 
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 
104     // The display string for the number.
105     public String displayNumber;
106 
107     // Whether the contact number is a voicemail number.
108     public boolean isVoicemail;
109 
110     /** The {@link UserType} of the contact */
111     public @UserType long contactUserType;
112 
113     /**
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     /**
120      * Constructor with required fields for the details of a call with a number associated with a
121      * contact.
122      */
PhoneCallDetails( Context context, CharSequence number, int numberPresentation, CharSequence formattedNumber, CharSequence postDialDigits, boolean isVoicemail)123     public PhoneCallDetails(
124             Context context,
125             CharSequence number,
126             int numberPresentation,
127             CharSequence formattedNumber,
128             CharSequence postDialDigits,
129             boolean isVoicemail) {
130         this.number = number;
131         this.numberPresentation = numberPresentation;
132         this.formattedNumber = formattedNumber;
133         this.isVoicemail = isVoicemail;
134         this.postDialDigits = postDialDigits.toString();
135         this.displayNumber = PhoneNumberDisplayUtil.getDisplayNumber(
136                 context,
137                 this.number,
138                 this.numberPresentation,
139                 this.formattedNumber,
140                 this.postDialDigits,
141                 this.isVoicemail).toString();
142     }
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      */
getPreferredName()150     public CharSequence getPreferredName() {
151         if (nameDisplayOrder == ContactsPreferences.DISPLAY_ORDER_PRIMARY
152                 || TextUtils.isEmpty(nameAlternative)) {
153             return namePrimary;
154         }
155         return nameAlternative;
156     }
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      */
createAccountLabelDescription(Resources resources, @Nullable String viaNumber, @Nullable CharSequence accountLabel)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     }
184 }
185