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