blob: 73622bf9b4005e21edd0d8bef94de8fe5eee9daf [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;
Nancy Chene80d6222014-10-08 20:17:55 -070027import android.telecom.PhoneAccountHandle;
Andrew Lee99e8adb2014-10-02 12:27:37 -070028import android.text.BidiFormatter;
29import android.text.TextDirectionHeuristics;
Chiao Cheng94b10b52012-08-17 16:59:12 -070030import android.text.TextUtils;
Andrew Leebf9cca22015-10-05 13:43:54 -070031import android.util.Log;
Chiao Cheng94b10b52012-08-17 16:59:12 -070032import android.view.LayoutInflater;
33import android.view.Menu;
34import android.view.MenuItem;
Yorke Lee0b458972015-09-18 12:55:30 -070035import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070036import android.view.View;
Chiao Cheng94b10b52012-08-17 16:59:12 -070037import android.widget.ListView;
Tyler Gunn18164c82014-06-09 10:20:57 -070038import android.widget.QuickContactBadge;
Chiao Cheng94b10b52012-08-17 16:59:12 -070039import android.widget.TextView;
40import android.widget.Toast;
41
Brian Attwell82043242015-02-03 14:13:58 -080042import com.android.contacts.common.CallUtil;
Andrew Leebf9cca22015-10-05 13:43:54 -070043import com.android.contacts.common.ClipboardUtils;
Andrew Lee7b127d42015-09-30 18:24:48 -070044import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
45import com.android.contacts.common.ContactPhotoManager;
46import com.android.contacts.common.GeoUtil;
47import com.android.contacts.common.interactions.TouchPointManager;
48import 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;
Yorke Leef44e5172015-10-01 17:16:43 -070052import com.android.dialer.onboard.OnboardingActivity;
Andrew Lee7c461dc2015-05-15 10:18:45 -070053import com.android.dialer.calllog.CallLogAsyncTaskUtil;
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 Leebf9cca22015-10-05 13:43:54 -070057import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
58import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener;
59import com.android.dialer.filterednumber.FilterNumberDialogFragment;
60import 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,
74 FilterNumberDialogFragment.OnBlockListener,
75 FilterNumberDialogFragment.OnUndoBlockListener {
76 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];
110 mNumber = TextUtils.isEmpty(mDetails.number) ?
111 null : mDetails.number.toString();
112 mDisplayNumber = mDetails.displayNumber;
113 final int numberPresentation = mDetails.numberPresentation;
114 final Uri contactUri = mDetails.contactUri;
115 final Uri photoUri = mDetails.photoUri;
116 final PhoneAccountHandle accountHandle = mDetails.accountHandle;
Andrew Lee7c461dc2015-05-15 10:18:45 -0700117
118 // Cache the details about the phone number.
Andrew Leee177fe62015-06-05 13:01:09 -0700119 mIsVoicemailNumber =
Andrew Leed3f6a6c2015-06-25 16:53:56 -0700120 PhoneNumberUtil.isVoicemailNumber(mContext, accountHandle, mNumber);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700121
Andrew Leebf9cca22015-10-05 13:43:54 -0700122 final CharSequence callLocationOrType = getNumberTypeOrLocation(mDetails);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700123
Andrew Leebf9cca22015-10-05 13:43:54 -0700124 final CharSequence displayNumber = mDetails.displayNumber;
Andrew Lee7c461dc2015-05-15 10:18:45 -0700125 final String displayNumberStr = mBidiFormatter.unicodeWrap(
126 displayNumber.toString(), TextDirectionHeuristics.LTR);
127
Andrew Leebf9cca22015-10-05 13:43:54 -0700128 if (!TextUtils.isEmpty(mDetails.name)) {
129 mCallerName.setText(mDetails.name);
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 Leee177fe62015-06-05 13:01:09 -0700141 String accountLabel = PhoneAccountUtils.getAccountLabel(mContext, accountHandle);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700142 if (!TextUtils.isEmpty(accountLabel)) {
143 mAccountLabel.setText(accountLabel);
144 mAccountLabel.setVisibility(View.VISIBLE);
145 } else {
146 mAccountLabel.setVisibility(View.GONE);
147 }
148
Andrew Leebf9cca22015-10-05 13:43:54 -0700149 final boolean canPlaceCallsTo =
150 PhoneNumberUtil.canPlaceCallsTo(mNumber, mDetails.numberPresentation);
151 mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE);
152
153 final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber);
154 final boolean showEditNumberBeforeCallAction =
Andrew Leee177fe62015-06-05 13:01:09 -0700155 canPlaceCallsTo && !isSipNumber && !mIsVoicemailNumber;
Andrew Leebf9cca22015-10-05 13:43:54 -0700156 mEditBeforeCallActionItem.setVisibility(
157 showEditNumberBeforeCallAction ? View.VISIBLE : View.GONE);
158
159 final boolean showReportAction = mContactInfoHelper.canReportAsInvalid(
160 mDetails.sourceType, mDetails.objectId);
161 mReportActionItem.setVisibility(
162 showReportAction ? View.VISIBLE : View.GONE);
163
164 updateBlockActionItem();
Andrew Lee7c461dc2015-05-15 10:18:45 -0700165 invalidateOptionsMenu();
166
Andrew Leebf9cca22015-10-05 13:43:54 -0700167 mHistoryList.setAdapter(
Andrew Leee177fe62015-06-05 13:01:09 -0700168 new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details));
Andrew Lee7c461dc2015-05-15 10:18:45 -0700169
170 String lookupKey = contactUri == null ? null
Tyler Gunn18b4a2e2015-08-05 08:18:37 -0700171 : UriUtils.getLookupKeyFromUri(contactUri);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700172
Andrew Leebf9cca22015-10-05 13:43:54 -0700173 final boolean isBusiness = mContactInfoHelper.isBusiness(mDetails.sourceType);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700174
175 final int contactType =
Andrew Leee177fe62015-06-05 13:01:09 -0700176 mIsVoicemailNumber ? ContactPhotoManager.TYPE_VOICEMAIL :
Andrew Lee7c461dc2015-05-15 10:18:45 -0700177 isBusiness ? ContactPhotoManager.TYPE_BUSINESS :
178 ContactPhotoManager.TYPE_DEFAULT;
179
180 String nameForDefaultImage;
Andrew Leebf9cca22015-10-05 13:43:54 -0700181 if (TextUtils.isEmpty(mDetails.name)) {
182 nameForDefaultImage = mDetails.displayNumber;
Andrew Lee7c461dc2015-05-15 10:18:45 -0700183 } else {
Andrew Leebf9cca22015-10-05 13:43:54 -0700184 nameForDefaultImage = mDetails.name.toString();
Andrew Lee7c461dc2015-05-15 10:18:45 -0700185 }
186
187 loadContactPhotos(
188 contactUri, photoUri, nameForDefaultImage, lookupKey, contactType);
189 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
190 }
191
192 /**
193 * Determines the location geocode text for a call, or the phone number type
194 * (if available).
195 *
196 * @param details The call details.
197 * @return The phone number type or location.
198 */
199 private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) {
200 if (!TextUtils.isEmpty(details.name)) {
201 return Phone.getTypeLabel(mResources, details.numberType,
202 details.numberLabel);
203 } else {
204 return details.geocode;
205 }
206 }
207 };
208
Andrew Leee177fe62015-06-05 13:01:09 -0700209 private Context mContext;
Andrew Leebf9cca22015-10-05 13:43:54 -0700210 private ContactInfoHelper mContactInfoHelper;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700211 private CallTypeHelper mCallTypeHelper;
Andrew Leebf9cca22015-10-05 13:43:54 -0700212 private ContactPhotoManager mContactPhotoManager;
213 private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler;
214 private BidiFormatter mBidiFormatter = BidiFormatter.getInstance();
215 private LayoutInflater mInflater;
216 private Resources mResources;
217
218 private PhoneCallDetails mDetails;
219 protected String mNumber;
220 private Uri mVoicemailUri;
221 private boolean mIsVoicemailNumber;
222 private String mDefaultCountryIso;
223 private String mDisplayNumber;
224
225 private ListView mHistoryList;
Tyler Gunn18164c82014-06-09 10:20:57 -0700226 private QuickContactBadge mQuickContactBadge;
227 private TextView mCallerName;
228 private TextView mCallerNumber;
Nancy Chen19702632014-07-25 13:23:16 -0700229 private TextView mAccountLabel;
Andrew Leee177fe62015-06-05 13:01:09 -0700230 private View mCallButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700231
Andrew Leebf9cca22015-10-05 13:43:54 -0700232 private View mBlockNumberActionItem;
233 private TextView mBlockNumberActionItemText;
234 private View mEditBeforeCallActionItem;
235 private View mReportActionItem;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700236
Andrew Leebf9cca22015-10-05 13:43:54 -0700237 private Integer mBlockedNumberId;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700238
Chiao Cheng94b10b52012-08-17 16:59:12 -0700239 @Override
240 protected void onCreate(Bundle icicle) {
241 super.onCreate(icicle);
242
Yorke Leef44e5172015-10-01 17:16:43 -0700243 if (OnboardingActivity.shouldStartOnboardingActivity(this)) {
244 OnboardingActivity.startOnboardingActivity(this);
245 finish();
246 }
247
Andrew Leee177fe62015-06-05 13:01:09 -0700248 mContext = this;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700249 mResources = getResources();
Andrew Leebf9cca22015-10-05 13:43:54 -0700250 mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this));
Chiao Cheng94b10b52012-08-17 16:59:12 -0700251 mCallTypeHelper = new CallTypeHelper(getResources());
Andrew Leebf9cca22015-10-05 13:43:54 -0700252 mFilteredNumberAsyncQueryHandler =
253 new FilteredNumberAsyncQueryHandler(getContentResolver());
Yorke Lee257b6f22014-07-31 14:16:44 -0700254
255 mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
256
Andrew Leebf9cca22015-10-05 13:43:54 -0700257 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
258
259 setContentView(R.layout.call_detail);
260 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
261
262 mHistoryList = (ListView) findViewById(R.id.history);
263 mHistoryList.addHeaderView(mInflater.inflate(R.layout.call_detail_header, null));
264 mHistoryList.addFooterView(
265 mInflater.inflate(R.layout.call_detail_footer, null), null, false);
Andrew Leeafdd8b92015-10-05 17:57:40 -0700266
Tyler Gunn18164c82014-06-09 10:20:57 -0700267 mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo);
268 mQuickContactBadge.setOverlay(null);
Brian Attwell74eb4ec2015-02-25 22:31:22 -0800269 mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
Tyler Gunn18164c82014-06-09 10:20:57 -0700270 mCallerName = (TextView) findViewById(R.id.caller_name);
271 mCallerNumber = (TextView) findViewById(R.id.caller_number);
Nancy Chen19702632014-07-25 13:23:16 -0700272 mAccountLabel = (TextView) findViewById(R.id.phone_account_label);
Chiao Cheng35071c02012-10-15 18:36:24 -0700273 mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700274 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Yorke Lee71513982015-02-25 20:23:53 -0800275
Yorke Leee3a2d132015-09-14 16:52:08 -0700276 mCallButton = findViewById(R.id.call_back_button);
Andrew Leee177fe62015-06-05 13:01:09 -0700277 mCallButton.setOnClickListener(new View.OnClickListener() {
278 @Override
279 public void onClick(View view) {
Yorke Leec8d6e162015-09-14 18:43:27 -0700280 mContext.startActivity(
281 new CallIntentBuilder(mNumber)
282 .setCallInitiationType(LogState.INITIATION_CALL_DETAILS)
283 .build());
Andrew Leee177fe62015-06-05 13:01:09 -0700284 }
285 });
286
Andrew Leebf9cca22015-10-05 13:43:54 -0700287 mBlockNumberActionItem = findViewById(R.id.call_detail_action_block);
288 mBlockNumberActionItem.setOnClickListener(this);
289 mBlockNumberActionItemText = (TextView) findViewById(R.id.call_detail_action_block_text);
290 mEditBeforeCallActionItem = findViewById(R.id.call_detail_action_edit_before_call);
291 mEditBeforeCallActionItem.setOnClickListener(this);
292 mReportActionItem = findViewById(R.id.call_detail_action_report);
293 mReportActionItem.setOnClickListener(this);
294
295 View copyActionItem = findViewById(R.id.call_detail_action_copy);
296 copyActionItem.setOnClickListener(this);
Yorke Lee257b6f22014-07-31 14:16:44 -0700297
Chiao Cheng94b10b52012-08-17 16:59:12 -0700298 if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
299 closeSystemDialogs();
300 }
301 }
302
303 @Override
304 public void onResume() {
305 super.onResume();
Andrew Lee2f05af32015-06-09 15:59:47 -0700306 getCallDetails();
307 }
Andrew Lee7c461dc2015-05-15 10:18:45 -0700308
Yorke Lee0b458972015-09-18 12:55:30 -0700309 @Override
Andrew Leebf9cca22015-10-05 13:43:54 -0700310 public void onBlockComplete(Uri uri) {
311 updateBlockActionItem();
312 }
313
314 @Override
315 public void onUndoBlockComplete() {
316 updateBlockActionItem();
317 }
318
319 @Override
Yorke Lee0b458972015-09-18 12:55:30 -0700320 public boolean dispatchTouchEvent(MotionEvent ev) {
321 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
322 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
323 }
324 return super.dispatchTouchEvent(ev);
325 }
326
Andrew Lee2f05af32015-06-09 15:59:47 -0700327 public void getCallDetails() {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700328 CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700329 }
330
Chiao Cheng94b10b52012-08-17 16:59:12 -0700331 /**
332 * Returns the list of URIs to show.
333 * <p>
334 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
335 * a list of ids in the call log added as an extra on the URI.
336 * <p>
337 * If both are available, the data on the intent takes precedence.
338 */
339 private Uri[] getCallLogEntryUris() {
Jay Shrauner757bdd32014-05-28 10:13:40 -0700340 final Uri uri = getIntent().getData();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700341 if (uri != null) {
342 // If there is a data on the intent, it takes precedence over the extra.
343 return new Uri[]{ uri };
344 }
Jay Shrauner757bdd32014-05-28 10:13:40 -0700345 final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
346 final int numIds = ids == null ? 0 : ids.length;
347 final Uri[] uris = new Uri[numIds];
348 for (int index = 0; index < numIds; ++index) {
Yorke Lee4aece952015-05-02 22:22:54 -0700349 uris[index] = ContentUris.withAppendedId(
350 TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700351 }
352 return uris;
353 }
354
Chiao Cheng94b10b52012-08-17 16:59:12 -0700355 /** Load the contact photos and places them in the corresponding views. */
Tyler Gunn18164c82014-06-09 10:20:57 -0700356 private void loadContactPhotos(Uri contactUri, Uri photoUri, String displayName,
357 String lookupKey, int contactType) {
358
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800359 final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey,
Tyler Gunn18164c82014-06-09 10:20:57 -0700360 contactType, true /* isCircular */);
361
362 mQuickContactBadge.assignContactUri(contactUri);
363 mQuickContactBadge.setContentDescription(
364 mResources.getString(R.string.description_contact_details, displayName));
365
366 mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, photoUri,
367 false /* darkTheme */, true /* isCircular */, request);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700368 }
369
Chiao Cheng94b10b52012-08-17 16:59:12 -0700370 @Override
371 public boolean onCreateOptionsMenu(Menu menu) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700372 final MenuItem deleteMenuItem = menu.add(
373 Menu.NONE,
374 R.id.call_detail_delete_menu_item,
375 Menu.NONE,
376 R.string.call_details_delete);
377 deleteMenuItem.setIcon(R.drawable.ic_delete_24dp);
378 deleteMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
379 deleteMenuItem.setOnMenuItemClickListener(this);
380
Chiao Cheng94b10b52012-08-17 16:59:12 -0700381 return super.onCreateOptionsMenu(menu);
382 }
383
384 @Override
Andrew Lee2f05af32015-06-09 15:59:47 -0700385 public boolean onMenuItemClick(MenuItem item) {
386 switch (item.getItemId()) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700387 case R.id.call_detail_delete_menu_item:
388 if (hasVoicemail()) {
389 CallLogAsyncTaskUtil.deleteVoicemail(
390 this, mVoicemailUri, mCallLogAsyncTaskListener);
391 } else {
392 final StringBuilder callIds = new StringBuilder();
393 for (Uri callUri : getCallLogEntryUris()) {
394 if (callIds.length() != 0) {
395 callIds.append(",");
396 }
397 callIds.append(ContentUris.parseId(callUri));
Andrew Lee2f05af32015-06-09 15:59:47 -0700398 }
Andrew Lee7b127d42015-09-30 18:24:48 -0700399 CallLogAsyncTaskUtil.deleteCalls(
400 this, callIds.toString(), mCallLogAsyncTaskListener);
Andrew Lee2f05af32015-06-09 15:59:47 -0700401 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700402 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700403 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700404 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700405 }
406
Andrew Leebf9cca22015-10-05 13:43:54 -0700407 @Override
408 public void onClick(View view) {
409 switch(view.getId()) {
410 case R.id.call_detail_action_block:
411 // TODO: Use helper, this code is repeated in several places.
412 FilterNumberDialogFragment newFragment =
413 FilterNumberDialogFragment.newInstance(
414 mBlockedNumberId, null, mNumber, null, mDisplayNumber);
415 // TODO: Cleanup this listener pattern. This only works correctly for undoing
416 // blocking, not undoing unblocking.
417 newFragment.setOnBlockListener(this);
418 newFragment.setOnUndoBlockListener(this);
419 newFragment.setParentView(findViewById(R.id.call_detail));
420 newFragment.show(
421 getFragmentManager(), FilterNumberDialogFragment.BLOCK_DIALOG_FRAGMENT);
422 break;
423 case R.id.call_detail_action_copy:
424 ClipboardUtils.copyText(mContext, null, mNumber, true);
425 break;
426 case R.id.call_detail_action_edit_before_call:
427 Intent dialIntent = new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber));
428 DialerUtils.startActivityWithErrorToast(mContext, dialIntent);
429 break;
430 default:
431 Log.wtf(TAG, "Unexpected onClick event from " + view);
432 break;
433 }
434 }
435
436 private void updateBlockActionItem() {
437 if (mDetails == null) {
438 return;
439 }
440
441 mFilteredNumberAsyncQueryHandler.startBlockedQuery(new OnCheckBlockedListener() {
442 @Override
443 public void onCheckComplete(Integer id) {
444 mBlockedNumberId = id;
445 if (mBlockedNumberId == null) {
446 mBlockNumberActionItemText.setText(R.string.action_block_number);
447 } else {
448 mBlockNumberActionItemText.setText(R.string.action_unblock_number);
449 }
450
451 mBlockNumberActionItem.setVisibility(View.VISIBLE);
452 }
453 }, null, mNumber, mDetails.countryIso);
454 }
455
Chiao Cheng94b10b52012-08-17 16:59:12 -0700456 private void closeSystemDialogs() {
457 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
458 }
Andrew Leebf9cca22015-10-05 13:43:54 -0700459
460 @NeededForTesting
461 public boolean hasVoicemail() {
462 return mVoicemailUri != null;
463 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700464}