Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.dialer; |
| 18 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
| 20 | import android.content.ContentResolver; |
| 21 | import android.content.ContentUris; |
| 22 | import android.content.ContentValues; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.res.Resources; |
| 26 | import android.database.Cursor; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 27 | import android.net.Uri; |
| 28 | import android.os.AsyncTask; |
| 29 | import android.os.Bundle; |
| 30 | import android.provider.CallLog; |
| 31 | import android.provider.CallLog.Calls; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 32 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 33 | import android.provider.VoicemailContract.Voicemails; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 34 | import android.telephony.TelephonyManager; |
| 35 | import android.text.TextUtils; |
| 36 | import android.util.Log; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 37 | import android.view.KeyEvent; |
| 38 | import android.view.LayoutInflater; |
| 39 | import android.view.Menu; |
| 40 | import android.view.MenuItem; |
| 41 | import android.view.View; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 42 | import android.widget.ListView; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 43 | import android.widget.QuickContactBadge; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 44 | import android.widget.TextView; |
| 45 | import android.widget.Toast; |
| 46 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 47 | import com.android.contacts.common.ContactPhotoManager; |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 48 | import com.android.contacts.common.CallUtil; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 49 | import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 50 | import com.android.contacts.common.GeoUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 51 | import com.android.dialer.calllog.CallDetailHistoryAdapter; |
| 52 | import com.android.dialer.calllog.CallTypeHelper; |
| 53 | import com.android.dialer.calllog.ContactInfo; |
| 54 | import com.android.dialer.calllog.ContactInfoHelper; |
Yorke Lee | 24ec319 | 2013-11-19 13:52:45 -0800 | [diff] [blame] | 55 | import com.android.dialer.calllog.PhoneNumberDisplayHelper; |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 56 | import com.android.dialer.calllog.PhoneNumberUtilsWrapper; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 57 | import com.android.dialer.util.AsyncTaskExecutor; |
| 58 | import com.android.dialer.util.AsyncTaskExecutors; |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 59 | import com.android.dialer.util.DialerUtils; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 60 | import com.android.dialer.voicemail.VoicemailPlaybackFragment; |
| 61 | import com.android.dialer.voicemail.VoicemailStatusHelper; |
| 62 | import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage; |
| 63 | import com.android.dialer.voicemail.VoicemailStatusHelperImpl; |
| 64 | |
| 65 | import java.util.List; |
| 66 | |
| 67 | /** |
| 68 | * Displays the details of a specific call log entry. |
| 69 | * <p> |
| 70 | * This activity can be either started with the URI of a single call log entry, or with the |
| 71 | * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries. |
| 72 | */ |
| 73 | public class CallDetailActivity extends Activity implements ProximitySensorAware { |
| 74 | private static final String TAG = "CallDetail"; |
| 75 | |
Yorke Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 76 | private static final int LOADER_ID = 0; |
| 77 | private static final String BUNDLE_CONTACT_URI_EXTRA = "contact_uri_extra"; |
| 78 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 79 | private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A'; |
| 80 | private static final char POP_DIRECTIONAL_FORMATTING = '\u202C'; |
| 81 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 82 | /** The time to wait before enabling the blank the screen due to the proximity sensor. */ |
| 83 | private static final long PROXIMITY_BLANK_DELAY_MILLIS = 100; |
| 84 | /** The time to wait before disabling the blank the screen due to the proximity sensor. */ |
| 85 | private static final long PROXIMITY_UNBLANK_DELAY_MILLIS = 500; |
| 86 | |
| 87 | /** The enumeration of {@link AsyncTask} objects used in this class. */ |
| 88 | public enum Tasks { |
| 89 | MARK_VOICEMAIL_READ, |
| 90 | DELETE_VOICEMAIL_AND_FINISH, |
| 91 | REMOVE_FROM_CALL_LOG_AND_FINISH, |
| 92 | UPDATE_PHONE_CALL_DETAILS, |
| 93 | } |
| 94 | |
| 95 | /** A long array extra containing ids of call log entries to display. */ |
| 96 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 97 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 98 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
| 99 | /** If we should immediately start playback of the voicemail, this extra will be set to true. */ |
| 100 | public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK"; |
| 101 | /** If the activity was triggered from a notification. */ |
| 102 | public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION"; |
| 103 | |
| 104 | private CallTypeHelper mCallTypeHelper; |
Yorke Lee | 24ec319 | 2013-11-19 13:52:45 -0800 | [diff] [blame] | 105 | private PhoneNumberDisplayHelper mPhoneNumberHelper; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 106 | private QuickContactBadge mQuickContactBadge; |
| 107 | private TextView mCallerName; |
| 108 | private TextView mCallerNumber; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 109 | private AsyncTaskExecutor mAsyncTaskExecutor; |
| 110 | private ContactInfoHelper mContactInfoHelper; |
| 111 | |
| 112 | private String mNumber = null; |
| 113 | private String mDefaultCountryIso; |
| 114 | |
| 115 | /* package */ LayoutInflater mInflater; |
| 116 | /* package */ Resources mResources; |
| 117 | /** Helper to load contact photos. */ |
| 118 | private ContactPhotoManager mContactPhotoManager; |
| 119 | /** Helper to make async queries to content resolver. */ |
| 120 | private CallDetailActivityQueryHandler mAsyncQueryHandler; |
| 121 | /** Helper to get voicemail status messages. */ |
| 122 | private VoicemailStatusHelper mVoicemailStatusHelper; |
| 123 | // Views related to voicemail status message. |
| 124 | private View mStatusMessageView; |
| 125 | private TextView mStatusMessageText; |
| 126 | private TextView mStatusMessageAction; |
| 127 | |
| 128 | /** Whether we should show "edit number before call" in the options menu. */ |
| 129 | private boolean mHasEditNumberBeforeCallOption; |
| 130 | /** Whether we should show "trash" in the options menu. */ |
| 131 | private boolean mHasTrashOption; |
| 132 | /** Whether we should show "remove from call log" in the options menu. */ |
| 133 | private boolean mHasRemoveFromCallLogOption; |
| 134 | |
| 135 | private ProximitySensorManager mProximitySensorManager; |
| 136 | private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener(); |
| 137 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 138 | /** Listener to changes in the proximity sensor state. */ |
| 139 | private class ProximitySensorListener implements ProximitySensorManager.Listener { |
| 140 | /** Used to show a blank view and hide the action bar. */ |
| 141 | private final Runnable mBlankRunnable = new Runnable() { |
| 142 | @Override |
| 143 | public void run() { |
| 144 | View blankView = findViewById(R.id.blank); |
| 145 | blankView.setVisibility(View.VISIBLE); |
| 146 | getActionBar().hide(); |
| 147 | } |
| 148 | }; |
| 149 | /** Used to remove the blank view and show the action bar. */ |
| 150 | private final Runnable mUnblankRunnable = new Runnable() { |
| 151 | @Override |
| 152 | public void run() { |
| 153 | View blankView = findViewById(R.id.blank); |
| 154 | blankView.setVisibility(View.GONE); |
| 155 | getActionBar().show(); |
| 156 | } |
| 157 | }; |
| 158 | |
| 159 | @Override |
| 160 | public synchronized void onNear() { |
| 161 | clearPendingRequests(); |
| 162 | postDelayed(mBlankRunnable, PROXIMITY_BLANK_DELAY_MILLIS); |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public synchronized void onFar() { |
| 167 | clearPendingRequests(); |
| 168 | postDelayed(mUnblankRunnable, PROXIMITY_UNBLANK_DELAY_MILLIS); |
| 169 | } |
| 170 | |
| 171 | /** Removed any delayed requests that may be pending. */ |
| 172 | public synchronized void clearPendingRequests() { |
| 173 | View blankView = findViewById(R.id.blank); |
| 174 | blankView.removeCallbacks(mBlankRunnable); |
| 175 | blankView.removeCallbacks(mUnblankRunnable); |
| 176 | } |
| 177 | |
| 178 | /** Post a {@link Runnable} with a delay on the main thread. */ |
| 179 | private synchronized void postDelayed(Runnable runnable, long delayMillis) { |
| 180 | // Post these instead of executing immediately so that: |
| 181 | // - They are guaranteed to be executed on the main thread. |
| 182 | // - If the sensor values changes rapidly for some time, the UI will not be |
| 183 | // updated immediately. |
| 184 | View blankView = findViewById(R.id.blank); |
| 185 | blankView.postDelayed(runnable, delayMillis); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | static final String[] CALL_LOG_PROJECTION = new String[] { |
| 190 | CallLog.Calls.DATE, |
| 191 | CallLog.Calls.DURATION, |
| 192 | CallLog.Calls.NUMBER, |
| 193 | CallLog.Calls.TYPE, |
| 194 | CallLog.Calls.COUNTRY_ISO, |
| 195 | CallLog.Calls.GEOCODED_LOCATION, |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 196 | CallLog.Calls.NUMBER_PRESENTATION, |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | static final int DATE_COLUMN_INDEX = 0; |
| 200 | static final int DURATION_COLUMN_INDEX = 1; |
| 201 | static final int NUMBER_COLUMN_INDEX = 2; |
| 202 | static final int CALL_TYPE_COLUMN_INDEX = 3; |
| 203 | static final int COUNTRY_ISO_COLUMN_INDEX = 4; |
| 204 | static final int GEOCODED_LOCATION_COLUMN_INDEX = 5; |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 205 | static final int NUMBER_PRESENTATION_COLUMN_INDEX = 6; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 206 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 207 | @Override |
| 208 | protected void onCreate(Bundle icicle) { |
| 209 | super.onCreate(icicle); |
| 210 | |
| 211 | setContentView(R.layout.call_detail); |
| 212 | |
| 213 | mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor(); |
| 214 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 215 | mResources = getResources(); |
| 216 | |
| 217 | mCallTypeHelper = new CallTypeHelper(getResources()); |
Yorke Lee | 24ec319 | 2013-11-19 13:52:45 -0800 | [diff] [blame] | 218 | mPhoneNumberHelper = new PhoneNumberDisplayHelper(mResources); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 219 | mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); |
| 220 | mAsyncQueryHandler = new CallDetailActivityQueryHandler(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 221 | mStatusMessageView = findViewById(R.id.voicemail_status); |
| 222 | mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message); |
| 223 | mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action); |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 224 | mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo); |
| 225 | mQuickContactBadge.setOverlay(null); |
| 226 | mCallerName = (TextView) findViewById(R.id.caller_name); |
| 227 | mCallerNumber = (TextView) findViewById(R.id.caller_number); |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 228 | mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 229 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
| 230 | mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener); |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 231 | mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); |
Chiao Cheng | adb742c | 2013-10-07 17:46:25 -0700 | [diff] [blame] | 232 | getActionBar().setDisplayHomeAsUpEnabled(true); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 233 | optionallyHandleVoicemail(); |
| 234 | if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) { |
| 235 | closeSystemDialogs(); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void onResume() { |
| 241 | super.onResume(); |
| 242 | updateData(getCallLogEntryUris()); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Handle voicemail playback or hide voicemail ui. |
| 247 | * <p> |
| 248 | * If the Intent used to start this Activity contains the suitable extras, then start voicemail |
| 249 | * playback. If it doesn't, then hide the voicemail ui. |
| 250 | */ |
| 251 | private void optionallyHandleVoicemail() { |
| 252 | View voicemailContainer = findViewById(R.id.voicemail_container); |
| 253 | if (hasVoicemail()) { |
| 254 | // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri |
| 255 | // to play and optionally start the playback. |
| 256 | // Do a query to fetch the voicemail status messages. |
| 257 | VoicemailPlaybackFragment playbackFragment = new VoicemailPlaybackFragment(); |
| 258 | Bundle fragmentArguments = new Bundle(); |
| 259 | fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, getVoicemailUri()); |
| 260 | if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) { |
| 261 | fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true); |
| 262 | } |
| 263 | playbackFragment.setArguments(fragmentArguments); |
| 264 | voicemailContainer.setVisibility(View.VISIBLE); |
| 265 | getFragmentManager().beginTransaction() |
Yorke Lee | aa536fd | 2013-07-29 11:31:04 -0700 | [diff] [blame] | 266 | .add(R.id.voicemail_container, playbackFragment) |
| 267 | .commitAllowingStateLoss(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 268 | mAsyncQueryHandler.startVoicemailStatusQuery(getVoicemailUri()); |
| 269 | markVoicemailAsRead(getVoicemailUri()); |
| 270 | } else { |
| 271 | // No voicemail uri: hide the status view. |
| 272 | mStatusMessageView.setVisibility(View.GONE); |
| 273 | voicemailContainer.setVisibility(View.GONE); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | private boolean hasVoicemail() { |
| 278 | return getVoicemailUri() != null; |
| 279 | } |
| 280 | |
| 281 | private Uri getVoicemailUri() { |
| 282 | return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
| 283 | } |
| 284 | |
| 285 | private void markVoicemailAsRead(final Uri voicemailUri) { |
| 286 | mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() { |
| 287 | @Override |
| 288 | public Void doInBackground(Void... params) { |
| 289 | ContentValues values = new ContentValues(); |
| 290 | values.put(Voicemails.IS_READ, true); |
| 291 | getContentResolver().update(voicemailUri, values, |
| 292 | Voicemails.IS_READ + " = 0", null); |
| 293 | return null; |
| 294 | } |
| 295 | }); |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Returns the list of URIs to show. |
| 300 | * <p> |
| 301 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 302 | * a list of ids in the call log added as an extra on the URI. |
| 303 | * <p> |
| 304 | * If both are available, the data on the intent takes precedence. |
| 305 | */ |
| 306 | private Uri[] getCallLogEntryUris() { |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 307 | final Uri uri = getIntent().getData(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 308 | if (uri != null) { |
| 309 | // If there is a data on the intent, it takes precedence over the extra. |
| 310 | return new Uri[]{ uri }; |
| 311 | } |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 312 | final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 313 | final int numIds = ids == null ? 0 : ids.length; |
| 314 | final Uri[] uris = new Uri[numIds]; |
| 315 | for (int index = 0; index < numIds; ++index) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 316 | uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]); |
| 317 | } |
| 318 | return uris; |
| 319 | } |
| 320 | |
| 321 | @Override |
| 322 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 323 | switch (keyCode) { |
| 324 | case KeyEvent.KEYCODE_CALL: { |
| 325 | // Make sure phone isn't already busy before starting direct call |
| 326 | TelephonyManager tm = (TelephonyManager) |
| 327 | getSystemService(Context.TELEPHONY_SERVICE); |
| 328 | if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 329 | DialerUtils.startActivityWithErrorToast(this, |
| 330 | CallUtil.getCallIntent(Uri.fromParts(CallUtil.SCHEME_TEL, mNumber, |
| 331 | null)), |
| 332 | R.string.call_not_available); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 333 | return true; |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | return super.onKeyDown(keyCode, event); |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Update user interface with details of given call. |
| 343 | * |
| 344 | * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed |
| 345 | */ |
| 346 | private void updateData(final Uri... callUris) { |
| 347 | class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> { |
| 348 | @Override |
| 349 | public PhoneCallDetails[] doInBackground(Void... params) { |
| 350 | // TODO: All phone calls correspond to the same person, so we can make a single |
| 351 | // lookup. |
| 352 | final int numCalls = callUris.length; |
| 353 | PhoneCallDetails[] details = new PhoneCallDetails[numCalls]; |
| 354 | try { |
| 355 | for (int index = 0; index < numCalls; ++index) { |
| 356 | details[index] = getPhoneCallDetailsForUri(callUris[index]); |
| 357 | } |
| 358 | return details; |
| 359 | } catch (IllegalArgumentException e) { |
| 360 | // Something went wrong reading in our primary data. |
| 361 | Log.w(TAG, "invalid URI starting call details", e); |
| 362 | return null; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | @Override |
| 367 | public void onPostExecute(PhoneCallDetails[] details) { |
| 368 | if (details == null) { |
| 369 | // Somewhere went wrong: we're going to bail out and show error to users. |
| 370 | Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error, |
| 371 | Toast.LENGTH_SHORT).show(); |
| 372 | finish(); |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | // We know that all calls are from the same number and the same contact, so pick the |
| 377 | // first. |
| 378 | PhoneCallDetails firstDetails = details[0]; |
| 379 | mNumber = firstDetails.number.toString(); |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 380 | final int numberPresentation = firstDetails.numberPresentation; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 381 | final Uri contactUri = firstDetails.contactUri; |
| 382 | final Uri photoUri = firstDetails.photoUri; |
| 383 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 384 | // Cache the details about the phone number. |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 385 | final boolean canPlaceCallsTo = |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 386 | PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation); |
| 387 | final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(); |
| 388 | final boolean isVoicemailNumber = phoneUtils.isVoicemailNumber(mNumber); |
| 389 | final boolean isSipNumber = phoneUtils.isSipNumber(mNumber); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 390 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 391 | final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 392 | |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 393 | final CharSequence displayNumber = |
| 394 | mPhoneNumberHelper.getDisplayNumber( |
| 395 | firstDetails.number, |
| 396 | firstDetails.numberPresentation, |
| 397 | firstDetails.formattedNumber); |
| 398 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 399 | if (!TextUtils.isEmpty(firstDetails.name)) { |
| 400 | mCallerName.setText(firstDetails.name); |
| 401 | mCallerNumber.setText(callLocationOrType + " " + displayNumber); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 402 | } else { |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 403 | mCallerName.setText(displayNumber); |
| 404 | if (!TextUtils.isEmpty(callLocationOrType)) { |
| 405 | mCallerNumber.setText(callLocationOrType); |
| 406 | mCallerNumber.setVisibility(View.VISIBLE); |
| 407 | } else { |
| 408 | mCallerNumber.setVisibility(View.GONE); |
| 409 | } |
| 410 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | mHasEditNumberBeforeCallOption = |
| 414 | canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; |
| 415 | mHasTrashOption = hasVoicemail(); |
| 416 | mHasRemoveFromCallLogOption = !hasVoicemail(); |
| 417 | invalidateOptionsMenu(); |
| 418 | |
| 419 | ListView historyList = (ListView) findViewById(R.id.history); |
| 420 | historyList.setAdapter( |
| 421 | new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater, |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 422 | mCallTypeHelper, details)); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 423 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 424 | String lookupKey = contactUri == null ? null |
| 425 | : ContactInfoHelper.getLookupKeyFromUri(contactUri); |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 426 | |
| 427 | final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType); |
| 428 | |
| 429 | final int contactType = |
| 430 | isVoicemailNumber? ContactPhotoManager.TYPE_VOICEMAIL : |
| 431 | isBusiness ? ContactPhotoManager.TYPE_BUSINESS : |
| 432 | ContactPhotoManager.TYPE_DEFAULT; |
| 433 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 434 | String nameForDefaultImage; |
| 435 | if (TextUtils.isEmpty(firstDetails.name)) { |
| 436 | nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(firstDetails.number, |
| 437 | firstDetails.numberPresentation, |
| 438 | firstDetails.formattedNumber).toString(); |
| 439 | } else { |
| 440 | nameForDefaultImage = firstDetails.name.toString(); |
| 441 | } |
| 442 | |
| 443 | loadContactPhotos( |
| 444 | contactUri, photoUri, nameForDefaultImage, lookupKey, contactType); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 445 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
| 446 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 447 | |
| 448 | /** |
| 449 | * Determines the location geocode text for a call, or the phone number type |
| 450 | * (if available). |
| 451 | * |
| 452 | * @param details The call details. |
| 453 | * @return The phone number type or location. |
| 454 | */ |
| 455 | private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) { |
| 456 | if (!TextUtils.isEmpty(details.name)) { |
| 457 | return Phone.getTypeLabel(mResources, details.numberType, |
| 458 | details.numberLabel); |
| 459 | } else { |
| 460 | return details.geocode; |
| 461 | } |
| 462 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 463 | } |
| 464 | mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask()); |
| 465 | } |
| 466 | |
| 467 | /** Return the phone call details for a given call log URI. */ |
| 468 | private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) { |
| 469 | ContentResolver resolver = getContentResolver(); |
| 470 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 471 | try { |
| 472 | if (callCursor == null || !callCursor.moveToFirst()) { |
| 473 | throw new IllegalArgumentException("Cannot find content: " + callUri); |
| 474 | } |
| 475 | |
| 476 | // Read call log specifics. |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 477 | final String number = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 478 | final int numberPresentation = callCursor.getInt( |
| 479 | NUMBER_PRESENTATION_COLUMN_INDEX); |
| 480 | final long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 481 | final long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 482 | final int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 483 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 484 | final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX); |
| 485 | |
| 486 | if (TextUtils.isEmpty(countryIso)) { |
| 487 | countryIso = mDefaultCountryIso; |
| 488 | } |
| 489 | |
| 490 | // Formatted phone number. |
| 491 | final CharSequence formattedNumber; |
| 492 | // Read contact specifics. |
| 493 | final CharSequence nameText; |
| 494 | final int numberType; |
| 495 | final CharSequence numberLabel; |
| 496 | final Uri photoUri; |
| 497 | final Uri lookupUri; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 498 | int sourceType; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 499 | // If this is not a regular number, there is no point in looking it up in the contacts. |
| 500 | ContactInfo info = |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 501 | PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) |
Yorke Lee | 1a7c196 | 2013-09-20 16:04:34 -0700 | [diff] [blame] | 502 | && !new PhoneNumberUtilsWrapper().isVoicemailNumber(number) |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 503 | ? mContactInfoHelper.lookupNumber(number, countryIso) |
| 504 | : null; |
| 505 | if (info == null) { |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 506 | formattedNumber = mPhoneNumberHelper.getDisplayNumber(number, |
| 507 | numberPresentation, null); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 508 | nameText = ""; |
| 509 | numberType = 0; |
| 510 | numberLabel = ""; |
| 511 | photoUri = null; |
| 512 | lookupUri = null; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 513 | sourceType = 0; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 514 | } else { |
| 515 | formattedNumber = info.formattedNumber; |
| 516 | nameText = info.name; |
| 517 | numberType = info.type; |
| 518 | numberLabel = info.label; |
| 519 | photoUri = info.photoUri; |
| 520 | lookupUri = info.lookupUri; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 521 | sourceType = info.sourceType; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 522 | } |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 523 | return new PhoneCallDetails(number, numberPresentation, |
| 524 | formattedNumber, countryIso, geocode, |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 525 | new int[]{ callType }, date, duration, |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 526 | nameText, numberType, numberLabel, lookupUri, photoUri, sourceType); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 527 | } finally { |
| 528 | if (callCursor != null) { |
| 529 | callCursor.close(); |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | /** Load the contact photos and places them in the corresponding views. */ |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 535 | private void loadContactPhotos(Uri contactUri, Uri photoUri, String displayName, |
| 536 | String lookupKey, int contactType) { |
| 537 | |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 538 | final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 539 | contactType, true /* isCircular */); |
| 540 | |
| 541 | mQuickContactBadge.assignContactUri(contactUri); |
| 542 | mQuickContactBadge.setContentDescription( |
| 543 | mResources.getString(R.string.description_contact_details, displayName)); |
| 544 | |
| 545 | mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, photoUri, |
| 546 | false /* darkTheme */, true /* isCircular */, request); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | static final class ViewEntry { |
| 550 | public final String text; |
| 551 | public final Intent primaryIntent; |
| 552 | /** The description for accessibility of the primary action. */ |
| 553 | public final String primaryDescription; |
| 554 | |
| 555 | public CharSequence label = null; |
| 556 | /** Icon for the secondary action. */ |
| 557 | public int secondaryIcon = 0; |
| 558 | /** Intent for the secondary action. If not null, an icon must be defined. */ |
| 559 | public Intent secondaryIntent = null; |
| 560 | /** The description for accessibility of the secondary action. */ |
| 561 | public String secondaryDescription = null; |
| 562 | |
| 563 | public ViewEntry(String text, Intent intent, String description) { |
| 564 | this.text = text; |
| 565 | primaryIntent = intent; |
| 566 | primaryDescription = description; |
| 567 | } |
| 568 | |
| 569 | public void setSecondaryAction(int icon, Intent intent, String description) { |
| 570 | secondaryIcon = icon; |
| 571 | secondaryIntent = intent; |
| 572 | secondaryDescription = description; |
| 573 | } |
| 574 | } |
| 575 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 576 | protected void updateVoicemailStatusMessage(Cursor statusCursor) { |
| 577 | if (statusCursor == null) { |
| 578 | mStatusMessageView.setVisibility(View.GONE); |
| 579 | return; |
| 580 | } |
| 581 | final StatusMessage message = getStatusMessage(statusCursor); |
| 582 | if (message == null || !message.showInCallDetails()) { |
| 583 | mStatusMessageView.setVisibility(View.GONE); |
| 584 | return; |
| 585 | } |
| 586 | |
| 587 | mStatusMessageView.setVisibility(View.VISIBLE); |
| 588 | mStatusMessageText.setText(message.callDetailsMessageId); |
| 589 | if (message.actionMessageId != -1) { |
| 590 | mStatusMessageAction.setText(message.actionMessageId); |
| 591 | } |
| 592 | if (message.actionUri != null) { |
| 593 | mStatusMessageAction.setClickable(true); |
| 594 | mStatusMessageAction.setOnClickListener(new View.OnClickListener() { |
| 595 | @Override |
| 596 | public void onClick(View v) { |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 597 | DialerUtils.startActivityWithErrorToast(CallDetailActivity.this, |
| 598 | new Intent(Intent.ACTION_VIEW, message.actionUri)); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 599 | } |
| 600 | }); |
| 601 | } else { |
| 602 | mStatusMessageAction.setClickable(false); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | private StatusMessage getStatusMessage(Cursor statusCursor) { |
| 607 | List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor); |
| 608 | if (messages.size() == 0) { |
| 609 | return null; |
| 610 | } |
| 611 | // There can only be a single status message per source package, so num of messages can |
| 612 | // at most be 1. |
| 613 | if (messages.size() > 1) { |
| 614 | Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." + |
| 615 | " Will use the first one.", messages.size())); |
| 616 | } |
| 617 | return messages.get(0); |
| 618 | } |
| 619 | |
| 620 | @Override |
| 621 | public boolean onCreateOptionsMenu(Menu menu) { |
| 622 | getMenuInflater().inflate(R.menu.call_details_options, menu); |
| 623 | return super.onCreateOptionsMenu(menu); |
| 624 | } |
| 625 | |
| 626 | @Override |
| 627 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 628 | // This action deletes all elements in the group from the call log. |
| 629 | // We don't have this action for voicemails, because you can just use the trash button. |
| 630 | menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption); |
| 631 | menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption); |
| 632 | menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption); |
| 633 | return super.onPrepareOptionsMenu(menu); |
| 634 | } |
| 635 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 636 | public void onMenuRemoveFromCallLog(MenuItem menuItem) { |
| 637 | final StringBuilder callIds = new StringBuilder(); |
| 638 | for (Uri callUri : getCallLogEntryUris()) { |
| 639 | if (callIds.length() != 0) { |
| 640 | callIds.append(","); |
| 641 | } |
| 642 | callIds.append(ContentUris.parseId(callUri)); |
| 643 | } |
| 644 | mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH, |
| 645 | new AsyncTask<Void, Void, Void>() { |
| 646 | @Override |
| 647 | public Void doInBackground(Void... params) { |
| 648 | getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL, |
| 649 | Calls._ID + " IN (" + callIds + ")", null); |
| 650 | return null; |
| 651 | } |
| 652 | |
| 653 | @Override |
| 654 | public void onPostExecute(Void result) { |
| 655 | finish(); |
| 656 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 657 | } |
| 658 | ); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | public void onMenuEditNumberBeforeCall(MenuItem menuItem) { |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 662 | startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber))); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | public void onMenuTrashVoicemail(MenuItem menuItem) { |
| 666 | final Uri voicemailUri = getVoicemailUri(); |
| 667 | mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH, |
| 668 | new AsyncTask<Void, Void, Void>() { |
| 669 | @Override |
| 670 | public Void doInBackground(Void... params) { |
| 671 | getContentResolver().delete(voicemailUri, null, null); |
| 672 | return null; |
| 673 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 674 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 675 | @Override |
| 676 | public void onPostExecute(Void result) { |
| 677 | finish(); |
| 678 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame^] | 679 | } |
| 680 | ); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | @Override |
| 684 | protected void onPause() { |
| 685 | // Immediately stop the proximity sensor. |
| 686 | disableProximitySensor(false); |
| 687 | mProximitySensorListener.clearPendingRequests(); |
| 688 | super.onPause(); |
| 689 | } |
| 690 | |
| 691 | @Override |
| 692 | public void enableProximitySensor() { |
| 693 | mProximitySensorManager.enable(); |
| 694 | } |
| 695 | |
| 696 | @Override |
| 697 | public void disableProximitySensor(boolean waitForFarState) { |
| 698 | mProximitySensorManager.disable(waitForFarState); |
| 699 | } |
| 700 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 701 | private void closeSystemDialogs() { |
| 702 | sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 703 | } |
| 704 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 705 | /** Returns the given text, forced to be left-to-right. */ |
| 706 | private static CharSequence forceLeftToRight(CharSequence text) { |
| 707 | StringBuilder sb = new StringBuilder(); |
| 708 | sb.append(LEFT_TO_RIGHT_EMBEDDING); |
| 709 | sb.append(text); |
| 710 | sb.append(POP_DIRECTIONAL_FORMATTING); |
| 711 | return sb.toString(); |
| 712 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 713 | } |