blob: 34e49a99b213683e015f8234d77a45f56c0bfa75 [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;
46import com.android.contacts.common.interactions.TouchPointManager;
Brandon Maxwell36aeec92015-10-23 12:01:00 -070047import com.android.contacts.common.preference.ContactsPreferences;
Andrew Lee7b127d42015-09-30 18:24:48 -070048import com.android.contacts.common.testing.NeededForTesting;
Tyler Gunn18b4a2e2015-08-05 08:18:37 -070049import com.android.contacts.common.util.UriUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070050import com.android.dialer.calllog.CallDetailHistoryAdapter;
Andrew Lee7c461dc2015-05-15 10:18:45 -070051import com.android.dialer.calllog.CallLogAsyncTaskUtil;
Ta-wei Yen862822f2015-11-09 11:47:45 -080052import com.android.dialer.calllog.CallLogAsyncTaskUtil.CallLogAsyncTaskListener;
Chiao Cheng94b10b52012-08-17 16:59:12 -070053import com.android.dialer.calllog.CallTypeHelper;
Chiao Cheng94b10b52012-08-17 16:59:12 -070054import com.android.dialer.calllog.ContactInfoHelper;
Nancy Chenb2eebaf2014-07-21 13:41:36 -070055import com.android.dialer.calllog.PhoneAccountUtils;
Andrew Leeaa264472015-10-16 13:11:38 -070056import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
Ta-wei Yen862822f2015-11-09 11:47:45 -080057import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener;
Andrew Leefcecace2015-10-28 17:36:49 -070058import com.android.dialer.filterednumber.BlockNumberDialogFragment;
Andrew Leeaa264472015-10-16 13:11:38 -070059import com.android.dialer.filterednumber.FilteredNumbersUtil;
Brandon Maxwelld81cc6c2015-11-05 16:27:40 -080060import com.android.dialer.logging.InteractionEvent;
61import com.android.dialer.logging.Logger;
Andrew Leebf9cca22015-10-05 13:43:54 -070062import com.android.dialer.util.DialerUtils;
Yorke Leee3a2d132015-09-14 16:52:08 -070063import com.android.dialer.util.IntentUtil.CallIntentBuilder;
Andrew Leed3f6a6c2015-06-25 16:53:56 -070064import com.android.dialer.util.PhoneNumberUtil;
Yorke Lee4aece952015-05-02 22:22:54 -070065import com.android.dialer.util.TelecomUtil;
Yorke Leec8d6e162015-09-14 18:43:27 -070066import com.android.incallui.Call.LogState;
Chiao Cheng94b10b52012-08-17 16:59:12 -070067
Chiao Cheng94b10b52012-08-17 16:59:12 -070068/**
69 * Displays the details of a specific call log entry.
70 * <p>
71 * This activity can be either started with the URI of a single call log entry, or with the
72 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
73 */
Nancy Chen44898ad2015-08-13 12:03:47 -070074public class CallDetailActivity extends AppCompatActivity
Andrew Leebf9cca22015-10-05 13:43:54 -070075 implements MenuItem.OnMenuItemClickListener, View.OnClickListener,
Andrew Leefcecace2015-10-28 17:36:49 -070076 BlockNumberDialogFragment.Callback {
Andrew Leebf9cca22015-10-05 13:43:54 -070077 private static final String TAG = CallDetailActivity.class.getSimpleName();
Chiao Cheng94b10b52012-08-17 16:59:12 -070078
Andrew Lee7c461dc2015-05-15 10:18:45 -070079 /** A long array extra containing ids of call log entries to display. */
Chiao Cheng94b10b52012-08-17 16:59:12 -070080 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
81 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
82 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
Chiao Cheng94b10b52012-08-17 16:59:12 -070083 /** If the activity was triggered from a notification. */
84 public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";
85
Yorke Lee8cd94232014-07-23 14:05:31 -070086 public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment";
87
Andrew Lee7c461dc2015-05-15 10:18:45 -070088 private CallLogAsyncTaskListener mCallLogAsyncTaskListener = new CallLogAsyncTaskListener() {
89 @Override
90 public void onDeleteCall() {
91 finish();
92 }
93
94 @Override
95 public void onDeleteVoicemail() {
96 finish();
97 }
98
99 @Override
100 public void onGetCallDetails(PhoneCallDetails[] details) {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700101 if (details == null) {
102 // Somewhere went wrong: we're going to bail out and show error to users.
Andrew Leee177fe62015-06-05 13:01:09 -0700103 Toast.makeText(mContext, R.string.toast_call_detail_error,
Andrew Lee7c461dc2015-05-15 10:18:45 -0700104 Toast.LENGTH_SHORT).show();
105 finish();
106 return;
107 }
108
Andrew Leebf9cca22015-10-05 13:43:54 -0700109 // All calls are from the same number and same contact, so pick the first detail.
110 mDetails = details[0];
Andrew Leeb67294e2015-10-16 12:56:28 -0700111 mNumber = TextUtils.isEmpty(mDetails.number) ? null : mDetails.number.toString();
Hall Liu35e44d42015-10-14 15:19:06 -0700112 mPostDialDigits = TextUtils.isEmpty(mDetails.postDialDigits)
113 ? "" : mDetails.postDialDigits;
Andrew Leebf9cca22015-10-05 13:43:54 -0700114 mDisplayNumber = mDetails.displayNumber;
Andrew Lee7c461dc2015-05-15 10:18:45 -0700115
Andrew Leebf9cca22015-10-05 13:43:54 -0700116 final CharSequence callLocationOrType = getNumberTypeOrLocation(mDetails);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700117
Hall Liu35e44d42015-10-14 15:19:06 -0700118 final CharSequence displayNumber;
119 if (!TextUtils.isEmpty(mDetails.postDialDigits)) {
120 displayNumber = mDetails.number + mDetails.postDialDigits;
121 } else {
122 displayNumber = mDetails.displayNumber;
123 }
124
Andrew Lee7c461dc2015-05-15 10:18:45 -0700125 final String displayNumberStr = mBidiFormatter.unicodeWrap(
126 displayNumber.toString(), TextDirectionHeuristics.LTR);
127
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700128 mDetails.nameDisplayOrder = mContactsPreferences.getDisplayOrder();
129
130 if (!TextUtils.isEmpty(mDetails.getPreferredName())) {
131 mCallerName.setText(mDetails.getPreferredName());
Andrew Lee7c461dc2015-05-15 10:18:45 -0700132 mCallerNumber.setText(callLocationOrType + " " + displayNumberStr);
133 } else {
134 mCallerName.setText(displayNumberStr);
135 if (!TextUtils.isEmpty(callLocationOrType)) {
136 mCallerNumber.setText(callLocationOrType);
137 mCallerNumber.setVisibility(View.VISIBLE);
138 } else {
139 mCallerNumber.setVisibility(View.GONE);
140 }
141 }
142
Andrew Leeb67294e2015-10-16 12:56:28 -0700143 String accountLabel =
144 PhoneAccountUtils.getAccountLabel(mContext, mDetails.accountHandle);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700145 if (!TextUtils.isEmpty(accountLabel)) {
146 mAccountLabel.setText(accountLabel);
147 mAccountLabel.setVisibility(View.VISIBLE);
148 } else {
149 mAccountLabel.setVisibility(View.GONE);
150 }
151
Andrew Leebf9cca22015-10-05 13:43:54 -0700152 final boolean canPlaceCallsTo =
153 PhoneNumberUtil.canPlaceCallsTo(mNumber, mDetails.numberPresentation);
154 mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE);
155
156 final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber);
Andrew Leeb67294e2015-10-16 12:56:28 -0700157 final boolean isVoicemailNumber =
158 PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber);
Andrew Leebf9cca22015-10-05 13:43:54 -0700159 final boolean showEditNumberBeforeCallAction =
Andrew Leeb67294e2015-10-16 12:56:28 -0700160 canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
Andrew Leebf9cca22015-10-05 13:43:54 -0700161 mEditBeforeCallActionItem.setVisibility(
162 showEditNumberBeforeCallAction ? View.VISIBLE : View.GONE);
163
164 final boolean showReportAction = mContactInfoHelper.canReportAsInvalid(
165 mDetails.sourceType, mDetails.objectId);
166 mReportActionItem.setVisibility(
167 showReportAction ? View.VISIBLE : View.GONE);
168
Andrew Lee7c461dc2015-05-15 10:18:45 -0700169 invalidateOptionsMenu();
170
Andrew Leebf9cca22015-10-05 13:43:54 -0700171 mHistoryList.setAdapter(
Andrew Leee177fe62015-06-05 13:01:09 -0700172 new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details));
Andrew Lee7c461dc2015-05-15 10:18:45 -0700173
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800174 updateFilteredNumberChanges();
175 updateContactPhoto();
Andrew Lee7c461dc2015-05-15 10:18:45 -0700176
Andrew Lee7c461dc2015-05-15 10:18:45 -0700177 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
178 }
179
180 /**
181 * Determines the location geocode text for a call, or the phone number type
182 * (if available).
183 *
184 * @param details The call details.
185 * @return The phone number type or location.
186 */
187 private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) {
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700188 if (!TextUtils.isEmpty(details.namePrimary)) {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700189 return Phone.getTypeLabel(mResources, details.numberType,
190 details.numberLabel);
191 } else {
192 return details.geocode;
193 }
194 }
195 };
196
Andrew Leee177fe62015-06-05 13:01:09 -0700197 private Context mContext;
Andrew Leebf9cca22015-10-05 13:43:54 -0700198 private ContactInfoHelper mContactInfoHelper;
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700199 private ContactsPreferences mContactsPreferences;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700200 private CallTypeHelper mCallTypeHelper;
Andrew Leebf9cca22015-10-05 13:43:54 -0700201 private ContactPhotoManager mContactPhotoManager;
202 private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler;
203 private BidiFormatter mBidiFormatter = BidiFormatter.getInstance();
204 private LayoutInflater mInflater;
205 private Resources mResources;
206
207 private PhoneCallDetails mDetails;
208 protected String mNumber;
209 private Uri mVoicemailUri;
Hall Liu35e44d42015-10-14 15:19:06 -0700210 private String mPostDialDigits = "";
Andrew Leebf9cca22015-10-05 13:43:54 -0700211 private String mDisplayNumber;
212
213 private ListView mHistoryList;
Tyler Gunn18164c82014-06-09 10:20:57 -0700214 private QuickContactBadge mQuickContactBadge;
215 private TextView mCallerName;
216 private TextView mCallerNumber;
Nancy Chen19702632014-07-25 13:23:16 -0700217 private TextView mAccountLabel;
Andrew Leee177fe62015-06-05 13:01:09 -0700218 private View mCallButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700219
Andrew Leef549abc2015-10-12 12:50:55 -0700220 private TextView mBlockNumberActionItem;
Andrew Leebf9cca22015-10-05 13:43:54 -0700221 private View mEditBeforeCallActionItem;
222 private View mReportActionItem;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700223
Andrew Leebf9cca22015-10-05 13:43:54 -0700224 private Integer mBlockedNumberId;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700225
Chiao Cheng94b10b52012-08-17 16:59:12 -0700226 @Override
227 protected void onCreate(Bundle icicle) {
228 super.onCreate(icicle);
229
Andrew Leee177fe62015-06-05 13:01:09 -0700230 mContext = this;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700231 mResources = getResources();
Andrew Leebf9cca22015-10-05 13:43:54 -0700232 mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this));
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700233 mContactsPreferences = new ContactsPreferences(mContext);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700234 mCallTypeHelper = new CallTypeHelper(getResources());
Andrew Leebf9cca22015-10-05 13:43:54 -0700235 mFilteredNumberAsyncQueryHandler =
236 new FilteredNumberAsyncQueryHandler(getContentResolver());
Yorke Lee257b6f22014-07-31 14:16:44 -0700237
238 mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
239
Andrew Leebf9cca22015-10-05 13:43:54 -0700240 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
241
242 setContentView(R.layout.call_detail);
243 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
244
245 mHistoryList = (ListView) findViewById(R.id.history);
246 mHistoryList.addHeaderView(mInflater.inflate(R.layout.call_detail_header, null));
247 mHistoryList.addFooterView(
248 mInflater.inflate(R.layout.call_detail_footer, null), null, false);
Andrew Leeafdd8b92015-10-05 17:57:40 -0700249
Tyler Gunn18164c82014-06-09 10:20:57 -0700250 mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo);
251 mQuickContactBadge.setOverlay(null);
Brian Attwell74eb4ec2015-02-25 22:31:22 -0800252 mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
Tyler Gunn18164c82014-06-09 10:20:57 -0700253 mCallerName = (TextView) findViewById(R.id.caller_name);
254 mCallerNumber = (TextView) findViewById(R.id.caller_number);
Nancy Chen19702632014-07-25 13:23:16 -0700255 mAccountLabel = (TextView) findViewById(R.id.phone_account_label);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700256 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Yorke Lee71513982015-02-25 20:23:53 -0800257
Yorke Leee3a2d132015-09-14 16:52:08 -0700258 mCallButton = findViewById(R.id.call_back_button);
Andrew Leee177fe62015-06-05 13:01:09 -0700259 mCallButton.setOnClickListener(new View.OnClickListener() {
260 @Override
261 public void onClick(View view) {
Andrew Leeb67294e2015-10-16 12:56:28 -0700262 if (TextUtils.isEmpty(mNumber)) {
263 return;
264 }
Yorke Leec8d6e162015-09-14 18:43:27 -0700265 mContext.startActivity(
Hall Liu35e44d42015-10-14 15:19:06 -0700266 new CallIntentBuilder(getDialableNumber())
Yorke Leec8d6e162015-09-14 18:43:27 -0700267 .setCallInitiationType(LogState.INITIATION_CALL_DETAILS)
268 .build());
Andrew Leee177fe62015-06-05 13:01:09 -0700269 }
270 });
271
Andrew Leef549abc2015-10-12 12:50:55 -0700272 mBlockNumberActionItem = (TextView) findViewById(R.id.call_detail_action_block);
Andrew Leebf9cca22015-10-05 13:43:54 -0700273 mBlockNumberActionItem.setOnClickListener(this);
Andrew Leebf9cca22015-10-05 13:43:54 -0700274 mEditBeforeCallActionItem = findViewById(R.id.call_detail_action_edit_before_call);
275 mEditBeforeCallActionItem.setOnClickListener(this);
276 mReportActionItem = findViewById(R.id.call_detail_action_report);
277 mReportActionItem.setOnClickListener(this);
278
279 View copyActionItem = findViewById(R.id.call_detail_action_copy);
280 copyActionItem.setOnClickListener(this);
Yorke Lee257b6f22014-07-31 14:16:44 -0700281
Chiao Cheng94b10b52012-08-17 16:59:12 -0700282 if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
283 closeSystemDialogs();
284 }
285 }
286
287 @Override
288 public void onResume() {
289 super.onResume();
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700290 mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
Andrew Lee2f05af32015-06-09 15:59:47 -0700291 getCallDetails();
292 }
Andrew Lee7c461dc2015-05-15 10:18:45 -0700293
Yorke Lee0b458972015-09-18 12:55:30 -0700294 @Override
295 public boolean dispatchTouchEvent(MotionEvent ev) {
296 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
297 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
298 }
299 return super.dispatchTouchEvent(ev);
300 }
301
Andrew Lee2f05af32015-06-09 15:59:47 -0700302 public void getCallDetails() {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700303 CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700304 }
305
Chiao Cheng94b10b52012-08-17 16:59:12 -0700306 /**
307 * Returns the list of URIs to show.
308 * <p>
309 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
310 * a list of ids in the call log added as an extra on the URI.
311 * <p>
312 * If both are available, the data on the intent takes precedence.
313 */
314 private Uri[] getCallLogEntryUris() {
Jay Shrauner757bdd32014-05-28 10:13:40 -0700315 final Uri uri = getIntent().getData();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700316 if (uri != null) {
317 // If there is a data on the intent, it takes precedence over the extra.
318 return new Uri[]{ uri };
319 }
Jay Shrauner757bdd32014-05-28 10:13:40 -0700320 final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
321 final int numIds = ids == null ? 0 : ids.length;
322 final Uri[] uris = new Uri[numIds];
323 for (int index = 0; index < numIds; ++index) {
Yorke Lee4aece952015-05-02 22:22:54 -0700324 uris[index] = ContentUris.withAppendedId(
325 TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700326 }
327 return uris;
328 }
329
Chiao Cheng94b10b52012-08-17 16:59:12 -0700330 @Override
331 public boolean onCreateOptionsMenu(Menu menu) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700332 final MenuItem deleteMenuItem = menu.add(
333 Menu.NONE,
334 R.id.call_detail_delete_menu_item,
335 Menu.NONE,
336 R.string.call_details_delete);
337 deleteMenuItem.setIcon(R.drawable.ic_delete_24dp);
338 deleteMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
339 deleteMenuItem.setOnMenuItemClickListener(this);
340
Chiao Cheng94b10b52012-08-17 16:59:12 -0700341 return super.onCreateOptionsMenu(menu);
342 }
343
344 @Override
Andrew Lee2f05af32015-06-09 15:59:47 -0700345 public boolean onMenuItemClick(MenuItem item) {
346 switch (item.getItemId()) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700347 case R.id.call_detail_delete_menu_item:
348 if (hasVoicemail()) {
349 CallLogAsyncTaskUtil.deleteVoicemail(
350 this, mVoicemailUri, mCallLogAsyncTaskListener);
351 } else {
352 final StringBuilder callIds = new StringBuilder();
353 for (Uri callUri : getCallLogEntryUris()) {
354 if (callIds.length() != 0) {
355 callIds.append(",");
356 }
357 callIds.append(ContentUris.parseId(callUri));
Andrew Lee2f05af32015-06-09 15:59:47 -0700358 }
Andrew Lee7b127d42015-09-30 18:24:48 -0700359 CallLogAsyncTaskUtil.deleteCalls(
360 this, callIds.toString(), mCallLogAsyncTaskListener);
Andrew Lee2f05af32015-06-09 15:59:47 -0700361 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700362 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700363 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700364 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700365 }
366
Andrew Leebf9cca22015-10-05 13:43:54 -0700367 @Override
368 public void onClick(View view) {
369 switch(view.getId()) {
370 case R.id.call_detail_action_block:
Andrew Leefcecace2015-10-28 17:36:49 -0700371 BlockNumberDialogFragment.show(
Andrew Lee8d0847c2015-10-13 13:07:58 -0700372 mBlockedNumberId,
Andrew Lee8d0847c2015-10-13 13:07:58 -0700373 mNumber,
Andrew Leeb67294e2015-10-16 12:56:28 -0700374 mDetails.countryIso,
Andrew Lee8d0847c2015-10-13 13:07:58 -0700375 mDisplayNumber,
376 R.id.call_detail,
377 getFragmentManager(),
378 this);
Andrew Leebf9cca22015-10-05 13:43:54 -0700379 break;
380 case R.id.call_detail_action_copy:
381 ClipboardUtils.copyText(mContext, null, mNumber, true);
382 break;
383 case R.id.call_detail_action_edit_before_call:
Hall Liu35e44d42015-10-14 15:19:06 -0700384 Intent dialIntent = new Intent(Intent.ACTION_DIAL,
385 CallUtil.getCallUri(getDialableNumber()));
Andrew Leebf9cca22015-10-05 13:43:54 -0700386 DialerUtils.startActivityWithErrorToast(mContext, dialIntent);
387 break;
388 default:
389 Log.wtf(TAG, "Unexpected onClick event from " + view);
390 break;
391 }
392 }
393
Andrew Lee8d0847c2015-10-13 13:07:58 -0700394 @Override
Brandon Maxwelld81cc6c2015-11-05 16:27:40 -0800395 public void onFilterNumberSuccess() {
396 Logger.logInteraction(InteractionEvent.BLOCK_NUMBER_CALL_DETAIL);
397 updateFilteredNumberChanges();
398 }
399
400 @Override
401 public void onUnfilterNumberSuccess() {
402 Logger.logInteraction(InteractionEvent.UNBLOCK_NUMBER_CALL_DETAIL);
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800403 updateFilteredNumberChanges();
Andrew Lee8d0847c2015-10-13 13:07:58 -0700404 }
405
406 @Override
407 public void onChangeFilteredNumberUndo() {
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800408 updateFilteredNumberChanges();
Andrew Lee8d0847c2015-10-13 13:07:58 -0700409 }
410
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800411 private void updateFilteredNumberChanges() {
Andrew Lee97e333c2015-10-29 17:40:27 -0700412 if (mDetails == null ||
413 !FilteredNumbersUtil.canBlockNumber(this, mNumber, mDetails.countryIso)) {
Andrew Leebf9cca22015-10-05 13:43:54 -0700414 return;
415 }
416
Andrew Lee4805ae02015-10-28 16:22:39 -0700417 final boolean success = mFilteredNumberAsyncQueryHandler.isBlockedNumber(
Andrew Leeb67294e2015-10-16 12:56:28 -0700418 new OnCheckBlockedListener() {
419 @Override
420 public void onCheckComplete(Integer id) {
421 mBlockedNumberId = id;
Andrew Leeb67294e2015-10-16 12:56:28 -0700422 updateBlockActionItem();
423 }
Andrew Lee4805ae02015-10-28 16:22:39 -0700424 }, mNumber, mDetails.countryIso);
Andrew Leeb67294e2015-10-16 12:56:28 -0700425
Andrew Lee4805ae02015-10-28 16:22:39 -0700426 if (!success) {
Andrew Leeb67294e2015-10-16 12:56:28 -0700427 updateBlockActionItem();
428 }
429 }
430
431 // Loads and displays the contact photo.
432 private void updateContactPhoto() {
433 if (mDetails == null) {
434 return;
435 }
436
Andrew Leeb67294e2015-10-16 12:56:28 -0700437 final boolean isVoicemailNumber =
438 PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber);
439 final boolean isBusiness = mContactInfoHelper.isBusiness(mDetails.sourceType);
440 int contactType = ContactPhotoManager.TYPE_DEFAULT;
441 if (isVoicemailNumber) {
442 contactType = ContactPhotoManager.TYPE_VOICEMAIL;
443 } else if (isBusiness) {
444 contactType = ContactPhotoManager.TYPE_BUSINESS;
445 }
446
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700447 final String displayName = TextUtils.isEmpty(mDetails.namePrimary)
448 ? mDetails.displayNumber : mDetails.namePrimary.toString();
Andrew Leeb67294e2015-10-16 12:56:28 -0700449 final String lookupKey = mDetails.contactUri == null
450 ? null : UriUtils.getLookupKeyFromUri(mDetails.contactUri);
451
452 final DefaultImageRequest request =
453 new DefaultImageRequest(displayName, lookupKey, contactType, true /* isCircular */);
454
455 mQuickContactBadge.assignContactUri(mDetails.contactUri);
456 mQuickContactBadge.setContentDescription(
457 mResources.getString(R.string.description_contact_details, displayName));
458
459 mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, mDetails.photoUri,
460 false /* darkTheme */, true /* isCircular */, request);
461 }
462
463 private void updateBlockActionItem() {
464 if (mBlockedNumberId == null) {
465 mBlockNumberActionItem.setText(R.string.action_block_number);
Yorke Lee516be4d2015-11-09 18:38:51 -0800466 mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds(
Andrew Leea6732f72015-10-19 22:44:06 -0700467 R.drawable.ic_call_detail_block, 0, 0, 0);
Andrew Leeb67294e2015-10-16 12:56:28 -0700468 } else {
469 mBlockNumberActionItem.setText(R.string.action_unblock_number);
Yorke Lee516be4d2015-11-09 18:38:51 -0800470 mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds(
Andrew Leea6732f72015-10-19 22:44:06 -0700471 R.drawable.ic_call_detail_unblock, 0, 0, 0);
Andrew Leeb67294e2015-10-16 12:56:28 -0700472 }
473
474 mBlockNumberActionItem.setVisibility(View.VISIBLE);
Andrew Leebf9cca22015-10-05 13:43:54 -0700475 }
476
Chiao Cheng94b10b52012-08-17 16:59:12 -0700477 private void closeSystemDialogs() {
478 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
479 }
Andrew Leebf9cca22015-10-05 13:43:54 -0700480
Hall Liu35e44d42015-10-14 15:19:06 -0700481 private String getDialableNumber() {
482 return mNumber + mPostDialDigits;
483 }
484
Andrew Leebf9cca22015-10-05 13:43:54 -0700485 @NeededForTesting
486 public boolean hasVoicemail() {
487 return mVoicemailUri != null;
488 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700489}