Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.dialer; |
| 18 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 19 | import android.content.ContentUris; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.res.Resources; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 25 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 26 | import android.support.v7.app.AppCompatActivity; |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 27 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 28 | import android.text.BidiFormatter; |
| 29 | import android.text.TextDirectionHeuristics; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 30 | import android.text.TextUtils; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 31 | import android.view.LayoutInflater; |
| 32 | import android.view.Menu; |
| 33 | import android.view.MenuItem; |
Yorke Lee | 0b45897 | 2015-09-18 12:55:30 -0700 | [diff] [blame] | 34 | import android.view.MotionEvent; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 35 | import android.view.View; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 36 | import android.widget.ListView; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 37 | import android.widget.QuickContactBadge; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 38 | import android.widget.TextView; |
| 39 | import android.widget.Toast; |
| 40 | |
Brian Attwell | 8204324 | 2015-02-03 14:13:58 -0800 | [diff] [blame] | 41 | import com.android.contacts.common.CallUtil; |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 42 | import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; |
| 43 | import com.android.contacts.common.ContactPhotoManager; |
| 44 | import com.android.contacts.common.GeoUtil; |
| 45 | import com.android.contacts.common.interactions.TouchPointManager; |
| 46 | import com.android.contacts.common.testing.NeededForTesting; |
Tyler Gunn | 18b4a2e | 2015-08-05 08:18:37 -0700 | [diff] [blame] | 47 | import com.android.contacts.common.util.UriUtils; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 48 | import com.android.dialer.calllog.CallDetailHistoryAdapter; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 49 | import com.android.dialer.calllog.CallLogAsyncTaskUtil.CallLogAsyncTaskListener; |
| 50 | import com.android.dialer.calllog.CallLogAsyncTaskUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 51 | import com.android.dialer.calllog.CallTypeHelper; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 52 | import com.android.dialer.calllog.ContactInfoHelper; |
Nancy Chen | b2eebaf | 2014-07-21 13:41:36 -0700 | [diff] [blame] | 53 | import com.android.dialer.calllog.PhoneAccountUtils; |
Yorke Lee | e3a2d13 | 2015-09-14 16:52:08 -0700 | [diff] [blame] | 54 | import com.android.dialer.util.IntentUtil.CallIntentBuilder; |
Andrew Lee | d3f6a6c | 2015-06-25 16:53:56 -0700 | [diff] [blame] | 55 | import com.android.dialer.util.PhoneNumberUtil; |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 56 | import com.android.dialer.util.TelecomUtil; |
Yorke Lee | c8d6e16 | 2015-09-14 18:43:27 -0700 | [diff] [blame] | 57 | import com.android.incallui.Call.LogState; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 58 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 59 | /** |
| 60 | * Displays the details of a specific call log entry. |
| 61 | * <p> |
| 62 | * This activity can be either started with the URI of a single call log entry, or with the |
| 63 | * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries. |
| 64 | */ |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 65 | public class CallDetailActivity extends AppCompatActivity |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 66 | implements MenuItem.OnMenuItemClickListener { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 67 | private static final String TAG = "CallDetail"; |
| 68 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 69 | /** A long array extra containing ids of call log entries to display. */ |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 70 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 71 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 72 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 73 | /** If the activity was triggered from a notification. */ |
| 74 | public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION"; |
| 75 | |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 76 | public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment"; |
| 77 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 78 | private CallLogAsyncTaskListener mCallLogAsyncTaskListener = new CallLogAsyncTaskListener() { |
| 79 | @Override |
| 80 | public void onDeleteCall() { |
| 81 | finish(); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public void onDeleteVoicemail() { |
| 86 | finish(); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public void onGetCallDetails(PhoneCallDetails[] details) { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 91 | if (details == null) { |
| 92 | // Somewhere went wrong: we're going to bail out and show error to users. |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 93 | Toast.makeText(mContext, R.string.toast_call_detail_error, |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 94 | Toast.LENGTH_SHORT).show(); |
| 95 | finish(); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | // We know that all calls are from the same number and the same contact, so pick the |
| 100 | // first. |
| 101 | PhoneCallDetails firstDetails = details[0]; |
| 102 | mNumber = TextUtils.isEmpty(firstDetails.number) ? |
| 103 | null : firstDetails.number.toString(); |
| 104 | final int numberPresentation = firstDetails.numberPresentation; |
| 105 | final Uri contactUri = firstDetails.contactUri; |
| 106 | final Uri photoUri = firstDetails.photoUri; |
| 107 | final PhoneAccountHandle accountHandle = firstDetails.accountHandle; |
| 108 | |
| 109 | // Cache the details about the phone number. |
| 110 | final boolean canPlaceCallsTo = |
Andrew Lee | d3f6a6c | 2015-06-25 16:53:56 -0700 | [diff] [blame] | 111 | PhoneNumberUtil.canPlaceCallsTo(mNumber, numberPresentation); |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 112 | mIsVoicemailNumber = |
Andrew Lee | d3f6a6c | 2015-06-25 16:53:56 -0700 | [diff] [blame] | 113 | PhoneNumberUtil.isVoicemailNumber(mContext, accountHandle, mNumber); |
| 114 | final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 115 | |
| 116 | final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails); |
| 117 | |
| 118 | final CharSequence displayNumber = firstDetails.displayNumber; |
| 119 | final String displayNumberStr = mBidiFormatter.unicodeWrap( |
| 120 | displayNumber.toString(), TextDirectionHeuristics.LTR); |
| 121 | |
| 122 | if (!TextUtils.isEmpty(firstDetails.name)) { |
| 123 | mCallerName.setText(firstDetails.name); |
| 124 | mCallerNumber.setText(callLocationOrType + " " + displayNumberStr); |
| 125 | } else { |
| 126 | mCallerName.setText(displayNumberStr); |
| 127 | if (!TextUtils.isEmpty(callLocationOrType)) { |
| 128 | mCallerNumber.setText(callLocationOrType); |
| 129 | mCallerNumber.setVisibility(View.VISIBLE); |
| 130 | } else { |
| 131 | mCallerNumber.setVisibility(View.GONE); |
| 132 | } |
| 133 | } |
| 134 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 135 | mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); |
| 136 | |
| 137 | String accountLabel = PhoneAccountUtils.getAccountLabel(mContext, accountHandle); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 138 | if (!TextUtils.isEmpty(accountLabel)) { |
| 139 | mAccountLabel.setText(accountLabel); |
| 140 | mAccountLabel.setVisibility(View.VISIBLE); |
| 141 | } else { |
| 142 | mAccountLabel.setVisibility(View.GONE); |
| 143 | } |
| 144 | |
| 145 | mHasEditNumberBeforeCallOption = |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 146 | canPlaceCallsTo && !isSipNumber && !mIsVoicemailNumber; |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 147 | mHasReportMenuOption = mContactInfoHelper.canReportAsInvalid( |
| 148 | firstDetails.sourceType, firstDetails.objectId); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 149 | invalidateOptionsMenu(); |
| 150 | |
| 151 | ListView historyList = (ListView) findViewById(R.id.history); |
| 152 | historyList.setAdapter( |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 153 | new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details)); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 154 | |
| 155 | String lookupKey = contactUri == null ? null |
Tyler Gunn | 18b4a2e | 2015-08-05 08:18:37 -0700 | [diff] [blame] | 156 | : UriUtils.getLookupKeyFromUri(contactUri); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 157 | |
| 158 | final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType); |
| 159 | |
| 160 | final int contactType = |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 161 | mIsVoicemailNumber ? ContactPhotoManager.TYPE_VOICEMAIL : |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 162 | isBusiness ? ContactPhotoManager.TYPE_BUSINESS : |
| 163 | ContactPhotoManager.TYPE_DEFAULT; |
| 164 | |
| 165 | String nameForDefaultImage; |
| 166 | if (TextUtils.isEmpty(firstDetails.name)) { |
| 167 | nameForDefaultImage = firstDetails.displayNumber; |
| 168 | } else { |
| 169 | nameForDefaultImage = firstDetails.name.toString(); |
| 170 | } |
| 171 | |
| 172 | loadContactPhotos( |
| 173 | contactUri, photoUri, nameForDefaultImage, lookupKey, contactType); |
| 174 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Determines the location geocode text for a call, or the phone number type |
| 179 | * (if available). |
| 180 | * |
| 181 | * @param details The call details. |
| 182 | * @return The phone number type or location. |
| 183 | */ |
| 184 | private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) { |
| 185 | if (!TextUtils.isEmpty(details.name)) { |
| 186 | return Phone.getTypeLabel(mResources, details.numberType, |
| 187 | details.numberLabel); |
| 188 | } else { |
| 189 | return details.geocode; |
| 190 | } |
| 191 | } |
| 192 | }; |
| 193 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 194 | private Context mContext; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 195 | private CallTypeHelper mCallTypeHelper; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 196 | private QuickContactBadge mQuickContactBadge; |
| 197 | private TextView mCallerName; |
| 198 | private TextView mCallerNumber; |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 199 | private TextView mAccountLabel; |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 200 | private View mCallButton; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 201 | private ContactInfoHelper mContactInfoHelper; |
| 202 | |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 203 | protected String mNumber; |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 204 | private boolean mIsVoicemailNumber; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 205 | private String mDefaultCountryIso; |
| 206 | |
| 207 | /* package */ LayoutInflater mInflater; |
| 208 | /* package */ Resources mResources; |
| 209 | /** Helper to load contact photos. */ |
| 210 | private ContactPhotoManager mContactPhotoManager; |
Andrew Lee | c1167e9 | 2015-05-18 11:27:54 -0700 | [diff] [blame] | 211 | |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 212 | private Uri mVoicemailUri; |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 213 | private BidiFormatter mBidiFormatter = BidiFormatter.getInstance(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 214 | |
| 215 | /** Whether we should show "edit number before call" in the options menu. */ |
| 216 | private boolean mHasEditNumberBeforeCallOption; |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 217 | private boolean mHasReportMenuOption; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 218 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 219 | @Override |
| 220 | protected void onCreate(Bundle icicle) { |
| 221 | super.onCreate(icicle); |
| 222 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 223 | mContext = this; |
| 224 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 225 | setContentView(R.layout.call_detail); |
| 226 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 227 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 228 | mResources = getResources(); |
| 229 | |
| 230 | mCallTypeHelper = new CallTypeHelper(getResources()); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 231 | |
| 232 | mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
| 233 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 234 | mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo); |
| 235 | mQuickContactBadge.setOverlay(null); |
Brian Attwell | 74eb4ec | 2015-02-25 22:31:22 -0800 | [diff] [blame] | 236 | mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE); |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 237 | mCallerName = (TextView) findViewById(R.id.caller_name); |
| 238 | mCallerNumber = (TextView) findViewById(R.id.caller_number); |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 239 | mAccountLabel = (TextView) findViewById(R.id.phone_account_label); |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 240 | mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 241 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
Yorke Lee | 7151398 | 2015-02-25 20:23:53 -0800 | [diff] [blame] | 242 | |
Yorke Lee | e3a2d13 | 2015-09-14 16:52:08 -0700 | [diff] [blame] | 243 | mCallButton = findViewById(R.id.call_back_button); |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 244 | mCallButton.setOnClickListener(new View.OnClickListener() { |
| 245 | @Override |
| 246 | public void onClick(View view) { |
Yorke Lee | c8d6e16 | 2015-09-14 18:43:27 -0700 | [diff] [blame] | 247 | mContext.startActivity( |
| 248 | new CallIntentBuilder(mNumber) |
| 249 | .setCallInitiationType(LogState.INITIATION_CALL_DETAILS) |
| 250 | .build()); |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 251 | } |
| 252 | }); |
| 253 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 254 | mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 255 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 256 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 257 | if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) { |
| 258 | closeSystemDialogs(); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public void onResume() { |
| 264 | super.onResume(); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 265 | getCallDetails(); |
| 266 | } |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 267 | |
Yorke Lee | 0b45897 | 2015-09-18 12:55:30 -0700 | [diff] [blame] | 268 | @Override |
| 269 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 270 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 271 | TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); |
| 272 | } |
| 273 | return super.dispatchTouchEvent(ev); |
| 274 | } |
| 275 | |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 276 | public void getCallDetails() { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 277 | CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 280 | @NeededForTesting |
| 281 | public boolean hasVoicemail() { |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 282 | return mVoicemailUri != null; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 285 | /** |
| 286 | * Returns the list of URIs to show. |
| 287 | * <p> |
| 288 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 289 | * a list of ids in the call log added as an extra on the URI. |
| 290 | * <p> |
| 291 | * If both are available, the data on the intent takes precedence. |
| 292 | */ |
| 293 | private Uri[] getCallLogEntryUris() { |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 294 | final Uri uri = getIntent().getData(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 295 | if (uri != null) { |
| 296 | // If there is a data on the intent, it takes precedence over the extra. |
| 297 | return new Uri[]{ uri }; |
| 298 | } |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 299 | final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 300 | final int numIds = ids == null ? 0 : ids.length; |
| 301 | final Uri[] uris = new Uri[numIds]; |
| 302 | for (int index = 0; index < numIds; ++index) { |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 303 | uris[index] = ContentUris.withAppendedId( |
| 304 | TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 305 | } |
| 306 | return uris; |
| 307 | } |
| 308 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 309 | /** Load the contact photos and places them in the corresponding views. */ |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 310 | private void loadContactPhotos(Uri contactUri, Uri photoUri, String displayName, |
| 311 | String lookupKey, int contactType) { |
| 312 | |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 313 | final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 314 | contactType, true /* isCircular */); |
| 315 | |
| 316 | mQuickContactBadge.assignContactUri(contactUri); |
| 317 | mQuickContactBadge.setContentDescription( |
| 318 | mResources.getString(R.string.description_contact_details, displayName)); |
| 319 | |
| 320 | mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, photoUri, |
| 321 | false /* darkTheme */, true /* isCircular */, request); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 324 | @Override |
| 325 | public boolean onCreateOptionsMenu(Menu menu) { |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 326 | final MenuItem deleteMenuItem = menu.add( |
| 327 | Menu.NONE, |
| 328 | R.id.call_detail_delete_menu_item, |
| 329 | Menu.NONE, |
| 330 | R.string.call_details_delete); |
| 331 | deleteMenuItem.setIcon(R.drawable.ic_delete_24dp); |
| 332 | deleteMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); |
| 333 | deleteMenuItem.setOnMenuItemClickListener(this); |
| 334 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 335 | getMenuInflater().inflate(R.menu.call_details_options, menu); |
| 336 | return super.onCreateOptionsMenu(menu); |
| 337 | } |
| 338 | |
| 339 | @Override |
| 340 | public boolean onPrepareOptionsMenu(Menu menu) { |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 341 | menu.findItem(R.id.menu_edit_number_before_call) |
| 342 | .setVisible(mHasEditNumberBeforeCallOption) |
| 343 | .setOnMenuItemClickListener(this); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 344 | menu.findItem(R.id.menu_report) |
| 345 | .setVisible(mHasReportMenuOption) |
| 346 | .setOnMenuItemClickListener(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 347 | return super.onPrepareOptionsMenu(menu); |
| 348 | } |
| 349 | |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 350 | @Override |
| 351 | public boolean onMenuItemClick(MenuItem item) { |
| 352 | switch (item.getItemId()) { |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 353 | case R.id.call_detail_delete_menu_item: |
| 354 | if (hasVoicemail()) { |
| 355 | CallLogAsyncTaskUtil.deleteVoicemail( |
| 356 | this, mVoicemailUri, mCallLogAsyncTaskListener); |
| 357 | } else { |
| 358 | final StringBuilder callIds = new StringBuilder(); |
| 359 | for (Uri callUri : getCallLogEntryUris()) { |
| 360 | if (callIds.length() != 0) { |
| 361 | callIds.append(","); |
| 362 | } |
| 363 | callIds.append(ContentUris.parseId(callUri)); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 364 | } |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 365 | CallLogAsyncTaskUtil.deleteCalls( |
| 366 | this, callIds.toString(), mCallLogAsyncTaskListener); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 367 | } |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 368 | break; |
| 369 | case R.id.menu_edit_number_before_call: |
| 370 | startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber))); |
| 371 | break; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 372 | } |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 373 | return true; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 376 | private void closeSystemDialogs() { |
| 377 | sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 378 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 379 | } |