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