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 | |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 19 | import com.google.common.annotations.VisibleForTesting; |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 20 | import com.android.dialer.calllog.PhoneNumberDisplayUtil; |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 21 | |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Nancy Chen | 87ba489 | 2014-06-11 17:56:07 -0700 | [diff] [blame] | 23 | import android.graphics.drawable.Drawable; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 24 | import android.net.Uri; |
| 25 | import android.provider.CallLog.Calls; |
| 26 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 27 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 28 | import android.text.TextUtils; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * The details of a phone call to be shown in the UI. |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 32 | * |
| 33 | * TODO: Create a builder, to make it easier to construct an instance. |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 34 | */ |
| 35 | public class PhoneCallDetails { |
| 36 | /** The number of the other party involved in the call. */ |
| 37 | public final CharSequence number; |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 38 | /** The number presenting rules set by the network, e.g., {@link Calls#PRESENTATION_ALLOWED} */ |
| 39 | public final int numberPresentation; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 40 | /** 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 Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 71 | /** |
| 72 | * The source type of the contact associated with this call. |
| 73 | */ |
| 74 | public final int sourceType; |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 75 | |
Nancy Chen | 87ba489 | 2014-06-11 17:56:07 -0700 | [diff] [blame] | 76 | /** |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 77 | * The unique identifier for the account associated with the call. |
| 78 | */ |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 79 | public final PhoneAccountHandle accountHandle; |
Tyler Gunn | 8b0e858 | 2014-07-10 12:28:43 -0700 | [diff] [blame] | 80 | /** |
| 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 Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 88 | /** |
| 89 | * Voicemail transcription |
| 90 | */ |
| 91 | public final String transcription; |
| 92 | |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 93 | public final String displayNumber; |
| 94 | public final boolean isVoicemail; |
| 95 | |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 96 | /** |
| 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 Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 101 | public PhoneCallDetails(Context context, CharSequence number, int numberPresentation, |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 102 | CharSequence formattedNumber, String countryIso, String geocode, |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 103 | 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 Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 107 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 108 | |
| 109 | /** Create the details for a call with a number not associated with a contact. */ |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 110 | public PhoneCallDetails(Context context, CharSequence number, int numberPresentation, |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 111 | CharSequence formattedNumber, String countryIso, String geocode, |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 112 | int[] callTypes, long date, long duration, |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 113 | 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 Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** Create the details for a call with a number associated with a contact. */ |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 121 | public PhoneCallDetails(Context context, CharSequence number, int numberPresentation, |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 122 | CharSequence formattedNumber, String countryIso, String geocode, |
| 123 | int[] callTypes, long date, long duration, CharSequence name, |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 124 | int numberType, CharSequence numberLabel, Uri contactUri, Uri photoUri, |
| 125 | int sourceType, PhoneAccountHandle accountHandle, int features, Long dataUsage, |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 126 | String transcription, boolean isVoicemail) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 127 | this.number = number; |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 128 | this.numberPresentation = numberPresentation; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 129 | 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 Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 140 | this.sourceType = sourceType; |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 141 | this.accountHandle = accountHandle; |
Tyler Gunn | 8b0e858 | 2014-07-10 12:28:43 -0700 | [diff] [blame] | 142 | this.features = features; |
| 143 | this.dataUsage = dataUsage; |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 144 | this.transcription = transcription; |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 145 | 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 Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 154 | } |
| 155 | } |