Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.dialer; |
| 18 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
| 20 | import android.content.ContentResolver; |
| 21 | import android.content.ContentUris; |
| 22 | import android.content.ContentValues; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.res.Resources; |
| 26 | import android.database.Cursor; |
| 27 | import android.graphics.drawable.Drawable; |
| 28 | import android.net.Uri; |
| 29 | import android.os.AsyncTask; |
| 30 | import android.os.Bundle; |
| 31 | import android.provider.CallLog; |
| 32 | import android.provider.CallLog.Calls; |
| 33 | import android.provider.Contacts.Intents.Insert; |
| 34 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 35 | import android.provider.ContactsContract.Contacts; |
| 36 | import android.provider.VoicemailContract.Voicemails; |
| 37 | import android.telephony.PhoneNumberUtils; |
| 38 | import android.telephony.TelephonyManager; |
| 39 | import android.text.TextUtils; |
| 40 | import android.util.Log; |
| 41 | import android.view.ActionMode; |
| 42 | import android.view.KeyEvent; |
| 43 | import android.view.LayoutInflater; |
| 44 | import android.view.Menu; |
| 45 | import android.view.MenuItem; |
| 46 | import android.view.View; |
| 47 | import android.widget.ImageButton; |
| 48 | import android.widget.ImageView; |
| 49 | import android.widget.ListView; |
| 50 | import android.widget.TextView; |
| 51 | import android.widget.Toast; |
| 52 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 53 | import com.android.contacts.common.ContactPhotoManager; |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 54 | import com.android.contacts.common.CallUtil; |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 55 | import com.android.contacts.common.ClipboardUtils; |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 56 | import com.android.contacts.common.GeoUtil; |
Yorke Lee | 58ebe5d | 2013-09-09 10:19:40 -0700 | [diff] [blame] | 57 | import com.android.contacts.common.util.UriUtils; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 58 | import com.android.dialer.BackScrollManager.ScrollableHeader; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 59 | import com.android.dialer.calllog.CallDetailHistoryAdapter; |
| 60 | import com.android.dialer.calllog.CallTypeHelper; |
| 61 | import com.android.dialer.calllog.ContactInfo; |
| 62 | import com.android.dialer.calllog.ContactInfoHelper; |
| 63 | import com.android.dialer.calllog.PhoneNumberHelper; |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 64 | import com.android.dialer.calllog.PhoneNumberUtilsWrapper; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 65 | import com.android.dialer.util.AsyncTaskExecutor; |
| 66 | import com.android.dialer.util.AsyncTaskExecutors; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 67 | import com.android.dialer.voicemail.VoicemailPlaybackFragment; |
| 68 | import com.android.dialer.voicemail.VoicemailStatusHelper; |
| 69 | import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage; |
| 70 | import com.android.dialer.voicemail.VoicemailStatusHelperImpl; |
| 71 | |
| 72 | import java.util.List; |
| 73 | |
| 74 | /** |
| 75 | * Displays the details of a specific call log entry. |
| 76 | * <p> |
| 77 | * This activity can be either started with the URI of a single call log entry, or with the |
| 78 | * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries. |
| 79 | */ |
| 80 | public class CallDetailActivity extends Activity implements ProximitySensorAware { |
| 81 | private static final String TAG = "CallDetail"; |
| 82 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 83 | private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A'; |
| 84 | private static final char POP_DIRECTIONAL_FORMATTING = '\u202C'; |
| 85 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 86 | /** The time to wait before enabling the blank the screen due to the proximity sensor. */ |
| 87 | private static final long PROXIMITY_BLANK_DELAY_MILLIS = 100; |
| 88 | /** The time to wait before disabling the blank the screen due to the proximity sensor. */ |
| 89 | private static final long PROXIMITY_UNBLANK_DELAY_MILLIS = 500; |
| 90 | |
| 91 | /** The enumeration of {@link AsyncTask} objects used in this class. */ |
| 92 | public enum Tasks { |
| 93 | MARK_VOICEMAIL_READ, |
| 94 | DELETE_VOICEMAIL_AND_FINISH, |
| 95 | REMOVE_FROM_CALL_LOG_AND_FINISH, |
| 96 | UPDATE_PHONE_CALL_DETAILS, |
| 97 | } |
| 98 | |
| 99 | /** A long array extra containing ids of call log entries to display. */ |
| 100 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 101 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 102 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
| 103 | /** If we should immediately start playback of the voicemail, this extra will be set to true. */ |
| 104 | public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK"; |
| 105 | /** If the activity was triggered from a notification. */ |
| 106 | public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION"; |
| 107 | |
| 108 | private CallTypeHelper mCallTypeHelper; |
| 109 | private PhoneNumberHelper mPhoneNumberHelper; |
| 110 | private PhoneCallDetailsHelper mPhoneCallDetailsHelper; |
| 111 | private TextView mHeaderTextView; |
| 112 | private View mHeaderOverlayView; |
| 113 | private ImageView mMainActionView; |
| 114 | private ImageButton mMainActionPushLayerView; |
| 115 | private ImageView mContactBackgroundView; |
| 116 | private AsyncTaskExecutor mAsyncTaskExecutor; |
| 117 | private ContactInfoHelper mContactInfoHelper; |
| 118 | |
| 119 | private String mNumber = null; |
| 120 | private String mDefaultCountryIso; |
| 121 | |
| 122 | /* package */ LayoutInflater mInflater; |
| 123 | /* package */ Resources mResources; |
| 124 | /** Helper to load contact photos. */ |
| 125 | private ContactPhotoManager mContactPhotoManager; |
| 126 | /** Helper to make async queries to content resolver. */ |
| 127 | private CallDetailActivityQueryHandler mAsyncQueryHandler; |
| 128 | /** Helper to get voicemail status messages. */ |
| 129 | private VoicemailStatusHelper mVoicemailStatusHelper; |
| 130 | // Views related to voicemail status message. |
| 131 | private View mStatusMessageView; |
| 132 | private TextView mStatusMessageText; |
| 133 | private TextView mStatusMessageAction; |
| 134 | |
| 135 | /** Whether we should show "edit number before call" in the options menu. */ |
| 136 | private boolean mHasEditNumberBeforeCallOption; |
| 137 | /** Whether we should show "trash" in the options menu. */ |
| 138 | private boolean mHasTrashOption; |
| 139 | /** Whether we should show "remove from call log" in the options menu. */ |
| 140 | private boolean mHasRemoveFromCallLogOption; |
| 141 | |
| 142 | private ProximitySensorManager mProximitySensorManager; |
| 143 | private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener(); |
| 144 | |
| 145 | /** |
| 146 | * The action mode used when the phone number is selected. This will be non-null only when the |
| 147 | * phone number is selected. |
| 148 | */ |
| 149 | private ActionMode mPhoneNumberActionMode; |
| 150 | |
| 151 | private CharSequence mPhoneNumberLabelToCopy; |
| 152 | private CharSequence mPhoneNumberToCopy; |
| 153 | |
| 154 | /** Listener to changes in the proximity sensor state. */ |
| 155 | private class ProximitySensorListener implements ProximitySensorManager.Listener { |
| 156 | /** Used to show a blank view and hide the action bar. */ |
| 157 | private final Runnable mBlankRunnable = new Runnable() { |
| 158 | @Override |
| 159 | public void run() { |
| 160 | View blankView = findViewById(R.id.blank); |
| 161 | blankView.setVisibility(View.VISIBLE); |
| 162 | getActionBar().hide(); |
| 163 | } |
| 164 | }; |
| 165 | /** Used to remove the blank view and show the action bar. */ |
| 166 | private final Runnable mUnblankRunnable = new Runnable() { |
| 167 | @Override |
| 168 | public void run() { |
| 169 | View blankView = findViewById(R.id.blank); |
| 170 | blankView.setVisibility(View.GONE); |
| 171 | getActionBar().show(); |
| 172 | } |
| 173 | }; |
| 174 | |
| 175 | @Override |
| 176 | public synchronized void onNear() { |
| 177 | clearPendingRequests(); |
| 178 | postDelayed(mBlankRunnable, PROXIMITY_BLANK_DELAY_MILLIS); |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public synchronized void onFar() { |
| 183 | clearPendingRequests(); |
| 184 | postDelayed(mUnblankRunnable, PROXIMITY_UNBLANK_DELAY_MILLIS); |
| 185 | } |
| 186 | |
| 187 | /** Removed any delayed requests that may be pending. */ |
| 188 | public synchronized void clearPendingRequests() { |
| 189 | View blankView = findViewById(R.id.blank); |
| 190 | blankView.removeCallbacks(mBlankRunnable); |
| 191 | blankView.removeCallbacks(mUnblankRunnable); |
| 192 | } |
| 193 | |
| 194 | /** Post a {@link Runnable} with a delay on the main thread. */ |
| 195 | private synchronized void postDelayed(Runnable runnable, long delayMillis) { |
| 196 | // Post these instead of executing immediately so that: |
| 197 | // - They are guaranteed to be executed on the main thread. |
| 198 | // - If the sensor values changes rapidly for some time, the UI will not be |
| 199 | // updated immediately. |
| 200 | View blankView = findViewById(R.id.blank); |
| 201 | blankView.postDelayed(runnable, delayMillis); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | static final String[] CALL_LOG_PROJECTION = new String[] { |
| 206 | CallLog.Calls.DATE, |
| 207 | CallLog.Calls.DURATION, |
| 208 | CallLog.Calls.NUMBER, |
| 209 | CallLog.Calls.TYPE, |
| 210 | CallLog.Calls.COUNTRY_ISO, |
| 211 | CallLog.Calls.GEOCODED_LOCATION, |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 212 | CallLog.Calls.NUMBER_PRESENTATION, |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | static final int DATE_COLUMN_INDEX = 0; |
| 216 | static final int DURATION_COLUMN_INDEX = 1; |
| 217 | static final int NUMBER_COLUMN_INDEX = 2; |
| 218 | static final int CALL_TYPE_COLUMN_INDEX = 3; |
| 219 | static final int COUNTRY_ISO_COLUMN_INDEX = 4; |
| 220 | static final int GEOCODED_LOCATION_COLUMN_INDEX = 5; |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 221 | static final int NUMBER_PRESENTATION_COLUMN_INDEX = 6; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 222 | |
| 223 | private final View.OnClickListener mPrimaryActionListener = new View.OnClickListener() { |
| 224 | @Override |
| 225 | public void onClick(View view) { |
| 226 | if (finishPhoneNumerSelectedActionModeIfShown()) { |
| 227 | return; |
| 228 | } |
| 229 | startActivity(((ViewEntry) view.getTag()).primaryIntent); |
| 230 | } |
| 231 | }; |
| 232 | |
| 233 | private final View.OnClickListener mSecondaryActionListener = new View.OnClickListener() { |
| 234 | @Override |
| 235 | public void onClick(View view) { |
| 236 | if (finishPhoneNumerSelectedActionModeIfShown()) { |
| 237 | return; |
| 238 | } |
| 239 | startActivity(((ViewEntry) view.getTag()).secondaryIntent); |
| 240 | } |
| 241 | }; |
| 242 | |
| 243 | private final View.OnLongClickListener mPrimaryLongClickListener = |
| 244 | new View.OnLongClickListener() { |
| 245 | @Override |
| 246 | public boolean onLongClick(View v) { |
| 247 | if (finishPhoneNumerSelectedActionModeIfShown()) { |
| 248 | return true; |
| 249 | } |
| 250 | startPhoneNumberSelectedActionMode(v); |
| 251 | return true; |
| 252 | } |
| 253 | }; |
| 254 | |
| 255 | @Override |
| 256 | protected void onCreate(Bundle icicle) { |
| 257 | super.onCreate(icicle); |
| 258 | |
| 259 | setContentView(R.layout.call_detail); |
| 260 | |
| 261 | mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor(); |
| 262 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 263 | mResources = getResources(); |
| 264 | |
| 265 | mCallTypeHelper = new CallTypeHelper(getResources()); |
| 266 | mPhoneNumberHelper = new PhoneNumberHelper(mResources); |
| 267 | mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper, |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 268 | new PhoneNumberUtilsWrapper()); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 269 | mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); |
| 270 | mAsyncQueryHandler = new CallDetailActivityQueryHandler(this); |
| 271 | mHeaderTextView = (TextView) findViewById(R.id.header_text); |
| 272 | mHeaderOverlayView = findViewById(R.id.photo_text_bar); |
| 273 | mStatusMessageView = findViewById(R.id.voicemail_status); |
| 274 | mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message); |
| 275 | mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action); |
| 276 | mMainActionView = (ImageView) findViewById(R.id.main_action); |
| 277 | mMainActionPushLayerView = (ImageButton) findViewById(R.id.main_action_push_layer); |
| 278 | mContactBackgroundView = (ImageView) findViewById(R.id.contact_background); |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 279 | mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 280 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
| 281 | mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener); |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 282 | mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); |
Chiao Cheng | adb742c | 2013-10-07 17:46:25 -0700 | [diff] [blame^] | 283 | getActionBar().setDisplayHomeAsUpEnabled(true); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 284 | optionallyHandleVoicemail(); |
| 285 | if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) { |
| 286 | closeSystemDialogs(); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public void onResume() { |
| 292 | super.onResume(); |
| 293 | updateData(getCallLogEntryUris()); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Handle voicemail playback or hide voicemail ui. |
| 298 | * <p> |
| 299 | * If the Intent used to start this Activity contains the suitable extras, then start voicemail |
| 300 | * playback. If it doesn't, then hide the voicemail ui. |
| 301 | */ |
| 302 | private void optionallyHandleVoicemail() { |
| 303 | View voicemailContainer = findViewById(R.id.voicemail_container); |
| 304 | if (hasVoicemail()) { |
| 305 | // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri |
| 306 | // to play and optionally start the playback. |
| 307 | // Do a query to fetch the voicemail status messages. |
| 308 | VoicemailPlaybackFragment playbackFragment = new VoicemailPlaybackFragment(); |
| 309 | Bundle fragmentArguments = new Bundle(); |
| 310 | fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, getVoicemailUri()); |
| 311 | if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) { |
| 312 | fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true); |
| 313 | } |
| 314 | playbackFragment.setArguments(fragmentArguments); |
| 315 | voicemailContainer.setVisibility(View.VISIBLE); |
| 316 | getFragmentManager().beginTransaction() |
Yorke Lee | aa536fd | 2013-07-29 11:31:04 -0700 | [diff] [blame] | 317 | .add(R.id.voicemail_container, playbackFragment) |
| 318 | .commitAllowingStateLoss(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 319 | mAsyncQueryHandler.startVoicemailStatusQuery(getVoicemailUri()); |
| 320 | markVoicemailAsRead(getVoicemailUri()); |
| 321 | } else { |
| 322 | // No voicemail uri: hide the status view. |
| 323 | mStatusMessageView.setVisibility(View.GONE); |
| 324 | voicemailContainer.setVisibility(View.GONE); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | private boolean hasVoicemail() { |
| 329 | return getVoicemailUri() != null; |
| 330 | } |
| 331 | |
| 332 | private Uri getVoicemailUri() { |
| 333 | return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
| 334 | } |
| 335 | |
| 336 | private void markVoicemailAsRead(final Uri voicemailUri) { |
| 337 | mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() { |
| 338 | @Override |
| 339 | public Void doInBackground(Void... params) { |
| 340 | ContentValues values = new ContentValues(); |
| 341 | values.put(Voicemails.IS_READ, true); |
| 342 | getContentResolver().update(voicemailUri, values, |
| 343 | Voicemails.IS_READ + " = 0", null); |
| 344 | return null; |
| 345 | } |
| 346 | }); |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Returns the list of URIs to show. |
| 351 | * <p> |
| 352 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 353 | * a list of ids in the call log added as an extra on the URI. |
| 354 | * <p> |
| 355 | * If both are available, the data on the intent takes precedence. |
| 356 | */ |
| 357 | private Uri[] getCallLogEntryUris() { |
| 358 | Uri uri = getIntent().getData(); |
| 359 | if (uri != null) { |
| 360 | // If there is a data on the intent, it takes precedence over the extra. |
| 361 | return new Uri[]{ uri }; |
| 362 | } |
| 363 | long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 364 | Uri[] uris = new Uri[ids.length]; |
| 365 | for (int index = 0; index < ids.length; ++index) { |
| 366 | uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]); |
| 367 | } |
| 368 | return uris; |
| 369 | } |
| 370 | |
| 371 | @Override |
| 372 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 373 | switch (keyCode) { |
| 374 | case KeyEvent.KEYCODE_CALL: { |
| 375 | // Make sure phone isn't already busy before starting direct call |
| 376 | TelephonyManager tm = (TelephonyManager) |
| 377 | getSystemService(Context.TELEPHONY_SERVICE); |
| 378 | if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 379 | startActivity(CallUtil.getCallIntent( |
| 380 | Uri.fromParts(CallUtil.SCHEME_TEL, mNumber, null))); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 381 | return true; |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | return super.onKeyDown(keyCode, event); |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Update user interface with details of given call. |
| 391 | * |
| 392 | * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed |
| 393 | */ |
| 394 | private void updateData(final Uri... callUris) { |
| 395 | class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> { |
| 396 | @Override |
| 397 | public PhoneCallDetails[] doInBackground(Void... params) { |
| 398 | // TODO: All phone calls correspond to the same person, so we can make a single |
| 399 | // lookup. |
| 400 | final int numCalls = callUris.length; |
| 401 | PhoneCallDetails[] details = new PhoneCallDetails[numCalls]; |
| 402 | try { |
| 403 | for (int index = 0; index < numCalls; ++index) { |
| 404 | details[index] = getPhoneCallDetailsForUri(callUris[index]); |
| 405 | } |
| 406 | return details; |
| 407 | } catch (IllegalArgumentException e) { |
| 408 | // Something went wrong reading in our primary data. |
| 409 | Log.w(TAG, "invalid URI starting call details", e); |
| 410 | return null; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | @Override |
| 415 | public void onPostExecute(PhoneCallDetails[] details) { |
| 416 | if (details == null) { |
| 417 | // Somewhere went wrong: we're going to bail out and show error to users. |
| 418 | Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error, |
| 419 | Toast.LENGTH_SHORT).show(); |
| 420 | finish(); |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | // We know that all calls are from the same number and the same contact, so pick the |
| 425 | // first. |
| 426 | PhoneCallDetails firstDetails = details[0]; |
| 427 | mNumber = firstDetails.number.toString(); |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 428 | final int numberPresentation = firstDetails.numberPresentation; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 429 | final Uri contactUri = firstDetails.contactUri; |
| 430 | final Uri photoUri = firstDetails.photoUri; |
| 431 | |
| 432 | // Set the details header, based on the first phone call. |
| 433 | mPhoneCallDetailsHelper.setCallDetailsHeader(mHeaderTextView, firstDetails); |
| 434 | |
| 435 | // Cache the details about the phone number. |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 436 | final boolean canPlaceCallsTo = |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 437 | PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation); |
| 438 | final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(); |
| 439 | final boolean isVoicemailNumber = phoneUtils.isVoicemailNumber(mNumber); |
| 440 | final boolean isSipNumber = phoneUtils.isSipNumber(mNumber); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 441 | |
| 442 | // Let user view contact details if they exist, otherwise add option to create new |
| 443 | // contact from this number. |
| 444 | final Intent mainActionIntent; |
| 445 | final int mainActionIcon; |
| 446 | final String mainActionDescription; |
| 447 | |
| 448 | final CharSequence nameOrNumber; |
| 449 | if (!TextUtils.isEmpty(firstDetails.name)) { |
| 450 | nameOrNumber = firstDetails.name; |
| 451 | } else { |
| 452 | nameOrNumber = firstDetails.number; |
| 453 | } |
| 454 | |
Yorke Lee | 58ebe5d | 2013-09-09 10:19:40 -0700 | [diff] [blame] | 455 | if (contactUri != null && !UriUtils.isEncodedContactUri(contactUri)) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 456 | mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri); |
| 457 | // This will launch People's detail contact screen, so we probably want to |
| 458 | // treat it as a separate People task. |
| 459 | mainActionIntent.setFlags( |
| 460 | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 461 | mainActionIcon = R.drawable.ic_contacts_holo_dark; |
| 462 | mainActionDescription = |
| 463 | getString(R.string.description_view_contact, nameOrNumber); |
| 464 | } else if (isVoicemailNumber) { |
| 465 | mainActionIntent = null; |
| 466 | mainActionIcon = 0; |
| 467 | mainActionDescription = null; |
| 468 | } else if (isSipNumber) { |
| 469 | // TODO: This item is currently disabled for SIP addresses, because |
| 470 | // the Insert.PHONE extra only works correctly for PSTN numbers. |
| 471 | // |
| 472 | // To fix this for SIP addresses, we need to: |
| 473 | // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if |
| 474 | // the current number is a SIP address |
| 475 | // - update the contacts UI code to handle Insert.SIP_ADDRESS by |
| 476 | // updating the SipAddress field |
| 477 | // and then we can remove the "!isSipNumber" check above. |
| 478 | mainActionIntent = null; |
| 479 | mainActionIcon = 0; |
| 480 | mainActionDescription = null; |
| 481 | } else if (canPlaceCallsTo) { |
| 482 | mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 483 | mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 484 | mainActionIntent.putExtra(Insert.PHONE, mNumber); |
| 485 | mainActionIcon = R.drawable.ic_add_contact_holo_dark; |
| 486 | mainActionDescription = getString(R.string.description_add_contact); |
| 487 | } else { |
| 488 | // If we cannot call the number, when we probably cannot add it as a contact either. |
| 489 | // This is usually the case of private, unknown, or payphone numbers. |
| 490 | mainActionIntent = null; |
| 491 | mainActionIcon = 0; |
| 492 | mainActionDescription = null; |
| 493 | } |
| 494 | |
| 495 | if (mainActionIntent == null) { |
| 496 | mMainActionView.setVisibility(View.INVISIBLE); |
| 497 | mMainActionPushLayerView.setVisibility(View.GONE); |
| 498 | mHeaderTextView.setVisibility(View.INVISIBLE); |
| 499 | mHeaderOverlayView.setVisibility(View.INVISIBLE); |
| 500 | } else { |
| 501 | mMainActionView.setVisibility(View.VISIBLE); |
| 502 | mMainActionView.setImageResource(mainActionIcon); |
| 503 | mMainActionPushLayerView.setVisibility(View.VISIBLE); |
| 504 | mMainActionPushLayerView.setOnClickListener(new View.OnClickListener() { |
| 505 | @Override |
| 506 | public void onClick(View v) { |
| 507 | startActivity(mainActionIntent); |
| 508 | } |
| 509 | }); |
| 510 | mMainActionPushLayerView.setContentDescription(mainActionDescription); |
| 511 | mHeaderTextView.setVisibility(View.VISIBLE); |
| 512 | mHeaderOverlayView.setVisibility(View.VISIBLE); |
| 513 | } |
| 514 | |
| 515 | // This action allows to call the number that places the call. |
| 516 | if (canPlaceCallsTo) { |
| 517 | final CharSequence displayNumber = |
| 518 | mPhoneNumberHelper.getDisplayNumber( |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 519 | firstDetails.number, |
| 520 | firstDetails.numberPresentation, |
| 521 | firstDetails.formattedNumber); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 522 | |
| 523 | ViewEntry entry = new ViewEntry( |
| 524 | getString(R.string.menu_callNumber, |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 525 | forceLeftToRight(displayNumber)), |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 526 | CallUtil.getCallIntent(mNumber), |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 527 | getString(R.string.description_call, nameOrNumber)); |
| 528 | |
| 529 | // Only show a label if the number is shown and it is not a SIP address. |
| 530 | if (!TextUtils.isEmpty(firstDetails.name) |
| 531 | && !TextUtils.isEmpty(firstDetails.number) |
| 532 | && !PhoneNumberUtils.isUriNumber(firstDetails.number.toString())) { |
| 533 | entry.label = Phone.getTypeLabel(mResources, firstDetails.numberType, |
| 534 | firstDetails.numberLabel); |
| 535 | } |
| 536 | |
| 537 | // The secondary action allows to send an SMS to the number that placed the |
| 538 | // call. |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 539 | if (phoneUtils.canSendSmsTo(mNumber, numberPresentation)) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 540 | entry.setSecondaryAction( |
Yorke Lee | aa536fd | 2013-07-29 11:31:04 -0700 | [diff] [blame] | 541 | R.drawable.ic_text_holo_light, |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 542 | new Intent(Intent.ACTION_SENDTO, |
| 543 | Uri.fromParts("sms", mNumber, null)), |
| 544 | getString(R.string.description_send_text_message, nameOrNumber)); |
| 545 | } |
| 546 | |
| 547 | configureCallButton(entry); |
| 548 | mPhoneNumberToCopy = displayNumber; |
| 549 | mPhoneNumberLabelToCopy = entry.label; |
| 550 | } else { |
| 551 | disableCallButton(); |
| 552 | mPhoneNumberToCopy = null; |
| 553 | mPhoneNumberLabelToCopy = null; |
| 554 | } |
| 555 | |
| 556 | mHasEditNumberBeforeCallOption = |
| 557 | canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; |
| 558 | mHasTrashOption = hasVoicemail(); |
| 559 | mHasRemoveFromCallLogOption = !hasVoicemail(); |
| 560 | invalidateOptionsMenu(); |
| 561 | |
| 562 | ListView historyList = (ListView) findViewById(R.id.history); |
| 563 | historyList.setAdapter( |
| 564 | new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater, |
| 565 | mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo, |
| 566 | findViewById(R.id.controls))); |
| 567 | BackScrollManager.bind( |
| 568 | new ScrollableHeader() { |
| 569 | private View mControls = findViewById(R.id.controls); |
| 570 | private View mPhoto = findViewById(R.id.contact_background_sizer); |
| 571 | private View mHeader = findViewById(R.id.photo_text_bar); |
Yorke Lee | ac09b51 | 2013-09-09 08:51:54 -0700 | [diff] [blame] | 572 | private View mSeparator = findViewById(R.id.separator); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 573 | |
| 574 | @Override |
| 575 | public void setOffset(int offset) { |
| 576 | mControls.setY(-offset); |
| 577 | } |
| 578 | |
| 579 | @Override |
| 580 | public int getMaximumScrollableHeaderOffset() { |
| 581 | // We can scroll the photo out, but we should keep the header if |
| 582 | // present. |
| 583 | if (mHeader.getVisibility() == View.VISIBLE) { |
| 584 | return mPhoto.getHeight() - mHeader.getHeight(); |
| 585 | } else { |
| 586 | // If the header is not present, we should also scroll out the |
| 587 | // separator line. |
| 588 | return mPhoto.getHeight() + mSeparator.getHeight(); |
| 589 | } |
| 590 | } |
| 591 | }, |
| 592 | historyList); |
| 593 | loadContactPhotos(photoUri); |
| 594 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
| 595 | } |
| 596 | } |
| 597 | mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask()); |
| 598 | } |
| 599 | |
| 600 | /** Return the phone call details for a given call log URI. */ |
| 601 | private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) { |
| 602 | ContentResolver resolver = getContentResolver(); |
| 603 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 604 | try { |
| 605 | if (callCursor == null || !callCursor.moveToFirst()) { |
| 606 | throw new IllegalArgumentException("Cannot find content: " + callUri); |
| 607 | } |
| 608 | |
| 609 | // Read call log specifics. |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 610 | final String number = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 611 | final int numberPresentation = callCursor.getInt( |
| 612 | NUMBER_PRESENTATION_COLUMN_INDEX); |
| 613 | final long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 614 | final long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 615 | final int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 616 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 617 | final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX); |
| 618 | |
| 619 | if (TextUtils.isEmpty(countryIso)) { |
| 620 | countryIso = mDefaultCountryIso; |
| 621 | } |
| 622 | |
| 623 | // Formatted phone number. |
| 624 | final CharSequence formattedNumber; |
| 625 | // Read contact specifics. |
| 626 | final CharSequence nameText; |
| 627 | final int numberType; |
| 628 | final CharSequence numberLabel; |
| 629 | final Uri photoUri; |
| 630 | final Uri lookupUri; |
| 631 | // If this is not a regular number, there is no point in looking it up in the contacts. |
| 632 | ContactInfo info = |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 633 | PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) |
Yorke Lee | 1a7c196 | 2013-09-20 16:04:34 -0700 | [diff] [blame] | 634 | && !new PhoneNumberUtilsWrapper().isVoicemailNumber(number) |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 635 | ? mContactInfoHelper.lookupNumber(number, countryIso) |
| 636 | : null; |
| 637 | if (info == null) { |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 638 | formattedNumber = mPhoneNumberHelper.getDisplayNumber(number, |
| 639 | numberPresentation, null); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 640 | nameText = ""; |
| 641 | numberType = 0; |
| 642 | numberLabel = ""; |
| 643 | photoUri = null; |
| 644 | lookupUri = null; |
| 645 | } else { |
| 646 | formattedNumber = info.formattedNumber; |
| 647 | nameText = info.name; |
| 648 | numberType = info.type; |
| 649 | numberLabel = info.label; |
| 650 | photoUri = info.photoUri; |
| 651 | lookupUri = info.lookupUri; |
| 652 | } |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 653 | return new PhoneCallDetails(number, numberPresentation, |
| 654 | formattedNumber, countryIso, geocode, |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 655 | new int[]{ callType }, date, duration, |
| 656 | nameText, numberType, numberLabel, lookupUri, photoUri); |
| 657 | } finally { |
| 658 | if (callCursor != null) { |
| 659 | callCursor.close(); |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | /** Load the contact photos and places them in the corresponding views. */ |
| 665 | private void loadContactPhotos(Uri photoUri) { |
| 666 | mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri, |
| 667 | mContactBackgroundView.getWidth(), true); |
| 668 | } |
| 669 | |
| 670 | static final class ViewEntry { |
| 671 | public final String text; |
| 672 | public final Intent primaryIntent; |
| 673 | /** The description for accessibility of the primary action. */ |
| 674 | public final String primaryDescription; |
| 675 | |
| 676 | public CharSequence label = null; |
| 677 | /** Icon for the secondary action. */ |
| 678 | public int secondaryIcon = 0; |
| 679 | /** Intent for the secondary action. If not null, an icon must be defined. */ |
| 680 | public Intent secondaryIntent = null; |
| 681 | /** The description for accessibility of the secondary action. */ |
| 682 | public String secondaryDescription = null; |
| 683 | |
| 684 | public ViewEntry(String text, Intent intent, String description) { |
| 685 | this.text = text; |
| 686 | primaryIntent = intent; |
| 687 | primaryDescription = description; |
| 688 | } |
| 689 | |
| 690 | public void setSecondaryAction(int icon, Intent intent, String description) { |
| 691 | secondaryIcon = icon; |
| 692 | secondaryIntent = intent; |
| 693 | secondaryDescription = description; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | /** Disables the call button area, e.g., for private numbers. */ |
| 698 | private void disableCallButton() { |
| 699 | findViewById(R.id.call_and_sms).setVisibility(View.GONE); |
| 700 | } |
| 701 | |
| 702 | /** Configures the call button area using the given entry. */ |
| 703 | private void configureCallButton(ViewEntry entry) { |
| 704 | View convertView = findViewById(R.id.call_and_sms); |
| 705 | convertView.setVisibility(View.VISIBLE); |
| 706 | |
| 707 | ImageView icon = (ImageView) convertView.findViewById(R.id.call_and_sms_icon); |
| 708 | View divider = convertView.findViewById(R.id.call_and_sms_divider); |
| 709 | TextView text = (TextView) convertView.findViewById(R.id.call_and_sms_text); |
| 710 | |
| 711 | View mainAction = convertView.findViewById(R.id.call_and_sms_main_action); |
| 712 | mainAction.setOnClickListener(mPrimaryActionListener); |
| 713 | mainAction.setTag(entry); |
| 714 | mainAction.setContentDescription(entry.primaryDescription); |
| 715 | mainAction.setOnLongClickListener(mPrimaryLongClickListener); |
| 716 | |
| 717 | if (entry.secondaryIntent != null) { |
| 718 | icon.setOnClickListener(mSecondaryActionListener); |
| 719 | icon.setImageResource(entry.secondaryIcon); |
| 720 | icon.setVisibility(View.VISIBLE); |
| 721 | icon.setTag(entry); |
| 722 | icon.setContentDescription(entry.secondaryDescription); |
| 723 | divider.setVisibility(View.VISIBLE); |
| 724 | } else { |
| 725 | icon.setVisibility(View.GONE); |
| 726 | divider.setVisibility(View.GONE); |
| 727 | } |
| 728 | text.setText(entry.text); |
| 729 | |
| 730 | TextView label = (TextView) convertView.findViewById(R.id.call_and_sms_label); |
| 731 | if (TextUtils.isEmpty(entry.label)) { |
| 732 | label.setVisibility(View.GONE); |
| 733 | } else { |
| 734 | label.setText(entry.label); |
| 735 | label.setVisibility(View.VISIBLE); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | protected void updateVoicemailStatusMessage(Cursor statusCursor) { |
| 740 | if (statusCursor == null) { |
| 741 | mStatusMessageView.setVisibility(View.GONE); |
| 742 | return; |
| 743 | } |
| 744 | final StatusMessage message = getStatusMessage(statusCursor); |
| 745 | if (message == null || !message.showInCallDetails()) { |
| 746 | mStatusMessageView.setVisibility(View.GONE); |
| 747 | return; |
| 748 | } |
| 749 | |
| 750 | mStatusMessageView.setVisibility(View.VISIBLE); |
| 751 | mStatusMessageText.setText(message.callDetailsMessageId); |
| 752 | if (message.actionMessageId != -1) { |
| 753 | mStatusMessageAction.setText(message.actionMessageId); |
| 754 | } |
| 755 | if (message.actionUri != null) { |
| 756 | mStatusMessageAction.setClickable(true); |
| 757 | mStatusMessageAction.setOnClickListener(new View.OnClickListener() { |
| 758 | @Override |
| 759 | public void onClick(View v) { |
| 760 | startActivity(new Intent(Intent.ACTION_VIEW, message.actionUri)); |
| 761 | } |
| 762 | }); |
| 763 | } else { |
| 764 | mStatusMessageAction.setClickable(false); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | private StatusMessage getStatusMessage(Cursor statusCursor) { |
| 769 | List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor); |
| 770 | if (messages.size() == 0) { |
| 771 | return null; |
| 772 | } |
| 773 | // There can only be a single status message per source package, so num of messages can |
| 774 | // at most be 1. |
| 775 | if (messages.size() > 1) { |
| 776 | Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." + |
| 777 | " Will use the first one.", messages.size())); |
| 778 | } |
| 779 | return messages.get(0); |
| 780 | } |
| 781 | |
| 782 | @Override |
| 783 | public boolean onCreateOptionsMenu(Menu menu) { |
| 784 | getMenuInflater().inflate(R.menu.call_details_options, menu); |
| 785 | return super.onCreateOptionsMenu(menu); |
| 786 | } |
| 787 | |
| 788 | @Override |
| 789 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 790 | // This action deletes all elements in the group from the call log. |
| 791 | // We don't have this action for voicemails, because you can just use the trash button. |
| 792 | menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption); |
| 793 | menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption); |
| 794 | menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption); |
| 795 | return super.onPrepareOptionsMenu(menu); |
| 796 | } |
| 797 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 798 | public void onMenuRemoveFromCallLog(MenuItem menuItem) { |
| 799 | final StringBuilder callIds = new StringBuilder(); |
| 800 | for (Uri callUri : getCallLogEntryUris()) { |
| 801 | if (callIds.length() != 0) { |
| 802 | callIds.append(","); |
| 803 | } |
| 804 | callIds.append(ContentUris.parseId(callUri)); |
| 805 | } |
| 806 | mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH, |
| 807 | new AsyncTask<Void, Void, Void>() { |
| 808 | @Override |
| 809 | public Void doInBackground(Void... params) { |
| 810 | getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL, |
| 811 | Calls._ID + " IN (" + callIds + ")", null); |
| 812 | return null; |
| 813 | } |
| 814 | |
| 815 | @Override |
| 816 | public void onPostExecute(Void result) { |
| 817 | finish(); |
| 818 | } |
| 819 | }); |
| 820 | } |
| 821 | |
| 822 | public void onMenuEditNumberBeforeCall(MenuItem menuItem) { |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 823 | startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber))); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | public void onMenuTrashVoicemail(MenuItem menuItem) { |
| 827 | final Uri voicemailUri = getVoicemailUri(); |
| 828 | mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH, |
| 829 | new AsyncTask<Void, Void, Void>() { |
| 830 | @Override |
| 831 | public Void doInBackground(Void... params) { |
| 832 | getContentResolver().delete(voicemailUri, null, null); |
| 833 | return null; |
| 834 | } |
| 835 | @Override |
| 836 | public void onPostExecute(Void result) { |
| 837 | finish(); |
| 838 | } |
| 839 | }); |
| 840 | } |
| 841 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 842 | /** Invoked when the user presses the home button in the action bar. */ |
| 843 | private void onHomeSelected() { |
| 844 | Intent intent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI); |
| 845 | // This will open the call log even if the detail view has been opened directly. |
| 846 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 847 | startActivity(intent); |
| 848 | finish(); |
| 849 | } |
| 850 | |
| 851 | @Override |
| 852 | protected void onPause() { |
| 853 | // Immediately stop the proximity sensor. |
| 854 | disableProximitySensor(false); |
| 855 | mProximitySensorListener.clearPendingRequests(); |
| 856 | super.onPause(); |
| 857 | } |
| 858 | |
| 859 | @Override |
| 860 | public void enableProximitySensor() { |
| 861 | mProximitySensorManager.enable(); |
| 862 | } |
| 863 | |
| 864 | @Override |
| 865 | public void disableProximitySensor(boolean waitForFarState) { |
| 866 | mProximitySensorManager.disable(waitForFarState); |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * If the phone number is selected, unselect it and return {@code true}. |
| 871 | * Otherwise, just {@code false}. |
| 872 | */ |
| 873 | private boolean finishPhoneNumerSelectedActionModeIfShown() { |
| 874 | if (mPhoneNumberActionMode == null) return false; |
| 875 | mPhoneNumberActionMode.finish(); |
| 876 | return true; |
| 877 | } |
| 878 | |
| 879 | private void startPhoneNumberSelectedActionMode(View targetView) { |
| 880 | mPhoneNumberActionMode = startActionMode(new PhoneNumberActionModeCallback(targetView)); |
| 881 | } |
| 882 | |
| 883 | private void closeSystemDialogs() { |
| 884 | sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 885 | } |
| 886 | |
| 887 | private class PhoneNumberActionModeCallback implements ActionMode.Callback { |
| 888 | private final View mTargetView; |
| 889 | private final Drawable mOriginalViewBackground; |
| 890 | |
| 891 | public PhoneNumberActionModeCallback(View targetView) { |
| 892 | mTargetView = targetView; |
| 893 | |
| 894 | // Highlight the phone number view. Remember the old background, and put a new one. |
| 895 | mOriginalViewBackground = mTargetView.getBackground(); |
| 896 | mTargetView.setBackgroundColor(getResources().getColor(R.color.item_selected)); |
| 897 | } |
| 898 | |
| 899 | @Override |
| 900 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
| 901 | if (TextUtils.isEmpty(mPhoneNumberToCopy)) return false; |
| 902 | |
| 903 | getMenuInflater().inflate(R.menu.call_details_cab, menu); |
| 904 | return true; |
| 905 | } |
| 906 | |
| 907 | @Override |
| 908 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
| 909 | return true; |
| 910 | } |
| 911 | |
| 912 | @Override |
| 913 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
| 914 | switch (item.getItemId()) { |
| 915 | case R.id.copy_phone_number: |
| 916 | ClipboardUtils.copyText(CallDetailActivity.this, mPhoneNumberLabelToCopy, |
| 917 | mPhoneNumberToCopy, true); |
| 918 | mode.finish(); // Close the CAB |
| 919 | return true; |
| 920 | } |
| 921 | return false; |
| 922 | } |
| 923 | |
| 924 | @Override |
| 925 | public void onDestroyActionMode(ActionMode mode) { |
| 926 | mPhoneNumberActionMode = null; |
| 927 | |
| 928 | // Restore the view background. |
| 929 | mTargetView.setBackground(mOriginalViewBackground); |
| 930 | } |
| 931 | } |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 932 | |
| 933 | /** Returns the given text, forced to be left-to-right. */ |
| 934 | private static CharSequence forceLeftToRight(CharSequence text) { |
| 935 | StringBuilder sb = new StringBuilder(); |
| 936 | sb.append(LEFT_TO_RIGHT_EMBEDDING); |
| 937 | sb.append(text); |
| 938 | sb.append(POP_DIRECTIONAL_FORMATTING); |
| 939 | return sb.toString(); |
| 940 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 941 | } |