blob: 098e9882ecaf68c31191f0f75999f5ae01da9234 [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.app.Activity;
Yorke Lee03459442013-10-30 18:29:32 -070020import android.app.LoaderManager.LoaderCallbacks;
Yorke Lee7d67c9b2013-12-05 12:28:04 -080021import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070022import android.content.ContentResolver;
23import android.content.ContentUris;
24import android.content.ContentValues;
25import android.content.Context;
26import android.content.Intent;
Yorke Lee03459442013-10-30 18:29:32 -070027import android.content.Loader;
Chiao Cheng94b10b52012-08-17 16:59:12 -070028import android.content.res.Resources;
29import android.database.Cursor;
30import android.graphics.drawable.Drawable;
31import android.net.Uri;
32import android.os.AsyncTask;
33import android.os.Bundle;
34import android.provider.CallLog;
Yorke Lee56cb0ef2014-02-21 10:02:18 -080035import android.provider.ContactsContract;
Chiao Cheng94b10b52012-08-17 16:59:12 -070036import android.provider.CallLog.Calls;
Chiao Cheng94b10b52012-08-17 16:59:12 -070037import android.provider.ContactsContract.CommonDataKinds.Phone;
38import android.provider.ContactsContract.Contacts;
Yorke Lee03459442013-10-30 18:29:32 -070039import android.provider.ContactsContract.DisplayNameSources;
40import android.provider.ContactsContract.Intents.Insert;
Chiao Cheng94b10b52012-08-17 16:59:12 -070041import android.provider.VoicemailContract.Voicemails;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.telephony.TelephonyManager;
43import android.text.TextUtils;
44import android.util.Log;
45import android.view.ActionMode;
46import android.view.KeyEvent;
47import android.view.LayoutInflater;
48import android.view.Menu;
49import android.view.MenuItem;
50import android.view.View;
51import android.widget.ImageButton;
52import android.widget.ImageView;
53import android.widget.ListView;
54import android.widget.TextView;
55import android.widget.Toast;
56
Chiao Cheng35071c02012-10-15 18:36:24 -070057import com.android.contacts.common.ContactPhotoManager;
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070058import com.android.contacts.common.CallUtil;
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070059import com.android.contacts.common.ClipboardUtils;
Yorke Lee56cb0ef2014-02-21 10:02:18 -080060import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
Chiao Cheng35071c02012-10-15 18:36:24 -070061import com.android.contacts.common.GeoUtil;
Yorke Lee03459442013-10-30 18:29:32 -070062import com.android.contacts.common.model.Contact;
63import com.android.contacts.common.model.ContactLoader;
Yorke Lee37d29852013-11-19 14:11:24 -080064import com.android.contacts.common.util.PhoneNumberHelper;
Yorke Lee58ebe5d2013-09-09 10:19:40 -070065import com.android.contacts.common.util.UriUtils;
Chiao Cheng91197042012-08-24 14:19:37 -070066import com.android.dialer.BackScrollManager.ScrollableHeader;
Chiao Cheng94b10b52012-08-17 16:59:12 -070067import com.android.dialer.calllog.CallDetailHistoryAdapter;
68import com.android.dialer.calllog.CallTypeHelper;
69import com.android.dialer.calllog.ContactInfo;
70import com.android.dialer.calllog.ContactInfoHelper;
Yorke Lee24ec3192013-11-19 13:52:45 -080071import com.android.dialer.calllog.PhoneNumberDisplayHelper;
Chiao Chengfb0a9342013-09-13 17:27:42 -070072import com.android.dialer.calllog.PhoneNumberUtilsWrapper;
Chiao Cheng91197042012-08-24 14:19:37 -070073import com.android.dialer.util.AsyncTaskExecutor;
74import com.android.dialer.util.AsyncTaskExecutors;
Yorke Lee39213592014-04-07 15:39:48 -070075import com.android.dialer.util.DialerUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070076import com.android.dialer.voicemail.VoicemailPlaybackFragment;
77import com.android.dialer.voicemail.VoicemailStatusHelper;
78import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage;
79import com.android.dialer.voicemail.VoicemailStatusHelperImpl;
80
81import java.util.List;
82
83/**
84 * Displays the details of a specific call log entry.
85 * <p>
86 * This activity can be either started with the URI of a single call log entry, or with the
87 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
88 */
89public class CallDetailActivity extends Activity implements ProximitySensorAware {
90 private static final String TAG = "CallDetail";
91
Yorke Lee03459442013-10-30 18:29:32 -070092 private static final int LOADER_ID = 0;
93 private static final String BUNDLE_CONTACT_URI_EXTRA = "contact_uri_extra";
94
Chiao Cheng35071c02012-10-15 18:36:24 -070095 private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A';
96 private static final char POP_DIRECTIONAL_FORMATTING = '\u202C';
97
Chiao Cheng94b10b52012-08-17 16:59:12 -070098 /** The time to wait before enabling the blank the screen due to the proximity sensor. */
99 private static final long PROXIMITY_BLANK_DELAY_MILLIS = 100;
100 /** The time to wait before disabling the blank the screen due to the proximity sensor. */
101 private static final long PROXIMITY_UNBLANK_DELAY_MILLIS = 500;
102
103 /** The enumeration of {@link AsyncTask} objects used in this class. */
104 public enum Tasks {
105 MARK_VOICEMAIL_READ,
106 DELETE_VOICEMAIL_AND_FINISH,
107 REMOVE_FROM_CALL_LOG_AND_FINISH,
108 UPDATE_PHONE_CALL_DETAILS,
109 }
110
111 /** A long array extra containing ids of call log entries to display. */
112 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
113 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
114 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
115 /** If we should immediately start playback of the voicemail, this extra will be set to true. */
116 public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK";
117 /** If the activity was triggered from a notification. */
118 public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";
119
120 private CallTypeHelper mCallTypeHelper;
Yorke Lee24ec3192013-11-19 13:52:45 -0800121 private PhoneNumberDisplayHelper mPhoneNumberHelper;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700122 private PhoneCallDetailsHelper mPhoneCallDetailsHelper;
123 private TextView mHeaderTextView;
124 private View mHeaderOverlayView;
125 private ImageView mMainActionView;
126 private ImageButton mMainActionPushLayerView;
127 private ImageView mContactBackgroundView;
128 private AsyncTaskExecutor mAsyncTaskExecutor;
129 private ContactInfoHelper mContactInfoHelper;
130
131 private String mNumber = null;
132 private String mDefaultCountryIso;
133
134 /* package */ LayoutInflater mInflater;
135 /* package */ Resources mResources;
136 /** Helper to load contact photos. */
137 private ContactPhotoManager mContactPhotoManager;
138 /** Helper to make async queries to content resolver. */
139 private CallDetailActivityQueryHandler mAsyncQueryHandler;
140 /** Helper to get voicemail status messages. */
141 private VoicemailStatusHelper mVoicemailStatusHelper;
142 // Views related to voicemail status message.
143 private View mStatusMessageView;
144 private TextView mStatusMessageText;
145 private TextView mStatusMessageAction;
146
147 /** Whether we should show "edit number before call" in the options menu. */
148 private boolean mHasEditNumberBeforeCallOption;
149 /** Whether we should show "trash" in the options menu. */
150 private boolean mHasTrashOption;
151 /** Whether we should show "remove from call log" in the options menu. */
152 private boolean mHasRemoveFromCallLogOption;
153
154 private ProximitySensorManager mProximitySensorManager;
155 private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener();
156
157 /**
158 * The action mode used when the phone number is selected. This will be non-null only when the
159 * phone number is selected.
160 */
161 private ActionMode mPhoneNumberActionMode;
162
163 private CharSequence mPhoneNumberLabelToCopy;
164 private CharSequence mPhoneNumberToCopy;
165
166 /** Listener to changes in the proximity sensor state. */
167 private class ProximitySensorListener implements ProximitySensorManager.Listener {
168 /** Used to show a blank view and hide the action bar. */
169 private final Runnable mBlankRunnable = new Runnable() {
170 @Override
171 public void run() {
172 View blankView = findViewById(R.id.blank);
173 blankView.setVisibility(View.VISIBLE);
174 getActionBar().hide();
175 }
176 };
177 /** Used to remove the blank view and show the action bar. */
178 private final Runnable mUnblankRunnable = new Runnable() {
179 @Override
180 public void run() {
181 View blankView = findViewById(R.id.blank);
182 blankView.setVisibility(View.GONE);
183 getActionBar().show();
184 }
185 };
186
187 @Override
188 public synchronized void onNear() {
189 clearPendingRequests();
190 postDelayed(mBlankRunnable, PROXIMITY_BLANK_DELAY_MILLIS);
191 }
192
193 @Override
194 public synchronized void onFar() {
195 clearPendingRequests();
196 postDelayed(mUnblankRunnable, PROXIMITY_UNBLANK_DELAY_MILLIS);
197 }
198
199 /** Removed any delayed requests that may be pending. */
200 public synchronized void clearPendingRequests() {
201 View blankView = findViewById(R.id.blank);
202 blankView.removeCallbacks(mBlankRunnable);
203 blankView.removeCallbacks(mUnblankRunnable);
204 }
205
206 /** Post a {@link Runnable} with a delay on the main thread. */
207 private synchronized void postDelayed(Runnable runnable, long delayMillis) {
208 // Post these instead of executing immediately so that:
209 // - They are guaranteed to be executed on the main thread.
210 // - If the sensor values changes rapidly for some time, the UI will not be
211 // updated immediately.
212 View blankView = findViewById(R.id.blank);
213 blankView.postDelayed(runnable, delayMillis);
214 }
215 }
216
217 static final String[] CALL_LOG_PROJECTION = new String[] {
218 CallLog.Calls.DATE,
219 CallLog.Calls.DURATION,
220 CallLog.Calls.NUMBER,
221 CallLog.Calls.TYPE,
222 CallLog.Calls.COUNTRY_ISO,
223 CallLog.Calls.GEOCODED_LOCATION,
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700224 CallLog.Calls.NUMBER_PRESENTATION,
Chiao Cheng94b10b52012-08-17 16:59:12 -0700225 };
226
227 static final int DATE_COLUMN_INDEX = 0;
228 static final int DURATION_COLUMN_INDEX = 1;
229 static final int NUMBER_COLUMN_INDEX = 2;
230 static final int CALL_TYPE_COLUMN_INDEX = 3;
231 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
232 static final int GEOCODED_LOCATION_COLUMN_INDEX = 5;
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700233 static final int NUMBER_PRESENTATION_COLUMN_INDEX = 6;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700234
235 private final View.OnClickListener mPrimaryActionListener = new View.OnClickListener() {
236 @Override
237 public void onClick(View view) {
238 if (finishPhoneNumerSelectedActionModeIfShown()) {
239 return;
240 }
Yorke Lee39213592014-04-07 15:39:48 -0700241 DialerUtils.startActivityWithErrorToast(CallDetailActivity.this,
242 ((ViewEntry) view.getTag()).primaryIntent);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700243 }
244 };
245
246 private final View.OnClickListener mSecondaryActionListener = new View.OnClickListener() {
247 @Override
248 public void onClick(View view) {
249 if (finishPhoneNumerSelectedActionModeIfShown()) {
250 return;
251 }
Yorke Lee39213592014-04-07 15:39:48 -0700252 DialerUtils.startActivityWithErrorToast(CallDetailActivity.this,
253 ((ViewEntry) view.getTag()).secondaryIntent);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700254 }
255 };
256
257 private final View.OnLongClickListener mPrimaryLongClickListener =
258 new View.OnLongClickListener() {
259 @Override
260 public boolean onLongClick(View v) {
261 if (finishPhoneNumerSelectedActionModeIfShown()) {
262 return true;
263 }
264 startPhoneNumberSelectedActionMode(v);
265 return true;
266 }
267 };
268
Yorke Lee03459442013-10-30 18:29:32 -0700269 private final LoaderCallbacks<Contact> mLoaderCallbacks = new LoaderCallbacks<Contact>() {
270 @Override
271 public void onLoaderReset(Loader<Contact> loader) {
272 }
273
274 @Override
275 public void onLoadFinished(Loader<Contact> loader, Contact data) {
276 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
277 intent.setType(Contacts.CONTENT_ITEM_TYPE);
278 if (data.getDisplayNameSource() >= DisplayNameSources.ORGANIZATION) {
279 intent.putExtra(Insert.NAME, data.getDisplayName());
280 }
281 intent.putExtra(Insert.DATA, data.getContentValues());
282 bindContactPhotoAction(intent, R.drawable.ic_add_contact_holo_dark,
283 getString(R.string.description_add_contact));
284 }
285
286 @Override
287 public Loader<Contact> onCreateLoader(int id, Bundle args) {
288 final Uri contactUri = args.getParcelable(BUNDLE_CONTACT_URI_EXTRA);
289 if (contactUri == null) {
290 Log.wtf(TAG, "No contact lookup uri provided.");
291 }
292 return new ContactLoader(CallDetailActivity.this, contactUri,
293 false /* loadGroupMetaData */, false /* loadInvitableAccountTypes */,
294 false /* postViewNotification */, true /* computeFormattedPhoneNumber */);
295 }
296 };
297
Chiao Cheng94b10b52012-08-17 16:59:12 -0700298 @Override
299 protected void onCreate(Bundle icicle) {
300 super.onCreate(icicle);
301
302 setContentView(R.layout.call_detail);
303
304 mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor();
305 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
306 mResources = getResources();
307
308 mCallTypeHelper = new CallTypeHelper(getResources());
Yorke Lee24ec3192013-11-19 13:52:45 -0800309 mPhoneNumberHelper = new PhoneNumberDisplayHelper(mResources);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700310 mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper,
Chiao Chengfb0a9342013-09-13 17:27:42 -0700311 new PhoneNumberUtilsWrapper());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700312 mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
313 mAsyncQueryHandler = new CallDetailActivityQueryHandler(this);
314 mHeaderTextView = (TextView) findViewById(R.id.header_text);
315 mHeaderOverlayView = findViewById(R.id.photo_text_bar);
316 mStatusMessageView = findViewById(R.id.voicemail_status);
317 mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message);
318 mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action);
319 mMainActionView = (ImageView) findViewById(R.id.main_action);
320 mMainActionPushLayerView = (ImageButton) findViewById(R.id.main_action_push_layer);
321 mContactBackgroundView = (ImageView) findViewById(R.id.contact_background);
Chiao Cheng35071c02012-10-15 18:36:24 -0700322 mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700323 mContactPhotoManager = ContactPhotoManager.getInstance(this);
324 mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener);
Chiao Cheng35071c02012-10-15 18:36:24 -0700325 mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this));
Chiao Chengadb742c2013-10-07 17:46:25 -0700326 getActionBar().setDisplayHomeAsUpEnabled(true);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700327 optionallyHandleVoicemail();
328 if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
329 closeSystemDialogs();
330 }
331 }
332
333 @Override
334 public void onResume() {
335 super.onResume();
336 updateData(getCallLogEntryUris());
337 }
338
339 /**
340 * Handle voicemail playback or hide voicemail ui.
341 * <p>
342 * If the Intent used to start this Activity contains the suitable extras, then start voicemail
343 * playback. If it doesn't, then hide the voicemail ui.
344 */
345 private void optionallyHandleVoicemail() {
346 View voicemailContainer = findViewById(R.id.voicemail_container);
347 if (hasVoicemail()) {
348 // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri
349 // to play and optionally start the playback.
350 // Do a query to fetch the voicemail status messages.
351 VoicemailPlaybackFragment playbackFragment = new VoicemailPlaybackFragment();
352 Bundle fragmentArguments = new Bundle();
353 fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, getVoicemailUri());
354 if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) {
355 fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true);
356 }
357 playbackFragment.setArguments(fragmentArguments);
358 voicemailContainer.setVisibility(View.VISIBLE);
359 getFragmentManager().beginTransaction()
Yorke Leeaa536fd2013-07-29 11:31:04 -0700360 .add(R.id.voicemail_container, playbackFragment)
361 .commitAllowingStateLoss();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700362 mAsyncQueryHandler.startVoicemailStatusQuery(getVoicemailUri());
363 markVoicemailAsRead(getVoicemailUri());
364 } else {
365 // No voicemail uri: hide the status view.
366 mStatusMessageView.setVisibility(View.GONE);
367 voicemailContainer.setVisibility(View.GONE);
368 }
369 }
370
371 private boolean hasVoicemail() {
372 return getVoicemailUri() != null;
373 }
374
375 private Uri getVoicemailUri() {
376 return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
377 }
378
379 private void markVoicemailAsRead(final Uri voicemailUri) {
380 mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() {
381 @Override
382 public Void doInBackground(Void... params) {
383 ContentValues values = new ContentValues();
384 values.put(Voicemails.IS_READ, true);
385 getContentResolver().update(voicemailUri, values,
386 Voicemails.IS_READ + " = 0", null);
387 return null;
388 }
389 });
390 }
391
392 /**
393 * Returns the list of URIs to show.
394 * <p>
395 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
396 * a list of ids in the call log added as an extra on the URI.
397 * <p>
398 * If both are available, the data on the intent takes precedence.
399 */
400 private Uri[] getCallLogEntryUris() {
Jay Shrauner757bdd32014-05-28 10:13:40 -0700401 final Uri uri = getIntent().getData();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700402 if (uri != null) {
403 // If there is a data on the intent, it takes precedence over the extra.
404 return new Uri[]{ uri };
405 }
Jay Shrauner757bdd32014-05-28 10:13:40 -0700406 final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
407 final int numIds = ids == null ? 0 : ids.length;
408 final Uri[] uris = new Uri[numIds];
409 for (int index = 0; index < numIds; ++index) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700410 uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]);
411 }
412 return uris;
413 }
414
415 @Override
416 public boolean onKeyDown(int keyCode, KeyEvent event) {
417 switch (keyCode) {
418 case KeyEvent.KEYCODE_CALL: {
419 // Make sure phone isn't already busy before starting direct call
420 TelephonyManager tm = (TelephonyManager)
421 getSystemService(Context.TELEPHONY_SERVICE);
422 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
Yorke Lee39213592014-04-07 15:39:48 -0700423 DialerUtils.startActivityWithErrorToast(this,
424 CallUtil.getCallIntent(Uri.fromParts(CallUtil.SCHEME_TEL, mNumber,
425 null)),
426 R.string.call_not_available);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700427 return true;
428 }
429 }
430 }
431
432 return super.onKeyDown(keyCode, event);
433 }
434
435 /**
436 * Update user interface with details of given call.
437 *
438 * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed
439 */
440 private void updateData(final Uri... callUris) {
441 class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> {
442 @Override
443 public PhoneCallDetails[] doInBackground(Void... params) {
444 // TODO: All phone calls correspond to the same person, so we can make a single
445 // lookup.
446 final int numCalls = callUris.length;
447 PhoneCallDetails[] details = new PhoneCallDetails[numCalls];
448 try {
449 for (int index = 0; index < numCalls; ++index) {
450 details[index] = getPhoneCallDetailsForUri(callUris[index]);
451 }
452 return details;
453 } catch (IllegalArgumentException e) {
454 // Something went wrong reading in our primary data.
455 Log.w(TAG, "invalid URI starting call details", e);
456 return null;
457 }
458 }
459
460 @Override
461 public void onPostExecute(PhoneCallDetails[] details) {
462 if (details == null) {
463 // Somewhere went wrong: we're going to bail out and show error to users.
464 Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error,
465 Toast.LENGTH_SHORT).show();
466 finish();
467 return;
468 }
469
470 // We know that all calls are from the same number and the same contact, so pick the
471 // first.
472 PhoneCallDetails firstDetails = details[0];
473 mNumber = firstDetails.number.toString();
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700474 final int numberPresentation = firstDetails.numberPresentation;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700475 final Uri contactUri = firstDetails.contactUri;
476 final Uri photoUri = firstDetails.photoUri;
477
478 // Set the details header, based on the first phone call.
479 mPhoneCallDetailsHelper.setCallDetailsHeader(mHeaderTextView, firstDetails);
480
481 // Cache the details about the phone number.
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700482 final boolean canPlaceCallsTo =
Chiao Chengfb0a9342013-09-13 17:27:42 -0700483 PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation);
484 final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper();
485 final boolean isVoicemailNumber = phoneUtils.isVoicemailNumber(mNumber);
486 final boolean isSipNumber = phoneUtils.isSipNumber(mNumber);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700487
488 // Let user view contact details if they exist, otherwise add option to create new
489 // contact from this number.
490 final Intent mainActionIntent;
491 final int mainActionIcon;
492 final String mainActionDescription;
493
494 final CharSequence nameOrNumber;
495 if (!TextUtils.isEmpty(firstDetails.name)) {
496 nameOrNumber = firstDetails.name;
497 } else {
498 nameOrNumber = firstDetails.number;
499 }
500
Yorke Leecce501c2013-11-08 07:54:23 -0800501 boolean skipBind = false;
502
Yorke Lee58ebe5d2013-09-09 10:19:40 -0700503 if (contactUri != null && !UriUtils.isEncodedContactUri(contactUri)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700504 mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri);
505 // This will launch People's detail contact screen, so we probably want to
506 // treat it as a separate People task.
507 mainActionIntent.setFlags(
508 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
509 mainActionIcon = R.drawable.ic_contacts_holo_dark;
510 mainActionDescription =
511 getString(R.string.description_view_contact, nameOrNumber);
Yorke Lee03459442013-10-30 18:29:32 -0700512 } else if (UriUtils.isEncodedContactUri(contactUri)) {
513 final Bundle bundle = new Bundle(1);
514 bundle.putParcelable(BUNDLE_CONTACT_URI_EXTRA, contactUri);
515 getLoaderManager().initLoader(LOADER_ID, bundle, mLoaderCallbacks);
516 mainActionIntent = null;
517 mainActionIcon = R.drawable.ic_add_contact_holo_dark;
518 mainActionDescription = getString(R.string.description_add_contact);
Yorke Leecce501c2013-11-08 07:54:23 -0800519 skipBind = true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700520 } else if (isVoicemailNumber) {
521 mainActionIntent = null;
522 mainActionIcon = 0;
523 mainActionDescription = null;
524 } else if (isSipNumber) {
525 // TODO: This item is currently disabled for SIP addresses, because
526 // the Insert.PHONE extra only works correctly for PSTN numbers.
527 //
528 // To fix this for SIP addresses, we need to:
529 // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if
530 // the current number is a SIP address
531 // - update the contacts UI code to handle Insert.SIP_ADDRESS by
532 // updating the SipAddress field
533 // and then we can remove the "!isSipNumber" check above.
534 mainActionIntent = null;
535 mainActionIcon = 0;
536 mainActionDescription = null;
537 } else if (canPlaceCallsTo) {
538 mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
539 mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE);
540 mainActionIntent.putExtra(Insert.PHONE, mNumber);
541 mainActionIcon = R.drawable.ic_add_contact_holo_dark;
542 mainActionDescription = getString(R.string.description_add_contact);
543 } else {
Yorke Lee03459442013-10-30 18:29:32 -0700544 // If we cannot call the number, when we probably cannot add it as a contact
545 // either. This is usually the case of private, unknown, or payphone numbers.
Chiao Cheng94b10b52012-08-17 16:59:12 -0700546 mainActionIntent = null;
547 mainActionIcon = 0;
548 mainActionDescription = null;
549 }
550
Yorke Leecce501c2013-11-08 07:54:23 -0800551 if (!skipBind) {
552 bindContactPhotoAction(mainActionIntent, mainActionIcon,
553 mainActionDescription);
554 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700555
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800556 final CharSequence displayNumber =
557 mPhoneNumberHelper.getDisplayNumber(
558 firstDetails.number,
559 firstDetails.numberPresentation,
560 firstDetails.formattedNumber);
561
Chiao Cheng94b10b52012-08-17 16:59:12 -0700562 // This action allows to call the number that places the call.
563 if (canPlaceCallsTo) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700564 ViewEntry entry = new ViewEntry(
565 getString(R.string.menu_callNumber,
Chiao Cheng35071c02012-10-15 18:36:24 -0700566 forceLeftToRight(displayNumber)),
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700567 CallUtil.getCallIntent(mNumber),
Chiao Cheng94b10b52012-08-17 16:59:12 -0700568 getString(R.string.description_call, nameOrNumber));
569
570 // Only show a label if the number is shown and it is not a SIP address.
571 if (!TextUtils.isEmpty(firstDetails.name)
572 && !TextUtils.isEmpty(firstDetails.number)
Yorke Lee37d29852013-11-19 14:11:24 -0800573 && !PhoneNumberHelper.isUriNumber(firstDetails.number.toString())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700574 entry.label = Phone.getTypeLabel(mResources, firstDetails.numberType,
575 firstDetails.numberLabel);
576 }
577
578 // The secondary action allows to send an SMS to the number that placed the
579 // call.
Chiao Chengfb0a9342013-09-13 17:27:42 -0700580 if (phoneUtils.canSendSmsTo(mNumber, numberPresentation)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700581 entry.setSecondaryAction(
Yorke Leeaa536fd2013-07-29 11:31:04 -0700582 R.drawable.ic_text_holo_light,
Chiao Cheng94b10b52012-08-17 16:59:12 -0700583 new Intent(Intent.ACTION_SENDTO,
584 Uri.fromParts("sms", mNumber, null)),
585 getString(R.string.description_send_text_message, nameOrNumber));
586 }
587
588 configureCallButton(entry);
589 mPhoneNumberToCopy = displayNumber;
590 mPhoneNumberLabelToCopy = entry.label;
591 } else {
592 disableCallButton();
593 mPhoneNumberToCopy = null;
594 mPhoneNumberLabelToCopy = null;
595 }
596
597 mHasEditNumberBeforeCallOption =
598 canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
599 mHasTrashOption = hasVoicemail();
600 mHasRemoveFromCallLogOption = !hasVoicemail();
601 invalidateOptionsMenu();
602
603 ListView historyList = (ListView) findViewById(R.id.history);
604 historyList.setAdapter(
605 new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater,
606 mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo,
607 findViewById(R.id.controls)));
608 BackScrollManager.bind(
609 new ScrollableHeader() {
610 private View mControls = findViewById(R.id.controls);
611 private View mPhoto = findViewById(R.id.contact_background_sizer);
612 private View mHeader = findViewById(R.id.photo_text_bar);
Yorke Leeac09b512013-09-09 08:51:54 -0700613 private View mSeparator = findViewById(R.id.separator);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700614
615 @Override
616 public void setOffset(int offset) {
617 mControls.setY(-offset);
618 }
619
620 @Override
621 public int getMaximumScrollableHeaderOffset() {
622 // We can scroll the photo out, but we should keep the header if
623 // present.
624 if (mHeader.getVisibility() == View.VISIBLE) {
625 return mPhoto.getHeight() - mHeader.getHeight();
626 } else {
627 // If the header is not present, we should also scroll out the
628 // separator line.
629 return mPhoto.getHeight() + mSeparator.getHeight();
630 }
631 }
632 },
633 historyList);
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800634
635 final String displayNameForDefaultImage = TextUtils.isEmpty(firstDetails.name) ?
636 displayNumber.toString() : firstDetails.name.toString();
637
638 final String lookupKey = ContactInfoHelper.getLookupKeyFromUri(contactUri);
639
640 final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType);
641
642 final int contactType =
643 isVoicemailNumber? ContactPhotoManager.TYPE_VOICEMAIL :
644 isBusiness ? ContactPhotoManager.TYPE_BUSINESS :
645 ContactPhotoManager.TYPE_DEFAULT;
646
647 loadContactPhotos(photoUri, displayNameForDefaultImage, lookupKey, contactType);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700648 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
649 }
650 }
651 mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask());
652 }
653
Yorke Lee03459442013-10-30 18:29:32 -0700654 private void bindContactPhotoAction(final Intent actionIntent, int actionIcon,
655 String actionDescription) {
656 if (actionIntent == null) {
657 mMainActionView.setVisibility(View.INVISIBLE);
658 mMainActionPushLayerView.setVisibility(View.GONE);
659 mHeaderTextView.setVisibility(View.INVISIBLE);
660 mHeaderOverlayView.setVisibility(View.INVISIBLE);
661 } else {
662 mMainActionView.setVisibility(View.VISIBLE);
663 mMainActionView.setImageResource(actionIcon);
664 mMainActionPushLayerView.setVisibility(View.VISIBLE);
665 mMainActionPushLayerView.setOnClickListener(new View.OnClickListener() {
666 @Override
667 public void onClick(View v) {
Yorke Lee39213592014-04-07 15:39:48 -0700668 DialerUtils.startActivityWithErrorToast(CallDetailActivity.this, actionIntent,
669 R.string.add_contact_not_available);
Yorke Lee03459442013-10-30 18:29:32 -0700670 }
671 });
672 mMainActionPushLayerView.setContentDescription(actionDescription);
673 mHeaderTextView.setVisibility(View.VISIBLE);
674 mHeaderOverlayView.setVisibility(View.VISIBLE);
675 }
676 }
677
Chiao Cheng94b10b52012-08-17 16:59:12 -0700678 /** Return the phone call details for a given call log URI. */
679 private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
680 ContentResolver resolver = getContentResolver();
681 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
682 try {
683 if (callCursor == null || !callCursor.moveToFirst()) {
684 throw new IllegalArgumentException("Cannot find content: " + callUri);
685 }
686
687 // Read call log specifics.
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700688 final String number = callCursor.getString(NUMBER_COLUMN_INDEX);
689 final int numberPresentation = callCursor.getInt(
690 NUMBER_PRESENTATION_COLUMN_INDEX);
691 final long date = callCursor.getLong(DATE_COLUMN_INDEX);
692 final long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
693 final int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700694 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
695 final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX);
696
697 if (TextUtils.isEmpty(countryIso)) {
698 countryIso = mDefaultCountryIso;
699 }
700
701 // Formatted phone number.
702 final CharSequence formattedNumber;
703 // Read contact specifics.
704 final CharSequence nameText;
705 final int numberType;
706 final CharSequence numberLabel;
707 final Uri photoUri;
708 final Uri lookupUri;
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800709 int sourceType;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700710 // If this is not a regular number, there is no point in looking it up in the contacts.
711 ContactInfo info =
Chiao Chengfb0a9342013-09-13 17:27:42 -0700712 PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
Yorke Lee1a7c1962013-09-20 16:04:34 -0700713 && !new PhoneNumberUtilsWrapper().isVoicemailNumber(number)
Chiao Cheng94b10b52012-08-17 16:59:12 -0700714 ? mContactInfoHelper.lookupNumber(number, countryIso)
715 : null;
716 if (info == null) {
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700717 formattedNumber = mPhoneNumberHelper.getDisplayNumber(number,
718 numberPresentation, null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700719 nameText = "";
720 numberType = 0;
721 numberLabel = "";
722 photoUri = null;
723 lookupUri = null;
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800724 sourceType = 0;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700725 } else {
726 formattedNumber = info.formattedNumber;
727 nameText = info.name;
728 numberType = info.type;
729 numberLabel = info.label;
730 photoUri = info.photoUri;
731 lookupUri = info.lookupUri;
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800732 sourceType = info.sourceType;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700733 }
Jay Shrauner719a7ad2013-05-30 15:41:13 -0700734 return new PhoneCallDetails(number, numberPresentation,
735 formattedNumber, countryIso, geocode,
Chiao Cheng94b10b52012-08-17 16:59:12 -0700736 new int[]{ callType }, date, duration,
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800737 nameText, numberType, numberLabel, lookupUri, photoUri, sourceType);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700738 } finally {
739 if (callCursor != null) {
740 callCursor.close();
741 }
742 }
743 }
744
745 /** Load the contact photos and places them in the corresponding views. */
Yorke Lee56cb0ef2014-02-21 10:02:18 -0800746 private void loadContactPhotos(Uri photoUri, String displayName, String lookupKey,
747 int contactType) {
748 final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey,
Yorke Leecb481aa2014-04-28 18:43:40 -0700749 contactType, false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700750 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri,
Yorke Leecb481aa2014-04-28 18:43:40 -0700751 mContactBackgroundView.getWidth(), true, false /* isCircular */, request);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700752 }
753
754 static final class ViewEntry {
755 public final String text;
756 public final Intent primaryIntent;
757 /** The description for accessibility of the primary action. */
758 public final String primaryDescription;
759
760 public CharSequence label = null;
761 /** Icon for the secondary action. */
762 public int secondaryIcon = 0;
763 /** Intent for the secondary action. If not null, an icon must be defined. */
764 public Intent secondaryIntent = null;
765 /** The description for accessibility of the secondary action. */
766 public String secondaryDescription = null;
767
768 public ViewEntry(String text, Intent intent, String description) {
769 this.text = text;
770 primaryIntent = intent;
771 primaryDescription = description;
772 }
773
774 public void setSecondaryAction(int icon, Intent intent, String description) {
775 secondaryIcon = icon;
776 secondaryIntent = intent;
777 secondaryDescription = description;
778 }
779 }
780
781 /** Disables the call button area, e.g., for private numbers. */
782 private void disableCallButton() {
783 findViewById(R.id.call_and_sms).setVisibility(View.GONE);
784 }
785
786 /** Configures the call button area using the given entry. */
787 private void configureCallButton(ViewEntry entry) {
788 View convertView = findViewById(R.id.call_and_sms);
789 convertView.setVisibility(View.VISIBLE);
790
791 ImageView icon = (ImageView) convertView.findViewById(R.id.call_and_sms_icon);
792 View divider = convertView.findViewById(R.id.call_and_sms_divider);
793 TextView text = (TextView) convertView.findViewById(R.id.call_and_sms_text);
794
795 View mainAction = convertView.findViewById(R.id.call_and_sms_main_action);
796 mainAction.setOnClickListener(mPrimaryActionListener);
797 mainAction.setTag(entry);
798 mainAction.setContentDescription(entry.primaryDescription);
799 mainAction.setOnLongClickListener(mPrimaryLongClickListener);
800
801 if (entry.secondaryIntent != null) {
802 icon.setOnClickListener(mSecondaryActionListener);
803 icon.setImageResource(entry.secondaryIcon);
804 icon.setVisibility(View.VISIBLE);
805 icon.setTag(entry);
806 icon.setContentDescription(entry.secondaryDescription);
807 divider.setVisibility(View.VISIBLE);
808 } else {
809 icon.setVisibility(View.GONE);
810 divider.setVisibility(View.GONE);
811 }
812 text.setText(entry.text);
813
814 TextView label = (TextView) convertView.findViewById(R.id.call_and_sms_label);
815 if (TextUtils.isEmpty(entry.label)) {
816 label.setVisibility(View.GONE);
817 } else {
818 label.setText(entry.label);
819 label.setVisibility(View.VISIBLE);
820 }
821 }
822
823 protected void updateVoicemailStatusMessage(Cursor statusCursor) {
824 if (statusCursor == null) {
825 mStatusMessageView.setVisibility(View.GONE);
826 return;
827 }
828 final StatusMessage message = getStatusMessage(statusCursor);
829 if (message == null || !message.showInCallDetails()) {
830 mStatusMessageView.setVisibility(View.GONE);
831 return;
832 }
833
834 mStatusMessageView.setVisibility(View.VISIBLE);
835 mStatusMessageText.setText(message.callDetailsMessageId);
836 if (message.actionMessageId != -1) {
837 mStatusMessageAction.setText(message.actionMessageId);
838 }
839 if (message.actionUri != null) {
840 mStatusMessageAction.setClickable(true);
841 mStatusMessageAction.setOnClickListener(new View.OnClickListener() {
842 @Override
843 public void onClick(View v) {
Yorke Lee39213592014-04-07 15:39:48 -0700844 DialerUtils.startActivityWithErrorToast(CallDetailActivity.this,
845 new Intent(Intent.ACTION_VIEW, message.actionUri));
Chiao Cheng94b10b52012-08-17 16:59:12 -0700846 }
847 });
848 } else {
849 mStatusMessageAction.setClickable(false);
850 }
851 }
852
853 private StatusMessage getStatusMessage(Cursor statusCursor) {
854 List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor);
855 if (messages.size() == 0) {
856 return null;
857 }
858 // There can only be a single status message per source package, so num of messages can
859 // at most be 1.
860 if (messages.size() > 1) {
861 Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." +
862 " Will use the first one.", messages.size()));
863 }
864 return messages.get(0);
865 }
866
867 @Override
868 public boolean onCreateOptionsMenu(Menu menu) {
869 getMenuInflater().inflate(R.menu.call_details_options, menu);
870 return super.onCreateOptionsMenu(menu);
871 }
872
873 @Override
874 public boolean onPrepareOptionsMenu(Menu menu) {
875 // This action deletes all elements in the group from the call log.
876 // We don't have this action for voicemails, because you can just use the trash button.
877 menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption);
878 menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption);
879 menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption);
880 return super.onPrepareOptionsMenu(menu);
881 }
882
Chiao Cheng94b10b52012-08-17 16:59:12 -0700883 public void onMenuRemoveFromCallLog(MenuItem menuItem) {
884 final StringBuilder callIds = new StringBuilder();
885 for (Uri callUri : getCallLogEntryUris()) {
886 if (callIds.length() != 0) {
887 callIds.append(",");
888 }
889 callIds.append(ContentUris.parseId(callUri));
890 }
891 mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH,
892 new AsyncTask<Void, Void, Void>() {
893 @Override
894 public Void doInBackground(Void... params) {
895 getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
896 Calls._ID + " IN (" + callIds + ")", null);
897 return null;
898 }
899
900 @Override
901 public void onPostExecute(Void result) {
902 finish();
903 }
904 });
905 }
906
907 public void onMenuEditNumberBeforeCall(MenuItem menuItem) {
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700908 startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber)));
Chiao Cheng94b10b52012-08-17 16:59:12 -0700909 }
910
911 public void onMenuTrashVoicemail(MenuItem menuItem) {
912 final Uri voicemailUri = getVoicemailUri();
913 mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH,
914 new AsyncTask<Void, Void, Void>() {
915 @Override
916 public Void doInBackground(Void... params) {
917 getContentResolver().delete(voicemailUri, null, null);
918 return null;
919 }
920 @Override
921 public void onPostExecute(Void result) {
922 finish();
923 }
924 });
925 }
926
Chiao Cheng94b10b52012-08-17 16:59:12 -0700927 /** Invoked when the user presses the home button in the action bar. */
928 private void onHomeSelected() {
929 Intent intent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI);
930 // This will open the call log even if the detail view has been opened directly.
931 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
932 startActivity(intent);
933 finish();
934 }
935
936 @Override
937 protected void onPause() {
938 // Immediately stop the proximity sensor.
939 disableProximitySensor(false);
940 mProximitySensorListener.clearPendingRequests();
941 super.onPause();
942 }
943
944 @Override
945 public void enableProximitySensor() {
946 mProximitySensorManager.enable();
947 }
948
949 @Override
950 public void disableProximitySensor(boolean waitForFarState) {
951 mProximitySensorManager.disable(waitForFarState);
952 }
953
954 /**
955 * If the phone number is selected, unselect it and return {@code true}.
956 * Otherwise, just {@code false}.
957 */
958 private boolean finishPhoneNumerSelectedActionModeIfShown() {
959 if (mPhoneNumberActionMode == null) return false;
960 mPhoneNumberActionMode.finish();
961 return true;
962 }
963
964 private void startPhoneNumberSelectedActionMode(View targetView) {
965 mPhoneNumberActionMode = startActionMode(new PhoneNumberActionModeCallback(targetView));
966 }
967
968 private void closeSystemDialogs() {
969 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
970 }
971
972 private class PhoneNumberActionModeCallback implements ActionMode.Callback {
973 private final View mTargetView;
974 private final Drawable mOriginalViewBackground;
975
976 public PhoneNumberActionModeCallback(View targetView) {
977 mTargetView = targetView;
978
979 // Highlight the phone number view. Remember the old background, and put a new one.
980 mOriginalViewBackground = mTargetView.getBackground();
981 mTargetView.setBackgroundColor(getResources().getColor(R.color.item_selected));
982 }
983
984 @Override
985 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
986 if (TextUtils.isEmpty(mPhoneNumberToCopy)) return false;
987
988 getMenuInflater().inflate(R.menu.call_details_cab, menu);
989 return true;
990 }
991
992 @Override
993 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
994 return true;
995 }
996
997 @Override
998 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
999 switch (item.getItemId()) {
1000 case R.id.copy_phone_number:
1001 ClipboardUtils.copyText(CallDetailActivity.this, mPhoneNumberLabelToCopy,
1002 mPhoneNumberToCopy, true);
1003 mode.finish(); // Close the CAB
1004 return true;
1005 }
1006 return false;
1007 }
1008
1009 @Override
1010 public void onDestroyActionMode(ActionMode mode) {
1011 mPhoneNumberActionMode = null;
1012
1013 // Restore the view background.
1014 mTargetView.setBackground(mOriginalViewBackground);
1015 }
1016 }
Chiao Cheng35071c02012-10-15 18:36:24 -07001017
1018 /** Returns the given text, forced to be left-to-right. */
1019 private static CharSequence forceLeftToRight(CharSequence text) {
1020 StringBuilder sb = new StringBuilder();
1021 sb.append(LEFT_TO_RIGHT_EMBEDDING);
1022 sb.append(text);
1023 sb.append(POP_DIRECTIONAL_FORMATTING);
1024 return sb.toString();
1025 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001026}