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