blob: 690b3e10afeab732bba9af49458407dbadecfe94 [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.DefaultImageRequest;
44import com.android.contacts.common.ContactPhotoManager;
45import 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.CallLogAsyncTaskListener;
52import com.android.dialer.calllog.CallLogAsyncTaskUtil;
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 Leebf9cca22015-10-05 13:43:54 -070056import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener;
Andrew Leeaa264472015-10-16 13:11:38 -070057import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
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;
Andrew Leebf9cca22015-10-05 13:43:54 -070060import com.android.dialer.util.DialerUtils;
Yorke Leee3a2d132015-09-14 16:52:08 -070061import com.android.dialer.util.IntentUtil.CallIntentBuilder;
Andrew Leed3f6a6c2015-06-25 16:53:56 -070062import com.android.dialer.util.PhoneNumberUtil;
Yorke Lee4aece952015-05-02 22:22:54 -070063import com.android.dialer.util.TelecomUtil;
Yorke Leec8d6e162015-09-14 18:43:27 -070064import com.android.incallui.Call.LogState;
Chiao Cheng94b10b52012-08-17 16:59:12 -070065
Chiao Cheng94b10b52012-08-17 16:59:12 -070066/**
67 * Displays the details of a specific call log entry.
68 * <p>
69 * This activity can be either started with the URI of a single call log entry, or with the
70 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
71 */
Nancy Chen44898ad2015-08-13 12:03:47 -070072public class CallDetailActivity extends AppCompatActivity
Andrew Leebf9cca22015-10-05 13:43:54 -070073 implements MenuItem.OnMenuItemClickListener, View.OnClickListener,
Andrew Leefcecace2015-10-28 17:36:49 -070074 BlockNumberDialogFragment.Callback {
Andrew Leebf9cca22015-10-05 13:43:54 -070075 private static final String TAG = CallDetailActivity.class.getSimpleName();
Chiao Cheng94b10b52012-08-17 16:59:12 -070076
Andrew Lee7c461dc2015-05-15 10:18:45 -070077 /** A long array extra containing ids of call log entries to display. */
Chiao Cheng94b10b52012-08-17 16:59:12 -070078 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
79 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
80 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
Chiao Cheng94b10b52012-08-17 16:59:12 -070081 /** If the activity was triggered from a notification. */
82 public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";
83
Yorke Lee8cd94232014-07-23 14:05:31 -070084 public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment";
85
Andrew Lee7c461dc2015-05-15 10:18:45 -070086 private CallLogAsyncTaskListener mCallLogAsyncTaskListener = new CallLogAsyncTaskListener() {
87 @Override
88 public void onDeleteCall() {
89 finish();
90 }
91
92 @Override
93 public void onDeleteVoicemail() {
94 finish();
95 }
96
97 @Override
98 public void onGetCallDetails(PhoneCallDetails[] details) {
Andrew Lee7c461dc2015-05-15 10:18:45 -070099 if (details == null) {
100 // Somewhere went wrong: we're going to bail out and show error to users.
Andrew Leee177fe62015-06-05 13:01:09 -0700101 Toast.makeText(mContext, R.string.toast_call_detail_error,
Andrew Lee7c461dc2015-05-15 10:18:45 -0700102 Toast.LENGTH_SHORT).show();
103 finish();
104 return;
105 }
106
Andrew Leebf9cca22015-10-05 13:43:54 -0700107 // All calls are from the same number and same contact, so pick the first detail.
108 mDetails = details[0];
Andrew Leeb67294e2015-10-16 12:56:28 -0700109 mNumber = TextUtils.isEmpty(mDetails.number) ? null : mDetails.number.toString();
Hall Liu35e44d42015-10-14 15:19:06 -0700110 mPostDialDigits = TextUtils.isEmpty(mDetails.postDialDigits)
111 ? "" : mDetails.postDialDigits;
Andrew Leebf9cca22015-10-05 13:43:54 -0700112 mDisplayNumber = mDetails.displayNumber;
Andrew Lee7c461dc2015-05-15 10:18:45 -0700113
Andrew Leebf9cca22015-10-05 13:43:54 -0700114 final CharSequence callLocationOrType = getNumberTypeOrLocation(mDetails);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700115
Hall Liu35e44d42015-10-14 15:19:06 -0700116 final CharSequence displayNumber;
117 if (!TextUtils.isEmpty(mDetails.postDialDigits)) {
118 displayNumber = mDetails.number + mDetails.postDialDigits;
119 } else {
120 displayNumber = mDetails.displayNumber;
121 }
122
Andrew Lee7c461dc2015-05-15 10:18:45 -0700123 final String displayNumberStr = mBidiFormatter.unicodeWrap(
124 displayNumber.toString(), TextDirectionHeuristics.LTR);
125
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700126 mDetails.nameDisplayOrder = mContactsPreferences.getDisplayOrder();
127
128 if (!TextUtils.isEmpty(mDetails.getPreferredName())) {
129 mCallerName.setText(mDetails.getPreferredName());
Andrew Lee7c461dc2015-05-15 10:18:45 -0700130 mCallerNumber.setText(callLocationOrType + " " + displayNumberStr);
131 } else {
132 mCallerName.setText(displayNumberStr);
133 if (!TextUtils.isEmpty(callLocationOrType)) {
134 mCallerNumber.setText(callLocationOrType);
135 mCallerNumber.setVisibility(View.VISIBLE);
136 } else {
137 mCallerNumber.setVisibility(View.GONE);
138 }
139 }
140
Andrew Leeb67294e2015-10-16 12:56:28 -0700141 String accountLabel =
142 PhoneAccountUtils.getAccountLabel(mContext, mDetails.accountHandle);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700143 if (!TextUtils.isEmpty(accountLabel)) {
144 mAccountLabel.setText(accountLabel);
145 mAccountLabel.setVisibility(View.VISIBLE);
146 } else {
147 mAccountLabel.setVisibility(View.GONE);
148 }
149
Andrew Leebf9cca22015-10-05 13:43:54 -0700150 final boolean canPlaceCallsTo =
151 PhoneNumberUtil.canPlaceCallsTo(mNumber, mDetails.numberPresentation);
152 mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE);
153
154 final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber);
Andrew Leeb67294e2015-10-16 12:56:28 -0700155 final boolean isVoicemailNumber =
156 PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber);
Andrew Leebf9cca22015-10-05 13:43:54 -0700157 final boolean showEditNumberBeforeCallAction =
Andrew Leeb67294e2015-10-16 12:56:28 -0700158 canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
Andrew Leebf9cca22015-10-05 13:43:54 -0700159 mEditBeforeCallActionItem.setVisibility(
160 showEditNumberBeforeCallAction ? View.VISIBLE : View.GONE);
161
162 final boolean showReportAction = mContactInfoHelper.canReportAsInvalid(
163 mDetails.sourceType, mDetails.objectId);
164 mReportActionItem.setVisibility(
165 showReportAction ? View.VISIBLE : View.GONE);
166
Andrew Lee7c461dc2015-05-15 10:18:45 -0700167 invalidateOptionsMenu();
168
Andrew Leebf9cca22015-10-05 13:43:54 -0700169 mHistoryList.setAdapter(
Andrew Leee177fe62015-06-05 13:01:09 -0700170 new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details));
Andrew Lee7c461dc2015-05-15 10:18:45 -0700171
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800172 updateFilteredNumberChanges();
173 updateContactPhoto();
Andrew Lee7c461dc2015-05-15 10:18:45 -0700174
Andrew Lee7c461dc2015-05-15 10:18:45 -0700175 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
176 }
177
178 /**
179 * Determines the location geocode text for a call, or the phone number type
180 * (if available).
181 *
182 * @param details The call details.
183 * @return The phone number type or location.
184 */
185 private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) {
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700186 if (!TextUtils.isEmpty(details.namePrimary)) {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700187 return Phone.getTypeLabel(mResources, details.numberType,
188 details.numberLabel);
189 } else {
190 return details.geocode;
191 }
192 }
193 };
194
Andrew Leee177fe62015-06-05 13:01:09 -0700195 private Context mContext;
Andrew Leebf9cca22015-10-05 13:43:54 -0700196 private ContactInfoHelper mContactInfoHelper;
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700197 private ContactsPreferences mContactsPreferences;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700198 private CallTypeHelper mCallTypeHelper;
Andrew Leebf9cca22015-10-05 13:43:54 -0700199 private ContactPhotoManager mContactPhotoManager;
200 private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler;
201 private BidiFormatter mBidiFormatter = BidiFormatter.getInstance();
202 private LayoutInflater mInflater;
203 private Resources mResources;
204
205 private PhoneCallDetails mDetails;
206 protected String mNumber;
207 private Uri mVoicemailUri;
Hall Liu35e44d42015-10-14 15:19:06 -0700208 private String mPostDialDigits = "";
Andrew Leebf9cca22015-10-05 13:43:54 -0700209 private String mDisplayNumber;
210
211 private ListView mHistoryList;
Tyler Gunn18164c82014-06-09 10:20:57 -0700212 private QuickContactBadge mQuickContactBadge;
213 private TextView mCallerName;
214 private TextView mCallerNumber;
Nancy Chen19702632014-07-25 13:23:16 -0700215 private TextView mAccountLabel;
Andrew Leee177fe62015-06-05 13:01:09 -0700216 private View mCallButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700217
Andrew Leef549abc2015-10-12 12:50:55 -0700218 private TextView mBlockNumberActionItem;
Andrew Leebf9cca22015-10-05 13:43:54 -0700219 private View mEditBeforeCallActionItem;
220 private View mReportActionItem;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700221
Andrew Leebf9cca22015-10-05 13:43:54 -0700222 private Integer mBlockedNumberId;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700223
Chiao Cheng94b10b52012-08-17 16:59:12 -0700224 @Override
225 protected void onCreate(Bundle icicle) {
226 super.onCreate(icicle);
227
Andrew Leee177fe62015-06-05 13:01:09 -0700228 mContext = this;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700229 mResources = getResources();
Andrew Leebf9cca22015-10-05 13:43:54 -0700230 mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this));
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700231 mContactsPreferences = new ContactsPreferences(mContext);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700232 mCallTypeHelper = new CallTypeHelper(getResources());
Andrew Leebf9cca22015-10-05 13:43:54 -0700233 mFilteredNumberAsyncQueryHandler =
234 new FilteredNumberAsyncQueryHandler(getContentResolver());
Yorke Lee257b6f22014-07-31 14:16:44 -0700235
236 mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
237
Andrew Leebf9cca22015-10-05 13:43:54 -0700238 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
239
240 setContentView(R.layout.call_detail);
241 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
242
243 mHistoryList = (ListView) findViewById(R.id.history);
244 mHistoryList.addHeaderView(mInflater.inflate(R.layout.call_detail_header, null));
245 mHistoryList.addFooterView(
246 mInflater.inflate(R.layout.call_detail_footer, null), null, false);
Andrew Leeafdd8b92015-10-05 17:57:40 -0700247
Tyler Gunn18164c82014-06-09 10:20:57 -0700248 mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo);
249 mQuickContactBadge.setOverlay(null);
Brian Attwell74eb4ec2015-02-25 22:31:22 -0800250 mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
Tyler Gunn18164c82014-06-09 10:20:57 -0700251 mCallerName = (TextView) findViewById(R.id.caller_name);
252 mCallerNumber = (TextView) findViewById(R.id.caller_number);
Nancy Chen19702632014-07-25 13:23:16 -0700253 mAccountLabel = (TextView) findViewById(R.id.phone_account_label);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700254 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Yorke Lee71513982015-02-25 20:23:53 -0800255
Yorke Leee3a2d132015-09-14 16:52:08 -0700256 mCallButton = findViewById(R.id.call_back_button);
Andrew Leee177fe62015-06-05 13:01:09 -0700257 mCallButton.setOnClickListener(new View.OnClickListener() {
258 @Override
259 public void onClick(View view) {
Andrew Leeb67294e2015-10-16 12:56:28 -0700260 if (TextUtils.isEmpty(mNumber)) {
261 return;
262 }
Yorke Leec8d6e162015-09-14 18:43:27 -0700263 mContext.startActivity(
Hall Liu35e44d42015-10-14 15:19:06 -0700264 new CallIntentBuilder(getDialableNumber())
Yorke Leec8d6e162015-09-14 18:43:27 -0700265 .setCallInitiationType(LogState.INITIATION_CALL_DETAILS)
266 .build());
Andrew Leee177fe62015-06-05 13:01:09 -0700267 }
268 });
269
Andrew Leef549abc2015-10-12 12:50:55 -0700270 mBlockNumberActionItem = (TextView) findViewById(R.id.call_detail_action_block);
Andrew Leebf9cca22015-10-05 13:43:54 -0700271 mBlockNumberActionItem.setOnClickListener(this);
Andrew Leebf9cca22015-10-05 13:43:54 -0700272 mEditBeforeCallActionItem = findViewById(R.id.call_detail_action_edit_before_call);
273 mEditBeforeCallActionItem.setOnClickListener(this);
274 mReportActionItem = findViewById(R.id.call_detail_action_report);
275 mReportActionItem.setOnClickListener(this);
276
277 View copyActionItem = findViewById(R.id.call_detail_action_copy);
278 copyActionItem.setOnClickListener(this);
Yorke Lee257b6f22014-07-31 14:16:44 -0700279
Chiao Cheng94b10b52012-08-17 16:59:12 -0700280 if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
281 closeSystemDialogs();
282 }
283 }
284
285 @Override
286 public void onResume() {
287 super.onResume();
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700288 mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
Andrew Lee2f05af32015-06-09 15:59:47 -0700289 getCallDetails();
290 }
Andrew Lee7c461dc2015-05-15 10:18:45 -0700291
Yorke Lee0b458972015-09-18 12:55:30 -0700292 @Override
293 public boolean dispatchTouchEvent(MotionEvent ev) {
294 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
295 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
296 }
297 return super.dispatchTouchEvent(ev);
298 }
299
Andrew Lee2f05af32015-06-09 15:59:47 -0700300 public void getCallDetails() {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700301 CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700302 }
303
Chiao Cheng94b10b52012-08-17 16:59:12 -0700304 /**
305 * Returns the list of URIs to show.
306 * <p>
307 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
308 * a list of ids in the call log added as an extra on the URI.
309 * <p>
310 * If both are available, the data on the intent takes precedence.
311 */
312 private Uri[] getCallLogEntryUris() {
Jay Shrauner757bdd32014-05-28 10:13:40 -0700313 final Uri uri = getIntent().getData();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700314 if (uri != null) {
315 // If there is a data on the intent, it takes precedence over the extra.
316 return new Uri[]{ uri };
317 }
Jay Shrauner757bdd32014-05-28 10:13:40 -0700318 final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
319 final int numIds = ids == null ? 0 : ids.length;
320 final Uri[] uris = new Uri[numIds];
321 for (int index = 0; index < numIds; ++index) {
Yorke Lee4aece952015-05-02 22:22:54 -0700322 uris[index] = ContentUris.withAppendedId(
323 TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700324 }
325 return uris;
326 }
327
Chiao Cheng94b10b52012-08-17 16:59:12 -0700328 @Override
329 public boolean onCreateOptionsMenu(Menu menu) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700330 final MenuItem deleteMenuItem = menu.add(
331 Menu.NONE,
332 R.id.call_detail_delete_menu_item,
333 Menu.NONE,
334 R.string.call_details_delete);
335 deleteMenuItem.setIcon(R.drawable.ic_delete_24dp);
336 deleteMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
337 deleteMenuItem.setOnMenuItemClickListener(this);
338
Chiao Cheng94b10b52012-08-17 16:59:12 -0700339 return super.onCreateOptionsMenu(menu);
340 }
341
342 @Override
Andrew Lee2f05af32015-06-09 15:59:47 -0700343 public boolean onMenuItemClick(MenuItem item) {
344 switch (item.getItemId()) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700345 case R.id.call_detail_delete_menu_item:
346 if (hasVoicemail()) {
347 CallLogAsyncTaskUtil.deleteVoicemail(
348 this, mVoicemailUri, mCallLogAsyncTaskListener);
349 } else {
350 final StringBuilder callIds = new StringBuilder();
351 for (Uri callUri : getCallLogEntryUris()) {
352 if (callIds.length() != 0) {
353 callIds.append(",");
354 }
355 callIds.append(ContentUris.parseId(callUri));
Andrew Lee2f05af32015-06-09 15:59:47 -0700356 }
Andrew Lee7b127d42015-09-30 18:24:48 -0700357 CallLogAsyncTaskUtil.deleteCalls(
358 this, callIds.toString(), mCallLogAsyncTaskListener);
Andrew Lee2f05af32015-06-09 15:59:47 -0700359 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700360 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700361 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700362 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700363 }
364
Andrew Leebf9cca22015-10-05 13:43:54 -0700365 @Override
366 public void onClick(View view) {
367 switch(view.getId()) {
368 case R.id.call_detail_action_block:
Andrew Leefcecace2015-10-28 17:36:49 -0700369 BlockNumberDialogFragment.show(
Ta-wei Yena5437e62015-11-05 14:13:12 -0800370 this,
Andrew Lee8d0847c2015-10-13 13:07:58 -0700371 mBlockedNumberId,
Andrew Lee8d0847c2015-10-13 13:07:58 -0700372 mNumber,
Andrew Leeb67294e2015-10-16 12:56:28 -0700373 mDetails.countryIso,
Andrew Lee8d0847c2015-10-13 13:07:58 -0700374 mDisplayNumber,
375 R.id.call_detail,
376 getFragmentManager(),
377 this);
Andrew Leebf9cca22015-10-05 13:43:54 -0700378 break;
379 case R.id.call_detail_action_copy:
380 ClipboardUtils.copyText(mContext, null, mNumber, true);
381 break;
382 case R.id.call_detail_action_edit_before_call:
Hall Liu35e44d42015-10-14 15:19:06 -0700383 Intent dialIntent = new Intent(Intent.ACTION_DIAL,
384 CallUtil.getCallUri(getDialableNumber()));
Andrew Leebf9cca22015-10-05 13:43:54 -0700385 DialerUtils.startActivityWithErrorToast(mContext, dialIntent);
386 break;
387 default:
388 Log.wtf(TAG, "Unexpected onClick event from " + view);
389 break;
390 }
391 }
392
Andrew Lee8d0847c2015-10-13 13:07:58 -0700393 @Override
394 public void onChangeFilteredNumberSuccess() {
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800395 updateFilteredNumberChanges();
Andrew Lee8d0847c2015-10-13 13:07:58 -0700396 }
397
398 @Override
399 public void onChangeFilteredNumberUndo() {
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800400 updateFilteredNumberChanges();
Andrew Lee8d0847c2015-10-13 13:07:58 -0700401 }
402
Ta-wei Yen0bdadcc2015-11-03 14:37:44 -0800403 private void updateFilteredNumberChanges() {
Andrew Lee97e333c2015-10-29 17:40:27 -0700404 if (mDetails == null ||
405 !FilteredNumbersUtil.canBlockNumber(this, mNumber, mDetails.countryIso)) {
Andrew Leebf9cca22015-10-05 13:43:54 -0700406 return;
407 }
408
Andrew Lee4805ae02015-10-28 16:22:39 -0700409 final boolean success = mFilteredNumberAsyncQueryHandler.isBlockedNumber(
Andrew Leeb67294e2015-10-16 12:56:28 -0700410 new OnCheckBlockedListener() {
411 @Override
412 public void onCheckComplete(Integer id) {
413 mBlockedNumberId = id;
Andrew Leeb67294e2015-10-16 12:56:28 -0700414 updateBlockActionItem();
415 }
Andrew Lee4805ae02015-10-28 16:22:39 -0700416 }, mNumber, mDetails.countryIso);
Andrew Leeb67294e2015-10-16 12:56:28 -0700417
Andrew Lee4805ae02015-10-28 16:22:39 -0700418 if (!success) {
Andrew Leeb67294e2015-10-16 12:56:28 -0700419 updateBlockActionItem();
420 }
421 }
422
423 // Loads and displays the contact photo.
424 private void updateContactPhoto() {
425 if (mDetails == null) {
426 return;
427 }
428
Andrew Leeb67294e2015-10-16 12:56:28 -0700429 final boolean isVoicemailNumber =
430 PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber);
431 final boolean isBusiness = mContactInfoHelper.isBusiness(mDetails.sourceType);
432 int contactType = ContactPhotoManager.TYPE_DEFAULT;
433 if (isVoicemailNumber) {
434 contactType = ContactPhotoManager.TYPE_VOICEMAIL;
435 } else if (isBusiness) {
436 contactType = ContactPhotoManager.TYPE_BUSINESS;
437 }
438
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700439 final String displayName = TextUtils.isEmpty(mDetails.namePrimary)
440 ? mDetails.displayNumber : mDetails.namePrimary.toString();
Andrew Leeb67294e2015-10-16 12:56:28 -0700441 final String lookupKey = mDetails.contactUri == null
442 ? null : UriUtils.getLookupKeyFromUri(mDetails.contactUri);
443
444 final DefaultImageRequest request =
445 new DefaultImageRequest(displayName, lookupKey, contactType, true /* isCircular */);
446
447 mQuickContactBadge.assignContactUri(mDetails.contactUri);
448 mQuickContactBadge.setContentDescription(
449 mResources.getString(R.string.description_contact_details, displayName));
450
451 mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, mDetails.photoUri,
452 false /* darkTheme */, true /* isCircular */, request);
453 }
454
455 private void updateBlockActionItem() {
456 if (mBlockedNumberId == null) {
457 mBlockNumberActionItem.setText(R.string.action_block_number);
Yorke Lee516be4d2015-11-09 18:38:51 -0800458 mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds(
Andrew Leea6732f72015-10-19 22:44:06 -0700459 R.drawable.ic_call_detail_block, 0, 0, 0);
Andrew Leeb67294e2015-10-16 12:56:28 -0700460 } else {
461 mBlockNumberActionItem.setText(R.string.action_unblock_number);
Yorke Lee516be4d2015-11-09 18:38:51 -0800462 mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds(
Andrew Leea6732f72015-10-19 22:44:06 -0700463 R.drawable.ic_call_detail_unblock, 0, 0, 0);
Andrew Leeb67294e2015-10-16 12:56:28 -0700464 }
465
466 mBlockNumberActionItem.setVisibility(View.VISIBLE);
Andrew Leebf9cca22015-10-05 13:43:54 -0700467 }
468
Chiao Cheng94b10b52012-08-17 16:59:12 -0700469 private void closeSystemDialogs() {
470 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
471 }
Andrew Leebf9cca22015-10-05 13:43:54 -0700472
Hall Liu35e44d42015-10-14 15:19:06 -0700473 private String getDialableNumber() {
474 return mNumber + mPostDialDigits;
475 }
476
Andrew Leebf9cca22015-10-05 13:43:54 -0700477 @NeededForTesting
478 public boolean hasVoicemail() {
479 return mVoicemailUri != null;
480 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700481}