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