blob: 94c2f001827bc3991fb5619e843966ddf9bc5a26 [file] [log] [blame]
Chiao Cheng94b10b52012-08-17 16:59:12 -07001/*
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
17package com.android.dialer;
18
Chiao Cheng94b10b52012-08-17 16:59:12 -070019import android.content.ContentUris;
Chiao Cheng94b10b52012-08-17 16:59:12 -070020import android.content.Context;
21import android.content.Intent;
22import android.content.res.Resources;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.net.Uri;
Chiao Cheng94b10b52012-08-17 16:59:12 -070024import android.os.Bundle;
Chiao Cheng94b10b52012-08-17 16:59:12 -070025import android.provider.ContactsContract.CommonDataKinds.Phone;
Nancy Chen44898ad2015-08-13 12:03:47 -070026import android.support.v7.app.AppCompatActivity;
Andrew Lee99e8adb2014-10-02 12:27:37 -070027import android.text.BidiFormatter;
28import android.text.TextDirectionHeuristics;
Chiao Cheng94b10b52012-08-17 16:59:12 -070029import android.text.TextUtils;
Andrew Leebf9cca22015-10-05 13:43:54 -070030import android.util.Log;
Chiao Cheng94b10b52012-08-17 16:59:12 -070031import android.view.LayoutInflater;
32import android.view.Menu;
33import android.view.MenuItem;
Yorke Lee0b458972015-09-18 12:55:30 -070034import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070035import android.view.View;
Chiao Cheng94b10b52012-08-17 16:59:12 -070036import android.widget.ListView;
Tyler Gunn18164c82014-06-09 10:20:57 -070037import android.widget.QuickContactBadge;
Chiao Cheng94b10b52012-08-17 16:59:12 -070038import android.widget.TextView;
39import android.widget.Toast;
40
Brian Attwell82043242015-02-03 14:13:58 -080041import com.android.contacts.common.CallUtil;
Andrew Leebf9cca22015-10-05 13:43:54 -070042import com.android.contacts.common.ClipboardUtils;
Andrew Lee7b127d42015-09-30 18:24:48 -070043import com.android.contacts.common.ContactPhotoManager;
Ta-wei Yen862822f2015-11-09 11:47:45 -080044import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
Andrew Lee7b127d42015-09-30 18:24:48 -070045import com.android.contacts.common.GeoUtil;
Wenyi Wang8005ef12015-11-24 15:31:41 -080046import com.android.contacts.common.compat.CompatUtils;
Andrew Lee7b127d42015-09-30 18:24:48 -070047import com.android.contacts.common.interactions.TouchPointManager;
Brandon Maxwell36aeec92015-10-23 12:01:00 -070048import com.android.contacts.common.preference.ContactsPreferences;
Andrew Lee7b127d42015-09-30 18:24:48 -070049import com.android.contacts.common.testing.NeededForTesting;
Tyler Gunn18b4a2e2015-08-05 08:18:37 -070050import com.android.contacts.common.util.UriUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070051import com.android.dialer.calllog.CallDetailHistoryAdapter;
Andrew Lee7c461dc2015-05-15 10:18:45 -070052import com.android.dialer.calllog.CallLogAsyncTaskUtil;
Ta-wei Yen862822f2015-11-09 11:47:45 -080053import com.android.dialer.calllog.CallLogAsyncTaskUtil.CallLogAsyncTaskListener;
Chiao Cheng94b10b52012-08-17 16:59:12 -070054import com.android.dialer.calllog.CallTypeHelper;
Chiao Cheng94b10b52012-08-17 16:59:12 -070055import com.android.dialer.calllog.ContactInfoHelper;
Nancy Chenb2eebaf2014-07-21 13:41:36 -070056import com.android.dialer.calllog.PhoneAccountUtils;
Brandon Maxwellc6ed1602016-03-06 13:52:20 -080057import com.android.dialer.compat.FilteredNumberCompat;
Andrew Leeaa264472015-10-16 13:11:38 -070058import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
Ta-wei Yen862822f2015-11-09 11:47:45 -080059import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener;
Andrew Leefcecace2015-10-28 17:36:49 -070060import com.android.dialer.filterednumber.BlockNumberDialogFragment;
Andrew Leeaa264472015-10-16 13:11:38 -070061import com.android.dialer.filterednumber.FilteredNumbersUtil;
Brandon Maxwelld81cc6c2015-11-05 16:27:40 -080062import com.android.dialer.logging.InteractionEvent;
63import com.android.dialer.logging.Logger;
Andrew Leebf9cca22015-10-05 13:43:54 -070064import com.android.dialer.util.DialerUtils;
Yorke Leee3a2d132015-09-14 16:52:08 -070065import com.android.dialer.util.IntentUtil.CallIntentBuilder;
Andrew Leed3f6a6c2015-06-25 16:53:56 -070066import com.android.dialer.util.PhoneNumberUtil;
Yorke Lee4aece952015-05-02 22:22:54 -070067import com.android.dialer.util.TelecomUtil;
Yorke Leec8d6e162015-09-14 18:43:27 -070068import com.android.incallui.Call.LogState;
Chiao Cheng94b10b52012-08-17 16:59:12 -070069
Chiao Cheng94b10b52012-08-17 16:59:12 -070070/**
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 Chen44898ad2015-08-13 12:03:47 -070076public class CallDetailActivity extends AppCompatActivity
Andrew Leebf9cca22015-10-05 13:43:54 -070077 implements MenuItem.OnMenuItemClickListener, View.OnClickListener,
Andrew Leefcecace2015-10-28 17:36:49 -070078 BlockNumberDialogFragment.Callback {
Andrew Leebf9cca22015-10-05 13:43:54 -070079 private static final String TAG = CallDetailActivity.class.getSimpleName();
Chiao Cheng94b10b52012-08-17 16:59:12 -070080
Andrew Lee7c461dc2015-05-15 10:18:45 -070081 /** A long array extra containing ids of call log entries to display. */
Chiao Cheng94b10b52012-08-17 16:59:12 -070082 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 Cheng94b10b52012-08-17 16:59:12 -070085 /** If the activity was triggered from a notification. */
86 public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";
87
Yorke Lee8cd94232014-07-23 14:05:31 -070088 public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment";
89
Andrew Lee7c461dc2015-05-15 10:18:45 -070090 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 Lee7c461dc2015-05-15 10:18:45 -0700103 if (details == null) {
104 // Somewhere went wrong: we're going to bail out and show error to users.
Andrew Leee177fe62015-06-05 13:01:09 -0700105 Toast.makeText(mContext, R.string.toast_call_detail_error,
Andrew Lee7c461dc2015-05-15 10:18:45 -0700106 Toast.LENGTH_SHORT).show();
107 finish();
108 return;
109 }
110
Andrew Leebf9cca22015-10-05 13:43:54 -0700111 // All calls are from the same number and same contact, so pick the first detail.
112 mDetails = details[0];
Andrew Leeb67294e2015-10-16 12:56:28 -0700113 mNumber = TextUtils.isEmpty(mDetails.number) ? null : mDetails.number.toString();
Hall Liu35e44d42015-10-14 15:19:06 -0700114 mPostDialDigits = TextUtils.isEmpty(mDetails.postDialDigits)
115 ? "" : mDetails.postDialDigits;
Andrew Leebf9cca22015-10-05 13:43:54 -0700116 mDisplayNumber = mDetails.displayNumber;
Andrew Lee7c461dc2015-05-15 10:18:45 -0700117
Andrew Leebf9cca22015-10-05 13:43:54 -0700118 final CharSequence callLocationOrType = getNumberTypeOrLocation(mDetails);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700119
Hall Liu35e44d42015-10-14 15:19:06 -0700120 final CharSequence displayNumber;
121 if (!TextUtils.isEmpty(mDetails.postDialDigits)) {
122 displayNumber = mDetails.number + mDetails.postDialDigits;
123 } else {
124 displayNumber = mDetails.displayNumber;
125 }
126
Andrew Lee7c461dc2015-05-15 10:18:45 -0700127 final String displayNumberStr = mBidiFormatter.unicodeWrap(
128 displayNumber.toString(), TextDirectionHeuristics.LTR);
129
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700130 mDetails.nameDisplayOrder = mContactsPreferences.getDisplayOrder();
131
132 if (!TextUtils.isEmpty(mDetails.getPreferredName())) {
133 mCallerName.setText(mDetails.getPreferredName());
Andrew Lee7c461dc2015-05-15 10:18:45 -0700134 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 Ebingera46ed832016-03-30 18:24:42 -0700145 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 Lee7c461dc2015-05-15 10:18:45 -0700159 if (!TextUtils.isEmpty(accountLabel)) {
160 mAccountLabel.setText(accountLabel);
Brad Ebingera46ed832016-03-30 18:24:42 -0700161 mAccountLabel.setContentDescription(accountContentDescription);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700162 mAccountLabel.setVisibility(View.VISIBLE);
163 } else {
164 mAccountLabel.setVisibility(View.GONE);
165 }
166
Andrew Leebf9cca22015-10-05 13:43:54 -0700167 final boolean canPlaceCallsTo =
168 PhoneNumberUtil.canPlaceCallsTo(mNumber, mDetails.numberPresentation);
169 mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE);
Nancy Chen6fa29e22016-01-14 16:04:42 -0800170 mCopyNumberActionItem.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE);
Brandon Maxwell3ec5d252016-03-17 16:01:57 -0700171
172 updateBlockActionItemVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE);
Andrew Leebf9cca22015-10-05 13:43:54 -0700173
174 final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber);
Andrew Leeb67294e2015-10-16 12:56:28 -0700175 final boolean isVoicemailNumber =
176 PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber);
Andrew Leebf9cca22015-10-05 13:43:54 -0700177 final boolean showEditNumberBeforeCallAction =
Andrew Leeb67294e2015-10-16 12:56:28 -0700178 canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
Andrew Leebf9cca22015-10-05 13:43:54 -0700179 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 Lee7c461dc2015-05-15 10:18:45 -0700187 invalidateOptionsMenu();
188
Andrew Leebf9cca22015-10-05 13:43:54 -0700189 mHistoryList.setAdapter(
Andrew Leee177fe62015-06-05 13:01:09 -0700190 new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details));
Andrew Lee7c461dc2015-05-15 10:18:45 -0700191
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800192 updateFilteredNumberChanges();
193 updateContactPhoto();
Andrew Lee7c461dc2015-05-15 10:18:45 -0700194
Andrew Lee7c461dc2015-05-15 10:18:45 -0700195 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 Maxwell36aeec92015-10-23 12:01:00 -0700206 if (!TextUtils.isEmpty(details.namePrimary)) {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700207 return Phone.getTypeLabel(mResources, details.numberType,
208 details.numberLabel);
209 } else {
210 return details.geocode;
211 }
212 }
213 };
214
Andrew Leee177fe62015-06-05 13:01:09 -0700215 private Context mContext;
Andrew Leebf9cca22015-10-05 13:43:54 -0700216 private ContactInfoHelper mContactInfoHelper;
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700217 private ContactsPreferences mContactsPreferences;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700218 private CallTypeHelper mCallTypeHelper;
Andrew Leebf9cca22015-10-05 13:43:54 -0700219 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 Liu35e44d42015-10-14 15:19:06 -0700228 private String mPostDialDigits = "";
Andrew Leebf9cca22015-10-05 13:43:54 -0700229 private String mDisplayNumber;
230
231 private ListView mHistoryList;
Tyler Gunn18164c82014-06-09 10:20:57 -0700232 private QuickContactBadge mQuickContactBadge;
233 private TextView mCallerName;
234 private TextView mCallerNumber;
Nancy Chen19702632014-07-25 13:23:16 -0700235 private TextView mAccountLabel;
Andrew Leee177fe62015-06-05 13:01:09 -0700236 private View mCallButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700237
Andrew Leef549abc2015-10-12 12:50:55 -0700238 private TextView mBlockNumberActionItem;
Andrew Leebf9cca22015-10-05 13:43:54 -0700239 private View mEditBeforeCallActionItem;
240 private View mReportActionItem;
Nancy Chen6fa29e22016-01-14 16:04:42 -0800241 private View mCopyNumberActionItem;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700242
Andrew Leebf9cca22015-10-05 13:43:54 -0700243 private Integer mBlockedNumberId;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700244
Chiao Cheng94b10b52012-08-17 16:59:12 -0700245 @Override
246 protected void onCreate(Bundle icicle) {
247 super.onCreate(icicle);
248
Andrew Leee177fe62015-06-05 13:01:09 -0700249 mContext = this;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700250 mResources = getResources();
Andrew Leebf9cca22015-10-05 13:43:54 -0700251 mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this));
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700252 mContactsPreferences = new ContactsPreferences(mContext);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700253 mCallTypeHelper = new CallTypeHelper(getResources());
Andrew Leebf9cca22015-10-05 13:43:54 -0700254 mFilteredNumberAsyncQueryHandler =
255 new FilteredNumberAsyncQueryHandler(getContentResolver());
Yorke Lee257b6f22014-07-31 14:16:44 -0700256
257 mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
258
Andrew Leebf9cca22015-10-05 13:43:54 -0700259 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 Leeafdd8b92015-10-05 17:57:40 -0700268
Tyler Gunn18164c82014-06-09 10:20:57 -0700269 mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo);
270 mQuickContactBadge.setOverlay(null);
Wenyi Wang8005ef12015-11-24 15:31:41 -0800271 if (CompatUtils.hasPrioritizedMimeType()) {
272 mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
273 }
Tyler Gunn18164c82014-06-09 10:20:57 -0700274 mCallerName = (TextView) findViewById(R.id.caller_name);
275 mCallerNumber = (TextView) findViewById(R.id.caller_number);
Nancy Chen19702632014-07-25 13:23:16 -0700276 mAccountLabel = (TextView) findViewById(R.id.phone_account_label);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700277 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Yorke Lee71513982015-02-25 20:23:53 -0800278
Yorke Leee3a2d132015-09-14 16:52:08 -0700279 mCallButton = findViewById(R.id.call_back_button);
Andrew Leee177fe62015-06-05 13:01:09 -0700280 mCallButton.setOnClickListener(new View.OnClickListener() {
281 @Override
282 public void onClick(View view) {
Andrew Leeb67294e2015-10-16 12:56:28 -0700283 if (TextUtils.isEmpty(mNumber)) {
284 return;
285 }
Yorke Leec8d6e162015-09-14 18:43:27 -0700286 mContext.startActivity(
Hall Liu35e44d42015-10-14 15:19:06 -0700287 new CallIntentBuilder(getDialableNumber())
Yorke Leec8d6e162015-09-14 18:43:27 -0700288 .setCallInitiationType(LogState.INITIATION_CALL_DETAILS)
289 .build());
Andrew Leee177fe62015-06-05 13:01:09 -0700290 }
291 });
292
Brandon Maxwell3ec5d252016-03-17 16:01:57 -0700293
Andrew Leef549abc2015-10-12 12:50:55 -0700294 mBlockNumberActionItem = (TextView) findViewById(R.id.call_detail_action_block);
Brandon Maxwell3ec5d252016-03-17 16:01:57 -0700295 updateBlockActionItemVisibility(View.VISIBLE);
Andrew Leebf9cca22015-10-05 13:43:54 -0700296 mBlockNumberActionItem.setOnClickListener(this);
Andrew Leebf9cca22015-10-05 13:43:54 -0700297 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 Chen6fa29e22016-01-14 16:04:42 -0800302 mCopyNumberActionItem = findViewById(R.id.call_detail_action_copy);
303 mCopyNumberActionItem.setOnClickListener(this);
Yorke Lee257b6f22014-07-31 14:16:44 -0700304
Chiao Cheng94b10b52012-08-17 16:59:12 -0700305 if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
306 closeSystemDialogs();
307 }
308 }
309
Brandon Maxwell3ec5d252016-03-17 16:01:57 -0700310 private void updateBlockActionItemVisibility(int visibility) {
311 if (!FilteredNumberCompat.canAttemptBlockOperations(mContext)) {
312 visibility = View.GONE;
313 }
314 mBlockNumberActionItem.setVisibility(visibility);
315 }
316
Chiao Cheng94b10b52012-08-17 16:59:12 -0700317 @Override
318 public void onResume() {
319 super.onResume();
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700320 mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
Andrew Lee2f05af32015-06-09 15:59:47 -0700321 getCallDetails();
322 }
Andrew Lee7c461dc2015-05-15 10:18:45 -0700323
Yorke Lee0b458972015-09-18 12:55:30 -0700324 @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 Lee2f05af32015-06-09 15:59:47 -0700332 public void getCallDetails() {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700333 CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700334 }
335
Chiao Cheng94b10b52012-08-17 16:59:12 -0700336 /**
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 Shrauner757bdd32014-05-28 10:13:40 -0700345 final Uri uri = getIntent().getData();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700346 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 Shrauner757bdd32014-05-28 10:13:40 -0700350 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 Lee4aece952015-05-02 22:22:54 -0700354 uris[index] = ContentUris.withAppendedId(
355 TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700356 }
357 return uris;
358 }
359
Chiao Cheng94b10b52012-08-17 16:59:12 -0700360 @Override
361 public boolean onCreateOptionsMenu(Menu menu) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700362 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 Cheng94b10b52012-08-17 16:59:12 -0700371 return super.onCreateOptionsMenu(menu);
372 }
373
374 @Override
Andrew Lee2f05af32015-06-09 15:59:47 -0700375 public boolean onMenuItemClick(MenuItem item) {
Sailesh Nepal68d86c62016-02-21 11:41:28 -0800376 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 Lee2f05af32015-06-09 15:59:47 -0700385 }
Sailesh Nepal68d86c62016-02-21 11:41:28 -0800386 callIds.append(ContentUris.parseId(callUri));
Andrew Lee2f05af32015-06-09 15:59:47 -0700387 }
Sailesh Nepal68d86c62016-02-21 11:41:28 -0800388 CallLogAsyncTaskUtil.deleteCalls(
389 this, callIds.toString(), mCallLogAsyncTaskListener);
390 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700391 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700392 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700393 }
394
Andrew Leebf9cca22015-10-05 13:43:54 -0700395 @Override
396 public void onClick(View view) {
Sailesh Nepal68d86c62016-02-21 11:41:28 -0800397 int resId = view.getId();
398 if (resId == R.id.call_detail_action_block) {
Brandon Maxwellc6ed1602016-03-06 13:52:20 -0800399 FilteredNumberCompat
Brandon Maxwell69be29f2016-03-06 15:58:33 -0800400 .showBlockNumberDialogFlow(mContext.getContentResolver(), mBlockedNumberId,
401 mNumber, mDetails.countryIso, mDisplayNumber, R.id.call_detail,
402 getFragmentManager(), this);
Sailesh Nepal68d86c62016-02-21 11:41:28 -0800403 } 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 Leebf9cca22015-10-05 13:43:54 -0700411 }
412 }
413
Andrew Lee8d0847c2015-10-13 13:07:58 -0700414 @Override
Brandon Maxwelld81cc6c2015-11-05 16:27:40 -0800415 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 Yen0bdadcc2015-11-03 14:37:44 -0800423 updateFilteredNumberChanges();
Andrew Lee8d0847c2015-10-13 13:07:58 -0700424 }
425
426 @Override
427 public void onChangeFilteredNumberUndo() {
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800428 updateFilteredNumberChanges();
Andrew Lee8d0847c2015-10-13 13:07:58 -0700429 }
430
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800431 private void updateFilteredNumberChanges() {
Andrew Lee97e333c2015-10-29 17:40:27 -0700432 if (mDetails == null ||
433 !FilteredNumbersUtil.canBlockNumber(this, mNumber, mDetails.countryIso)) {
Andrew Leebf9cca22015-10-05 13:43:54 -0700434 return;
435 }
436
Andrew Lee4805ae02015-10-28 16:22:39 -0700437 final boolean success = mFilteredNumberAsyncQueryHandler.isBlockedNumber(
Andrew Leeb67294e2015-10-16 12:56:28 -0700438 new OnCheckBlockedListener() {
439 @Override
440 public void onCheckComplete(Integer id) {
441 mBlockedNumberId = id;
Andrew Leeb67294e2015-10-16 12:56:28 -0700442 updateBlockActionItem();
443 }
Andrew Lee4805ae02015-10-28 16:22:39 -0700444 }, mNumber, mDetails.countryIso);
Andrew Leeb67294e2015-10-16 12:56:28 -0700445
Andrew Lee4805ae02015-10-28 16:22:39 -0700446 if (!success) {
Andrew Leeb67294e2015-10-16 12:56:28 -0700447 updateBlockActionItem();
448 }
449 }
450
451 // Loads and displays the contact photo.
452 private void updateContactPhoto() {
453 if (mDetails == null) {
454 return;
455 }
456
Andrew Leeb67294e2015-10-16 12:56:28 -0700457 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 Maxwell36aeec92015-10-23 12:01:00 -0700467 final String displayName = TextUtils.isEmpty(mDetails.namePrimary)
468 ? mDetails.displayNumber : mDetails.namePrimary.toString();
Andrew Leeb67294e2015-10-16 12:56:28 -0700469 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 Lee516be4d2015-11-09 18:38:51 -0800486 mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds(
Andrew Leea6732f72015-10-19 22:44:06 -0700487 R.drawable.ic_call_detail_block, 0, 0, 0);
Andrew Leeb67294e2015-10-16 12:56:28 -0700488 } else {
489 mBlockNumberActionItem.setText(R.string.action_unblock_number);
Yorke Lee516be4d2015-11-09 18:38:51 -0800490 mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds(
Andrew Leea6732f72015-10-19 22:44:06 -0700491 R.drawable.ic_call_detail_unblock, 0, 0, 0);
Andrew Leeb67294e2015-10-16 12:56:28 -0700492 }
Andrew Leebf9cca22015-10-05 13:43:54 -0700493 }
494
Chiao Cheng94b10b52012-08-17 16:59:12 -0700495 private void closeSystemDialogs() {
496 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
497 }
Andrew Leebf9cca22015-10-05 13:43:54 -0700498
Hall Liu35e44d42015-10-14 15:19:06 -0700499 private String getDialableNumber() {
500 return mNumber + mPostDialDigits;
501 }
502
Andrew Leebf9cca22015-10-05 13:43:54 -0700503 @NeededForTesting
504 public boolean hasVoicemail() {
505 return mVoicemailUri != null;
506 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700507}