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; |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 30 | import android.support.v7.app.ActionBar; |
| 31 | import android.support.v7.app.AppCompatActivity; |
Tyler Gunn | 9dc924c | 2014-09-12 09:33:50 -0700 | [diff] [blame] | 32 | import android.telecom.PhoneAccount; |
Nancy Chen | e80d622 | 2014-10-08 20:17:55 -0700 | [diff] [blame] | 33 | import android.telecom.PhoneAccountHandle; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 34 | import android.telephony.TelephonyManager; |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 35 | import android.text.BidiFormatter; |
| 36 | import android.text.TextDirectionHeuristics; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 37 | import android.text.TextUtils; |
| 38 | import android.util.Log; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 39 | import android.view.KeyEvent; |
| 40 | import android.view.LayoutInflater; |
| 41 | import android.view.Menu; |
| 42 | import android.view.MenuItem; |
| 43 | import android.view.View; |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 44 | import android.widget.LinearLayout; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 45 | import android.widget.ListView; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 46 | import android.widget.QuickContactBadge; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 47 | import android.widget.TextView; |
| 48 | import android.widget.Toast; |
| 49 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 50 | import com.android.contacts.common.ContactPhotoManager; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 51 | import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; |
Yorke Lee | 2a61302 | 2015-07-01 14:28:13 -0700 | [diff] [blame] | 52 | import com.android.contacts.common.util.PermissionsUtil; |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 53 | import com.android.contacts.common.GeoUtil; |
Brian Attwell | 8204324 | 2015-02-03 14:13:58 -0800 | [diff] [blame] | 54 | import com.android.contacts.common.CallUtil; |
Tyler Gunn | 18b4a2e | 2015-08-05 08:18:37 -0700 | [diff] [blame] | 55 | import com.android.contacts.common.util.UriUtils; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 56 | import com.android.dialer.calllog.CallDetailHistoryAdapter; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 57 | import com.android.dialer.calllog.CallLogAsyncTaskUtil.CallLogAsyncTaskListener; |
| 58 | import com.android.dialer.calllog.CallLogAsyncTaskUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 59 | import com.android.dialer.calllog.CallTypeHelper; |
| 60 | import com.android.dialer.calllog.ContactInfo; |
| 61 | import com.android.dialer.calllog.ContactInfoHelper; |
Nancy Chen | b2eebaf | 2014-07-21 13:41:36 -0700 | [diff] [blame] | 62 | import com.android.dialer.calllog.PhoneAccountUtils; |
Andrew Lee | 49efd91 | 2015-05-19 12:17:26 -0700 | [diff] [blame] | 63 | import com.android.dialer.calllog.PhoneNumberDisplayUtil; |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 64 | import com.android.dialer.util.DialerUtils; |
Andrew Lee | d3f6a6c | 2015-06-25 16:53:56 -0700 | [diff] [blame] | 65 | import com.android.dialer.util.IntentUtil; |
| 66 | import com.android.dialer.util.PhoneNumberUtil; |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 67 | import com.android.dialer.util.TelecomUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 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 | */ |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 77 | public class CallDetailActivity extends AppCompatActivity |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 78 | implements MenuItem.OnMenuItemClickListener { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 79 | private static final String TAG = "CallDetail"; |
| 80 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 81 | /** A long array extra containing ids of call log entries to display. */ |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 82 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 83 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 84 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 85 | /** If the activity was triggered from a notification. */ |
| 86 | public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION"; |
| 87 | |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 88 | public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment"; |
| 89 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 90 | private CallLogAsyncTaskListener mCallLogAsyncTaskListener = new CallLogAsyncTaskListener() { |
| 91 | @Override |
| 92 | public void onDeleteCall() { |
| 93 | finish(); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void onDeleteVoicemail() { |
| 98 | finish(); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public void onGetCallDetails(PhoneCallDetails[] details) { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 103 | if (details == null) { |
| 104 | // 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] | 105 | Toast.makeText(mContext, R.string.toast_call_detail_error, |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 106 | Toast.LENGTH_SHORT).show(); |
| 107 | finish(); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | // We know that all calls are from the same number and the same contact, so pick the |
| 112 | // first. |
| 113 | PhoneCallDetails firstDetails = details[0]; |
| 114 | mNumber = TextUtils.isEmpty(firstDetails.number) ? |
| 115 | null : firstDetails.number.toString(); |
| 116 | final int numberPresentation = firstDetails.numberPresentation; |
| 117 | final Uri contactUri = firstDetails.contactUri; |
| 118 | final Uri photoUri = firstDetails.photoUri; |
| 119 | final PhoneAccountHandle accountHandle = firstDetails.accountHandle; |
| 120 | |
| 121 | // Cache the details about the phone number. |
| 122 | final boolean canPlaceCallsTo = |
Andrew Lee | d3f6a6c | 2015-06-25 16:53:56 -0700 | [diff] [blame] | 123 | PhoneNumberUtil.canPlaceCallsTo(mNumber, numberPresentation); |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 124 | mIsVoicemailNumber = |
Andrew Lee | d3f6a6c | 2015-06-25 16:53:56 -0700 | [diff] [blame] | 125 | PhoneNumberUtil.isVoicemailNumber(mContext, accountHandle, mNumber); |
| 126 | final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 127 | |
| 128 | final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails); |
| 129 | |
| 130 | final CharSequence displayNumber = firstDetails.displayNumber; |
| 131 | final String displayNumberStr = mBidiFormatter.unicodeWrap( |
| 132 | displayNumber.toString(), TextDirectionHeuristics.LTR); |
| 133 | |
| 134 | if (!TextUtils.isEmpty(firstDetails.name)) { |
| 135 | mCallerName.setText(firstDetails.name); |
| 136 | mCallerNumber.setText(callLocationOrType + " " + displayNumberStr); |
| 137 | } else { |
| 138 | mCallerName.setText(displayNumberStr); |
| 139 | if (!TextUtils.isEmpty(callLocationOrType)) { |
| 140 | mCallerNumber.setText(callLocationOrType); |
| 141 | mCallerNumber.setVisibility(View.VISIBLE); |
| 142 | } else { |
| 143 | mCallerNumber.setVisibility(View.GONE); |
| 144 | } |
| 145 | } |
| 146 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 147 | mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); |
| 148 | |
| 149 | String accountLabel = PhoneAccountUtils.getAccountLabel(mContext, accountHandle); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 150 | if (!TextUtils.isEmpty(accountLabel)) { |
| 151 | mAccountLabel.setText(accountLabel); |
| 152 | mAccountLabel.setVisibility(View.VISIBLE); |
| 153 | } else { |
| 154 | mAccountLabel.setVisibility(View.GONE); |
| 155 | } |
| 156 | |
| 157 | mHasEditNumberBeforeCallOption = |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 158 | canPlaceCallsTo && !isSipNumber && !mIsVoicemailNumber; |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 159 | mHasReportMenuOption = mContactInfoHelper.canReportAsInvalid( |
| 160 | firstDetails.sourceType, firstDetails.objectId); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 161 | invalidateOptionsMenu(); |
| 162 | |
| 163 | ListView historyList = (ListView) findViewById(R.id.history); |
| 164 | historyList.setAdapter( |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 165 | new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details)); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 166 | |
| 167 | String lookupKey = contactUri == null ? null |
Tyler Gunn | 18b4a2e | 2015-08-05 08:18:37 -0700 | [diff] [blame] | 168 | : UriUtils.getLookupKeyFromUri(contactUri); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 169 | |
| 170 | final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType); |
| 171 | |
| 172 | final int contactType = |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 173 | mIsVoicemailNumber ? ContactPhotoManager.TYPE_VOICEMAIL : |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 174 | isBusiness ? ContactPhotoManager.TYPE_BUSINESS : |
| 175 | ContactPhotoManager.TYPE_DEFAULT; |
| 176 | |
| 177 | String nameForDefaultImage; |
| 178 | if (TextUtils.isEmpty(firstDetails.name)) { |
| 179 | nameForDefaultImage = firstDetails.displayNumber; |
| 180 | } else { |
| 181 | nameForDefaultImage = firstDetails.name.toString(); |
| 182 | } |
| 183 | |
| 184 | loadContactPhotos( |
| 185 | contactUri, photoUri, nameForDefaultImage, lookupKey, contactType); |
| 186 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Determines the location geocode text for a call, or the phone number type |
| 191 | * (if available). |
| 192 | * |
| 193 | * @param details The call details. |
| 194 | * @return The phone number type or location. |
| 195 | */ |
| 196 | private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) { |
| 197 | if (!TextUtils.isEmpty(details.name)) { |
| 198 | return Phone.getTypeLabel(mResources, details.numberType, |
| 199 | details.numberLabel); |
| 200 | } else { |
| 201 | return details.geocode; |
| 202 | } |
| 203 | } |
| 204 | }; |
| 205 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 206 | private Context mContext; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 207 | private CallTypeHelper mCallTypeHelper; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 208 | private QuickContactBadge mQuickContactBadge; |
| 209 | private TextView mCallerName; |
| 210 | private TextView mCallerNumber; |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 211 | private TextView mAccountLabel; |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 212 | private View mCallButton; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 213 | private ContactInfoHelper mContactInfoHelper; |
| 214 | |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 215 | protected String mNumber; |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 216 | private boolean mIsVoicemailNumber; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 217 | private String mDefaultCountryIso; |
| 218 | |
| 219 | /* package */ LayoutInflater mInflater; |
| 220 | /* package */ Resources mResources; |
| 221 | /** Helper to load contact photos. */ |
| 222 | private ContactPhotoManager mContactPhotoManager; |
Andrew Lee | c1167e9 | 2015-05-18 11:27:54 -0700 | [diff] [blame] | 223 | |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 224 | private Uri mVoicemailUri; |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 225 | private BidiFormatter mBidiFormatter = BidiFormatter.getInstance(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 226 | |
| 227 | /** Whether we should show "edit number before call" in the options menu. */ |
| 228 | private boolean mHasEditNumberBeforeCallOption; |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 229 | private boolean mHasReportMenuOption; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 230 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 231 | @Override |
| 232 | protected void onCreate(Bundle icicle) { |
| 233 | super.onCreate(icicle); |
| 234 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 235 | mContext = this; |
| 236 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 237 | setContentView(R.layout.call_detail); |
| 238 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 239 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 240 | mResources = getResources(); |
| 241 | |
| 242 | mCallTypeHelper = new CallTypeHelper(getResources()); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 243 | |
| 244 | mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
| 245 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 246 | mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo); |
| 247 | mQuickContactBadge.setOverlay(null); |
Brian Attwell | 74eb4ec | 2015-02-25 22:31:22 -0800 | [diff] [blame] | 248 | mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE); |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 249 | mCallerName = (TextView) findViewById(R.id.caller_name); |
| 250 | mCallerNumber = (TextView) findViewById(R.id.caller_number); |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 251 | mAccountLabel = (TextView) findViewById(R.id.phone_account_label); |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 252 | mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 253 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
Yorke Lee | 7151398 | 2015-02-25 20:23:53 -0800 | [diff] [blame] | 254 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 255 | mCallButton = (View) findViewById(R.id.call_back_button); |
| 256 | mCallButton.setOnClickListener(new View.OnClickListener() { |
| 257 | @Override |
| 258 | public void onClick(View view) { |
| 259 | mContext.startActivity(IntentUtil.getCallIntent(mNumber)); |
| 260 | } |
| 261 | }); |
| 262 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 263 | mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 264 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 265 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 266 | if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) { |
| 267 | closeSystemDialogs(); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public void onResume() { |
| 273 | super.onResume(); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 274 | getCallDetails(); |
| 275 | } |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 276 | |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 277 | public void getCallDetails() { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 278 | CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 281 | private 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) { |
| 326 | getMenuInflater().inflate(R.menu.call_details_options, menu); |
| 327 | return super.onCreateOptionsMenu(menu); |
| 328 | } |
| 329 | |
| 330 | @Override |
| 331 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 332 | // This action deletes all elements in the group from the call log. |
| 333 | // 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] | 334 | menu.findItem(R.id.menu_remove_from_call_log) |
| 335 | .setVisible(!hasVoicemail()) |
| 336 | .setOnMenuItemClickListener(this); |
| 337 | menu.findItem(R.id.menu_edit_number_before_call) |
| 338 | .setVisible(mHasEditNumberBeforeCallOption) |
| 339 | .setOnMenuItemClickListener(this); |
| 340 | menu.findItem(R.id.menu_trash) |
| 341 | .setVisible(hasVoicemail()) |
| 342 | .setOnMenuItemClickListener(this); |
| 343 | menu.findItem(R.id.menu_report) |
| 344 | .setVisible(mHasReportMenuOption) |
| 345 | .setOnMenuItemClickListener(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 346 | return super.onPrepareOptionsMenu(menu); |
| 347 | } |
| 348 | |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 349 | @Override |
| 350 | public boolean onMenuItemClick(MenuItem item) { |
| 351 | switch (item.getItemId()) { |
| 352 | case R.id.menu_remove_from_call_log: |
| 353 | final StringBuilder callIds = new StringBuilder(); |
| 354 | for (Uri callUri : getCallLogEntryUris()) { |
| 355 | if (callIds.length() != 0) { |
| 356 | callIds.append(","); |
| 357 | } |
| 358 | callIds.append(ContentUris.parseId(callUri)); |
| 359 | } |
| 360 | CallLogAsyncTaskUtil.deleteCalls( |
| 361 | this, callIds.toString(), mCallLogAsyncTaskListener); |
| 362 | break; |
| 363 | case R.id.menu_edit_number_before_call: |
| 364 | startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber))); |
| 365 | break; |
| 366 | case R.id.menu_trash: |
| 367 | CallLogAsyncTaskUtil.deleteVoicemail( |
| 368 | this, mVoicemailUri, mCallLogAsyncTaskListener); |
| 369 | break; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 370 | } |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 371 | return true; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 374 | private void closeSystemDialogs() { |
| 375 | sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 376 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 377 | } |