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