blob: 2aff61c4c0d010f8cbb1f63277a94de81e57df51 [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 Leebf9cca22015-10-05 13:43:54 -070058import com.android.dialer.filterednumber.FilterNumberDialogFragment;
Andrew Leeaa264472015-10-16 13:11:38 -070059import com.android.dialer.filterednumber.FilteredNumbersUtil;
60import com.android.dialer.onboard.OnboardingActivity;
Andrew Leebf9cca22015-10-05 13:43:54 -070061import com.android.dialer.util.DialerUtils;
Yorke Leee3a2d132015-09-14 16:52:08 -070062import com.android.dialer.util.IntentUtil.CallIntentBuilder;
Andrew Leed3f6a6c2015-06-25 16:53:56 -070063import com.android.dialer.util.PhoneNumberUtil;
Yorke Lee4aece952015-05-02 22:22:54 -070064import com.android.dialer.util.TelecomUtil;
Yorke Leec8d6e162015-09-14 18:43:27 -070065import com.android.incallui.Call.LogState;
Chiao Cheng94b10b52012-08-17 16:59:12 -070066
Chiao Cheng94b10b52012-08-17 16:59:12 -070067/**
68 * Displays the details of a specific call log entry.
69 * <p>
70 * This activity can be either started with the URI of a single call log entry, or with the
71 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
72 */
Nancy Chen44898ad2015-08-13 12:03:47 -070073public class CallDetailActivity extends AppCompatActivity
Andrew Leebf9cca22015-10-05 13:43:54 -070074 implements MenuItem.OnMenuItemClickListener, View.OnClickListener,
Andrew Lee8d0847c2015-10-13 13:07:58 -070075 FilterNumberDialogFragment.Callback {
Andrew Leebf9cca22015-10-05 13:43:54 -070076 private static final String TAG = CallDetailActivity.class.getSimpleName();
Chiao Cheng94b10b52012-08-17 16:59:12 -070077
Andrew Lee7c461dc2015-05-15 10:18:45 -070078 /** A long array extra containing ids of call log entries to display. */
Chiao Cheng94b10b52012-08-17 16:59:12 -070079 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
80 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
81 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
Chiao Cheng94b10b52012-08-17 16:59:12 -070082 /** If the activity was triggered from a notification. */
83 public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";
84
Yorke Lee8cd94232014-07-23 14:05:31 -070085 public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment";
86
Andrew Lee7c461dc2015-05-15 10:18:45 -070087 private CallLogAsyncTaskListener mCallLogAsyncTaskListener = new CallLogAsyncTaskListener() {
88 @Override
89 public void onDeleteCall() {
90 finish();
91 }
92
93 @Override
94 public void onDeleteVoicemail() {
95 finish();
96 }
97
98 @Override
99 public void onGetCallDetails(PhoneCallDetails[] details) {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700100 if (details == null) {
101 // Somewhere went wrong: we're going to bail out and show error to users.
Andrew Leee177fe62015-06-05 13:01:09 -0700102 Toast.makeText(mContext, R.string.toast_call_detail_error,
Andrew Lee7c461dc2015-05-15 10:18:45 -0700103 Toast.LENGTH_SHORT).show();
104 finish();
105 return;
106 }
107
Andrew Leebf9cca22015-10-05 13:43:54 -0700108 // All calls are from the same number and same contact, so pick the first detail.
109 mDetails = details[0];
Andrew Leeb67294e2015-10-16 12:56:28 -0700110 mNumber = TextUtils.isEmpty(mDetails.number) ? null : mDetails.number.toString();
Andrew Leebf9cca22015-10-05 13:43:54 -0700111 mDisplayNumber = mDetails.displayNumber;
Andrew Lee7c461dc2015-05-15 10:18:45 -0700112
Andrew Leebf9cca22015-10-05 13:43:54 -0700113 final CharSequence callLocationOrType = getNumberTypeOrLocation(mDetails);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700114
Andrew Leebf9cca22015-10-05 13:43:54 -0700115 final CharSequence displayNumber = mDetails.displayNumber;
Andrew Lee7c461dc2015-05-15 10:18:45 -0700116 final String displayNumberStr = mBidiFormatter.unicodeWrap(
117 displayNumber.toString(), TextDirectionHeuristics.LTR);
118
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700119 mDetails.nameDisplayOrder = mContactsPreferences.getDisplayOrder();
120
121 if (!TextUtils.isEmpty(mDetails.getPreferredName())) {
122 mCallerName.setText(mDetails.getPreferredName());
Andrew Lee7c461dc2015-05-15 10:18:45 -0700123 mCallerNumber.setText(callLocationOrType + " " + displayNumberStr);
124 } else {
125 mCallerName.setText(displayNumberStr);
126 if (!TextUtils.isEmpty(callLocationOrType)) {
127 mCallerNumber.setText(callLocationOrType);
128 mCallerNumber.setVisibility(View.VISIBLE);
129 } else {
130 mCallerNumber.setVisibility(View.GONE);
131 }
132 }
133
Andrew Leeb67294e2015-10-16 12:56:28 -0700134 String accountLabel =
135 PhoneAccountUtils.getAccountLabel(mContext, mDetails.accountHandle);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700136 if (!TextUtils.isEmpty(accountLabel)) {
137 mAccountLabel.setText(accountLabel);
138 mAccountLabel.setVisibility(View.VISIBLE);
139 } else {
140 mAccountLabel.setVisibility(View.GONE);
141 }
142
Andrew Leebf9cca22015-10-05 13:43:54 -0700143 final boolean canPlaceCallsTo =
144 PhoneNumberUtil.canPlaceCallsTo(mNumber, mDetails.numberPresentation);
145 mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE);
146
147 final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber);
Andrew Leeb67294e2015-10-16 12:56:28 -0700148 final boolean isVoicemailNumber =
149 PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber);
Andrew Leebf9cca22015-10-05 13:43:54 -0700150 final boolean showEditNumberBeforeCallAction =
Andrew Leeb67294e2015-10-16 12:56:28 -0700151 canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
Andrew Leebf9cca22015-10-05 13:43:54 -0700152 mEditBeforeCallActionItem.setVisibility(
153 showEditNumberBeforeCallAction ? View.VISIBLE : View.GONE);
154
155 final boolean showReportAction = mContactInfoHelper.canReportAsInvalid(
156 mDetails.sourceType, mDetails.objectId);
157 mReportActionItem.setVisibility(
158 showReportAction ? View.VISIBLE : View.GONE);
159
Andrew Lee7c461dc2015-05-15 10:18:45 -0700160 invalidateOptionsMenu();
161
Andrew Leebf9cca22015-10-05 13:43:54 -0700162 mHistoryList.setAdapter(
Andrew Leee177fe62015-06-05 13:01:09 -0700163 new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details));
Andrew Lee7c461dc2015-05-15 10:18:45 -0700164
Andrew Leeb67294e2015-10-16 12:56:28 -0700165 updatePhotoAndBlockActionItem();
Andrew Lee7c461dc2015-05-15 10:18:45 -0700166
Andrew Lee7c461dc2015-05-15 10:18:45 -0700167 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
168 }
169
170 /**
171 * Determines the location geocode text for a call, or the phone number type
172 * (if available).
173 *
174 * @param details The call details.
175 * @return The phone number type or location.
176 */
177 private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) {
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700178 if (!TextUtils.isEmpty(details.namePrimary)) {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700179 return Phone.getTypeLabel(mResources, details.numberType,
180 details.numberLabel);
181 } else {
182 return details.geocode;
183 }
184 }
185 };
186
Andrew Leee177fe62015-06-05 13:01:09 -0700187 private Context mContext;
Andrew Leebf9cca22015-10-05 13:43:54 -0700188 private ContactInfoHelper mContactInfoHelper;
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700189 private ContactsPreferences mContactsPreferences;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700190 private CallTypeHelper mCallTypeHelper;
Andrew Leebf9cca22015-10-05 13:43:54 -0700191 private ContactPhotoManager mContactPhotoManager;
192 private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler;
193 private BidiFormatter mBidiFormatter = BidiFormatter.getInstance();
194 private LayoutInflater mInflater;
195 private Resources mResources;
196
197 private PhoneCallDetails mDetails;
198 protected String mNumber;
199 private Uri mVoicemailUri;
Andrew Leebf9cca22015-10-05 13:43:54 -0700200 private String mDefaultCountryIso;
201 private String mDisplayNumber;
202
203 private ListView mHistoryList;
Tyler Gunn18164c82014-06-09 10:20:57 -0700204 private QuickContactBadge mQuickContactBadge;
205 private TextView mCallerName;
206 private TextView mCallerNumber;
Nancy Chen19702632014-07-25 13:23:16 -0700207 private TextView mAccountLabel;
Andrew Leee177fe62015-06-05 13:01:09 -0700208 private View mCallButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700209
Andrew Leef549abc2015-10-12 12:50:55 -0700210 private TextView mBlockNumberActionItem;
Andrew Leebf9cca22015-10-05 13:43:54 -0700211 private View mEditBeforeCallActionItem;
212 private View mReportActionItem;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700213
Andrew Leebf9cca22015-10-05 13:43:54 -0700214 private Integer mBlockedNumberId;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700215
Chiao Cheng94b10b52012-08-17 16:59:12 -0700216 @Override
217 protected void onCreate(Bundle icicle) {
218 super.onCreate(icicle);
219
Yorke Leef44e5172015-10-01 17:16:43 -0700220 if (OnboardingActivity.shouldStartOnboardingActivity(this)) {
221 OnboardingActivity.startOnboardingActivity(this);
222 finish();
223 }
224
Andrew Leee177fe62015-06-05 13:01:09 -0700225 mContext = this;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700226 mResources = getResources();
Andrew Leebf9cca22015-10-05 13:43:54 -0700227 mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this));
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700228 mContactsPreferences = new ContactsPreferences(mContext);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700229 mCallTypeHelper = new CallTypeHelper(getResources());
Andrew Leebf9cca22015-10-05 13:43:54 -0700230 mFilteredNumberAsyncQueryHandler =
231 new FilteredNumberAsyncQueryHandler(getContentResolver());
Yorke Lee257b6f22014-07-31 14:16:44 -0700232
233 mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
234
Andrew Leebf9cca22015-10-05 13:43:54 -0700235 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
236
237 setContentView(R.layout.call_detail);
238 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
239
240 mHistoryList = (ListView) findViewById(R.id.history);
241 mHistoryList.addHeaderView(mInflater.inflate(R.layout.call_detail_header, null));
242 mHistoryList.addFooterView(
243 mInflater.inflate(R.layout.call_detail_footer, null), null, false);
Andrew Leeafdd8b92015-10-05 17:57:40 -0700244
Tyler Gunn18164c82014-06-09 10:20:57 -0700245 mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo);
246 mQuickContactBadge.setOverlay(null);
Brian Attwell74eb4ec2015-02-25 22:31:22 -0800247 mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
Tyler Gunn18164c82014-06-09 10:20:57 -0700248 mCallerName = (TextView) findViewById(R.id.caller_name);
249 mCallerNumber = (TextView) findViewById(R.id.caller_number);
Nancy Chen19702632014-07-25 13:23:16 -0700250 mAccountLabel = (TextView) findViewById(R.id.phone_account_label);
Chiao Cheng35071c02012-10-15 18:36:24 -0700251 mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700252 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Yorke Lee71513982015-02-25 20:23:53 -0800253
Yorke Leee3a2d132015-09-14 16:52:08 -0700254 mCallButton = findViewById(R.id.call_back_button);
Andrew Leee177fe62015-06-05 13:01:09 -0700255 mCallButton.setOnClickListener(new View.OnClickListener() {
256 @Override
257 public void onClick(View view) {
Andrew Leeb67294e2015-10-16 12:56:28 -0700258 if (TextUtils.isEmpty(mNumber)) {
259 return;
260 }
Yorke Leec8d6e162015-09-14 18:43:27 -0700261 mContext.startActivity(
262 new CallIntentBuilder(mNumber)
263 .setCallInitiationType(LogState.INITIATION_CALL_DETAILS)
264 .build());
Andrew Leee177fe62015-06-05 13:01:09 -0700265 }
266 });
267
Andrew Leef549abc2015-10-12 12:50:55 -0700268 mBlockNumberActionItem = (TextView) findViewById(R.id.call_detail_action_block);
Andrew Leebf9cca22015-10-05 13:43:54 -0700269 mBlockNumberActionItem.setOnClickListener(this);
Andrew Leebf9cca22015-10-05 13:43:54 -0700270 mEditBeforeCallActionItem = findViewById(R.id.call_detail_action_edit_before_call);
271 mEditBeforeCallActionItem.setOnClickListener(this);
272 mReportActionItem = findViewById(R.id.call_detail_action_report);
273 mReportActionItem.setOnClickListener(this);
274
275 View copyActionItem = findViewById(R.id.call_detail_action_copy);
276 copyActionItem.setOnClickListener(this);
Yorke Lee257b6f22014-07-31 14:16:44 -0700277
Chiao Cheng94b10b52012-08-17 16:59:12 -0700278 if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
279 closeSystemDialogs();
280 }
281 }
282
283 @Override
284 public void onResume() {
285 super.onResume();
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700286 mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
Andrew Lee2f05af32015-06-09 15:59:47 -0700287 getCallDetails();
288 }
Andrew Lee7c461dc2015-05-15 10:18:45 -0700289
Yorke Lee0b458972015-09-18 12:55:30 -0700290 @Override
291 public boolean dispatchTouchEvent(MotionEvent ev) {
292 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
293 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
294 }
295 return super.dispatchTouchEvent(ev);
296 }
297
Andrew Lee2f05af32015-06-09 15:59:47 -0700298 public void getCallDetails() {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700299 CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700300 }
301
Chiao Cheng94b10b52012-08-17 16:59:12 -0700302 /**
303 * Returns the list of URIs to show.
304 * <p>
305 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
306 * a list of ids in the call log added as an extra on the URI.
307 * <p>
308 * If both are available, the data on the intent takes precedence.
309 */
310 private Uri[] getCallLogEntryUris() {
Jay Shrauner757bdd32014-05-28 10:13:40 -0700311 final Uri uri = getIntent().getData();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700312 if (uri != null) {
313 // If there is a data on the intent, it takes precedence over the extra.
314 return new Uri[]{ uri };
315 }
Jay Shrauner757bdd32014-05-28 10:13:40 -0700316 final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
317 final int numIds = ids == null ? 0 : ids.length;
318 final Uri[] uris = new Uri[numIds];
319 for (int index = 0; index < numIds; ++index) {
Yorke Lee4aece952015-05-02 22:22:54 -0700320 uris[index] = ContentUris.withAppendedId(
321 TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700322 }
323 return uris;
324 }
325
Chiao Cheng94b10b52012-08-17 16:59:12 -0700326 @Override
327 public boolean onCreateOptionsMenu(Menu menu) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700328 final MenuItem deleteMenuItem = menu.add(
329 Menu.NONE,
330 R.id.call_detail_delete_menu_item,
331 Menu.NONE,
332 R.string.call_details_delete);
333 deleteMenuItem.setIcon(R.drawable.ic_delete_24dp);
334 deleteMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
335 deleteMenuItem.setOnMenuItemClickListener(this);
336
Chiao Cheng94b10b52012-08-17 16:59:12 -0700337 return super.onCreateOptionsMenu(menu);
338 }
339
340 @Override
Andrew Lee2f05af32015-06-09 15:59:47 -0700341 public boolean onMenuItemClick(MenuItem item) {
342 switch (item.getItemId()) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700343 case R.id.call_detail_delete_menu_item:
344 if (hasVoicemail()) {
345 CallLogAsyncTaskUtil.deleteVoicemail(
346 this, mVoicemailUri, mCallLogAsyncTaskListener);
347 } else {
348 final StringBuilder callIds = new StringBuilder();
349 for (Uri callUri : getCallLogEntryUris()) {
350 if (callIds.length() != 0) {
351 callIds.append(",");
352 }
353 callIds.append(ContentUris.parseId(callUri));
Andrew Lee2f05af32015-06-09 15:59:47 -0700354 }
Andrew Lee7b127d42015-09-30 18:24:48 -0700355 CallLogAsyncTaskUtil.deleteCalls(
356 this, callIds.toString(), mCallLogAsyncTaskListener);
Andrew Lee2f05af32015-06-09 15:59:47 -0700357 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700358 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700359 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700360 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700361 }
362
Andrew Leebf9cca22015-10-05 13:43:54 -0700363 @Override
364 public void onClick(View view) {
365 switch(view.getId()) {
366 case R.id.call_detail_action_block:
Andrew Lee8d0847c2015-10-13 13:07:58 -0700367 FilterNumberDialogFragment.show(
368 mBlockedNumberId,
369 null /* normalizedNumber */,
370 mNumber,
Andrew Leeb67294e2015-10-16 12:56:28 -0700371 mDetails.countryIso,
Andrew Lee8d0847c2015-10-13 13:07:58 -0700372 mDisplayNumber,
373 R.id.call_detail,
374 getFragmentManager(),
375 this);
Andrew Leebf9cca22015-10-05 13:43:54 -0700376 break;
377 case R.id.call_detail_action_copy:
378 ClipboardUtils.copyText(mContext, null, mNumber, true);
379 break;
380 case R.id.call_detail_action_edit_before_call:
381 Intent dialIntent = new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber));
382 DialerUtils.startActivityWithErrorToast(mContext, dialIntent);
383 break;
384 default:
385 Log.wtf(TAG, "Unexpected onClick event from " + view);
386 break;
387 }
388 }
389
Andrew Lee8d0847c2015-10-13 13:07:58 -0700390 @Override
391 public void onChangeFilteredNumberSuccess() {
Andrew Leeb67294e2015-10-16 12:56:28 -0700392 updatePhotoAndBlockActionItem();
Andrew Lee8d0847c2015-10-13 13:07:58 -0700393 }
394
395 @Override
396 public void onChangeFilteredNumberUndo() {
Andrew Leeb67294e2015-10-16 12:56:28 -0700397 updatePhotoAndBlockActionItem();
Andrew Lee8d0847c2015-10-13 13:07:58 -0700398 }
399
Andrew Leeb67294e2015-10-16 12:56:28 -0700400 private void updatePhotoAndBlockActionItem() {
Andrew Leeaa264472015-10-16 13:11:38 -0700401 if (mDetails == null || !FilteredNumbersUtil.canBlockNumber(this, mNumber)) {
Andrew Leebf9cca22015-10-05 13:43:54 -0700402 return;
403 }
404
Andrew Leeb67294e2015-10-16 12:56:28 -0700405 boolean failed = mFilteredNumberAsyncQueryHandler.startBlockedQuery(
406 new OnCheckBlockedListener() {
407 @Override
408 public void onCheckComplete(Integer id) {
409 mBlockedNumberId = id;
Andrew Leebf9cca22015-10-05 13:43:54 -0700410
Andrew Leeb67294e2015-10-16 12:56:28 -0700411 updateContactPhoto();
412 updateBlockActionItem();
413 }
414 }, null, mNumber, mDetails.countryIso);
415
416 if (failed) {
417 updateContactPhoto();
418 updateBlockActionItem();
419 }
420 }
421
422 // Loads and displays the contact photo.
423 private void updateContactPhoto() {
424 if (mDetails == null) {
425 return;
426 }
427
428 if (mBlockedNumberId != null) {
429 mQuickContactBadge.setImageDrawable(mContext.getDrawable(R.drawable.blocked_contact));
430 return;
431 }
432
433 final boolean isVoicemailNumber =
434 PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber);
435 final boolean isBusiness = mContactInfoHelper.isBusiness(mDetails.sourceType);
436 int contactType = ContactPhotoManager.TYPE_DEFAULT;
437 if (isVoicemailNumber) {
438 contactType = ContactPhotoManager.TYPE_VOICEMAIL;
439 } else if (isBusiness) {
440 contactType = ContactPhotoManager.TYPE_BUSINESS;
441 }
442
Brandon Maxwell36aeec92015-10-23 12:01:00 -0700443 final String displayName = TextUtils.isEmpty(mDetails.namePrimary)
444 ? mDetails.displayNumber : mDetails.namePrimary.toString();
Andrew Leeb67294e2015-10-16 12:56:28 -0700445 final String lookupKey = mDetails.contactUri == null
446 ? null : UriUtils.getLookupKeyFromUri(mDetails.contactUri);
447
448 final DefaultImageRequest request =
449 new DefaultImageRequest(displayName, lookupKey, contactType, true /* isCircular */);
450
451 mQuickContactBadge.assignContactUri(mDetails.contactUri);
452 mQuickContactBadge.setContentDescription(
453 mResources.getString(R.string.description_contact_details, displayName));
454
455 mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, mDetails.photoUri,
456 false /* darkTheme */, true /* isCircular */, request);
457 }
458
459 private void updateBlockActionItem() {
460 if (mBlockedNumberId == null) {
461 mBlockNumberActionItem.setText(R.string.action_block_number);
Andrew Leea6732f72015-10-19 22:44:06 -0700462 mBlockNumberActionItem.setCompoundDrawablesWithIntrinsicBounds(
463 R.drawable.ic_call_detail_block, 0, 0, 0);
Andrew Leeb67294e2015-10-16 12:56:28 -0700464 } else {
465 mBlockNumberActionItem.setText(R.string.action_unblock_number);
Andrew Leea6732f72015-10-19 22:44:06 -0700466 mBlockNumberActionItem.setCompoundDrawablesWithIntrinsicBounds(
467 R.drawable.ic_call_detail_unblock, 0, 0, 0);
Andrew Leeb67294e2015-10-16 12:56:28 -0700468 }
469
470 mBlockNumberActionItem.setVisibility(View.VISIBLE);
Andrew Leebf9cca22015-10-05 13:43:54 -0700471 }
472
Chiao Cheng94b10b52012-08-17 16:59:12 -0700473 private void closeSystemDialogs() {
474 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
475 }
Andrew Leebf9cca22015-10-05 13:43:54 -0700476
477 @NeededForTesting
478 public boolean hasVoicemail() {
479 return mVoicemailUri != null;
480 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700481}