Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 19 | import android.content.ContentUris; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.res.Resources; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 25 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 26 | import android.support.v7.app.AppCompatActivity; |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 27 | import android.text.BidiFormatter; |
| 28 | import android.text.TextDirectionHeuristics; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 29 | import android.text.TextUtils; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 30 | import android.util.Log; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 31 | import android.view.LayoutInflater; |
| 32 | import android.view.Menu; |
| 33 | import android.view.MenuItem; |
Yorke Lee | 0b45897 | 2015-09-18 12:55:30 -0700 | [diff] [blame] | 34 | import android.view.MotionEvent; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 35 | import android.view.View; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 36 | import android.widget.ListView; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 37 | import android.widget.QuickContactBadge; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 38 | import android.widget.TextView; |
| 39 | import android.widget.Toast; |
| 40 | |
Brian Attwell | 8204324 | 2015-02-03 14:13:58 -0800 | [diff] [blame] | 41 | import com.android.contacts.common.CallUtil; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 42 | import com.android.contacts.common.ClipboardUtils; |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 43 | import com.android.contacts.common.ContactPhotoManager; |
Ta-wei Yen | 862822f | 2015-11-09 11:47:45 -0800 | [diff] [blame] | 44 | import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 45 | import com.android.contacts.common.GeoUtil; |
Wenyi Wang | 8005ef1 | 2015-11-24 15:31:41 -0800 | [diff] [blame] | 46 | import com.android.contacts.common.compat.CompatUtils; |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 47 | import com.android.contacts.common.interactions.TouchPointManager; |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 48 | import com.android.contacts.common.preference.ContactsPreferences; |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 49 | import com.android.contacts.common.testing.NeededForTesting; |
Tyler Gunn | 18b4a2e | 2015-08-05 08:18:37 -0700 | [diff] [blame] | 50 | import com.android.contacts.common.util.UriUtils; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 51 | import com.android.dialer.calllog.CallDetailHistoryAdapter; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 52 | import com.android.dialer.calllog.CallLogAsyncTaskUtil; |
Ta-wei Yen | 862822f | 2015-11-09 11:47:45 -0800 | [diff] [blame] | 53 | import com.android.dialer.calllog.CallLogAsyncTaskUtil.CallLogAsyncTaskListener; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 54 | import com.android.dialer.calllog.CallTypeHelper; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 55 | import com.android.dialer.calllog.ContactInfoHelper; |
Nancy Chen | b2eebaf | 2014-07-21 13:41:36 -0700 | [diff] [blame] | 56 | import com.android.dialer.calllog.PhoneAccountUtils; |
Brandon Maxwell | c6ed160 | 2016-03-06 13:52:20 -0800 | [diff] [blame] | 57 | import com.android.dialer.compat.FilteredNumberCompat; |
Andrew Lee | aa26447 | 2015-10-16 13:11:38 -0700 | [diff] [blame] | 58 | import com.android.dialer.database.FilteredNumberAsyncQueryHandler; |
Ta-wei Yen | 862822f | 2015-11-09 11:47:45 -0800 | [diff] [blame] | 59 | import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; |
Andrew Lee | fcecace | 2015-10-28 17:36:49 -0700 | [diff] [blame] | 60 | import com.android.dialer.filterednumber.BlockNumberDialogFragment; |
Andrew Lee | aa26447 | 2015-10-16 13:11:38 -0700 | [diff] [blame] | 61 | import com.android.dialer.filterednumber.FilteredNumbersUtil; |
Brandon Maxwell | d81cc6c | 2015-11-05 16:27:40 -0800 | [diff] [blame] | 62 | import com.android.dialer.logging.InteractionEvent; |
| 63 | import com.android.dialer.logging.Logger; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 64 | import com.android.dialer.util.DialerUtils; |
Yorke Lee | e3a2d13 | 2015-09-14 16:52:08 -0700 | [diff] [blame] | 65 | import com.android.dialer.util.IntentUtil.CallIntentBuilder; |
Andrew Lee | d3f6a6c | 2015-06-25 16:53:56 -0700 | [diff] [blame] | 66 | import com.android.dialer.util.PhoneNumberUtil; |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 67 | import com.android.dialer.util.TelecomUtil; |
Yorke Lee | c8d6e16 | 2015-09-14 18:43:27 -0700 | [diff] [blame] | 68 | import com.android.incallui.Call.LogState; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 69 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 70 | /** |
| 71 | * Displays the details of a specific call log entry. |
| 72 | * <p> |
| 73 | * This activity can be either started with the URI of a single call log entry, or with the |
| 74 | * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries. |
| 75 | */ |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 76 | public class CallDetailActivity extends AppCompatActivity |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 77 | implements MenuItem.OnMenuItemClickListener, View.OnClickListener, |
Andrew Lee | fcecace | 2015-10-28 17:36:49 -0700 | [diff] [blame] | 78 | BlockNumberDialogFragment.Callback { |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 79 | private static final String TAG = CallDetailActivity.class.getSimpleName(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 80 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 81 | /** A long array extra containing ids of call log entries to display. */ |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 82 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 83 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 84 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 85 | /** If the activity was triggered from a notification. */ |
| 86 | public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION"; |
| 87 | |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 88 | public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment"; |
| 89 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 90 | private CallLogAsyncTaskListener mCallLogAsyncTaskListener = new CallLogAsyncTaskListener() { |
| 91 | @Override |
| 92 | public void onDeleteCall() { |
| 93 | finish(); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void onDeleteVoicemail() { |
| 98 | finish(); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public void onGetCallDetails(PhoneCallDetails[] details) { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 103 | if (details == null) { |
| 104 | // Somewhere went wrong: we're going to bail out and show error to users. |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 105 | Toast.makeText(mContext, R.string.toast_call_detail_error, |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 106 | Toast.LENGTH_SHORT).show(); |
| 107 | finish(); |
| 108 | return; |
| 109 | } |
| 110 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 111 | // All calls are from the same number and same contact, so pick the first detail. |
| 112 | mDetails = details[0]; |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 113 | mNumber = TextUtils.isEmpty(mDetails.number) ? null : mDetails.number.toString(); |
Hall Liu | 35e44d4 | 2015-10-14 15:19:06 -0700 | [diff] [blame] | 114 | mPostDialDigits = TextUtils.isEmpty(mDetails.postDialDigits) |
| 115 | ? "" : mDetails.postDialDigits; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 116 | mDisplayNumber = mDetails.displayNumber; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 117 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 118 | final CharSequence callLocationOrType = getNumberTypeOrLocation(mDetails); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 119 | |
Hall Liu | 35e44d4 | 2015-10-14 15:19:06 -0700 | [diff] [blame] | 120 | final CharSequence displayNumber; |
| 121 | if (!TextUtils.isEmpty(mDetails.postDialDigits)) { |
| 122 | displayNumber = mDetails.number + mDetails.postDialDigits; |
| 123 | } else { |
| 124 | displayNumber = mDetails.displayNumber; |
| 125 | } |
| 126 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 127 | final String displayNumberStr = mBidiFormatter.unicodeWrap( |
| 128 | displayNumber.toString(), TextDirectionHeuristics.LTR); |
| 129 | |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 130 | mDetails.nameDisplayOrder = mContactsPreferences.getDisplayOrder(); |
| 131 | |
| 132 | if (!TextUtils.isEmpty(mDetails.getPreferredName())) { |
| 133 | mCallerName.setText(mDetails.getPreferredName()); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 134 | mCallerNumber.setText(callLocationOrType + " " + displayNumberStr); |
| 135 | } else { |
| 136 | mCallerName.setText(displayNumberStr); |
| 137 | if (!TextUtils.isEmpty(callLocationOrType)) { |
| 138 | mCallerNumber.setText(callLocationOrType); |
| 139 | mCallerNumber.setVisibility(View.VISIBLE); |
| 140 | } else { |
| 141 | mCallerNumber.setVisibility(View.GONE); |
| 142 | } |
| 143 | } |
| 144 | |
Brad Ebinger | a46ed83 | 2016-03-30 18:24:42 -0700 | [diff] [blame^] | 145 | CharSequence accountLabel = PhoneAccountUtils.getAccountLabel(mContext, |
| 146 | mDetails.accountHandle); |
| 147 | CharSequence accountContentDescription = |
| 148 | PhoneCallDetails.createAccountLabelDescription(mResources, mDetails.viaNumber, |
| 149 | accountLabel); |
| 150 | if (!TextUtils.isEmpty(mDetails.viaNumber)) { |
| 151 | if (!TextUtils.isEmpty(accountLabel)) { |
| 152 | accountLabel = mResources.getString(R.string.call_log_via_number_phone_account, |
| 153 | accountLabel, mDetails.viaNumber); |
| 154 | } else { |
| 155 | accountLabel = mResources.getString(R.string.call_log_via_number, |
| 156 | mDetails.viaNumber); |
| 157 | } |
| 158 | } |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 159 | if (!TextUtils.isEmpty(accountLabel)) { |
| 160 | mAccountLabel.setText(accountLabel); |
Brad Ebinger | a46ed83 | 2016-03-30 18:24:42 -0700 | [diff] [blame^] | 161 | mAccountLabel.setContentDescription(accountContentDescription); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 162 | mAccountLabel.setVisibility(View.VISIBLE); |
| 163 | } else { |
| 164 | mAccountLabel.setVisibility(View.GONE); |
| 165 | } |
| 166 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 167 | final boolean canPlaceCallsTo = |
| 168 | PhoneNumberUtil.canPlaceCallsTo(mNumber, mDetails.numberPresentation); |
| 169 | mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); |
Nancy Chen | 6fa29e2 | 2016-01-14 16:04:42 -0800 | [diff] [blame] | 170 | mCopyNumberActionItem.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); |
Brandon Maxwell | 3ec5d25 | 2016-03-17 16:01:57 -0700 | [diff] [blame] | 171 | |
| 172 | updateBlockActionItemVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 173 | |
| 174 | final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber); |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 175 | final boolean isVoicemailNumber = |
| 176 | PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 177 | final boolean showEditNumberBeforeCallAction = |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 178 | canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 179 | mEditBeforeCallActionItem.setVisibility( |
| 180 | showEditNumberBeforeCallAction ? View.VISIBLE : View.GONE); |
| 181 | |
| 182 | final boolean showReportAction = mContactInfoHelper.canReportAsInvalid( |
| 183 | mDetails.sourceType, mDetails.objectId); |
| 184 | mReportActionItem.setVisibility( |
| 185 | showReportAction ? View.VISIBLE : View.GONE); |
| 186 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 187 | invalidateOptionsMenu(); |
| 188 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 189 | mHistoryList.setAdapter( |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 190 | new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details)); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 191 | |
Ta-wei Yen | 0bdadcc | 2015-11-03 14:37:44 -0800 | [diff] [blame] | 192 | updateFilteredNumberChanges(); |
| 193 | updateContactPhoto(); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 194 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 195 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Determines the location geocode text for a call, or the phone number type |
| 200 | * (if available). |
| 201 | * |
| 202 | * @param details The call details. |
| 203 | * @return The phone number type or location. |
| 204 | */ |
| 205 | private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) { |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 206 | if (!TextUtils.isEmpty(details.namePrimary)) { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 207 | return Phone.getTypeLabel(mResources, details.numberType, |
| 208 | details.numberLabel); |
| 209 | } else { |
| 210 | return details.geocode; |
| 211 | } |
| 212 | } |
| 213 | }; |
| 214 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 215 | private Context mContext; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 216 | private ContactInfoHelper mContactInfoHelper; |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 217 | private ContactsPreferences mContactsPreferences; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 218 | private CallTypeHelper mCallTypeHelper; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 219 | private ContactPhotoManager mContactPhotoManager; |
| 220 | private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler; |
| 221 | private BidiFormatter mBidiFormatter = BidiFormatter.getInstance(); |
| 222 | private LayoutInflater mInflater; |
| 223 | private Resources mResources; |
| 224 | |
| 225 | private PhoneCallDetails mDetails; |
| 226 | protected String mNumber; |
| 227 | private Uri mVoicemailUri; |
Hall Liu | 35e44d4 | 2015-10-14 15:19:06 -0700 | [diff] [blame] | 228 | private String mPostDialDigits = ""; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 229 | private String mDisplayNumber; |
| 230 | |
| 231 | private ListView mHistoryList; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 232 | private QuickContactBadge mQuickContactBadge; |
| 233 | private TextView mCallerName; |
| 234 | private TextView mCallerNumber; |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 235 | private TextView mAccountLabel; |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 236 | private View mCallButton; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 237 | |
Andrew Lee | f549abc | 2015-10-12 12:50:55 -0700 | [diff] [blame] | 238 | private TextView mBlockNumberActionItem; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 239 | private View mEditBeforeCallActionItem; |
| 240 | private View mReportActionItem; |
Nancy Chen | 6fa29e2 | 2016-01-14 16:04:42 -0800 | [diff] [blame] | 241 | private View mCopyNumberActionItem; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 242 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 243 | private Integer mBlockedNumberId; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 244 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 245 | @Override |
| 246 | protected void onCreate(Bundle icicle) { |
| 247 | super.onCreate(icicle); |
| 248 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 249 | mContext = this; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 250 | mResources = getResources(); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 251 | mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 252 | mContactsPreferences = new ContactsPreferences(mContext); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 253 | mCallTypeHelper = new CallTypeHelper(getResources()); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 254 | mFilteredNumberAsyncQueryHandler = |
| 255 | new FilteredNumberAsyncQueryHandler(getContentResolver()); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 256 | |
| 257 | mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
| 258 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 259 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
| 260 | |
| 261 | setContentView(R.layout.call_detail); |
| 262 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 263 | |
| 264 | mHistoryList = (ListView) findViewById(R.id.history); |
| 265 | mHistoryList.addHeaderView(mInflater.inflate(R.layout.call_detail_header, null)); |
| 266 | mHistoryList.addFooterView( |
| 267 | mInflater.inflate(R.layout.call_detail_footer, null), null, false); |
Andrew Lee | afdd8b9 | 2015-10-05 17:57:40 -0700 | [diff] [blame] | 268 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 269 | mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo); |
| 270 | mQuickContactBadge.setOverlay(null); |
Wenyi Wang | 8005ef1 | 2015-11-24 15:31:41 -0800 | [diff] [blame] | 271 | if (CompatUtils.hasPrioritizedMimeType()) { |
| 272 | mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE); |
| 273 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 274 | mCallerName = (TextView) findViewById(R.id.caller_name); |
| 275 | mCallerNumber = (TextView) findViewById(R.id.caller_number); |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 276 | mAccountLabel = (TextView) findViewById(R.id.phone_account_label); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 277 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
Yorke Lee | 7151398 | 2015-02-25 20:23:53 -0800 | [diff] [blame] | 278 | |
Yorke Lee | e3a2d13 | 2015-09-14 16:52:08 -0700 | [diff] [blame] | 279 | mCallButton = findViewById(R.id.call_back_button); |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 280 | mCallButton.setOnClickListener(new View.OnClickListener() { |
| 281 | @Override |
| 282 | public void onClick(View view) { |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 283 | if (TextUtils.isEmpty(mNumber)) { |
| 284 | return; |
| 285 | } |
Yorke Lee | c8d6e16 | 2015-09-14 18:43:27 -0700 | [diff] [blame] | 286 | mContext.startActivity( |
Hall Liu | 35e44d4 | 2015-10-14 15:19:06 -0700 | [diff] [blame] | 287 | new CallIntentBuilder(getDialableNumber()) |
Yorke Lee | c8d6e16 | 2015-09-14 18:43:27 -0700 | [diff] [blame] | 288 | .setCallInitiationType(LogState.INITIATION_CALL_DETAILS) |
| 289 | .build()); |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 290 | } |
| 291 | }); |
| 292 | |
Brandon Maxwell | 3ec5d25 | 2016-03-17 16:01:57 -0700 | [diff] [blame] | 293 | |
Andrew Lee | f549abc | 2015-10-12 12:50:55 -0700 | [diff] [blame] | 294 | mBlockNumberActionItem = (TextView) findViewById(R.id.call_detail_action_block); |
Brandon Maxwell | 3ec5d25 | 2016-03-17 16:01:57 -0700 | [diff] [blame] | 295 | updateBlockActionItemVisibility(View.VISIBLE); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 296 | mBlockNumberActionItem.setOnClickListener(this); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 297 | mEditBeforeCallActionItem = findViewById(R.id.call_detail_action_edit_before_call); |
| 298 | mEditBeforeCallActionItem.setOnClickListener(this); |
| 299 | mReportActionItem = findViewById(R.id.call_detail_action_report); |
| 300 | mReportActionItem.setOnClickListener(this); |
| 301 | |
Nancy Chen | 6fa29e2 | 2016-01-14 16:04:42 -0800 | [diff] [blame] | 302 | mCopyNumberActionItem = findViewById(R.id.call_detail_action_copy); |
| 303 | mCopyNumberActionItem.setOnClickListener(this); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 304 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 305 | if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) { |
| 306 | closeSystemDialogs(); |
| 307 | } |
| 308 | } |
| 309 | |
Brandon Maxwell | 3ec5d25 | 2016-03-17 16:01:57 -0700 | [diff] [blame] | 310 | private void updateBlockActionItemVisibility(int visibility) { |
| 311 | if (!FilteredNumberCompat.canAttemptBlockOperations(mContext)) { |
| 312 | visibility = View.GONE; |
| 313 | } |
| 314 | mBlockNumberActionItem.setVisibility(visibility); |
| 315 | } |
| 316 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 317 | @Override |
| 318 | public void onResume() { |
| 319 | super.onResume(); |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 320 | mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 321 | getCallDetails(); |
| 322 | } |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 323 | |
Yorke Lee | 0b45897 | 2015-09-18 12:55:30 -0700 | [diff] [blame] | 324 | @Override |
| 325 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 326 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 327 | TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); |
| 328 | } |
| 329 | return super.dispatchTouchEvent(ev); |
| 330 | } |
| 331 | |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 332 | public void getCallDetails() { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 333 | CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 336 | /** |
| 337 | * Returns the list of URIs to show. |
| 338 | * <p> |
| 339 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 340 | * a list of ids in the call log added as an extra on the URI. |
| 341 | * <p> |
| 342 | * If both are available, the data on the intent takes precedence. |
| 343 | */ |
| 344 | private Uri[] getCallLogEntryUris() { |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 345 | final Uri uri = getIntent().getData(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 346 | if (uri != null) { |
| 347 | // If there is a data on the intent, it takes precedence over the extra. |
| 348 | return new Uri[]{ uri }; |
| 349 | } |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 350 | final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 351 | final int numIds = ids == null ? 0 : ids.length; |
| 352 | final Uri[] uris = new Uri[numIds]; |
| 353 | for (int index = 0; index < numIds; ++index) { |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 354 | uris[index] = ContentUris.withAppendedId( |
| 355 | TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 356 | } |
| 357 | return uris; |
| 358 | } |
| 359 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 360 | @Override |
| 361 | public boolean onCreateOptionsMenu(Menu menu) { |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 362 | final MenuItem deleteMenuItem = menu.add( |
| 363 | Menu.NONE, |
| 364 | R.id.call_detail_delete_menu_item, |
| 365 | Menu.NONE, |
| 366 | R.string.call_details_delete); |
| 367 | deleteMenuItem.setIcon(R.drawable.ic_delete_24dp); |
| 368 | deleteMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); |
| 369 | deleteMenuItem.setOnMenuItemClickListener(this); |
| 370 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 371 | return super.onCreateOptionsMenu(menu); |
| 372 | } |
| 373 | |
| 374 | @Override |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 375 | public boolean onMenuItemClick(MenuItem item) { |
Sailesh Nepal | 68d86c6 | 2016-02-21 11:41:28 -0800 | [diff] [blame] | 376 | if (item.getItemId() == R.id.call_detail_delete_menu_item) { |
| 377 | if (hasVoicemail()) { |
| 378 | CallLogAsyncTaskUtil.deleteVoicemail( |
| 379 | this, mVoicemailUri, mCallLogAsyncTaskListener); |
| 380 | } else { |
| 381 | final StringBuilder callIds = new StringBuilder(); |
| 382 | for (Uri callUri : getCallLogEntryUris()) { |
| 383 | if (callIds.length() != 0) { |
| 384 | callIds.append(","); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 385 | } |
Sailesh Nepal | 68d86c6 | 2016-02-21 11:41:28 -0800 | [diff] [blame] | 386 | callIds.append(ContentUris.parseId(callUri)); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 387 | } |
Sailesh Nepal | 68d86c6 | 2016-02-21 11:41:28 -0800 | [diff] [blame] | 388 | CallLogAsyncTaskUtil.deleteCalls( |
| 389 | this, callIds.toString(), mCallLogAsyncTaskListener); |
| 390 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 391 | } |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 392 | return true; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 395 | @Override |
| 396 | public void onClick(View view) { |
Sailesh Nepal | 68d86c6 | 2016-02-21 11:41:28 -0800 | [diff] [blame] | 397 | int resId = view.getId(); |
| 398 | if (resId == R.id.call_detail_action_block) { |
Brandon Maxwell | c6ed160 | 2016-03-06 13:52:20 -0800 | [diff] [blame] | 399 | FilteredNumberCompat |
Brandon Maxwell | 69be29f | 2016-03-06 15:58:33 -0800 | [diff] [blame] | 400 | .showBlockNumberDialogFlow(mContext.getContentResolver(), mBlockedNumberId, |
| 401 | mNumber, mDetails.countryIso, mDisplayNumber, R.id.call_detail, |
| 402 | getFragmentManager(), this); |
Sailesh Nepal | 68d86c6 | 2016-02-21 11:41:28 -0800 | [diff] [blame] | 403 | } else if (resId == R.id.call_detail_action_copy) { |
| 404 | ClipboardUtils.copyText(mContext, null, mNumber, true); |
| 405 | } else if (resId == R.id.call_detail_action_edit_before_call) { |
| 406 | Intent dialIntent = new Intent(Intent.ACTION_DIAL, |
| 407 | CallUtil.getCallUri(getDialableNumber())); |
| 408 | DialerUtils.startActivityWithErrorToast(mContext, dialIntent); |
| 409 | } else { |
| 410 | Log.wtf(TAG, "Unexpected onClick event from " + view); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
Andrew Lee | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame] | 414 | @Override |
Brandon Maxwell | d81cc6c | 2015-11-05 16:27:40 -0800 | [diff] [blame] | 415 | public void onFilterNumberSuccess() { |
| 416 | Logger.logInteraction(InteractionEvent.BLOCK_NUMBER_CALL_DETAIL); |
| 417 | updateFilteredNumberChanges(); |
| 418 | } |
| 419 | |
| 420 | @Override |
| 421 | public void onUnfilterNumberSuccess() { |
| 422 | Logger.logInteraction(InteractionEvent.UNBLOCK_NUMBER_CALL_DETAIL); |
Ta-wei Yen | 0bdadcc | 2015-11-03 14:37:44 -0800 | [diff] [blame] | 423 | updateFilteredNumberChanges(); |
Andrew Lee | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | @Override |
| 427 | public void onChangeFilteredNumberUndo() { |
Ta-wei Yen | 0bdadcc | 2015-11-03 14:37:44 -0800 | [diff] [blame] | 428 | updateFilteredNumberChanges(); |
Andrew Lee | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Ta-wei Yen | 0bdadcc | 2015-11-03 14:37:44 -0800 | [diff] [blame] | 431 | private void updateFilteredNumberChanges() { |
Andrew Lee | 97e333c | 2015-10-29 17:40:27 -0700 | [diff] [blame] | 432 | if (mDetails == null || |
| 433 | !FilteredNumbersUtil.canBlockNumber(this, mNumber, mDetails.countryIso)) { |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 434 | return; |
| 435 | } |
| 436 | |
Andrew Lee | 4805ae0 | 2015-10-28 16:22:39 -0700 | [diff] [blame] | 437 | final boolean success = mFilteredNumberAsyncQueryHandler.isBlockedNumber( |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 438 | new OnCheckBlockedListener() { |
| 439 | @Override |
| 440 | public void onCheckComplete(Integer id) { |
| 441 | mBlockedNumberId = id; |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 442 | updateBlockActionItem(); |
| 443 | } |
Andrew Lee | 4805ae0 | 2015-10-28 16:22:39 -0700 | [diff] [blame] | 444 | }, mNumber, mDetails.countryIso); |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 445 | |
Andrew Lee | 4805ae0 | 2015-10-28 16:22:39 -0700 | [diff] [blame] | 446 | if (!success) { |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 447 | updateBlockActionItem(); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | // Loads and displays the contact photo. |
| 452 | private void updateContactPhoto() { |
| 453 | if (mDetails == null) { |
| 454 | return; |
| 455 | } |
| 456 | |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 457 | final boolean isVoicemailNumber = |
| 458 | PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber); |
| 459 | final boolean isBusiness = mContactInfoHelper.isBusiness(mDetails.sourceType); |
| 460 | int contactType = ContactPhotoManager.TYPE_DEFAULT; |
| 461 | if (isVoicemailNumber) { |
| 462 | contactType = ContactPhotoManager.TYPE_VOICEMAIL; |
| 463 | } else if (isBusiness) { |
| 464 | contactType = ContactPhotoManager.TYPE_BUSINESS; |
| 465 | } |
| 466 | |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 467 | final String displayName = TextUtils.isEmpty(mDetails.namePrimary) |
| 468 | ? mDetails.displayNumber : mDetails.namePrimary.toString(); |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 469 | final String lookupKey = mDetails.contactUri == null |
| 470 | ? null : UriUtils.getLookupKeyFromUri(mDetails.contactUri); |
| 471 | |
| 472 | final DefaultImageRequest request = |
| 473 | new DefaultImageRequest(displayName, lookupKey, contactType, true /* isCircular */); |
| 474 | |
| 475 | mQuickContactBadge.assignContactUri(mDetails.contactUri); |
| 476 | mQuickContactBadge.setContentDescription( |
| 477 | mResources.getString(R.string.description_contact_details, displayName)); |
| 478 | |
| 479 | mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, mDetails.photoUri, |
| 480 | false /* darkTheme */, true /* isCircular */, request); |
| 481 | } |
| 482 | |
| 483 | private void updateBlockActionItem() { |
| 484 | if (mBlockedNumberId == null) { |
| 485 | mBlockNumberActionItem.setText(R.string.action_block_number); |
Yorke Lee | 516be4d | 2015-11-09 18:38:51 -0800 | [diff] [blame] | 486 | mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds( |
Andrew Lee | a6732f7 | 2015-10-19 22:44:06 -0700 | [diff] [blame] | 487 | R.drawable.ic_call_detail_block, 0, 0, 0); |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 488 | } else { |
| 489 | mBlockNumberActionItem.setText(R.string.action_unblock_number); |
Yorke Lee | 516be4d | 2015-11-09 18:38:51 -0800 | [diff] [blame] | 490 | mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds( |
Andrew Lee | a6732f7 | 2015-10-19 22:44:06 -0700 | [diff] [blame] | 491 | R.drawable.ic_call_detail_unblock, 0, 0, 0); |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 492 | } |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 495 | private void closeSystemDialogs() { |
| 496 | sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 497 | } |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 498 | |
Hall Liu | 35e44d4 | 2015-10-14 15:19:06 -0700 | [diff] [blame] | 499 | private String getDialableNumber() { |
| 500 | return mNumber + mPostDialDigits; |
| 501 | } |
| 502 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 503 | @NeededForTesting |
| 504 | public boolean hasVoicemail() { |
| 505 | return mVoicemailUri != null; |
| 506 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 507 | } |