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; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.content.res.Resources; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 25 | import android.net.Uri; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 26 | import android.os.Bundle; |
Yorke Lee | 7151398 | 2015-02-25 20:23:53 -0800 | [diff] [blame] | 27 | import android.os.PowerManager; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 28 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 29 | import android.provider.VoicemailContract.Voicemails; |
Tyler Gunn | 9dc924c | 2014-09-12 09:33:50 -0700 | [diff] [blame] | 30 | import android.telecom.PhoneAccount; |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 31 | import android.telecom.PhoneAccountHandle; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 32 | import android.telephony.TelephonyManager; |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 33 | import android.text.BidiFormatter; |
| 34 | import android.text.TextDirectionHeuristics; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 35 | import android.text.TextUtils; |
| 36 | import android.util.Log; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 37 | import android.view.KeyEvent; |
| 38 | import android.view.LayoutInflater; |
| 39 | import android.view.Menu; |
| 40 | import android.view.MenuItem; |
| 41 | import android.view.View; |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 42 | import android.widget.LinearLayout; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 43 | import android.widget.ListView; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 44 | import android.widget.QuickContactBadge; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 45 | import android.widget.TextView; |
| 46 | import android.widget.Toast; |
| 47 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 48 | import com.android.contacts.common.ContactPhotoManager; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 49 | import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 50 | import com.android.contacts.common.GeoUtil; |
Brian Attwell | 8204324 | 2015-02-03 14:13:58 -0800 | [diff] [blame] | 51 | import com.android.contacts.common.CallUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 52 | import com.android.dialer.calllog.CallDetailHistoryAdapter; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame^] | 53 | import com.android.dialer.calllog.CallLogAsyncTaskUtil.CallLogAsyncTaskListener; |
| 54 | import com.android.dialer.calllog.CallLogAsyncTaskUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 55 | import com.android.dialer.calllog.CallTypeHelper; |
| 56 | import com.android.dialer.calllog.ContactInfo; |
| 57 | import com.android.dialer.calllog.ContactInfoHelper; |
Nancy Chen | b2eebaf | 2014-07-21 13:41:36 -0700 | [diff] [blame] | 58 | import com.android.dialer.calllog.PhoneAccountUtils; |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 59 | import com.android.dialer.calllog.PhoneNumberDisplayUtil; |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 60 | import com.android.dialer.calllog.PhoneNumberUtilsWrapper; |
Andrew Lee | 247df6e | 2015-05-12 19:09:00 -0700 | [diff] [blame] | 61 | import com.android.dialer.util.IntentUtil; |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 62 | import com.android.dialer.util.DialerUtils; |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 63 | import com.android.dialer.util.TelecomUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 64 | import com.android.dialer.voicemail.VoicemailPlaybackFragment; |
| 65 | import com.android.dialer.voicemail.VoicemailStatusHelper; |
| 66 | import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage; |
| 67 | import com.android.dialer.voicemail.VoicemailStatusHelperImpl; |
| 68 | |
| 69 | import java.util.List; |
| 70 | |
| 71 | /** |
| 72 | * Displays the details of a specific call log entry. |
| 73 | * <p> |
| 74 | * This activity can be either started with the URI of a single call log entry, or with the |
| 75 | * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries. |
| 76 | */ |
Andrew Lee | 93b816f | 2015-05-13 12:23:35 -0700 | [diff] [blame] | 77 | public class CallDetailActivity extends Activity { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 78 | private static final String TAG = "CallDetail"; |
| 79 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame^] | 80 | /** A long array extra containing ids of call log entries to display. */ |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 81 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 82 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 83 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
| 84 | /** If we should immediately start playback of the voicemail, this extra will be set to true. */ |
| 85 | public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK"; |
| 86 | /** If the activity was triggered from a notification. */ |
| 87 | public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION"; |
| 88 | |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 89 | public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment"; |
| 90 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame^] | 91 | private CallLogAsyncTaskListener mCallLogAsyncTaskListener = new CallLogAsyncTaskListener() { |
| 92 | @Override |
| 93 | public void onDeleteCall() { |
| 94 | finish(); |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public void onDeleteVoicemail() { |
| 99 | finish(); |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public void onGetCallDetails(PhoneCallDetails[] details) { |
| 104 | Context context = CallDetailActivity.this; |
| 105 | |
| 106 | if (details == null) { |
| 107 | // Somewhere went wrong: we're going to bail out and show error to users. |
| 108 | Toast.makeText(context, R.string.toast_call_detail_error, |
| 109 | Toast.LENGTH_SHORT).show(); |
| 110 | finish(); |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | // We know that all calls are from the same number and the same contact, so pick the |
| 115 | // first. |
| 116 | PhoneCallDetails firstDetails = details[0]; |
| 117 | mNumber = TextUtils.isEmpty(firstDetails.number) ? |
| 118 | null : firstDetails.number.toString(); |
| 119 | final int numberPresentation = firstDetails.numberPresentation; |
| 120 | final Uri contactUri = firstDetails.contactUri; |
| 121 | final Uri photoUri = firstDetails.photoUri; |
| 122 | final PhoneAccountHandle accountHandle = firstDetails.accountHandle; |
| 123 | |
| 124 | // Cache the details about the phone number. |
| 125 | final boolean canPlaceCallsTo = |
| 126 | PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation); |
| 127 | final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(context); |
| 128 | final boolean isVoicemailNumber = |
| 129 | phoneUtils.isVoicemailNumber(accountHandle, mNumber); |
| 130 | final boolean isSipNumber = PhoneNumberUtilsWrapper.isSipNumber(mNumber); |
| 131 | |
| 132 | final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails); |
| 133 | |
| 134 | final CharSequence displayNumber = firstDetails.displayNumber; |
| 135 | final String displayNumberStr = mBidiFormatter.unicodeWrap( |
| 136 | displayNumber.toString(), TextDirectionHeuristics.LTR); |
| 137 | |
| 138 | if (!TextUtils.isEmpty(firstDetails.name)) { |
| 139 | mCallerName.setText(firstDetails.name); |
| 140 | mCallerNumber.setText(callLocationOrType + " " + displayNumberStr); |
| 141 | } else { |
| 142 | mCallerName.setText(displayNumberStr); |
| 143 | if (!TextUtils.isEmpty(callLocationOrType)) { |
| 144 | mCallerNumber.setText(callLocationOrType); |
| 145 | mCallerNumber.setVisibility(View.VISIBLE); |
| 146 | } else { |
| 147 | mCallerNumber.setVisibility(View.GONE); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | String accountLabel = PhoneAccountUtils.getAccountLabel(context, accountHandle); |
| 152 | if (!TextUtils.isEmpty(accountLabel)) { |
| 153 | mAccountLabel.setText(accountLabel); |
| 154 | mAccountLabel.setVisibility(View.VISIBLE); |
| 155 | } else { |
| 156 | mAccountLabel.setVisibility(View.GONE); |
| 157 | } |
| 158 | |
| 159 | mHasEditNumberBeforeCallOption = |
| 160 | canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; |
| 161 | mHasTrashOption = hasVoicemail(); |
| 162 | mHasRemoveFromCallLogOption = !hasVoicemail(); |
| 163 | invalidateOptionsMenu(); |
| 164 | |
| 165 | ListView historyList = (ListView) findViewById(R.id.history); |
| 166 | historyList.setAdapter( |
| 167 | new CallDetailHistoryAdapter(context, mInflater, mCallTypeHelper, details)); |
| 168 | |
| 169 | String lookupKey = contactUri == null ? null |
| 170 | : ContactInfoHelper.getLookupKeyFromUri(contactUri); |
| 171 | |
| 172 | final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType); |
| 173 | |
| 174 | final int contactType = |
| 175 | isVoicemailNumber ? ContactPhotoManager.TYPE_VOICEMAIL : |
| 176 | isBusiness ? ContactPhotoManager.TYPE_BUSINESS : |
| 177 | ContactPhotoManager.TYPE_DEFAULT; |
| 178 | |
| 179 | String nameForDefaultImage; |
| 180 | if (TextUtils.isEmpty(firstDetails.name)) { |
| 181 | nameForDefaultImage = firstDetails.displayNumber; |
| 182 | } else { |
| 183 | nameForDefaultImage = firstDetails.name.toString(); |
| 184 | } |
| 185 | |
| 186 | loadContactPhotos( |
| 187 | contactUri, photoUri, nameForDefaultImage, lookupKey, contactType); |
| 188 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Determines the location geocode text for a call, or the phone number type |
| 193 | * (if available). |
| 194 | * |
| 195 | * @param details The call details. |
| 196 | * @return The phone number type or location. |
| 197 | */ |
| 198 | private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) { |
| 199 | if (!TextUtils.isEmpty(details.name)) { |
| 200 | return Phone.getTypeLabel(mResources, details.numberType, |
| 201 | details.numberLabel); |
| 202 | } else { |
| 203 | return details.geocode; |
| 204 | } |
| 205 | } |
| 206 | }; |
| 207 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 208 | private CallTypeHelper mCallTypeHelper; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 209 | private QuickContactBadge mQuickContactBadge; |
| 210 | private TextView mCallerName; |
| 211 | private TextView mCallerNumber; |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 212 | private TextView mAccountLabel; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 213 | private ContactInfoHelper mContactInfoHelper; |
| 214 | |
| 215 | private String mNumber = null; |
| 216 | private String mDefaultCountryIso; |
| 217 | |
| 218 | /* package */ LayoutInflater mInflater; |
| 219 | /* package */ Resources mResources; |
| 220 | /** Helper to load contact photos. */ |
| 221 | private ContactPhotoManager mContactPhotoManager; |
Andrew Lee | c1167e9 | 2015-05-18 11:27:54 -0700 | [diff] [blame] | 222 | |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 223 | private LinearLayout mVoicemailHeader; |
| 224 | |
| 225 | private Uri mVoicemailUri; |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 226 | private BidiFormatter mBidiFormatter = BidiFormatter.getInstance(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 227 | |
| 228 | /** Whether we should show "edit number before call" in the options menu. */ |
| 229 | private boolean mHasEditNumberBeforeCallOption; |
| 230 | /** Whether we should show "trash" in the options menu. */ |
| 231 | private boolean mHasTrashOption; |
| 232 | /** Whether we should show "remove from call log" in the options menu. */ |
| 233 | private boolean mHasRemoveFromCallLogOption; |
| 234 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 235 | @Override |
| 236 | protected void onCreate(Bundle icicle) { |
| 237 | super.onCreate(icicle); |
| 238 | |
| 239 | setContentView(R.layout.call_detail); |
| 240 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 241 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 242 | mResources = getResources(); |
| 243 | |
| 244 | mCallTypeHelper = new CallTypeHelper(getResources()); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 245 | |
| 246 | mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
| 247 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 248 | mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo); |
| 249 | mQuickContactBadge.setOverlay(null); |
Brian Attwell | 74eb4ec | 2015-02-25 22:31:22 -0800 | [diff] [blame] | 250 | mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE); |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 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); |
Yorke Lee | 7151398 | 2015-02-25 20:23:53 -0800 | [diff] [blame] | 256 | |
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(); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame^] | 269 | |
| 270 | CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Handle voicemail playback or hide voicemail ui. |
| 275 | * <p> |
| 276 | * 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] | 277 | * playback. If it doesn't, then don't inflate the voicemail ui. |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 278 | */ |
| 279 | private void optionallyHandleVoicemail() { |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 280 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 281 | if (hasVoicemail()) { |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 282 | LayoutInflater inflater = |
| 283 | (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 284 | mVoicemailHeader = |
| 285 | (LinearLayout) inflater.inflate(R.layout.call_details_voicemail_header, null); |
| 286 | View voicemailContainer = mVoicemailHeader.findViewById(R.id.voicemail_container); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 287 | ListView historyList = (ListView) findViewById(R.id.history); |
| 288 | historyList.addHeaderView(mVoicemailHeader); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 289 | // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri |
| 290 | // to play and optionally start the playback. |
| 291 | // Do a query to fetch the voicemail status messages. |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 292 | VoicemailPlaybackFragment playbackFragment; |
| 293 | |
| 294 | playbackFragment = (VoicemailPlaybackFragment) getFragmentManager().findFragmentByTag( |
| 295 | VOICEMAIL_FRAGMENT_TAG); |
| 296 | |
| 297 | if (playbackFragment == null) { |
| 298 | playbackFragment = new VoicemailPlaybackFragment(); |
| 299 | Bundle fragmentArguments = new Bundle(); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 300 | fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, mVoicemailUri); |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 301 | if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) { |
| 302 | fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true); |
| 303 | } |
| 304 | playbackFragment.setArguments(fragmentArguments); |
| 305 | getFragmentManager().beginTransaction() |
| 306 | .add(R.id.voicemail_container, playbackFragment, VOICEMAIL_FRAGMENT_TAG) |
| 307 | .commitAllowingStateLoss(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 308 | } |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 309 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 310 | voicemailContainer.setVisibility(View.VISIBLE); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame^] | 311 | CallLogAsyncTaskUtil.markVoicemailAsRead(this, mVoicemailUri); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
| 315 | private boolean hasVoicemail() { |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 316 | return mVoicemailUri != null; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 319 | /** |
| 320 | * Returns the list of URIs to show. |
| 321 | * <p> |
| 322 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 323 | * a list of ids in the call log added as an extra on the URI. |
| 324 | * <p> |
| 325 | * If both are available, the data on the intent takes precedence. |
| 326 | */ |
| 327 | private Uri[] getCallLogEntryUris() { |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 328 | final Uri uri = getIntent().getData(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 329 | if (uri != null) { |
| 330 | // If there is a data on the intent, it takes precedence over the extra. |
| 331 | return new Uri[]{ uri }; |
| 332 | } |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 333 | final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 334 | final int numIds = ids == null ? 0 : ids.length; |
| 335 | final Uri[] uris = new Uri[numIds]; |
| 336 | for (int index = 0; index < numIds; ++index) { |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 337 | uris[index] = ContentUris.withAppendedId( |
| 338 | TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 339 | } |
| 340 | return uris; |
| 341 | } |
| 342 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 343 | /** Load the contact photos and places them in the corresponding views. */ |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 344 | private void loadContactPhotos(Uri contactUri, Uri photoUri, String displayName, |
| 345 | String lookupKey, int contactType) { |
| 346 | |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 347 | final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 348 | contactType, true /* isCircular */); |
| 349 | |
| 350 | mQuickContactBadge.assignContactUri(contactUri); |
| 351 | mQuickContactBadge.setContentDescription( |
| 352 | mResources.getString(R.string.description_contact_details, displayName)); |
| 353 | |
| 354 | mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, photoUri, |
| 355 | false /* darkTheme */, true /* isCircular */, request); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 358 | @Override |
| 359 | public boolean onCreateOptionsMenu(Menu menu) { |
| 360 | getMenuInflater().inflate(R.menu.call_details_options, menu); |
| 361 | return super.onCreateOptionsMenu(menu); |
| 362 | } |
| 363 | |
| 364 | @Override |
| 365 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 366 | // This action deletes all elements in the group from the call log. |
| 367 | // We don't have this action for voicemails, because you can just use the trash button. |
| 368 | menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption); |
| 369 | menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption); |
| 370 | menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption); |
| 371 | return super.onPrepareOptionsMenu(menu); |
| 372 | } |
| 373 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 374 | public void onMenuRemoveFromCallLog(MenuItem menuItem) { |
| 375 | final StringBuilder callIds = new StringBuilder(); |
| 376 | for (Uri callUri : getCallLogEntryUris()) { |
| 377 | if (callIds.length() != 0) { |
| 378 | callIds.append(","); |
| 379 | } |
| 380 | callIds.append(ContentUris.parseId(callUri)); |
| 381 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 382 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame^] | 383 | CallLogAsyncTaskUtil.deleteCalls(this, callIds.toString(), mCallLogAsyncTaskListener); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | public void onMenuEditNumberBeforeCall(MenuItem menuItem) { |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 387 | startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber))); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | public void onMenuTrashVoicemail(MenuItem menuItem) { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame^] | 391 | CallLogAsyncTaskUtil.deleteVoicemail(this, mVoicemailUri, mCallLogAsyncTaskListener); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 394 | private void closeSystemDialogs() { |
| 395 | sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 396 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 397 | } |