blob: 843e19352a690e0ece5355efccf1c0eb975467f2 [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
Yorke Lee8cd94232014-07-23 14:05:31 -070019import com.google.common.annotations.VisibleForTesting;
Andrew Lee49efd912015-05-19 12:17:26 -070020import com.android.dialer.calllog.PhoneNumberDisplayUtil;
Yorke Lee8cd94232014-07-23 14:05:31 -070021
Andrew Lee49efd912015-05-19 12:17:26 -070022import android.content.Context;
Nancy Chen87ba4892014-06-11 17:56:07 -070023import android.graphics.drawable.Drawable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070024import android.net.Uri;
25import android.provider.CallLog.Calls;
26import android.provider.ContactsContract.CommonDataKinds.Phone;
Nancy Chene80d6222014-10-08 20:17:55 -070027import android.telecom.PhoneAccountHandle;
Andrew Lee49efd912015-05-19 12:17:26 -070028import android.text.TextUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070029
30/**
31 * The details of a phone call to be shown in the UI.
Andrew Lee49efd912015-05-19 12:17:26 -070032 *
33 * TODO: Create a builder, to make it easier to construct an instance.
Chiao Cheng94b10b52012-08-17 16:59:12 -070034 */
35public class PhoneCallDetails {
36 /** The number of the other party involved in the call. */
37 public final CharSequence number;
Jay Shrauner719a7ad2013-05-30 15:41:13 -070038 /** The number presenting rules set by the network, e.g., {@link Calls#PRESENTATION_ALLOWED} */
39 public final int numberPresentation;
Chiao Cheng94b10b52012-08-17 16:59:12 -070040 /** The formatted version of {@link #number}. */
41 public final CharSequence formattedNumber;
42 /** The country corresponding with the phone number. */
43 public final String countryIso;
44 /** The geocoded location for the phone number. */
45 public final String geocode;
46 /**
47 * The type of calls, as defined in the call log table, e.g., {@link Calls#INCOMING_TYPE}.
48 * <p>
49 * There might be multiple types if this represents a set of entries grouped together.
50 */
51 public final int[] callTypes;
52 /** The date of the call, in milliseconds since the epoch. */
53 public final long date;
54 /** The duration of the call in milliseconds, or 0 for missed calls. */
55 public final long duration;
56 /** The name of the contact, or the empty string. */
57 public final CharSequence name;
58 /** The type of phone, e.g., {@link Phone#TYPE_HOME}, 0 if not available. */
59 public final int numberType;
60 /** The custom label associated with the phone number in the contact, or the empty string. */
61 public final CharSequence numberLabel;
62 /** The URI of the contact associated with this phone call. */
63 public final Uri contactUri;
64 /**
65 * The photo URI of the picture of the contact that is associated with this phone call or
66 * null if there is none.
67 * <p>
68 * This is meant to store the high-res photo only.
69 */
70 public final Uri photoUri;
Yorke Lee56cb0ef2014-02-21 10:02:18 -080071 /**
72 * The source type of the contact associated with this call.
73 */
74 public final int sourceType;
Nancy Chene80d6222014-10-08 20:17:55 -070075
Nancy Chen87ba4892014-06-11 17:56:07 -070076 /**
Nancy Chen19702632014-07-25 13:23:16 -070077 * The unique identifier for the account associated with the call.
78 */
Nancy Chene80d6222014-10-08 20:17:55 -070079 public final PhoneAccountHandle accountHandle;
Tyler Gunn8b0e8582014-07-10 12:28:43 -070080 /**
81 * Features applicable to this call.
82 */
83 public final int features;
84 /**
85 * Total data usage for this call.
86 */
87 public final Long dataUsage;
Yorke Lee8cd94232014-07-23 14:05:31 -070088 /**
89 * Voicemail transcription
90 */
91 public final String transcription;
92
Andrew Lee49efd912015-05-19 12:17:26 -070093 public final String displayNumber;
94 public final boolean isVoicemail;
95
Yorke Lee8cd94232014-07-23 14:05:31 -070096 /**
97 * Create the details for a call, with empty defaults specified for extra fields that are
98 * not necessary for testing.
99 */
100 @VisibleForTesting
Andrew Lee49efd912015-05-19 12:17:26 -0700101 public PhoneCallDetails(Context context, CharSequence number, int numberPresentation,
Yorke Lee8cd94232014-07-23 14:05:31 -0700102 CharSequence formattedNumber, String countryIso, String geocode,
Andrew Lee49efd912015-05-19 12:17:26 -0700103 int[] callTypes, long date, long duration, boolean isVoicemail) {
104 this(context, number, numberPresentation, formattedNumber, countryIso, geocode,
105 callTypes, date, duration, "", 0, "", null, null, 0, null, 0, null, null,
106 isVoicemail);
Yorke Lee8cd94232014-07-23 14:05:31 -0700107 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700108
109 /** Create the details for a call with a number not associated with a contact. */
Andrew Lee49efd912015-05-19 12:17:26 -0700110 public PhoneCallDetails(Context context, CharSequence number, int numberPresentation,
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700111 CharSequence formattedNumber, String countryIso, String geocode,
Nancy Chene80d6222014-10-08 20:17:55 -0700112 int[] callTypes, long date, long duration,
Andrew Lee49efd912015-05-19 12:17:26 -0700113 PhoneAccountHandle accountHandle, int features, Long dataUsage, String transcription,
114 boolean isVoicemail) {
115 this(context, number, numberPresentation, formattedNumber, countryIso, geocode,
116 callTypes, date, duration, "", 0, "", null, null, 0, accountHandle, features,
117 dataUsage, transcription, isVoicemail);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700118 }
119
120 /** Create the details for a call with a number associated with a contact. */
Andrew Lee49efd912015-05-19 12:17:26 -0700121 public PhoneCallDetails(Context context, CharSequence number, int numberPresentation,
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700122 CharSequence formattedNumber, String countryIso, String geocode,
123 int[] callTypes, long date, long duration, CharSequence name,
Nancy Chene80d6222014-10-08 20:17:55 -0700124 int numberType, CharSequence numberLabel, Uri contactUri, Uri photoUri,
125 int sourceType, PhoneAccountHandle accountHandle, int features, Long dataUsage,
Andrew Lee49efd912015-05-19 12:17:26 -0700126 String transcription, boolean isVoicemail) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700127 this.number = number;
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700128 this.numberPresentation = numberPresentation;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700129 this.formattedNumber = formattedNumber;
130 this.countryIso = countryIso;
131 this.geocode = geocode;
132 this.callTypes = callTypes;
133 this.date = date;
134 this.duration = duration;
135 this.name = name;
136 this.numberType = numberType;
137 this.numberLabel = numberLabel;
138 this.contactUri = contactUri;
139 this.photoUri = photoUri;
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800140 this.sourceType = sourceType;
Nancy Chene80d6222014-10-08 20:17:55 -0700141 this.accountHandle = accountHandle;
Tyler Gunn8b0e8582014-07-10 12:28:43 -0700142 this.features = features;
143 this.dataUsage = dataUsage;
Yorke Lee8cd94232014-07-23 14:05:31 -0700144 this.transcription = transcription;
Andrew Lee49efd912015-05-19 12:17:26 -0700145 this.isVoicemail = isVoicemail;
146
147 this.displayNumber = PhoneNumberDisplayUtil.getDisplayNumber(
148 context,
149 this.accountHandle,
150 this.number,
151 this.numberPresentation,
152 this.formattedNumber,
153 this.isVoicemail).toString();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700154 }
155}