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