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