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