blob: a43ec3edcfd0f9c7105cb14e6f17b86573ffe7c2 [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;
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 Lee7b127d42015-09-30 18:24:48 -070042import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
43import com.android.contacts.common.ContactPhotoManager;
44import com.android.contacts.common.GeoUtil;
45import com.android.contacts.common.interactions.TouchPointManager;
46import com.android.contacts.common.testing.NeededForTesting;
Tyler Gunn18b4a2e2015-08-05 08:18:37 -070047import com.android.contacts.common.util.UriUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import com.android.dialer.calllog.CallDetailHistoryAdapter;
Andrew Lee7c461dc2015-05-15 10:18:45 -070049import com.android.dialer.calllog.CallLogAsyncTaskUtil.CallLogAsyncTaskListener;
50import com.android.dialer.calllog.CallLogAsyncTaskUtil;
Chiao Cheng94b10b52012-08-17 16:59:12 -070051import com.android.dialer.calllog.CallTypeHelper;
Chiao Cheng94b10b52012-08-17 16:59:12 -070052import com.android.dialer.calllog.ContactInfoHelper;
Nancy Chenb2eebaf2014-07-21 13:41:36 -070053import com.android.dialer.calllog.PhoneAccountUtils;
Yorke Leee3a2d132015-09-14 16:52:08 -070054import com.android.dialer.util.IntentUtil.CallIntentBuilder;
Andrew Leed3f6a6c2015-06-25 16:53:56 -070055import com.android.dialer.util.PhoneNumberUtil;
Yorke Lee4aece952015-05-02 22:22:54 -070056import com.android.dialer.util.TelecomUtil;
Yorke Leec8d6e162015-09-14 18:43:27 -070057import com.android.incallui.Call.LogState;
Chiao Cheng94b10b52012-08-17 16:59:12 -070058
Chiao Cheng94b10b52012-08-17 16:59:12 -070059/**
60 * Displays the details of a specific call log entry.
61 * <p>
62 * This activity can be either started with the URI of a single call log entry, or with the
63 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
64 */
Nancy Chen44898ad2015-08-13 12:03:47 -070065public class CallDetailActivity extends AppCompatActivity
Andrew Lee2f05af32015-06-09 15:59:47 -070066 implements MenuItem.OnMenuItemClickListener {
Chiao Cheng94b10b52012-08-17 16:59:12 -070067 private static final String TAG = "CallDetail";
68
Andrew Lee7c461dc2015-05-15 10:18:45 -070069 /** A long array extra containing ids of call log entries to display. */
Chiao Cheng94b10b52012-08-17 16:59:12 -070070 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
71 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
72 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
Chiao Cheng94b10b52012-08-17 16:59:12 -070073 /** If the activity was triggered from a notification. */
74 public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";
75
Yorke Lee8cd94232014-07-23 14:05:31 -070076 public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment";
77
Andrew Lee7c461dc2015-05-15 10:18:45 -070078 private CallLogAsyncTaskListener mCallLogAsyncTaskListener = new CallLogAsyncTaskListener() {
79 @Override
80 public void onDeleteCall() {
81 finish();
82 }
83
84 @Override
85 public void onDeleteVoicemail() {
86 finish();
87 }
88
89 @Override
90 public void onGetCallDetails(PhoneCallDetails[] details) {
Andrew Lee7c461dc2015-05-15 10:18:45 -070091 if (details == null) {
92 // Somewhere went wrong: we're going to bail out and show error to users.
Andrew Leee177fe62015-06-05 13:01:09 -070093 Toast.makeText(mContext, R.string.toast_call_detail_error,
Andrew Lee7c461dc2015-05-15 10:18:45 -070094 Toast.LENGTH_SHORT).show();
95 finish();
96 return;
97 }
98
99 // We know that all calls are from the same number and the same contact, so pick the
100 // first.
101 PhoneCallDetails firstDetails = details[0];
102 mNumber = TextUtils.isEmpty(firstDetails.number) ?
103 null : firstDetails.number.toString();
104 final int numberPresentation = firstDetails.numberPresentation;
105 final Uri contactUri = firstDetails.contactUri;
106 final Uri photoUri = firstDetails.photoUri;
107 final PhoneAccountHandle accountHandle = firstDetails.accountHandle;
108
109 // Cache the details about the phone number.
110 final boolean canPlaceCallsTo =
Andrew Leed3f6a6c2015-06-25 16:53:56 -0700111 PhoneNumberUtil.canPlaceCallsTo(mNumber, numberPresentation);
Andrew Leee177fe62015-06-05 13:01:09 -0700112 mIsVoicemailNumber =
Andrew Leed3f6a6c2015-06-25 16:53:56 -0700113 PhoneNumberUtil.isVoicemailNumber(mContext, accountHandle, mNumber);
114 final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700115
116 final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails);
117
118 final CharSequence displayNumber = firstDetails.displayNumber;
119 final String displayNumberStr = mBidiFormatter.unicodeWrap(
120 displayNumber.toString(), TextDirectionHeuristics.LTR);
121
122 if (!TextUtils.isEmpty(firstDetails.name)) {
123 mCallerName.setText(firstDetails.name);
124 mCallerNumber.setText(callLocationOrType + " " + displayNumberStr);
125 } else {
126 mCallerName.setText(displayNumberStr);
127 if (!TextUtils.isEmpty(callLocationOrType)) {
128 mCallerNumber.setText(callLocationOrType);
129 mCallerNumber.setVisibility(View.VISIBLE);
130 } else {
131 mCallerNumber.setVisibility(View.GONE);
132 }
133 }
134
Andrew Leee177fe62015-06-05 13:01:09 -0700135 mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE);
136
137 String accountLabel = PhoneAccountUtils.getAccountLabel(mContext, accountHandle);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700138 if (!TextUtils.isEmpty(accountLabel)) {
139 mAccountLabel.setText(accountLabel);
140 mAccountLabel.setVisibility(View.VISIBLE);
141 } else {
142 mAccountLabel.setVisibility(View.GONE);
143 }
144
145 mHasEditNumberBeforeCallOption =
Andrew Leee177fe62015-06-05 13:01:09 -0700146 canPlaceCallsTo && !isSipNumber && !mIsVoicemailNumber;
Andrew Lee2f05af32015-06-09 15:59:47 -0700147 mHasReportMenuOption = mContactInfoHelper.canReportAsInvalid(
148 firstDetails.sourceType, firstDetails.objectId);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700149 invalidateOptionsMenu();
150
151 ListView historyList = (ListView) findViewById(R.id.history);
152 historyList.setAdapter(
Andrew Leee177fe62015-06-05 13:01:09 -0700153 new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details));
Andrew Lee7c461dc2015-05-15 10:18:45 -0700154
155 String lookupKey = contactUri == null ? null
Tyler Gunn18b4a2e2015-08-05 08:18:37 -0700156 : UriUtils.getLookupKeyFromUri(contactUri);
Andrew Lee7c461dc2015-05-15 10:18:45 -0700157
158 final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType);
159
160 final int contactType =
Andrew Leee177fe62015-06-05 13:01:09 -0700161 mIsVoicemailNumber ? ContactPhotoManager.TYPE_VOICEMAIL :
Andrew Lee7c461dc2015-05-15 10:18:45 -0700162 isBusiness ? ContactPhotoManager.TYPE_BUSINESS :
163 ContactPhotoManager.TYPE_DEFAULT;
164
165 String nameForDefaultImage;
166 if (TextUtils.isEmpty(firstDetails.name)) {
167 nameForDefaultImage = firstDetails.displayNumber;
168 } else {
169 nameForDefaultImage = firstDetails.name.toString();
170 }
171
172 loadContactPhotos(
173 contactUri, photoUri, nameForDefaultImage, lookupKey, contactType);
174 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
175 }
176
177 /**
178 * Determines the location geocode text for a call, or the phone number type
179 * (if available).
180 *
181 * @param details The call details.
182 * @return The phone number type or location.
183 */
184 private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) {
185 if (!TextUtils.isEmpty(details.name)) {
186 return Phone.getTypeLabel(mResources, details.numberType,
187 details.numberLabel);
188 } else {
189 return details.geocode;
190 }
191 }
192 };
193
Andrew Leee177fe62015-06-05 13:01:09 -0700194 private Context mContext;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700195 private CallTypeHelper mCallTypeHelper;
Tyler Gunn18164c82014-06-09 10:20:57 -0700196 private QuickContactBadge mQuickContactBadge;
197 private TextView mCallerName;
198 private TextView mCallerNumber;
Nancy Chen19702632014-07-25 13:23:16 -0700199 private TextView mAccountLabel;
Andrew Leee177fe62015-06-05 13:01:09 -0700200 private View mCallButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700201 private ContactInfoHelper mContactInfoHelper;
202
Andrew Lee2f05af32015-06-09 15:59:47 -0700203 protected String mNumber;
Andrew Leee177fe62015-06-05 13:01:09 -0700204 private boolean mIsVoicemailNumber;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700205 private String mDefaultCountryIso;
206
207 /* package */ LayoutInflater mInflater;
208 /* package */ Resources mResources;
209 /** Helper to load contact photos. */
210 private ContactPhotoManager mContactPhotoManager;
Andrew Leec1167e92015-05-18 11:27:54 -0700211
Yorke Lee257b6f22014-07-31 14:16:44 -0700212 private Uri mVoicemailUri;
Andrew Lee99e8adb2014-10-02 12:27:37 -0700213 private BidiFormatter mBidiFormatter = BidiFormatter.getInstance();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700214
215 /** Whether we should show "edit number before call" in the options menu. */
216 private boolean mHasEditNumberBeforeCallOption;
Andrew Lee2f05af32015-06-09 15:59:47 -0700217 private boolean mHasReportMenuOption;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700218
Chiao Cheng94b10b52012-08-17 16:59:12 -0700219 @Override
220 protected void onCreate(Bundle icicle) {
221 super.onCreate(icicle);
222
Andrew Leee177fe62015-06-05 13:01:09 -0700223 mContext = this;
224
Chiao Cheng94b10b52012-08-17 16:59:12 -0700225 setContentView(R.layout.call_detail);
226
Chiao Cheng94b10b52012-08-17 16:59:12 -0700227 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
228 mResources = getResources();
229
230 mCallTypeHelper = new CallTypeHelper(getResources());
Yorke Lee257b6f22014-07-31 14:16:44 -0700231
232 mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
233
Andrew Leeafdd8b92015-10-05 17:57:40 -0700234 ListView historyList = (ListView) findViewById(R.id.history);
235 historyList.addHeaderView(mInflater.inflate(R.layout.call_detail_header, null));
236
Tyler Gunn18164c82014-06-09 10:20:57 -0700237 mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo);
238 mQuickContactBadge.setOverlay(null);
Brian Attwell74eb4ec2015-02-25 22:31:22 -0800239 mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
Tyler Gunn18164c82014-06-09 10:20:57 -0700240 mCallerName = (TextView) findViewById(R.id.caller_name);
241 mCallerNumber = (TextView) findViewById(R.id.caller_number);
Nancy Chen19702632014-07-25 13:23:16 -0700242 mAccountLabel = (TextView) findViewById(R.id.phone_account_label);
Chiao Cheng35071c02012-10-15 18:36:24 -0700243 mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700244 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Yorke Lee71513982015-02-25 20:23:53 -0800245
Yorke Leee3a2d132015-09-14 16:52:08 -0700246 mCallButton = findViewById(R.id.call_back_button);
Andrew Leee177fe62015-06-05 13:01:09 -0700247 mCallButton.setOnClickListener(new View.OnClickListener() {
248 @Override
249 public void onClick(View view) {
Yorke Leec8d6e162015-09-14 18:43:27 -0700250 mContext.startActivity(
251 new CallIntentBuilder(mNumber)
252 .setCallInitiationType(LogState.INITIATION_CALL_DETAILS)
253 .build());
Andrew Leee177fe62015-06-05 13:01:09 -0700254 }
255 });
256
Chiao Cheng35071c02012-10-15 18:36:24 -0700257 mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this));
Nancy Chen44898ad2015-08-13 12:03:47 -0700258 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Yorke Lee257b6f22014-07-31 14:16:44 -0700259
Chiao Cheng94b10b52012-08-17 16:59:12 -0700260 if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
261 closeSystemDialogs();
262 }
263 }
264
265 @Override
266 public void onResume() {
267 super.onResume();
Andrew Lee2f05af32015-06-09 15:59:47 -0700268 getCallDetails();
269 }
Andrew Lee7c461dc2015-05-15 10:18:45 -0700270
Yorke Lee0b458972015-09-18 12:55:30 -0700271 @Override
272 public boolean dispatchTouchEvent(MotionEvent ev) {
273 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
274 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
275 }
276 return super.dispatchTouchEvent(ev);
277 }
278
Andrew Lee2f05af32015-06-09 15:59:47 -0700279 public void getCallDetails() {
Andrew Lee7c461dc2015-05-15 10:18:45 -0700280 CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700281 }
282
Andrew Lee7b127d42015-09-30 18:24:48 -0700283 @NeededForTesting
284 public boolean hasVoicemail() {
Yorke Lee257b6f22014-07-31 14:16:44 -0700285 return mVoicemailUri != null;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700286 }
287
Chiao Cheng94b10b52012-08-17 16:59:12 -0700288 /**
289 * Returns the list of URIs to show.
290 * <p>
291 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
292 * a list of ids in the call log added as an extra on the URI.
293 * <p>
294 * If both are available, the data on the intent takes precedence.
295 */
296 private Uri[] getCallLogEntryUris() {
Jay Shrauner757bdd32014-05-28 10:13:40 -0700297 final Uri uri = getIntent().getData();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700298 if (uri != null) {
299 // If there is a data on the intent, it takes precedence over the extra.
300 return new Uri[]{ uri };
301 }
Jay Shrauner757bdd32014-05-28 10:13:40 -0700302 final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
303 final int numIds = ids == null ? 0 : ids.length;
304 final Uri[] uris = new Uri[numIds];
305 for (int index = 0; index < numIds; ++index) {
Yorke Lee4aece952015-05-02 22:22:54 -0700306 uris[index] = ContentUris.withAppendedId(
307 TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700308 }
309 return uris;
310 }
311
Chiao Cheng94b10b52012-08-17 16:59:12 -0700312 /** Load the contact photos and places them in the corresponding views. */
Tyler Gunn18164c82014-06-09 10:20:57 -0700313 private void loadContactPhotos(Uri contactUri, Uri photoUri, String displayName,
314 String lookupKey, int contactType) {
315
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800316 final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey,
Tyler Gunn18164c82014-06-09 10:20:57 -0700317 contactType, true /* isCircular */);
318
319 mQuickContactBadge.assignContactUri(contactUri);
320 mQuickContactBadge.setContentDescription(
321 mResources.getString(R.string.description_contact_details, displayName));
322
323 mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, photoUri,
324 false /* darkTheme */, true /* isCircular */, request);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700325 }
326
Chiao Cheng94b10b52012-08-17 16:59:12 -0700327 @Override
328 public boolean onCreateOptionsMenu(Menu menu) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700329 final MenuItem deleteMenuItem = menu.add(
330 Menu.NONE,
331 R.id.call_detail_delete_menu_item,
332 Menu.NONE,
333 R.string.call_details_delete);
334 deleteMenuItem.setIcon(R.drawable.ic_delete_24dp);
335 deleteMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
336 deleteMenuItem.setOnMenuItemClickListener(this);
337
Chiao Cheng94b10b52012-08-17 16:59:12 -0700338 getMenuInflater().inflate(R.menu.call_details_options, menu);
339 return super.onCreateOptionsMenu(menu);
340 }
341
342 @Override
343 public boolean onPrepareOptionsMenu(Menu menu) {
Andrew Lee2f05af32015-06-09 15:59:47 -0700344 menu.findItem(R.id.menu_edit_number_before_call)
345 .setVisible(mHasEditNumberBeforeCallOption)
346 .setOnMenuItemClickListener(this);
Andrew Lee2f05af32015-06-09 15:59:47 -0700347 menu.findItem(R.id.menu_report)
348 .setVisible(mHasReportMenuOption)
349 .setOnMenuItemClickListener(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700350 return super.onPrepareOptionsMenu(menu);
351 }
352
Andrew Lee2f05af32015-06-09 15:59:47 -0700353 @Override
354 public boolean onMenuItemClick(MenuItem item) {
355 switch (item.getItemId()) {
Andrew Lee7b127d42015-09-30 18:24:48 -0700356 case R.id.call_detail_delete_menu_item:
357 if (hasVoicemail()) {
358 CallLogAsyncTaskUtil.deleteVoicemail(
359 this, mVoicemailUri, mCallLogAsyncTaskListener);
360 } else {
361 final StringBuilder callIds = new StringBuilder();
362 for (Uri callUri : getCallLogEntryUris()) {
363 if (callIds.length() != 0) {
364 callIds.append(",");
365 }
366 callIds.append(ContentUris.parseId(callUri));
Andrew Lee2f05af32015-06-09 15:59:47 -0700367 }
Andrew Lee7b127d42015-09-30 18:24:48 -0700368 CallLogAsyncTaskUtil.deleteCalls(
369 this, callIds.toString(), mCallLogAsyncTaskListener);
Andrew Lee2f05af32015-06-09 15:59:47 -0700370 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700371 break;
372 case R.id.menu_edit_number_before_call:
373 startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber)));
374 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700375 }
Andrew Lee2f05af32015-06-09 15:59:47 -0700376 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700377 }
378
Chiao Cheng94b10b52012-08-17 16:59:12 -0700379 private void closeSystemDialogs() {
380 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
381 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700382}