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; |
Yorke Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 20 | import android.app.LoaderManager.LoaderCallbacks; |
Yorke Lee | 7d67c9b | 2013-12-05 12:28:04 -0800 | [diff] [blame] | 21 | import android.content.ActivityNotFoundException; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 22 | import android.content.ContentResolver; |
| 23 | import android.content.ContentUris; |
| 24 | import android.content.ContentValues; |
| 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
Yorke Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 27 | import android.content.Loader; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 28 | import android.content.res.Resources; |
| 29 | import android.database.Cursor; |
| 30 | import android.graphics.drawable.Drawable; |
| 31 | import android.net.Uri; |
| 32 | import android.os.AsyncTask; |
| 33 | import android.os.Bundle; |
| 34 | import android.provider.CallLog; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 35 | import android.provider.ContactsContract; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 36 | import android.provider.CallLog.Calls; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 37 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 38 | import android.provider.ContactsContract.Contacts; |
Yorke Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 39 | import android.provider.ContactsContract.DisplayNameSources; |
| 40 | import android.provider.ContactsContract.Intents.Insert; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 41 | import android.provider.VoicemailContract.Voicemails; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 42 | import android.telephony.TelephonyManager; |
| 43 | import android.text.TextUtils; |
| 44 | import android.util.Log; |
| 45 | import android.view.ActionMode; |
| 46 | import android.view.KeyEvent; |
| 47 | import android.view.LayoutInflater; |
| 48 | import android.view.Menu; |
| 49 | import android.view.MenuItem; |
| 50 | import android.view.View; |
| 51 | import android.widget.ImageButton; |
| 52 | import android.widget.ImageView; |
| 53 | import android.widget.ListView; |
| 54 | import android.widget.TextView; |
| 55 | import android.widget.Toast; |
| 56 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 57 | import com.android.contacts.common.ContactPhotoManager; |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 58 | import com.android.contacts.common.CallUtil; |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 59 | import com.android.contacts.common.ClipboardUtils; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 60 | import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 61 | import com.android.contacts.common.GeoUtil; |
Yorke Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 62 | import com.android.contacts.common.model.Contact; |
| 63 | import com.android.contacts.common.model.ContactLoader; |
Yorke Lee | 37d2985 | 2013-11-19 14:11:24 -0800 | [diff] [blame] | 64 | import com.android.contacts.common.util.PhoneNumberHelper; |
Yorke Lee | 58ebe5d | 2013-09-09 10:19:40 -0700 | [diff] [blame] | 65 | import com.android.contacts.common.util.UriUtils; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 66 | import com.android.dialer.BackScrollManager.ScrollableHeader; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 67 | import com.android.dialer.calllog.CallDetailHistoryAdapter; |
| 68 | import com.android.dialer.calllog.CallTypeHelper; |
| 69 | import com.android.dialer.calllog.ContactInfo; |
| 70 | import com.android.dialer.calllog.ContactInfoHelper; |
Yorke Lee | 24ec319 | 2013-11-19 13:52:45 -0800 | [diff] [blame] | 71 | import com.android.dialer.calllog.PhoneNumberDisplayHelper; |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 72 | import com.android.dialer.calllog.PhoneNumberUtilsWrapper; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 73 | import com.android.dialer.util.AsyncTaskExecutor; |
| 74 | import com.android.dialer.util.AsyncTaskExecutors; |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 75 | import com.android.dialer.util.DialerUtils; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 76 | import com.android.dialer.voicemail.VoicemailPlaybackFragment; |
| 77 | import com.android.dialer.voicemail.VoicemailStatusHelper; |
| 78 | import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage; |
| 79 | import com.android.dialer.voicemail.VoicemailStatusHelperImpl; |
| 80 | |
| 81 | import 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 | */ |
| 89 | public class CallDetailActivity extends Activity implements ProximitySensorAware { |
| 90 | private static final String TAG = "CallDetail"; |
| 91 | |
Yorke Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 92 | private static final int LOADER_ID = 0; |
| 93 | private static final String BUNDLE_CONTACT_URI_EXTRA = "contact_uri_extra"; |
| 94 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 95 | private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A'; |
| 96 | private static final char POP_DIRECTIONAL_FORMATTING = '\u202C'; |
| 97 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 98 | /** 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 Lee | 24ec319 | 2013-11-19 13:52:45 -0800 | [diff] [blame] | 121 | private PhoneNumberDisplayHelper mPhoneNumberHelper; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 122 | 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 Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 224 | CallLog.Calls.NUMBER_PRESENTATION, |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 225 | }; |
| 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 Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 233 | static final int NUMBER_PRESENTATION_COLUMN_INDEX = 6; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 234 | |
| 235 | private final View.OnClickListener mPrimaryActionListener = new View.OnClickListener() { |
| 236 | @Override |
| 237 | public void onClick(View view) { |
| 238 | if (finishPhoneNumerSelectedActionModeIfShown()) { |
| 239 | return; |
| 240 | } |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 241 | DialerUtils.startActivityWithErrorToast(CallDetailActivity.this, |
| 242 | ((ViewEntry) view.getTag()).primaryIntent); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 243 | } |
| 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 Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 252 | DialerUtils.startActivityWithErrorToast(CallDetailActivity.this, |
| 253 | ((ViewEntry) view.getTag()).secondaryIntent); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 254 | } |
| 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 Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 269 | 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 Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 298 | @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 Lee | 24ec319 | 2013-11-19 13:52:45 -0800 | [diff] [blame] | 309 | mPhoneNumberHelper = new PhoneNumberDisplayHelper(mResources); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 310 | mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper, |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 311 | new PhoneNumberUtilsWrapper()); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 312 | 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 Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 322 | mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 323 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
| 324 | mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener); |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 325 | mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); |
Chiao Cheng | adb742c | 2013-10-07 17:46:25 -0700 | [diff] [blame] | 326 | getActionBar().setDisplayHomeAsUpEnabled(true); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 327 | 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 Lee | aa536fd | 2013-07-29 11:31:04 -0700 | [diff] [blame] | 360 | .add(R.id.voicemail_container, playbackFragment) |
| 361 | .commitAllowingStateLoss(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 362 | 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() { |
| 401 | Uri uri = getIntent().getData(); |
| 402 | if (uri != null) { |
| 403 | // If there is a data on the intent, it takes precedence over the extra. |
| 404 | return new Uri[]{ uri }; |
| 405 | } |
| 406 | long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 407 | Uri[] uris = new Uri[ids.length]; |
| 408 | for (int index = 0; index < ids.length; ++index) { |
| 409 | uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]); |
| 410 | } |
| 411 | return uris; |
| 412 | } |
| 413 | |
| 414 | @Override |
| 415 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 416 | switch (keyCode) { |
| 417 | case KeyEvent.KEYCODE_CALL: { |
| 418 | // Make sure phone isn't already busy before starting direct call |
| 419 | TelephonyManager tm = (TelephonyManager) |
| 420 | getSystemService(Context.TELEPHONY_SERVICE); |
| 421 | if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 422 | DialerUtils.startActivityWithErrorToast(this, |
| 423 | CallUtil.getCallIntent(Uri.fromParts(CallUtil.SCHEME_TEL, mNumber, |
| 424 | null)), |
| 425 | R.string.call_not_available); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 426 | return true; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | return super.onKeyDown(keyCode, event); |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Update user interface with details of given call. |
| 436 | * |
| 437 | * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed |
| 438 | */ |
| 439 | private void updateData(final Uri... callUris) { |
| 440 | class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> { |
| 441 | @Override |
| 442 | public PhoneCallDetails[] doInBackground(Void... params) { |
| 443 | // TODO: All phone calls correspond to the same person, so we can make a single |
| 444 | // lookup. |
| 445 | final int numCalls = callUris.length; |
| 446 | PhoneCallDetails[] details = new PhoneCallDetails[numCalls]; |
| 447 | try { |
| 448 | for (int index = 0; index < numCalls; ++index) { |
| 449 | details[index] = getPhoneCallDetailsForUri(callUris[index]); |
| 450 | } |
| 451 | return details; |
| 452 | } catch (IllegalArgumentException e) { |
| 453 | // Something went wrong reading in our primary data. |
| 454 | Log.w(TAG, "invalid URI starting call details", e); |
| 455 | return null; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | @Override |
| 460 | public void onPostExecute(PhoneCallDetails[] details) { |
| 461 | if (details == null) { |
| 462 | // Somewhere went wrong: we're going to bail out and show error to users. |
| 463 | Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error, |
| 464 | Toast.LENGTH_SHORT).show(); |
| 465 | finish(); |
| 466 | return; |
| 467 | } |
| 468 | |
| 469 | // We know that all calls are from the same number and the same contact, so pick the |
| 470 | // first. |
| 471 | PhoneCallDetails firstDetails = details[0]; |
| 472 | mNumber = firstDetails.number.toString(); |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 473 | final int numberPresentation = firstDetails.numberPresentation; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 474 | final Uri contactUri = firstDetails.contactUri; |
| 475 | final Uri photoUri = firstDetails.photoUri; |
| 476 | |
| 477 | // Set the details header, based on the first phone call. |
| 478 | mPhoneCallDetailsHelper.setCallDetailsHeader(mHeaderTextView, firstDetails); |
| 479 | |
| 480 | // Cache the details about the phone number. |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 481 | final boolean canPlaceCallsTo = |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 482 | PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation); |
| 483 | final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(); |
| 484 | final boolean isVoicemailNumber = phoneUtils.isVoicemailNumber(mNumber); |
| 485 | final boolean isSipNumber = phoneUtils.isSipNumber(mNumber); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 486 | |
| 487 | // Let user view contact details if they exist, otherwise add option to create new |
| 488 | // contact from this number. |
| 489 | final Intent mainActionIntent; |
| 490 | final int mainActionIcon; |
| 491 | final String mainActionDescription; |
| 492 | |
| 493 | final CharSequence nameOrNumber; |
| 494 | if (!TextUtils.isEmpty(firstDetails.name)) { |
| 495 | nameOrNumber = firstDetails.name; |
| 496 | } else { |
| 497 | nameOrNumber = firstDetails.number; |
| 498 | } |
| 499 | |
Yorke Lee | cce501c | 2013-11-08 07:54:23 -0800 | [diff] [blame] | 500 | boolean skipBind = false; |
| 501 | |
Yorke Lee | 58ebe5d | 2013-09-09 10:19:40 -0700 | [diff] [blame] | 502 | if (contactUri != null && !UriUtils.isEncodedContactUri(contactUri)) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 503 | mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri); |
| 504 | // This will launch People's detail contact screen, so we probably want to |
| 505 | // treat it as a separate People task. |
| 506 | mainActionIntent.setFlags( |
| 507 | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 508 | mainActionIcon = R.drawable.ic_contacts_holo_dark; |
| 509 | mainActionDescription = |
| 510 | getString(R.string.description_view_contact, nameOrNumber); |
Yorke Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 511 | } else if (UriUtils.isEncodedContactUri(contactUri)) { |
| 512 | final Bundle bundle = new Bundle(1); |
| 513 | bundle.putParcelable(BUNDLE_CONTACT_URI_EXTRA, contactUri); |
| 514 | getLoaderManager().initLoader(LOADER_ID, bundle, mLoaderCallbacks); |
| 515 | mainActionIntent = null; |
| 516 | mainActionIcon = R.drawable.ic_add_contact_holo_dark; |
| 517 | mainActionDescription = getString(R.string.description_add_contact); |
Yorke Lee | cce501c | 2013-11-08 07:54:23 -0800 | [diff] [blame] | 518 | skipBind = true; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 519 | } else if (isVoicemailNumber) { |
| 520 | mainActionIntent = null; |
| 521 | mainActionIcon = 0; |
| 522 | mainActionDescription = null; |
| 523 | } else if (isSipNumber) { |
| 524 | // TODO: This item is currently disabled for SIP addresses, because |
| 525 | // the Insert.PHONE extra only works correctly for PSTN numbers. |
| 526 | // |
| 527 | // To fix this for SIP addresses, we need to: |
| 528 | // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if |
| 529 | // the current number is a SIP address |
| 530 | // - update the contacts UI code to handle Insert.SIP_ADDRESS by |
| 531 | // updating the SipAddress field |
| 532 | // and then we can remove the "!isSipNumber" check above. |
| 533 | mainActionIntent = null; |
| 534 | mainActionIcon = 0; |
| 535 | mainActionDescription = null; |
| 536 | } else if (canPlaceCallsTo) { |
| 537 | mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 538 | mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 539 | mainActionIntent.putExtra(Insert.PHONE, mNumber); |
| 540 | mainActionIcon = R.drawable.ic_add_contact_holo_dark; |
| 541 | mainActionDescription = getString(R.string.description_add_contact); |
| 542 | } else { |
Yorke Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 543 | // If we cannot call the number, when we probably cannot add it as a contact |
| 544 | // either. This is usually the case of private, unknown, or payphone numbers. |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 545 | mainActionIntent = null; |
| 546 | mainActionIcon = 0; |
| 547 | mainActionDescription = null; |
| 548 | } |
| 549 | |
Yorke Lee | cce501c | 2013-11-08 07:54:23 -0800 | [diff] [blame] | 550 | if (!skipBind) { |
| 551 | bindContactPhotoAction(mainActionIntent, mainActionIcon, |
| 552 | mainActionDescription); |
| 553 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 554 | |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 555 | final CharSequence displayNumber = |
| 556 | mPhoneNumberHelper.getDisplayNumber( |
| 557 | firstDetails.number, |
| 558 | firstDetails.numberPresentation, |
| 559 | firstDetails.formattedNumber); |
| 560 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 561 | // This action allows to call the number that places the call. |
| 562 | if (canPlaceCallsTo) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 563 | ViewEntry entry = new ViewEntry( |
| 564 | getString(R.string.menu_callNumber, |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 565 | forceLeftToRight(displayNumber)), |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 566 | CallUtil.getCallIntent(mNumber), |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 567 | getString(R.string.description_call, nameOrNumber)); |
| 568 | |
| 569 | // Only show a label if the number is shown and it is not a SIP address. |
| 570 | if (!TextUtils.isEmpty(firstDetails.name) |
| 571 | && !TextUtils.isEmpty(firstDetails.number) |
Yorke Lee | 37d2985 | 2013-11-19 14:11:24 -0800 | [diff] [blame] | 572 | && !PhoneNumberHelper.isUriNumber(firstDetails.number.toString())) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 573 | entry.label = Phone.getTypeLabel(mResources, firstDetails.numberType, |
| 574 | firstDetails.numberLabel); |
| 575 | } |
| 576 | |
| 577 | // The secondary action allows to send an SMS to the number that placed the |
| 578 | // call. |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 579 | if (phoneUtils.canSendSmsTo(mNumber, numberPresentation)) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 580 | entry.setSecondaryAction( |
Yorke Lee | aa536fd | 2013-07-29 11:31:04 -0700 | [diff] [blame] | 581 | R.drawable.ic_text_holo_light, |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 582 | new Intent(Intent.ACTION_SENDTO, |
| 583 | Uri.fromParts("sms", mNumber, null)), |
| 584 | getString(R.string.description_send_text_message, nameOrNumber)); |
| 585 | } |
| 586 | |
| 587 | configureCallButton(entry); |
| 588 | mPhoneNumberToCopy = displayNumber; |
| 589 | mPhoneNumberLabelToCopy = entry.label; |
| 590 | } else { |
| 591 | disableCallButton(); |
| 592 | mPhoneNumberToCopy = null; |
| 593 | mPhoneNumberLabelToCopy = null; |
| 594 | } |
| 595 | |
| 596 | mHasEditNumberBeforeCallOption = |
| 597 | canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; |
| 598 | mHasTrashOption = hasVoicemail(); |
| 599 | mHasRemoveFromCallLogOption = !hasVoicemail(); |
| 600 | invalidateOptionsMenu(); |
| 601 | |
| 602 | ListView historyList = (ListView) findViewById(R.id.history); |
| 603 | historyList.setAdapter( |
| 604 | new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater, |
| 605 | mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo, |
| 606 | findViewById(R.id.controls))); |
| 607 | BackScrollManager.bind( |
| 608 | new ScrollableHeader() { |
| 609 | private View mControls = findViewById(R.id.controls); |
| 610 | private View mPhoto = findViewById(R.id.contact_background_sizer); |
| 611 | private View mHeader = findViewById(R.id.photo_text_bar); |
Yorke Lee | ac09b51 | 2013-09-09 08:51:54 -0700 | [diff] [blame] | 612 | private View mSeparator = findViewById(R.id.separator); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 613 | |
| 614 | @Override |
| 615 | public void setOffset(int offset) { |
| 616 | mControls.setY(-offset); |
| 617 | } |
| 618 | |
| 619 | @Override |
| 620 | public int getMaximumScrollableHeaderOffset() { |
| 621 | // We can scroll the photo out, but we should keep the header if |
| 622 | // present. |
| 623 | if (mHeader.getVisibility() == View.VISIBLE) { |
| 624 | return mPhoto.getHeight() - mHeader.getHeight(); |
| 625 | } else { |
| 626 | // If the header is not present, we should also scroll out the |
| 627 | // separator line. |
| 628 | return mPhoto.getHeight() + mSeparator.getHeight(); |
| 629 | } |
| 630 | } |
| 631 | }, |
| 632 | historyList); |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 633 | |
| 634 | final String displayNameForDefaultImage = TextUtils.isEmpty(firstDetails.name) ? |
| 635 | displayNumber.toString() : firstDetails.name.toString(); |
| 636 | |
| 637 | final String lookupKey = ContactInfoHelper.getLookupKeyFromUri(contactUri); |
| 638 | |
| 639 | final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType); |
| 640 | |
| 641 | final int contactType = |
| 642 | isVoicemailNumber? ContactPhotoManager.TYPE_VOICEMAIL : |
| 643 | isBusiness ? ContactPhotoManager.TYPE_BUSINESS : |
| 644 | ContactPhotoManager.TYPE_DEFAULT; |
| 645 | |
| 646 | loadContactPhotos(photoUri, displayNameForDefaultImage, lookupKey, contactType); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 647 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
| 648 | } |
| 649 | } |
| 650 | mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask()); |
| 651 | } |
| 652 | |
Yorke Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 653 | private void bindContactPhotoAction(final Intent actionIntent, int actionIcon, |
| 654 | String actionDescription) { |
| 655 | if (actionIntent == null) { |
| 656 | mMainActionView.setVisibility(View.INVISIBLE); |
| 657 | mMainActionPushLayerView.setVisibility(View.GONE); |
| 658 | mHeaderTextView.setVisibility(View.INVISIBLE); |
| 659 | mHeaderOverlayView.setVisibility(View.INVISIBLE); |
| 660 | } else { |
| 661 | mMainActionView.setVisibility(View.VISIBLE); |
| 662 | mMainActionView.setImageResource(actionIcon); |
| 663 | mMainActionPushLayerView.setVisibility(View.VISIBLE); |
| 664 | mMainActionPushLayerView.setOnClickListener(new View.OnClickListener() { |
| 665 | @Override |
| 666 | public void onClick(View v) { |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 667 | DialerUtils.startActivityWithErrorToast(CallDetailActivity.this, actionIntent, |
| 668 | R.string.add_contact_not_available); |
Yorke Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 669 | } |
| 670 | }); |
| 671 | mMainActionPushLayerView.setContentDescription(actionDescription); |
| 672 | mHeaderTextView.setVisibility(View.VISIBLE); |
| 673 | mHeaderOverlayView.setVisibility(View.VISIBLE); |
| 674 | } |
| 675 | } |
| 676 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 677 | /** Return the phone call details for a given call log URI. */ |
| 678 | private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) { |
| 679 | ContentResolver resolver = getContentResolver(); |
| 680 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 681 | try { |
| 682 | if (callCursor == null || !callCursor.moveToFirst()) { |
| 683 | throw new IllegalArgumentException("Cannot find content: " + callUri); |
| 684 | } |
| 685 | |
| 686 | // Read call log specifics. |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 687 | final String number = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 688 | final int numberPresentation = callCursor.getInt( |
| 689 | NUMBER_PRESENTATION_COLUMN_INDEX); |
| 690 | final long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 691 | final long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 692 | final int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 693 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 694 | final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX); |
| 695 | |
| 696 | if (TextUtils.isEmpty(countryIso)) { |
| 697 | countryIso = mDefaultCountryIso; |
| 698 | } |
| 699 | |
| 700 | // Formatted phone number. |
| 701 | final CharSequence formattedNumber; |
| 702 | // Read contact specifics. |
| 703 | final CharSequence nameText; |
| 704 | final int numberType; |
| 705 | final CharSequence numberLabel; |
| 706 | final Uri photoUri; |
| 707 | final Uri lookupUri; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 708 | int sourceType; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 709 | // If this is not a regular number, there is no point in looking it up in the contacts. |
| 710 | ContactInfo info = |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 711 | PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) |
Yorke Lee | 1a7c196 | 2013-09-20 16:04:34 -0700 | [diff] [blame] | 712 | && !new PhoneNumberUtilsWrapper().isVoicemailNumber(number) |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 713 | ? mContactInfoHelper.lookupNumber(number, countryIso) |
| 714 | : null; |
| 715 | if (info == null) { |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 716 | formattedNumber = mPhoneNumberHelper.getDisplayNumber(number, |
| 717 | numberPresentation, null); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 718 | nameText = ""; |
| 719 | numberType = 0; |
| 720 | numberLabel = ""; |
| 721 | photoUri = null; |
| 722 | lookupUri = null; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 723 | sourceType = 0; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 724 | } else { |
| 725 | formattedNumber = info.formattedNumber; |
| 726 | nameText = info.name; |
| 727 | numberType = info.type; |
| 728 | numberLabel = info.label; |
| 729 | photoUri = info.photoUri; |
| 730 | lookupUri = info.lookupUri; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 731 | sourceType = info.sourceType; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 732 | } |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 733 | return new PhoneCallDetails(number, numberPresentation, |
| 734 | formattedNumber, countryIso, geocode, |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 735 | new int[]{ callType }, date, duration, |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 736 | nameText, numberType, numberLabel, lookupUri, photoUri, sourceType); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 737 | } finally { |
| 738 | if (callCursor != null) { |
| 739 | callCursor.close(); |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | /** Load the contact photos and places them in the corresponding views. */ |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 745 | private void loadContactPhotos(Uri photoUri, String displayName, String lookupKey, |
| 746 | int contactType) { |
| 747 | final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, |
| 748 | contactType); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 749 | mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri, |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 750 | mContactBackgroundView.getWidth(), true, request); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | static final class ViewEntry { |
| 754 | public final String text; |
| 755 | public final Intent primaryIntent; |
| 756 | /** The description for accessibility of the primary action. */ |
| 757 | public final String primaryDescription; |
| 758 | |
| 759 | public CharSequence label = null; |
| 760 | /** Icon for the secondary action. */ |
| 761 | public int secondaryIcon = 0; |
| 762 | /** Intent for the secondary action. If not null, an icon must be defined. */ |
| 763 | public Intent secondaryIntent = null; |
| 764 | /** The description for accessibility of the secondary action. */ |
| 765 | public String secondaryDescription = null; |
| 766 | |
| 767 | public ViewEntry(String text, Intent intent, String description) { |
| 768 | this.text = text; |
| 769 | primaryIntent = intent; |
| 770 | primaryDescription = description; |
| 771 | } |
| 772 | |
| 773 | public void setSecondaryAction(int icon, Intent intent, String description) { |
| 774 | secondaryIcon = icon; |
| 775 | secondaryIntent = intent; |
| 776 | secondaryDescription = description; |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | /** Disables the call button area, e.g., for private numbers. */ |
| 781 | private void disableCallButton() { |
| 782 | findViewById(R.id.call_and_sms).setVisibility(View.GONE); |
| 783 | } |
| 784 | |
| 785 | /** Configures the call button area using the given entry. */ |
| 786 | private void configureCallButton(ViewEntry entry) { |
| 787 | View convertView = findViewById(R.id.call_and_sms); |
| 788 | convertView.setVisibility(View.VISIBLE); |
| 789 | |
| 790 | ImageView icon = (ImageView) convertView.findViewById(R.id.call_and_sms_icon); |
| 791 | View divider = convertView.findViewById(R.id.call_and_sms_divider); |
| 792 | TextView text = (TextView) convertView.findViewById(R.id.call_and_sms_text); |
| 793 | |
| 794 | View mainAction = convertView.findViewById(R.id.call_and_sms_main_action); |
| 795 | mainAction.setOnClickListener(mPrimaryActionListener); |
| 796 | mainAction.setTag(entry); |
| 797 | mainAction.setContentDescription(entry.primaryDescription); |
| 798 | mainAction.setOnLongClickListener(mPrimaryLongClickListener); |
| 799 | |
| 800 | if (entry.secondaryIntent != null) { |
| 801 | icon.setOnClickListener(mSecondaryActionListener); |
| 802 | icon.setImageResource(entry.secondaryIcon); |
| 803 | icon.setVisibility(View.VISIBLE); |
| 804 | icon.setTag(entry); |
| 805 | icon.setContentDescription(entry.secondaryDescription); |
| 806 | divider.setVisibility(View.VISIBLE); |
| 807 | } else { |
| 808 | icon.setVisibility(View.GONE); |
| 809 | divider.setVisibility(View.GONE); |
| 810 | } |
| 811 | text.setText(entry.text); |
| 812 | |
| 813 | TextView label = (TextView) convertView.findViewById(R.id.call_and_sms_label); |
| 814 | if (TextUtils.isEmpty(entry.label)) { |
| 815 | label.setVisibility(View.GONE); |
| 816 | } else { |
| 817 | label.setText(entry.label); |
| 818 | label.setVisibility(View.VISIBLE); |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | protected void updateVoicemailStatusMessage(Cursor statusCursor) { |
| 823 | if (statusCursor == null) { |
| 824 | mStatusMessageView.setVisibility(View.GONE); |
| 825 | return; |
| 826 | } |
| 827 | final StatusMessage message = getStatusMessage(statusCursor); |
| 828 | if (message == null || !message.showInCallDetails()) { |
| 829 | mStatusMessageView.setVisibility(View.GONE); |
| 830 | return; |
| 831 | } |
| 832 | |
| 833 | mStatusMessageView.setVisibility(View.VISIBLE); |
| 834 | mStatusMessageText.setText(message.callDetailsMessageId); |
| 835 | if (message.actionMessageId != -1) { |
| 836 | mStatusMessageAction.setText(message.actionMessageId); |
| 837 | } |
| 838 | if (message.actionUri != null) { |
| 839 | mStatusMessageAction.setClickable(true); |
| 840 | mStatusMessageAction.setOnClickListener(new View.OnClickListener() { |
| 841 | @Override |
| 842 | public void onClick(View v) { |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 843 | DialerUtils.startActivityWithErrorToast(CallDetailActivity.this, |
| 844 | new Intent(Intent.ACTION_VIEW, message.actionUri)); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 845 | } |
| 846 | }); |
| 847 | } else { |
| 848 | mStatusMessageAction.setClickable(false); |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | private StatusMessage getStatusMessage(Cursor statusCursor) { |
| 853 | List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor); |
| 854 | if (messages.size() == 0) { |
| 855 | return null; |
| 856 | } |
| 857 | // There can only be a single status message per source package, so num of messages can |
| 858 | // at most be 1. |
| 859 | if (messages.size() > 1) { |
| 860 | Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." + |
| 861 | " Will use the first one.", messages.size())); |
| 862 | } |
| 863 | return messages.get(0); |
| 864 | } |
| 865 | |
| 866 | @Override |
| 867 | public boolean onCreateOptionsMenu(Menu menu) { |
| 868 | getMenuInflater().inflate(R.menu.call_details_options, menu); |
| 869 | return super.onCreateOptionsMenu(menu); |
| 870 | } |
| 871 | |
| 872 | @Override |
| 873 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 874 | // This action deletes all elements in the group from the call log. |
| 875 | // We don't have this action for voicemails, because you can just use the trash button. |
| 876 | menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption); |
| 877 | menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption); |
| 878 | menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption); |
| 879 | return super.onPrepareOptionsMenu(menu); |
| 880 | } |
| 881 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 882 | public void onMenuRemoveFromCallLog(MenuItem menuItem) { |
| 883 | final StringBuilder callIds = new StringBuilder(); |
| 884 | for (Uri callUri : getCallLogEntryUris()) { |
| 885 | if (callIds.length() != 0) { |
| 886 | callIds.append(","); |
| 887 | } |
| 888 | callIds.append(ContentUris.parseId(callUri)); |
| 889 | } |
| 890 | mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH, |
| 891 | new AsyncTask<Void, Void, Void>() { |
| 892 | @Override |
| 893 | public Void doInBackground(Void... params) { |
| 894 | getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL, |
| 895 | Calls._ID + " IN (" + callIds + ")", null); |
| 896 | return null; |
| 897 | } |
| 898 | |
| 899 | @Override |
| 900 | public void onPostExecute(Void result) { |
| 901 | finish(); |
| 902 | } |
| 903 | }); |
| 904 | } |
| 905 | |
| 906 | public void onMenuEditNumberBeforeCall(MenuItem menuItem) { |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 907 | startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber))); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | public void onMenuTrashVoicemail(MenuItem menuItem) { |
| 911 | final Uri voicemailUri = getVoicemailUri(); |
| 912 | mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH, |
| 913 | new AsyncTask<Void, Void, Void>() { |
| 914 | @Override |
| 915 | public Void doInBackground(Void... params) { |
| 916 | getContentResolver().delete(voicemailUri, null, null); |
| 917 | return null; |
| 918 | } |
| 919 | @Override |
| 920 | public void onPostExecute(Void result) { |
| 921 | finish(); |
| 922 | } |
| 923 | }); |
| 924 | } |
| 925 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 926 | /** Invoked when the user presses the home button in the action bar. */ |
| 927 | private void onHomeSelected() { |
| 928 | Intent intent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI); |
| 929 | // This will open the call log even if the detail view has been opened directly. |
| 930 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 931 | startActivity(intent); |
| 932 | finish(); |
| 933 | } |
| 934 | |
| 935 | @Override |
| 936 | protected void onPause() { |
| 937 | // Immediately stop the proximity sensor. |
| 938 | disableProximitySensor(false); |
| 939 | mProximitySensorListener.clearPendingRequests(); |
| 940 | super.onPause(); |
| 941 | } |
| 942 | |
| 943 | @Override |
| 944 | public void enableProximitySensor() { |
| 945 | mProximitySensorManager.enable(); |
| 946 | } |
| 947 | |
| 948 | @Override |
| 949 | public void disableProximitySensor(boolean waitForFarState) { |
| 950 | mProximitySensorManager.disable(waitForFarState); |
| 951 | } |
| 952 | |
| 953 | /** |
| 954 | * If the phone number is selected, unselect it and return {@code true}. |
| 955 | * Otherwise, just {@code false}. |
| 956 | */ |
| 957 | private boolean finishPhoneNumerSelectedActionModeIfShown() { |
| 958 | if (mPhoneNumberActionMode == null) return false; |
| 959 | mPhoneNumberActionMode.finish(); |
| 960 | return true; |
| 961 | } |
| 962 | |
| 963 | private void startPhoneNumberSelectedActionMode(View targetView) { |
| 964 | mPhoneNumberActionMode = startActionMode(new PhoneNumberActionModeCallback(targetView)); |
| 965 | } |
| 966 | |
| 967 | private void closeSystemDialogs() { |
| 968 | sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 969 | } |
| 970 | |
| 971 | private class PhoneNumberActionModeCallback implements ActionMode.Callback { |
| 972 | private final View mTargetView; |
| 973 | private final Drawable mOriginalViewBackground; |
| 974 | |
| 975 | public PhoneNumberActionModeCallback(View targetView) { |
| 976 | mTargetView = targetView; |
| 977 | |
| 978 | // Highlight the phone number view. Remember the old background, and put a new one. |
| 979 | mOriginalViewBackground = mTargetView.getBackground(); |
| 980 | mTargetView.setBackgroundColor(getResources().getColor(R.color.item_selected)); |
| 981 | } |
| 982 | |
| 983 | @Override |
| 984 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
| 985 | if (TextUtils.isEmpty(mPhoneNumberToCopy)) return false; |
| 986 | |
| 987 | getMenuInflater().inflate(R.menu.call_details_cab, menu); |
| 988 | return true; |
| 989 | } |
| 990 | |
| 991 | @Override |
| 992 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
| 993 | return true; |
| 994 | } |
| 995 | |
| 996 | @Override |
| 997 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
| 998 | switch (item.getItemId()) { |
| 999 | case R.id.copy_phone_number: |
| 1000 | ClipboardUtils.copyText(CallDetailActivity.this, mPhoneNumberLabelToCopy, |
| 1001 | mPhoneNumberToCopy, true); |
| 1002 | mode.finish(); // Close the CAB |
| 1003 | return true; |
| 1004 | } |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
| 1008 | @Override |
| 1009 | public void onDestroyActionMode(ActionMode mode) { |
| 1010 | mPhoneNumberActionMode = null; |
| 1011 | |
| 1012 | // Restore the view background. |
| 1013 | mTargetView.setBackground(mOriginalViewBackground); |
| 1014 | } |
| 1015 | } |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 1016 | |
| 1017 | /** Returns the given text, forced to be left-to-right. */ |
| 1018 | private static CharSequence forceLeftToRight(CharSequence text) { |
| 1019 | StringBuilder sb = new StringBuilder(); |
| 1020 | sb.append(LEFT_TO_RIGHT_EMBEDDING); |
| 1021 | sb.append(text); |
| 1022 | sb.append(POP_DIRECTIONAL_FORMATTING); |
| 1023 | return sb.toString(); |
| 1024 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1025 | } |