blob: c045967a2d80782daee4beeaf44cc3af2e018763 [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;
Andrew Leeaa264472015-10-16 13:11:38 -070057import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
Ta-wei Yen862822f2015-11-09 11:47:45 -080058import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener;
Andrew Leefcecace2015-10-28 17:36:49 -070059import com.android.dialer.filterednumber.BlockNumberDialogFragment;
Andrew Leeaa264472015-10-16 13:11:38 -070060import com.android.dialer.filterednumber.FilteredNumbersUtil;
Brandon Maxwelld81cc6c2015-11-05 16:27:40 -080061import com.android.dialer.logging.InteractionEvent;
62import com.android.dialer.logging.Logger;
Andrew Leebf9cca22015-10-05 13:43:54 -070063import com.android.dialer.util.DialerUtils;
Yorke Leee3a2d132015-09-14 16:52:08 -070064import com.android.dialer.util.IntentUtil.CallIntentBuilder;
Andrew Leed3f6a6c2015-06-25 16:53:56 -070065import com.android.dialer.util.PhoneNumberUtil;
Yorke Lee4aece952015-05-02 22:22:54 -070066import com.android.dialer.util.TelecomUtil;
Yorke Leec8d6e162015-09-14 18:43:27 -070067import com.android.incallui.Call.LogState;
Chiao Cheng94b10b52012-08-17 16:59:12 -070068
Chiao Cheng94b10b52012-08-17 16:59:12 -070069/**
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 Chen44898ad2015-08-13 12:03:47 -070075public class CallDetailActivity extends AppCompatActivity
Andrew Leebf9cca22015-10-05 13:43:54 -070076 implements MenuItem.OnMenuItemClickListener, View.OnClickListener,
Andrew Leefcecace2015-10-28 17:36:49 -070077 BlockNumberDialogFragment.Callback {
Andrew Leebf9cca22015-10-05 13:43:54 -070078 private static final String TAG = CallDetailActivity.class.getSimpleName();
Chiao Cheng94b10b52012-08-17 16:59:12 -070079
Andrew Lee7c461dc2015-05-15 10:18:45 -070080 /** A long array extra containing ids of call log entries to display. */
Chiao Cheng94b10b52012-08-17 16:59:12 -070081 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 Cheng94b10b52012-08-17 16:59:12 -070084 /** If the activity was triggered from a notification. */
85 public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";
86
Yorke Lee8cd94232014-07-23 14:05:31 -070087 public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment";
88
Andrew Lee7c461dc2015-05-15 10:18:45 -070089 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 Lee7c461dc2015-05-15 10:18:45 -0700102 if (details == null) {
103 // Somewhere went wrong: we're going to bail out and show error to users.
Andrew Leee177fe62015-06-05 13:01:09 -0700104 Toast.makeText(mContext, R.string.toast_call_detail_error,
Andrew Lee7c461dc2015-05-15 10:18:45 -0700105 Toast.LENGTH_SHORT).show();
106 finish();
107 return;
108 }
109
Andrew Leebf9cca22015-10-05 13:43:54 -0700110 // All calls are from the same number and same contact, so pick the first detail.
111 mDetails = details[0];
Andrew Leeb67294e2015-10-16 12:56:28 -0700112 mNumber = TextUtils.isEmpty(mDetails.number) ? null : mDetails.number.toString();
Hall Liu35e44d42015-10-14 15:19:06 -0700113 mPostDialDigits = TextUtils.isEmpty(mDetails.postDialDigits)
114 ? "" : mDetails.postDialDigits;
Andrew Leebf9cca22015-10-05 13:43:54 -0700115 mDisplayNumber = mDetails.displayNumber;
Andrew Lee7c461dc2015-05-15 10:18:45 -0700116
Andrew Leebf9cca22015-10-05 13:43:54 -0700117 final CharSequence callLocationOrType = getNumberTypeOrLocation(mDetails);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700118
Hall Liu35e44d42015-10-14 15:19:06 -0700119 final CharSequence displayNumber;
120 if (!TextUtils.isEmpty(mDetails.postDialDigits)) {
121 displayNumber = mDetails.number + mDetails.postDialDigits;
122 } else {
123 displayNumber = mDetails.displayNumber;
124 }
125
Andrew Lee7c461dc2015-05-15 10:18:45 -0700126 final String displayNumberStr = mBidiFormatter.unicodeWrap(
127 displayNumber.toString(), TextDirectionHeuristics.LTR);
128
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700129 mDetails.nameDisplayOrder = mContactsPreferences.getDisplayOrder();
130
131 if (!TextUtils.isEmpty(mDetails.getPreferredName())) {
132 mCallerName.setText(mDetails.getPreferredName());
Andrew Lee7c461dc2015-05-15 10:18:45 -0700133 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 Leeb67294e2015-10-16 12:56:28 -0700144 String accountLabel =
145 PhoneAccountUtils.getAccountLabel(mContext, mDetails.accountHandle);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700146 if (!TextUtils.isEmpty(accountLabel)) {
147 mAccountLabel.setText(accountLabel);
148 mAccountLabel.setVisibility(View.VISIBLE);
149 } else {
150 mAccountLabel.setVisibility(View.GONE);
151 }
152
Andrew Leebf9cca22015-10-05 13:43:54 -0700153 final boolean canPlaceCallsTo =
154 PhoneNumberUtil.canPlaceCallsTo(mNumber, mDetails.numberPresentation);
155 mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE);
156
157 final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber);
Andrew Leeb67294e2015-10-16 12:56:28 -0700158 final boolean isVoicemailNumber =
159 PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber);
Andrew Leebf9cca22015-10-05 13:43:54 -0700160 final boolean showEditNumberBeforeCallAction =
Andrew Leeb67294e2015-10-16 12:56:28 -0700161 canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
Andrew Leebf9cca22015-10-05 13:43:54 -0700162 mEditBeforeCallActionItem.setVisibility(
163 showEditNumberBeforeCallAction ? View.VISIBLE : View.GONE);
164
165 final boolean showReportAction = mContactInfoHelper.canReportAsInvalid(
166 mDetails.sourceType, mDetails.objectId);
167 mReportActionItem.setVisibility(
168 showReportAction ? View.VISIBLE : View.GONE);
169
Andrew Lee7c461dc2015-05-15 10:18:45 -0700170 invalidateOptionsMenu();
171
Andrew Leebf9cca22015-10-05 13:43:54 -0700172 mHistoryList.setAdapter(
Andrew Leee177fe62015-06-05 13:01:09 -0700173 new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details));
Andrew Lee7c461dc2015-05-15 10:18:45 -0700174
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800175 updateFilteredNumberChanges();
176 updateContactPhoto();
Andrew Lee7c461dc2015-05-15 10:18:45 -0700177
Andrew Lee7c461dc2015-05-15 10:18:45 -0700178 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
179 }
180
181 /**
182 * Determines the location geocode text for a call, or the phone number type
183 * (if available).
184 *
185 * @param details The call details.
186 * @return The phone number type or location.
187 */
188 private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) {
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700189 if (!TextUtils.isEmpty(details.namePrimary)) {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700190 return Phone.getTypeLabel(mResources, details.numberType,
191 details.numberLabel);
192 } else {
193 return details.geocode;
194 }
195 }
196 };
197
Andrew Leee177fe62015-06-05 13:01:09 -0700198 private Context mContext;
Andrew Leebf9cca22015-10-05 13:43:54 -0700199 private ContactInfoHelper mContactInfoHelper;
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700200 private ContactsPreferences mContactsPreferences;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700201 private CallTypeHelper mCallTypeHelper;
Andrew Leebf9cca22015-10-05 13:43:54 -0700202 private ContactPhotoManager mContactPhotoManager;
203 private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler;
204 private BidiFormatter mBidiFormatter = BidiFormatter.getInstance();
205 private LayoutInflater mInflater;
206 private Resources mResources;
207
208 private PhoneCallDetails mDetails;
209 protected String mNumber;
210 private Uri mVoicemailUri;
Hall Liu35e44d42015-10-14 15:19:06 -0700211 private String mPostDialDigits = "";
Andrew Leebf9cca22015-10-05 13:43:54 -0700212 private String mDisplayNumber;
213
214 private ListView mHistoryList;
Tyler Gunn18164c82014-06-09 10:20:57 -0700215 private QuickContactBadge mQuickContactBadge;
216 private TextView mCallerName;
217 private TextView mCallerNumber;
Nancy Chen19702632014-07-25 13:23:16 -0700218 private TextView mAccountLabel;
Andrew Leee177fe62015-06-05 13:01:09 -0700219 private View mCallButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700220
Andrew Leef549abc2015-10-12 12:50:55 -0700221 private TextView mBlockNumberActionItem;
Andrew Leebf9cca22015-10-05 13:43:54 -0700222 private View mEditBeforeCallActionItem;
223 private View mReportActionItem;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700224
Andrew Leebf9cca22015-10-05 13:43:54 -0700225 private Integer mBlockedNumberId;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700226
Chiao Cheng94b10b52012-08-17 16:59:12 -0700227 @Override
228 protected void onCreate(Bundle icicle) {
229 super.onCreate(icicle);
230
Andrew Leee177fe62015-06-05 13:01:09 -0700231 mContext = this;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700232 mResources = getResources();
Andrew Leebf9cca22015-10-05 13:43:54 -0700233 mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this));
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700234 mContactsPreferences = new ContactsPreferences(mContext);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700235 mCallTypeHelper = new CallTypeHelper(getResources());
Andrew Leebf9cca22015-10-05 13:43:54 -0700236 mFilteredNumberAsyncQueryHandler =
237 new FilteredNumberAsyncQueryHandler(getContentResolver());
Yorke Lee257b6f22014-07-31 14:16:44 -0700238
239 mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
240
Andrew Leebf9cca22015-10-05 13:43:54 -0700241 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
242
243 setContentView(R.layout.call_detail);
244 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
245
246 mHistoryList = (ListView) findViewById(R.id.history);
247 mHistoryList.addHeaderView(mInflater.inflate(R.layout.call_detail_header, null));
248 mHistoryList.addFooterView(
249 mInflater.inflate(R.layout.call_detail_footer, null), null, false);
Andrew Leeafdd8b92015-10-05 17:57:40 -0700250
Tyler Gunn18164c82014-06-09 10:20:57 -0700251 mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo);
252 mQuickContactBadge.setOverlay(null);
Wenyi Wang8005ef12015-11-24 15:31:41 -0800253 if (CompatUtils.hasPrioritizedMimeType()) {
254 mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
255 }
Tyler Gunn18164c82014-06-09 10:20:57 -0700256 mCallerName = (TextView) findViewById(R.id.caller_name);
257 mCallerNumber = (TextView) findViewById(R.id.caller_number);
Nancy Chen19702632014-07-25 13:23:16 -0700258 mAccountLabel = (TextView) findViewById(R.id.phone_account_label);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700259 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Yorke Lee71513982015-02-25 20:23:53 -0800260
Yorke Leee3a2d132015-09-14 16:52:08 -0700261 mCallButton = findViewById(R.id.call_back_button);
Andrew Leee177fe62015-06-05 13:01:09 -0700262 mCallButton.setOnClickListener(new View.OnClickListener() {
263 @Override
264 public void onClick(View view) {
Andrew Leeb67294e2015-10-16 12:56:28 -0700265 if (TextUtils.isEmpty(mNumber)) {
266 return;
267 }
Yorke Leec8d6e162015-09-14 18:43:27 -0700268 mContext.startActivity(
Hall Liu35e44d42015-10-14 15:19:06 -0700269 new CallIntentBuilder(getDialableNumber())
Yorke Leec8d6e162015-09-14 18:43:27 -0700270 .setCallInitiationType(LogState.INITIATION_CALL_DETAILS)
271 .build());
Andrew Leee177fe62015-06-05 13:01:09 -0700272 }
273 });
274
Andrew Leef549abc2015-10-12 12:50:55 -0700275 mBlockNumberActionItem = (TextView) findViewById(R.id.call_detail_action_block);
Andrew Leebf9cca22015-10-05 13:43:54 -0700276 mBlockNumberActionItem.setOnClickListener(this);
Andrew Leebf9cca22015-10-05 13:43:54 -0700277 mEditBeforeCallActionItem = findViewById(R.id.call_detail_action_edit_before_call);
278 mEditBeforeCallActionItem.setOnClickListener(this);
279 mReportActionItem = findViewById(R.id.call_detail_action_report);
280 mReportActionItem.setOnClickListener(this);
281
282 View copyActionItem = findViewById(R.id.call_detail_action_copy);
283 copyActionItem.setOnClickListener(this);
Yorke Lee257b6f22014-07-31 14:16:44 -0700284
Chiao Cheng94b10b52012-08-17 16:59:12 -0700285 if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
286 closeSystemDialogs();
287 }
288 }
289
290 @Override
291 public void onResume() {
292 super.onResume();
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700293 mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
Andrew Lee2f05af32015-06-09 15:59:47 -0700294 getCallDetails();
295 }
Andrew Lee7c461dc2015-05-15 10:18:45 -0700296
Yorke Lee0b458972015-09-18 12:55:30 -0700297 @Override
298 public boolean dispatchTouchEvent(MotionEvent ev) {
299 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
300 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
301 }
302 return super.dispatchTouchEvent(ev);
303 }
304
Andrew Lee2f05af32015-06-09 15:59:47 -0700305 public void getCallDetails() {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700306 CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700307 }
308
Chiao Cheng94b10b52012-08-17 16:59:12 -0700309 /**
310 * Returns the list of URIs to show.
311 * <p>
312 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
313 * a list of ids in the call log added as an extra on the URI.
314 * <p>
315 * If both are available, the data on the intent takes precedence.
316 */
317 private Uri[] getCallLogEntryUris() {
Jay Shrauner757bdd32014-05-28 10:13:40 -0700318 final Uri uri = getIntent().getData();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700319 if (uri != null) {
320 // If there is a data on the intent, it takes precedence over the extra.
321 return new Uri[]{ uri };
322 }
Jay Shrauner757bdd32014-05-28 10:13:40 -0700323 final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
324 final int numIds = ids == null ? 0 : ids.length;
325 final Uri[] uris = new Uri[numIds];
326 for (int index = 0; index < numIds; ++index) {
Yorke Lee4aece952015-05-02 22:22:54 -0700327 uris[index] = ContentUris.withAppendedId(
328 TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700329 }
330 return uris;
331 }
332
Chiao Cheng94b10b52012-08-17 16:59:12 -0700333 @Override
334 public boolean onCreateOptionsMenu(Menu menu) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700335 final MenuItem deleteMenuItem = menu.add(
336 Menu.NONE,
337 R.id.call_detail_delete_menu_item,
338 Menu.NONE,
339 R.string.call_details_delete);
340 deleteMenuItem.setIcon(R.drawable.ic_delete_24dp);
341 deleteMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
342 deleteMenuItem.setOnMenuItemClickListener(this);
343
Chiao Cheng94b10b52012-08-17 16:59:12 -0700344 return super.onCreateOptionsMenu(menu);
345 }
346
347 @Override
Andrew Lee2f05af32015-06-09 15:59:47 -0700348 public boolean onMenuItemClick(MenuItem item) {
349 switch (item.getItemId()) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700350 case R.id.call_detail_delete_menu_item:
351 if (hasVoicemail()) {
352 CallLogAsyncTaskUtil.deleteVoicemail(
353 this, mVoicemailUri, mCallLogAsyncTaskListener);
354 } else {
355 final StringBuilder callIds = new StringBuilder();
356 for (Uri callUri : getCallLogEntryUris()) {
357 if (callIds.length() != 0) {
358 callIds.append(",");
359 }
360 callIds.append(ContentUris.parseId(callUri));
Andrew Lee2f05af32015-06-09 15:59:47 -0700361 }
Andrew Lee7b127d42015-09-30 18:24:48 -0700362 CallLogAsyncTaskUtil.deleteCalls(
363 this, callIds.toString(), mCallLogAsyncTaskListener);
Andrew Lee2f05af32015-06-09 15:59:47 -0700364 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700365 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700366 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700367 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700368 }
369
Andrew Leebf9cca22015-10-05 13:43:54 -0700370 @Override
371 public void onClick(View view) {
372 switch(view.getId()) {
373 case R.id.call_detail_action_block:
Andrew Leefcecace2015-10-28 17:36:49 -0700374 BlockNumberDialogFragment.show(
Andrew Lee8d0847c2015-10-13 13:07:58 -0700375 mBlockedNumberId,
Andrew Lee8d0847c2015-10-13 13:07:58 -0700376 mNumber,
Andrew Leeb67294e2015-10-16 12:56:28 -0700377 mDetails.countryIso,
Andrew Lee8d0847c2015-10-13 13:07:58 -0700378 mDisplayNumber,
379 R.id.call_detail,
380 getFragmentManager(),
381 this);
Andrew Leebf9cca22015-10-05 13:43:54 -0700382 break;
383 case R.id.call_detail_action_copy:
384 ClipboardUtils.copyText(mContext, null, mNumber, true);
385 break;
386 case R.id.call_detail_action_edit_before_call:
Hall Liu35e44d42015-10-14 15:19:06 -0700387 Intent dialIntent = new Intent(Intent.ACTION_DIAL,
388 CallUtil.getCallUri(getDialableNumber()));
Andrew Leebf9cca22015-10-05 13:43:54 -0700389 DialerUtils.startActivityWithErrorToast(mContext, dialIntent);
390 break;
391 default:
392 Log.wtf(TAG, "Unexpected onClick event from " + view);
393 break;
394 }
395 }
396
Andrew Lee8d0847c2015-10-13 13:07:58 -0700397 @Override
Brandon Maxwelld81cc6c2015-11-05 16:27:40 -0800398 public void onFilterNumberSuccess() {
399 Logger.logInteraction(InteractionEvent.BLOCK_NUMBER_CALL_DETAIL);
400 updateFilteredNumberChanges();
401 }
402
403 @Override
404 public void onUnfilterNumberSuccess() {
405 Logger.logInteraction(InteractionEvent.UNBLOCK_NUMBER_CALL_DETAIL);
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800406 updateFilteredNumberChanges();
Andrew Lee8d0847c2015-10-13 13:07:58 -0700407 }
408
409 @Override
410 public void onChangeFilteredNumberUndo() {
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800411 updateFilteredNumberChanges();
Andrew Lee8d0847c2015-10-13 13:07:58 -0700412 }
413
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800414 private void updateFilteredNumberChanges() {
Andrew Lee97e333c2015-10-29 17:40:27 -0700415 if (mDetails == null ||
416 !FilteredNumbersUtil.canBlockNumber(this, mNumber, mDetails.countryIso)) {
Andrew Leebf9cca22015-10-05 13:43:54 -0700417 return;
418 }
419
Andrew Lee4805ae02015-10-28 16:22:39 -0700420 final boolean success = mFilteredNumberAsyncQueryHandler.isBlockedNumber(
Andrew Leeb67294e2015-10-16 12:56:28 -0700421 new OnCheckBlockedListener() {
422 @Override
423 public void onCheckComplete(Integer id) {
424 mBlockedNumberId = id;
Andrew Leeb67294e2015-10-16 12:56:28 -0700425 updateBlockActionItem();
426 }
Andrew Lee4805ae02015-10-28 16:22:39 -0700427 }, mNumber, mDetails.countryIso);
Andrew Leeb67294e2015-10-16 12:56:28 -0700428
Andrew Lee4805ae02015-10-28 16:22:39 -0700429 if (!success) {
Andrew Leeb67294e2015-10-16 12:56:28 -0700430 updateBlockActionItem();
431 }
432 }
433
434 // Loads and displays the contact photo.
435 private void updateContactPhoto() {
436 if (mDetails == null) {
437 return;
438 }
439
Andrew Leeb67294e2015-10-16 12:56:28 -0700440 final boolean isVoicemailNumber =
441 PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber);
442 final boolean isBusiness = mContactInfoHelper.isBusiness(mDetails.sourceType);
443 int contactType = ContactPhotoManager.TYPE_DEFAULT;
444 if (isVoicemailNumber) {
445 contactType = ContactPhotoManager.TYPE_VOICEMAIL;
446 } else if (isBusiness) {
447 contactType = ContactPhotoManager.TYPE_BUSINESS;
448 }
449
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700450 final String displayName = TextUtils.isEmpty(mDetails.namePrimary)
451 ? mDetails.displayNumber : mDetails.namePrimary.toString();
Andrew Leeb67294e2015-10-16 12:56:28 -0700452 final String lookupKey = mDetails.contactUri == null
453 ? null : UriUtils.getLookupKeyFromUri(mDetails.contactUri);
454
455 final DefaultImageRequest request =
456 new DefaultImageRequest(displayName, lookupKey, contactType, true /* isCircular */);
457
458 mQuickContactBadge.assignContactUri(mDetails.contactUri);
459 mQuickContactBadge.setContentDescription(
460 mResources.getString(R.string.description_contact_details, displayName));
461
462 mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, mDetails.photoUri,
463 false /* darkTheme */, true /* isCircular */, request);
464 }
465
466 private void updateBlockActionItem() {
467 if (mBlockedNumberId == null) {
468 mBlockNumberActionItem.setText(R.string.action_block_number);
Yorke Lee516be4d2015-11-09 18:38:51 -0800469 mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds(
Andrew Leea6732f72015-10-19 22:44:06 -0700470 R.drawable.ic_call_detail_block, 0, 0, 0);
Andrew Leeb67294e2015-10-16 12:56:28 -0700471 } else {
472 mBlockNumberActionItem.setText(R.string.action_unblock_number);
Yorke Lee516be4d2015-11-09 18:38:51 -0800473 mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds(
Andrew Leea6732f72015-10-19 22:44:06 -0700474 R.drawable.ic_call_detail_unblock, 0, 0, 0);
Andrew Leeb67294e2015-10-16 12:56:28 -0700475 }
476
477 mBlockNumberActionItem.setVisibility(View.VISIBLE);
Andrew Leebf9cca22015-10-05 13:43:54 -0700478 }
479
Chiao Cheng94b10b52012-08-17 16:59:12 -0700480 private void closeSystemDialogs() {
481 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
482 }
Andrew Leebf9cca22015-10-05 13:43:54 -0700483
Hall Liu35e44d42015-10-14 15:19:06 -0700484 private String getDialableNumber() {
485 return mNumber + mPostDialDigits;
486 }
487
Andrew Leebf9cca22015-10-05 13:43:54 -0700488 @NeededForTesting
489 public boolean hasVoicemail() {
490 return mVoicemailUri != null;
491 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700492}