blob: 2401c4767a70914c80cc8b6f54e6bb8b32131238 [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
Brian Attwellbeab3bb2014-10-27 12:24:49 -070019import android.app.Activity;
Chiao Cheng94b10b52012-08-17 16:59:12 -070020import android.content.ContentResolver;
21import android.content.ContentUris;
22import android.content.ContentValues;
23import android.content.Context;
24import android.content.Intent;
25import android.content.res.Resources;
26import android.database.Cursor;
Chiao Cheng94b10b52012-08-17 16:59:12 -070027import android.net.Uri;
28import android.os.AsyncTask;
29import android.os.Bundle;
Yorke Lee71513982015-02-25 20:23:53 -080030import android.os.PowerManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070031import android.provider.CallLog;
32import android.provider.CallLog.Calls;
Chiao Cheng94b10b52012-08-17 16:59:12 -070033import android.provider.ContactsContract.CommonDataKinds.Phone;
Chiao Cheng94b10b52012-08-17 16:59:12 -070034import android.provider.VoicemailContract.Voicemails;
Tyler Gunn9dc924c2014-09-12 09:33:50 -070035import android.telecom.PhoneAccount;
Nancy Chene80d6222014-10-08 20:17:55 -070036import android.telecom.PhoneAccountHandle;
Chiao Cheng94b10b52012-08-17 16:59:12 -070037import android.telephony.TelephonyManager;
Andrew Lee99e8adb2014-10-02 12:27:37 -070038import android.text.BidiFormatter;
39import android.text.TextDirectionHeuristics;
Chiao Cheng94b10b52012-08-17 16:59:12 -070040import android.text.TextUtils;
41import android.util.Log;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.view.KeyEvent;
43import android.view.LayoutInflater;
44import android.view.Menu;
45import android.view.MenuItem;
46import android.view.View;
Yorke Lee257b6f22014-07-31 14:16:44 -070047import android.widget.LinearLayout;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.widget.ListView;
Tyler Gunn18164c82014-06-09 10:20:57 -070049import android.widget.QuickContactBadge;
Chiao Cheng94b10b52012-08-17 16:59:12 -070050import android.widget.TextView;
51import android.widget.Toast;
52
Chiao Cheng35071c02012-10-15 18:36:24 -070053import com.android.contacts.common.ContactPhotoManager;
Yorke Lee56cb0ef2014-02-21 10:02:18 -080054import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
Chiao Cheng35071c02012-10-15 18:36:24 -070055import com.android.contacts.common.GeoUtil;
Brian Attwell82043242015-02-03 14:13:58 -080056import com.android.contacts.common.CallUtil;
Chiao Cheng94b10b52012-08-17 16:59:12 -070057import com.android.dialer.calllog.CallDetailHistoryAdapter;
Nancy Chenf153bf42015-05-06 19:29:56 -070058import com.android.dialer.calllog.CallLogNotificationsService;
Chiao Cheng94b10b52012-08-17 16:59:12 -070059import com.android.dialer.calllog.CallTypeHelper;
60import com.android.dialer.calllog.ContactInfo;
61import com.android.dialer.calllog.ContactInfoHelper;
Nancy Chenb2eebaf2014-07-21 13:41:36 -070062import com.android.dialer.calllog.PhoneAccountUtils;
Yorke Lee24ec3192013-11-19 13:52:45 -080063import com.android.dialer.calllog.PhoneNumberDisplayHelper;
Chiao Chengfb0a9342013-09-13 17:27:42 -070064import com.android.dialer.calllog.PhoneNumberUtilsWrapper;
Chiao Cheng91197042012-08-24 14:19:37 -070065import com.android.dialer.util.AsyncTaskExecutor;
66import com.android.dialer.util.AsyncTaskExecutors;
Andrew Lee247df6e2015-05-12 19:09:00 -070067import com.android.dialer.util.IntentUtil;
Yorke Lee39213592014-04-07 15:39:48 -070068import com.android.dialer.util.DialerUtils;
Yorke Lee4aece952015-05-02 22:22:54 -070069import com.android.dialer.util.TelecomUtil;
Chiao Cheng94b10b52012-08-17 16:59:12 -070070import com.android.dialer.voicemail.VoicemailPlaybackFragment;
71import com.android.dialer.voicemail.VoicemailStatusHelper;
72import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage;
73import com.android.dialer.voicemail.VoicemailStatusHelperImpl;
74
75import java.util.List;
76
77/**
78 * Displays the details of a specific call log entry.
79 * <p>
80 * This activity can be either started with the URI of a single call log entry, or with the
81 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
82 */
Andrew Lee93b816f2015-05-13 12:23:35 -070083public class CallDetailActivity extends Activity {
Chiao Cheng94b10b52012-08-17 16:59:12 -070084 private static final String TAG = "CallDetail";
85
Chiao Cheng35071c02012-10-15 18:36:24 -070086 private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A';
87 private static final char POP_DIRECTIONAL_FORMATTING = '\u202C';
88
Chiao Cheng94b10b52012-08-17 16:59:12 -070089 /** The enumeration of {@link AsyncTask} objects used in this class. */
90 public enum Tasks {
91 MARK_VOICEMAIL_READ,
92 DELETE_VOICEMAIL_AND_FINISH,
93 REMOVE_FROM_CALL_LOG_AND_FINISH,
94 UPDATE_PHONE_CALL_DETAILS,
95 }
96
97 /** A long array extra containing ids of call log entries to display. */
98 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
99 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
100 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
101 /** If we should immediately start playback of the voicemail, this extra will be set to true. */
102 public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK";
103 /** If the activity was triggered from a notification. */
104 public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";
105
Yorke Lee8cd94232014-07-23 14:05:31 -0700106 public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment";
107
Chiao Cheng94b10b52012-08-17 16:59:12 -0700108 private CallTypeHelper mCallTypeHelper;
Yorke Lee24ec3192013-11-19 13:52:45 -0800109 private PhoneNumberDisplayHelper mPhoneNumberHelper;
Tyler Gunn18164c82014-06-09 10:20:57 -0700110 private QuickContactBadge mQuickContactBadge;
111 private TextView mCallerName;
112 private TextView mCallerNumber;
Nancy Chen19702632014-07-25 13:23:16 -0700113 private TextView mAccountLabel;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700114 private AsyncTaskExecutor mAsyncTaskExecutor;
115 private ContactInfoHelper mContactInfoHelper;
116
117 private String mNumber = null;
118 private String mDefaultCountryIso;
119
120 /* package */ LayoutInflater mInflater;
121 /* package */ Resources mResources;
122 /** Helper to load contact photos. */
123 private ContactPhotoManager mContactPhotoManager;
Andrew Leec1167e92015-05-18 11:27:54 -0700124
Yorke Lee257b6f22014-07-31 14:16:44 -0700125 private LinearLayout mVoicemailHeader;
126
127 private Uri mVoicemailUri;
Andrew Lee99e8adb2014-10-02 12:27:37 -0700128 private BidiFormatter mBidiFormatter = BidiFormatter.getInstance();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700129
130 /** Whether we should show "edit number before call" in the options menu. */
131 private boolean mHasEditNumberBeforeCallOption;
132 /** Whether we should show "trash" in the options menu. */
133 private boolean mHasTrashOption;
134 /** Whether we should show "remove from call log" in the options menu. */
135 private boolean mHasRemoveFromCallLogOption;
136
Chiao Cheng94b10b52012-08-17 16:59:12 -0700137 static final String[] CALL_LOG_PROJECTION = new String[] {
138 CallLog.Calls.DATE,
139 CallLog.Calls.DURATION,
140 CallLog.Calls.NUMBER,
141 CallLog.Calls.TYPE,
142 CallLog.Calls.COUNTRY_ISO,
143 CallLog.Calls.GEOCODED_LOCATION,
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700144 CallLog.Calls.NUMBER_PRESENTATION,
Ihab Awadc8daf202014-07-02 14:03:28 -0700145 CallLog.Calls.PHONE_ACCOUNT_COMPONENT_NAME,
146 CallLog.Calls.PHONE_ACCOUNT_ID,
Tyler Gunn8b0e8582014-07-10 12:28:43 -0700147 CallLog.Calls.FEATURES,
Yorke Lee8cd94232014-07-23 14:05:31 -0700148 CallLog.Calls.DATA_USAGE,
149 CallLog.Calls.TRANSCRIPTION
Chiao Cheng94b10b52012-08-17 16:59:12 -0700150 };
151
152 static final int DATE_COLUMN_INDEX = 0;
153 static final int DURATION_COLUMN_INDEX = 1;
154 static final int NUMBER_COLUMN_INDEX = 2;
155 static final int CALL_TYPE_COLUMN_INDEX = 3;
156 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
157 static final int GEOCODED_LOCATION_COLUMN_INDEX = 5;
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700158 static final int NUMBER_PRESENTATION_COLUMN_INDEX = 6;
Ihab Awad1d1bd0d2014-06-30 21:24:01 -0700159 static final int ACCOUNT_COMPONENT_NAME = 7;
160 static final int ACCOUNT_ID = 8;
Tyler Gunn8b0e8582014-07-10 12:28:43 -0700161 static final int FEATURES = 9;
162 static final int DATA_USAGE = 10;
Yorke Lee8cd94232014-07-23 14:05:31 -0700163 static final int TRANSCRIPTION_COLUMN_INDEX = 11;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700164
Chiao Cheng94b10b52012-08-17 16:59:12 -0700165 @Override
166 protected void onCreate(Bundle icicle) {
167 super.onCreate(icicle);
168
169 setContentView(R.layout.call_detail);
170
171 mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor();
172 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
173 mResources = getResources();
174
175 mCallTypeHelper = new CallTypeHelper(getResources());
Nancy Chene80d6222014-10-08 20:17:55 -0700176 mPhoneNumberHelper = new PhoneNumberDisplayHelper(this, mResources);
Yorke Lee257b6f22014-07-31 14:16:44 -0700177
178 mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
179
Tyler Gunn18164c82014-06-09 10:20:57 -0700180 mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo);
181 mQuickContactBadge.setOverlay(null);
Brian Attwell74eb4ec2015-02-25 22:31:22 -0800182 mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
Tyler Gunn18164c82014-06-09 10:20:57 -0700183 mCallerName = (TextView) findViewById(R.id.caller_name);
184 mCallerNumber = (TextView) findViewById(R.id.caller_number);
Nancy Chen19702632014-07-25 13:23:16 -0700185 mAccountLabel = (TextView) findViewById(R.id.phone_account_label);
Chiao Cheng35071c02012-10-15 18:36:24 -0700186 mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700187 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Yorke Lee71513982015-02-25 20:23:53 -0800188
Chiao Cheng35071c02012-10-15 18:36:24 -0700189 mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this));
Chiao Chengadb742c2013-10-07 17:46:25 -0700190 getActionBar().setDisplayHomeAsUpEnabled(true);
Yorke Lee257b6f22014-07-31 14:16:44 -0700191
Chiao Cheng94b10b52012-08-17 16:59:12 -0700192 optionallyHandleVoicemail();
193 if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
194 closeSystemDialogs();
195 }
196 }
197
198 @Override
199 public void onResume() {
200 super.onResume();
201 updateData(getCallLogEntryUris());
202 }
203
204 /**
205 * Handle voicemail playback or hide voicemail ui.
206 * <p>
207 * If the Intent used to start this Activity contains the suitable extras, then start voicemail
Yorke Lee257b6f22014-07-31 14:16:44 -0700208 * playback. If it doesn't, then don't inflate the voicemail ui.
Chiao Cheng94b10b52012-08-17 16:59:12 -0700209 */
210 private void optionallyHandleVoicemail() {
Yorke Lee257b6f22014-07-31 14:16:44 -0700211
Chiao Cheng94b10b52012-08-17 16:59:12 -0700212 if (hasVoicemail()) {
Yorke Lee257b6f22014-07-31 14:16:44 -0700213 LayoutInflater inflater =
214 (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
215 mVoicemailHeader =
216 (LinearLayout) inflater.inflate(R.layout.call_details_voicemail_header, null);
217 View voicemailContainer = mVoicemailHeader.findViewById(R.id.voicemail_container);
Yorke Lee257b6f22014-07-31 14:16:44 -0700218 ListView historyList = (ListView) findViewById(R.id.history);
219 historyList.addHeaderView(mVoicemailHeader);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700220 // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri
221 // to play and optionally start the playback.
222 // Do a query to fetch the voicemail status messages.
Yorke Lee8cd94232014-07-23 14:05:31 -0700223 VoicemailPlaybackFragment playbackFragment;
224
225 playbackFragment = (VoicemailPlaybackFragment) getFragmentManager().findFragmentByTag(
226 VOICEMAIL_FRAGMENT_TAG);
227
228 if (playbackFragment == null) {
229 playbackFragment = new VoicemailPlaybackFragment();
230 Bundle fragmentArguments = new Bundle();
Yorke Lee257b6f22014-07-31 14:16:44 -0700231 fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, mVoicemailUri);
Yorke Lee8cd94232014-07-23 14:05:31 -0700232 if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) {
233 fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true);
234 }
235 playbackFragment.setArguments(fragmentArguments);
236 getFragmentManager().beginTransaction()
237 .add(R.id.voicemail_container, playbackFragment, VOICEMAIL_FRAGMENT_TAG)
238 .commitAllowingStateLoss();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700239 }
Yorke Lee8cd94232014-07-23 14:05:31 -0700240
Chiao Cheng94b10b52012-08-17 16:59:12 -0700241 voicemailContainer.setVisibility(View.VISIBLE);
Yorke Lee257b6f22014-07-31 14:16:44 -0700242 markVoicemailAsRead(mVoicemailUri);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700243 }
244 }
245
246 private boolean hasVoicemail() {
Yorke Lee257b6f22014-07-31 14:16:44 -0700247 return mVoicemailUri != null;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700248 }
249
250 private void markVoicemailAsRead(final Uri voicemailUri) {
251 mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() {
252 @Override
253 public Void doInBackground(Void... params) {
254 ContentValues values = new ContentValues();
255 values.put(Voicemails.IS_READ, true);
256 getContentResolver().update(voicemailUri, values,
257 Voicemails.IS_READ + " = 0", null);
Nancy Chenf153bf42015-05-06 19:29:56 -0700258 Intent intent = new Intent(getBaseContext(), CallLogNotificationsService.class);
259 intent.setAction(CallLogNotificationsService.ACTION_MARK_NEW_VOICEMAILS_AS_OLD);
260 getBaseContext().startService(intent);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700261 return null;
262 }
263 });
264 }
265
266 /**
267 * Returns the list of URIs to show.
268 * <p>
269 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
270 * a list of ids in the call log added as an extra on the URI.
271 * <p>
272 * If both are available, the data on the intent takes precedence.
273 */
274 private Uri[] getCallLogEntryUris() {
Jay Shrauner757bdd32014-05-28 10:13:40 -0700275 final Uri uri = getIntent().getData();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700276 if (uri != null) {
277 // If there is a data on the intent, it takes precedence over the extra.
278 return new Uri[]{ uri };
279 }
Jay Shrauner757bdd32014-05-28 10:13:40 -0700280 final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
281 final int numIds = ids == null ? 0 : ids.length;
282 final Uri[] uris = new Uri[numIds];
283 for (int index = 0; index < numIds; ++index) {
Yorke Lee4aece952015-05-02 22:22:54 -0700284 uris[index] = ContentUris.withAppendedId(
285 TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700286 }
287 return uris;
288 }
289
Chiao Cheng94b10b52012-08-17 16:59:12 -0700290 /**
291 * Update user interface with details of given call.
292 *
Nancy Chene80d6222014-10-08 20:17:55 -0700293 * @param callUris URIs into {@link android.provider.CallLog.Calls} of the calls to be displayed
Chiao Cheng94b10b52012-08-17 16:59:12 -0700294 */
295 private void updateData(final Uri... callUris) {
296 class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> {
297 @Override
298 public PhoneCallDetails[] doInBackground(Void... params) {
299 // TODO: All phone calls correspond to the same person, so we can make a single
300 // lookup.
301 final int numCalls = callUris.length;
302 PhoneCallDetails[] details = new PhoneCallDetails[numCalls];
303 try {
304 for (int index = 0; index < numCalls; ++index) {
305 details[index] = getPhoneCallDetailsForUri(callUris[index]);
306 }
307 return details;
308 } catch (IllegalArgumentException e) {
309 // Something went wrong reading in our primary data.
310 Log.w(TAG, "invalid URI starting call details", e);
311 return null;
312 }
313 }
314
315 @Override
316 public void onPostExecute(PhoneCallDetails[] details) {
Nancy Chene80d6222014-10-08 20:17:55 -0700317 Context context = CallDetailActivity.this;
318
Chiao Cheng94b10b52012-08-17 16:59:12 -0700319 if (details == null) {
320 // Somewhere went wrong: we're going to bail out and show error to users.
Nancy Chene80d6222014-10-08 20:17:55 -0700321 Toast.makeText(context, R.string.toast_call_detail_error,
Chiao Cheng94b10b52012-08-17 16:59:12 -0700322 Toast.LENGTH_SHORT).show();
323 finish();
324 return;
325 }
326
327 // We know that all calls are from the same number and the same contact, so pick the
328 // first.
329 PhoneCallDetails firstDetails = details[0];
Nancy Chen164d9d52015-03-09 16:24:08 -0700330 mNumber = TextUtils.isEmpty(firstDetails.number) ?
331 null : firstDetails.number.toString();
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700332 final int numberPresentation = firstDetails.numberPresentation;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700333 final Uri contactUri = firstDetails.contactUri;
334 final Uri photoUri = firstDetails.photoUri;
Nancy Chene80d6222014-10-08 20:17:55 -0700335 final PhoneAccountHandle accountHandle = firstDetails.accountHandle;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700336
Chiao Cheng94b10b52012-08-17 16:59:12 -0700337 // Cache the details about the phone number.
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700338 final boolean canPlaceCallsTo =
Chiao Chengfb0a9342013-09-13 17:27:42 -0700339 PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation);
Nancy Chene80d6222014-10-08 20:17:55 -0700340 final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(context);
341 final boolean isVoicemailNumber =
342 phoneUtils.isVoicemailNumber(accountHandle, mNumber);
343 final boolean isSipNumber = PhoneNumberUtilsWrapper.isSipNumber(mNumber);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700344
Tyler Gunn18164c82014-06-09 10:20:57 -0700345 final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700346
Nancy Chene80d6222014-10-08 20:17:55 -0700347 final CharSequence displayNumber =
348 mPhoneNumberHelper.getDisplayNumber(
349 firstDetails.accountHandle,
350 firstDetails.number,
351 firstDetails.numberPresentation,
352 firstDetails.formattedNumber);
Andrew Lee99e8adb2014-10-02 12:27:37 -0700353 final String displayNumberStr = mBidiFormatter.unicodeWrap(
354 displayNumber.toString(), TextDirectionHeuristics.LTR);
355
Tyler Gunn18164c82014-06-09 10:20:57 -0700356 if (!TextUtils.isEmpty(firstDetails.name)) {
357 mCallerName.setText(firstDetails.name);
Andrew Lee99e8adb2014-10-02 12:27:37 -0700358 mCallerNumber.setText(callLocationOrType + " " + displayNumberStr);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700359 } else {
Andrew Lee99e8adb2014-10-02 12:27:37 -0700360 mCallerName.setText(displayNumberStr);
Tyler Gunn18164c82014-06-09 10:20:57 -0700361 if (!TextUtils.isEmpty(callLocationOrType)) {
362 mCallerNumber.setText(callLocationOrType);
363 mCallerNumber.setVisibility(View.VISIBLE);
364 } else {
365 mCallerNumber.setVisibility(View.GONE);
366 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700367 }
368
Nancy Chene80d6222014-10-08 20:17:55 -0700369 String accountLabel = PhoneAccountUtils.getAccountLabel(context, accountHandle);
370 if (!TextUtils.isEmpty(accountLabel)) {
371 mAccountLabel.setText(accountLabel);
Nancy Chen19702632014-07-25 13:23:16 -0700372 mAccountLabel.setVisibility(View.VISIBLE);
373 } else {
374 mAccountLabel.setVisibility(View.GONE);
375 }
376
Chiao Cheng94b10b52012-08-17 16:59:12 -0700377 mHasEditNumberBeforeCallOption =
378 canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
379 mHasTrashOption = hasVoicemail();
380 mHasRemoveFromCallLogOption = !hasVoicemail();
381 invalidateOptionsMenu();
382
383 ListView historyList = (ListView) findViewById(R.id.history);
384 historyList.setAdapter(
Nancy Chene80d6222014-10-08 20:17:55 -0700385 new CallDetailHistoryAdapter(context, mInflater, mCallTypeHelper, details));
Chiao Cheng94b10b52012-08-17 16:59:12 -0700386
Tyler Gunn18164c82014-06-09 10:20:57 -0700387 String lookupKey = contactUri == null ? null
388 : ContactInfoHelper.getLookupKeyFromUri(contactUri);
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800389
390 final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType);
391
392 final int contactType =
393 isVoicemailNumber? ContactPhotoManager.TYPE_VOICEMAIL :
394 isBusiness ? ContactPhotoManager.TYPE_BUSINESS :
395 ContactPhotoManager.TYPE_DEFAULT;
396
Tyler Gunn18164c82014-06-09 10:20:57 -0700397 String nameForDefaultImage;
398 if (TextUtils.isEmpty(firstDetails.name)) {
Nancy Chene80d6222014-10-08 20:17:55 -0700399 nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(
400 firstDetails.accountHandle,
401 firstDetails.number,
Tyler Gunn18164c82014-06-09 10:20:57 -0700402 firstDetails.numberPresentation,
403 firstDetails.formattedNumber).toString();
404 } else {
405 nameForDefaultImage = firstDetails.name.toString();
406 }
407
408 loadContactPhotos(
409 contactUri, photoUri, nameForDefaultImage, lookupKey, contactType);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700410 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
411 }
Tyler Gunn18164c82014-06-09 10:20:57 -0700412
413 /**
414 * Determines the location geocode text for a call, or the phone number type
415 * (if available).
416 *
417 * @param details The call details.
418 * @return The phone number type or location.
419 */
420 private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) {
421 if (!TextUtils.isEmpty(details.name)) {
422 return Phone.getTypeLabel(mResources, details.numberType,
423 details.numberLabel);
424 } else {
425 return details.geocode;
426 }
427 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700428 }
429 mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask());
430 }
431
432 /** Return the phone call details for a given call log URI. */
433 private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
434 ContentResolver resolver = getContentResolver();
435 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
436 try {
437 if (callCursor == null || !callCursor.moveToFirst()) {
438 throw new IllegalArgumentException("Cannot find content: " + callUri);
439 }
440
441 // Read call log specifics.
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700442 final String number = callCursor.getString(NUMBER_COLUMN_INDEX);
443 final int numberPresentation = callCursor.getInt(
444 NUMBER_PRESENTATION_COLUMN_INDEX);
445 final long date = callCursor.getLong(DATE_COLUMN_INDEX);
446 final long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
447 final int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700448 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
449 final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX);
Yorke Lee8cd94232014-07-23 14:05:31 -0700450 final String transcription = callCursor.getString(TRANSCRIPTION_COLUMN_INDEX);
Nancy Chenb2eebaf2014-07-21 13:41:36 -0700451
Nancy Chene80d6222014-10-08 20:17:55 -0700452 final PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount(
Nancy Chenb2eebaf2014-07-21 13:41:36 -0700453 callCursor.getString(ACCOUNT_COMPONENT_NAME),
Nancy Chene80d6222014-10-08 20:17:55 -0700454 callCursor.getString(ACCOUNT_ID));
Chiao Cheng94b10b52012-08-17 16:59:12 -0700455
456 if (TextUtils.isEmpty(countryIso)) {
457 countryIso = mDefaultCountryIso;
458 }
459
460 // Formatted phone number.
461 final CharSequence formattedNumber;
462 // Read contact specifics.
463 final CharSequence nameText;
464 final int numberType;
465 final CharSequence numberLabel;
466 final Uri photoUri;
467 final Uri lookupUri;
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800468 int sourceType;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700469 // If this is not a regular number, there is no point in looking it up in the contacts.
470 ContactInfo info =
Chiao Chengfb0a9342013-09-13 17:27:42 -0700471 PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
Nancy Chene80d6222014-10-08 20:17:55 -0700472 && !new PhoneNumberUtilsWrapper(this).isVoicemailNumber(accountHandle, number)
Chiao Cheng94b10b52012-08-17 16:59:12 -0700473 ? mContactInfoHelper.lookupNumber(number, countryIso)
474 : null;
475 if (info == null) {
Nancy Chene80d6222014-10-08 20:17:55 -0700476 formattedNumber = mPhoneNumberHelper.getDisplayNumber(accountHandle, number,
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700477 numberPresentation, null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700478 nameText = "";
479 numberType = 0;
480 numberLabel = "";
481 photoUri = null;
482 lookupUri = null;
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800483 sourceType = 0;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700484 } else {
485 formattedNumber = info.formattedNumber;
486 nameText = info.name;
487 numberType = info.type;
488 numberLabel = info.label;
489 photoUri = info.photoUri;
490 lookupUri = info.lookupUri;
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800491 sourceType = info.sourceType;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700492 }
Tyler Gunn8b0e8582014-07-10 12:28:43 -0700493 final int features = callCursor.getInt(FEATURES);
494 Long dataUsage = null;
495 if (!callCursor.isNull(DATA_USAGE)) {
496 dataUsage = callCursor.getLong(DATA_USAGE);
497 }
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700498 return new PhoneCallDetails(number, numberPresentation,
499 formattedNumber, countryIso, geocode,
Chiao Cheng94b10b52012-08-17 16:59:12 -0700500 new int[]{ callType }, date, duration,
Nancy Chen87ba4892014-06-11 17:56:07 -0700501 nameText, numberType, numberLabel, lookupUri, photoUri, sourceType,
Nancy Chene80d6222014-10-08 20:17:55 -0700502 accountHandle, features, dataUsage, transcription);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700503 } finally {
504 if (callCursor != null) {
505 callCursor.close();
506 }
507 }
508 }
509
510 /** Load the contact photos and places them in the corresponding views. */
Tyler Gunn18164c82014-06-09 10:20:57 -0700511 private void loadContactPhotos(Uri contactUri, Uri photoUri, String displayName,
512 String lookupKey, int contactType) {
513
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800514 final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey,
Tyler Gunn18164c82014-06-09 10:20:57 -0700515 contactType, true /* isCircular */);
516
517 mQuickContactBadge.assignContactUri(contactUri);
518 mQuickContactBadge.setContentDescription(
519 mResources.getString(R.string.description_contact_details, displayName));
520
521 mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, photoUri,
522 false /* darkTheme */, true /* isCircular */, request);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700523 }
524
Chiao Cheng94b10b52012-08-17 16:59:12 -0700525 @Override
526 public boolean onCreateOptionsMenu(Menu menu) {
527 getMenuInflater().inflate(R.menu.call_details_options, menu);
528 return super.onCreateOptionsMenu(menu);
529 }
530
531 @Override
532 public boolean onPrepareOptionsMenu(Menu menu) {
533 // This action deletes all elements in the group from the call log.
534 // We don't have this action for voicemails, because you can just use the trash button.
535 menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption);
536 menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption);
537 menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption);
538 return super.onPrepareOptionsMenu(menu);
539 }
540
Chiao Cheng94b10b52012-08-17 16:59:12 -0700541 public void onMenuRemoveFromCallLog(MenuItem menuItem) {
542 final StringBuilder callIds = new StringBuilder();
543 for (Uri callUri : getCallLogEntryUris()) {
544 if (callIds.length() != 0) {
545 callIds.append(",");
546 }
547 callIds.append(ContentUris.parseId(callUri));
548 }
549 mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH,
550 new AsyncTask<Void, Void, Void>() {
551 @Override
552 public Void doInBackground(Void... params) {
Yorke Lee4aece952015-05-02 22:22:54 -0700553 getContentResolver().delete(
554 TelecomUtil.getCallLogUri(CallDetailActivity.this),
Chiao Cheng94b10b52012-08-17 16:59:12 -0700555 Calls._ID + " IN (" + callIds + ")", null);
556 return null;
557 }
558
559 @Override
560 public void onPostExecute(Void result) {
561 finish();
562 }
Tyler Gunn18164c82014-06-09 10:20:57 -0700563 }
564 );
Chiao Cheng94b10b52012-08-17 16:59:12 -0700565 }
566
567 public void onMenuEditNumberBeforeCall(MenuItem menuItem) {
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700568 startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber)));
Chiao Cheng94b10b52012-08-17 16:59:12 -0700569 }
570
571 public void onMenuTrashVoicemail(MenuItem menuItem) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700572 mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH,
573 new AsyncTask<Void, Void, Void>() {
574 @Override
575 public Void doInBackground(Void... params) {
Yorke Lee257b6f22014-07-31 14:16:44 -0700576 getContentResolver().delete(mVoicemailUri, null, null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700577 return null;
578 }
Tyler Gunn18164c82014-06-09 10:20:57 -0700579
Chiao Cheng94b10b52012-08-17 16:59:12 -0700580 @Override
581 public void onPostExecute(Void result) {
582 finish();
583 }
Tyler Gunn18164c82014-06-09 10:20:57 -0700584 }
585 );
Chiao Cheng94b10b52012-08-17 16:59:12 -0700586 }
587
Chiao Cheng94b10b52012-08-17 16:59:12 -0700588 private void closeSystemDialogs() {
589 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
590 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700591}