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; |
Andrew Lee | 99e8adb | 2014-10-02 12:27:37 -0700 | [diff] [blame] | 27 | import android.text.BidiFormatter; |
| 28 | import android.text.TextDirectionHeuristics; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 29 | import android.text.TextUtils; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 30 | import android.util.Log; |
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 | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 42 | import com.android.contacts.common.ClipboardUtils; |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 43 | import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; |
| 44 | import com.android.contacts.common.ContactPhotoManager; |
| 45 | import com.android.contacts.common.GeoUtil; |
| 46 | import com.android.contacts.common.interactions.TouchPointManager; |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 47 | import com.android.contacts.common.preference.ContactsPreferences; |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 48 | import com.android.contacts.common.testing.NeededForTesting; |
Tyler Gunn | 18b4a2e | 2015-08-05 08:18:37 -0700 | [diff] [blame] | 49 | import com.android.contacts.common.util.UriUtils; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 50 | import com.android.dialer.calllog.CallDetailHistoryAdapter; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 51 | import com.android.dialer.calllog.CallLogAsyncTaskUtil.CallLogAsyncTaskListener; |
| 52 | import com.android.dialer.calllog.CallLogAsyncTaskUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 53 | import com.android.dialer.calllog.CallTypeHelper; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 54 | import com.android.dialer.calllog.ContactInfoHelper; |
Nancy Chen | b2eebaf | 2014-07-21 13:41:36 -0700 | [diff] [blame] | 55 | import com.android.dialer.calllog.PhoneAccountUtils; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 56 | import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; |
Andrew Lee | aa26447 | 2015-10-16 13:11:38 -0700 | [diff] [blame] | 57 | import com.android.dialer.database.FilteredNumberAsyncQueryHandler; |
Andrew Lee | fcecace | 2015-10-28 17:36:49 -0700 | [diff] [blame] | 58 | import com.android.dialer.filterednumber.BlockNumberDialogFragment; |
Andrew Lee | aa26447 | 2015-10-16 13:11:38 -0700 | [diff] [blame] | 59 | import com.android.dialer.filterednumber.FilteredNumbersUtil; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 60 | import com.android.dialer.util.DialerUtils; |
Yorke Lee | e3a2d13 | 2015-09-14 16:52:08 -0700 | [diff] [blame] | 61 | import com.android.dialer.util.IntentUtil.CallIntentBuilder; |
Andrew Lee | d3f6a6c | 2015-06-25 16:53:56 -0700 | [diff] [blame] | 62 | import com.android.dialer.util.PhoneNumberUtil; |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 63 | import com.android.dialer.util.TelecomUtil; |
Yorke Lee | c8d6e16 | 2015-09-14 18:43:27 -0700 | [diff] [blame] | 64 | import com.android.incallui.Call.LogState; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 65 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 66 | /** |
| 67 | * Displays the details of a specific call log entry. |
| 68 | * <p> |
| 69 | * This activity can be either started with the URI of a single call log entry, or with the |
| 70 | * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries. |
| 71 | */ |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 72 | public class CallDetailActivity extends AppCompatActivity |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 73 | implements MenuItem.OnMenuItemClickListener, View.OnClickListener, |
Andrew Lee | fcecace | 2015-10-28 17:36:49 -0700 | [diff] [blame] | 74 | BlockNumberDialogFragment.Callback { |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 75 | private static final String TAG = CallDetailActivity.class.getSimpleName(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 76 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 77 | /** A long array extra containing ids of call log entries to display. */ |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 78 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 79 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 80 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 81 | /** If the activity was triggered from a notification. */ |
| 82 | public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION"; |
| 83 | |
Yorke Lee | 8cd9423 | 2014-07-23 14:05:31 -0700 | [diff] [blame] | 84 | public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment"; |
| 85 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 86 | private CallLogAsyncTaskListener mCallLogAsyncTaskListener = new CallLogAsyncTaskListener() { |
| 87 | @Override |
| 88 | public void onDeleteCall() { |
| 89 | finish(); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public void onDeleteVoicemail() { |
| 94 | finish(); |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public void onGetCallDetails(PhoneCallDetails[] details) { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 99 | if (details == null) { |
| 100 | // 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] | 101 | Toast.makeText(mContext, R.string.toast_call_detail_error, |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 102 | Toast.LENGTH_SHORT).show(); |
| 103 | finish(); |
| 104 | return; |
| 105 | } |
| 106 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 107 | // All calls are from the same number and same contact, so pick the first detail. |
| 108 | mDetails = details[0]; |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 109 | mNumber = TextUtils.isEmpty(mDetails.number) ? null : mDetails.number.toString(); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 110 | mDisplayNumber = mDetails.displayNumber; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 111 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 112 | final CharSequence callLocationOrType = getNumberTypeOrLocation(mDetails); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 113 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 114 | final CharSequence displayNumber = mDetails.displayNumber; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 115 | final String displayNumberStr = mBidiFormatter.unicodeWrap( |
| 116 | displayNumber.toString(), TextDirectionHeuristics.LTR); |
| 117 | |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 118 | mDetails.nameDisplayOrder = mContactsPreferences.getDisplayOrder(); |
| 119 | |
| 120 | if (!TextUtils.isEmpty(mDetails.getPreferredName())) { |
| 121 | mCallerName.setText(mDetails.getPreferredName()); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 122 | mCallerNumber.setText(callLocationOrType + " " + displayNumberStr); |
| 123 | } else { |
| 124 | mCallerName.setText(displayNumberStr); |
| 125 | if (!TextUtils.isEmpty(callLocationOrType)) { |
| 126 | mCallerNumber.setText(callLocationOrType); |
| 127 | mCallerNumber.setVisibility(View.VISIBLE); |
| 128 | } else { |
| 129 | mCallerNumber.setVisibility(View.GONE); |
| 130 | } |
| 131 | } |
| 132 | |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 133 | String accountLabel = |
| 134 | PhoneAccountUtils.getAccountLabel(mContext, mDetails.accountHandle); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 135 | if (!TextUtils.isEmpty(accountLabel)) { |
| 136 | mAccountLabel.setText(accountLabel); |
| 137 | mAccountLabel.setVisibility(View.VISIBLE); |
| 138 | } else { |
| 139 | mAccountLabel.setVisibility(View.GONE); |
| 140 | } |
| 141 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 142 | final boolean canPlaceCallsTo = |
| 143 | PhoneNumberUtil.canPlaceCallsTo(mNumber, mDetails.numberPresentation); |
| 144 | mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); |
| 145 | |
| 146 | final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber); |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 147 | final boolean isVoicemailNumber = |
| 148 | PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 149 | final boolean showEditNumberBeforeCallAction = |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 150 | canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 151 | mEditBeforeCallActionItem.setVisibility( |
| 152 | showEditNumberBeforeCallAction ? View.VISIBLE : View.GONE); |
| 153 | |
| 154 | final boolean showReportAction = mContactInfoHelper.canReportAsInvalid( |
| 155 | mDetails.sourceType, mDetails.objectId); |
| 156 | mReportActionItem.setVisibility( |
| 157 | showReportAction ? View.VISIBLE : View.GONE); |
| 158 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 159 | invalidateOptionsMenu(); |
| 160 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 161 | mHistoryList.setAdapter( |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 162 | new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details)); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 163 | |
Ta-wei Yen | 0bdadcc | 2015-11-03 14:37:44 -0800 | [diff] [blame] | 164 | updateFilteredNumberChanges(); |
| 165 | updateContactPhoto(); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 166 | |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 167 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Determines the location geocode text for a call, or the phone number type |
| 172 | * (if available). |
| 173 | * |
| 174 | * @param details The call details. |
| 175 | * @return The phone number type or location. |
| 176 | */ |
| 177 | private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) { |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 178 | if (!TextUtils.isEmpty(details.namePrimary)) { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 179 | return Phone.getTypeLabel(mResources, details.numberType, |
| 180 | details.numberLabel); |
| 181 | } else { |
| 182 | return details.geocode; |
| 183 | } |
| 184 | } |
| 185 | }; |
| 186 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 187 | private Context mContext; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 188 | private ContactInfoHelper mContactInfoHelper; |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 189 | private ContactsPreferences mContactsPreferences; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 190 | private CallTypeHelper mCallTypeHelper; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 191 | private ContactPhotoManager mContactPhotoManager; |
| 192 | private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler; |
| 193 | private BidiFormatter mBidiFormatter = BidiFormatter.getInstance(); |
| 194 | private LayoutInflater mInflater; |
| 195 | private Resources mResources; |
| 196 | |
| 197 | private PhoneCallDetails mDetails; |
| 198 | protected String mNumber; |
| 199 | private Uri mVoicemailUri; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 200 | private String mDisplayNumber; |
| 201 | |
| 202 | private ListView mHistoryList; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 203 | private QuickContactBadge mQuickContactBadge; |
| 204 | private TextView mCallerName; |
| 205 | private TextView mCallerNumber; |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 206 | private TextView mAccountLabel; |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 207 | private View mCallButton; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 208 | |
Andrew Lee | f549abc | 2015-10-12 12:50:55 -0700 | [diff] [blame] | 209 | private TextView mBlockNumberActionItem; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 210 | private View mEditBeforeCallActionItem; |
| 211 | private View mReportActionItem; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 212 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 213 | private Integer mBlockedNumberId; |
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; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 220 | mResources = getResources(); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 221 | mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 222 | mContactsPreferences = new ContactsPreferences(mContext); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 223 | mCallTypeHelper = new CallTypeHelper(getResources()); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 224 | mFilteredNumberAsyncQueryHandler = |
| 225 | new FilteredNumberAsyncQueryHandler(getContentResolver()); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 226 | |
| 227 | mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
| 228 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 229 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
| 230 | |
| 231 | setContentView(R.layout.call_detail); |
| 232 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 233 | |
| 234 | mHistoryList = (ListView) findViewById(R.id.history); |
| 235 | mHistoryList.addHeaderView(mInflater.inflate(R.layout.call_detail_header, null)); |
| 236 | mHistoryList.addFooterView( |
| 237 | mInflater.inflate(R.layout.call_detail_footer, null), null, false); |
Andrew Lee | afdd8b9 | 2015-10-05 17:57:40 -0700 | [diff] [blame] | 238 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 239 | mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo); |
| 240 | mQuickContactBadge.setOverlay(null); |
Brian Attwell | 74eb4ec | 2015-02-25 22:31:22 -0800 | [diff] [blame] | 241 | mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE); |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 242 | mCallerName = (TextView) findViewById(R.id.caller_name); |
| 243 | mCallerNumber = (TextView) findViewById(R.id.caller_number); |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 244 | mAccountLabel = (TextView) findViewById(R.id.phone_account_label); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 245 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
Yorke Lee | 7151398 | 2015-02-25 20:23:53 -0800 | [diff] [blame] | 246 | |
Yorke Lee | e3a2d13 | 2015-09-14 16:52:08 -0700 | [diff] [blame] | 247 | mCallButton = findViewById(R.id.call_back_button); |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 248 | mCallButton.setOnClickListener(new View.OnClickListener() { |
| 249 | @Override |
| 250 | public void onClick(View view) { |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 251 | if (TextUtils.isEmpty(mNumber)) { |
| 252 | return; |
| 253 | } |
Yorke Lee | c8d6e16 | 2015-09-14 18:43:27 -0700 | [diff] [blame] | 254 | mContext.startActivity( |
| 255 | new CallIntentBuilder(mNumber) |
| 256 | .setCallInitiationType(LogState.INITIATION_CALL_DETAILS) |
| 257 | .build()); |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 258 | } |
| 259 | }); |
| 260 | |
Andrew Lee | f549abc | 2015-10-12 12:50:55 -0700 | [diff] [blame] | 261 | mBlockNumberActionItem = (TextView) findViewById(R.id.call_detail_action_block); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 262 | mBlockNumberActionItem.setOnClickListener(this); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 263 | mEditBeforeCallActionItem = findViewById(R.id.call_detail_action_edit_before_call); |
| 264 | mEditBeforeCallActionItem.setOnClickListener(this); |
| 265 | mReportActionItem = findViewById(R.id.call_detail_action_report); |
| 266 | mReportActionItem.setOnClickListener(this); |
| 267 | |
| 268 | View copyActionItem = findViewById(R.id.call_detail_action_copy); |
| 269 | copyActionItem.setOnClickListener(this); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 270 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 271 | if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) { |
| 272 | closeSystemDialogs(); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public void onResume() { |
| 278 | super.onResume(); |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 279 | mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 280 | getCallDetails(); |
| 281 | } |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 282 | |
Yorke Lee | 0b45897 | 2015-09-18 12:55:30 -0700 | [diff] [blame] | 283 | @Override |
| 284 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 285 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 286 | TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); |
| 287 | } |
| 288 | return super.dispatchTouchEvent(ev); |
| 289 | } |
| 290 | |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 291 | public void getCallDetails() { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 292 | CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 295 | /** |
| 296 | * Returns the list of URIs to show. |
| 297 | * <p> |
| 298 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 299 | * a list of ids in the call log added as an extra on the URI. |
| 300 | * <p> |
| 301 | * If both are available, the data on the intent takes precedence. |
| 302 | */ |
| 303 | private Uri[] getCallLogEntryUris() { |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 304 | final Uri uri = getIntent().getData(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 305 | if (uri != null) { |
| 306 | // If there is a data on the intent, it takes precedence over the extra. |
| 307 | return new Uri[]{ uri }; |
| 308 | } |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 309 | final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 310 | final int numIds = ids == null ? 0 : ids.length; |
| 311 | final Uri[] uris = new Uri[numIds]; |
| 312 | for (int index = 0; index < numIds; ++index) { |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 313 | uris[index] = ContentUris.withAppendedId( |
| 314 | TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 315 | } |
| 316 | return uris; |
| 317 | } |
| 318 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 319 | @Override |
| 320 | public boolean onCreateOptionsMenu(Menu menu) { |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 321 | final MenuItem deleteMenuItem = menu.add( |
| 322 | Menu.NONE, |
| 323 | R.id.call_detail_delete_menu_item, |
| 324 | Menu.NONE, |
| 325 | R.string.call_details_delete); |
| 326 | deleteMenuItem.setIcon(R.drawable.ic_delete_24dp); |
| 327 | deleteMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); |
| 328 | deleteMenuItem.setOnMenuItemClickListener(this); |
| 329 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 330 | return super.onCreateOptionsMenu(menu); |
| 331 | } |
| 332 | |
| 333 | @Override |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 334 | public boolean onMenuItemClick(MenuItem item) { |
| 335 | switch (item.getItemId()) { |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 336 | case R.id.call_detail_delete_menu_item: |
| 337 | if (hasVoicemail()) { |
| 338 | CallLogAsyncTaskUtil.deleteVoicemail( |
| 339 | this, mVoicemailUri, mCallLogAsyncTaskListener); |
| 340 | } else { |
| 341 | final StringBuilder callIds = new StringBuilder(); |
| 342 | for (Uri callUri : getCallLogEntryUris()) { |
| 343 | if (callIds.length() != 0) { |
| 344 | callIds.append(","); |
| 345 | } |
| 346 | callIds.append(ContentUris.parseId(callUri)); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 347 | } |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 348 | CallLogAsyncTaskUtil.deleteCalls( |
| 349 | this, callIds.toString(), mCallLogAsyncTaskListener); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 350 | } |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 351 | break; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 352 | } |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 353 | return true; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 356 | @Override |
| 357 | public void onClick(View view) { |
| 358 | switch(view.getId()) { |
| 359 | case R.id.call_detail_action_block: |
Andrew Lee | fcecace | 2015-10-28 17:36:49 -0700 | [diff] [blame] | 360 | BlockNumberDialogFragment.show( |
Ta-wei Yen | a5437e6 | 2015-11-05 14:13:12 -0800 | [diff] [blame] | 361 | this, |
Andrew Lee | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame] | 362 | mBlockedNumberId, |
Andrew Lee | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame] | 363 | mNumber, |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 364 | mDetails.countryIso, |
Andrew Lee | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame] | 365 | mDisplayNumber, |
| 366 | R.id.call_detail, |
| 367 | getFragmentManager(), |
| 368 | this); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 369 | break; |
| 370 | case R.id.call_detail_action_copy: |
| 371 | ClipboardUtils.copyText(mContext, null, mNumber, true); |
| 372 | break; |
| 373 | case R.id.call_detail_action_edit_before_call: |
| 374 | Intent dialIntent = new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber)); |
| 375 | DialerUtils.startActivityWithErrorToast(mContext, dialIntent); |
| 376 | break; |
| 377 | default: |
| 378 | Log.wtf(TAG, "Unexpected onClick event from " + view); |
| 379 | break; |
| 380 | } |
| 381 | } |
| 382 | |
Andrew Lee | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame] | 383 | @Override |
| 384 | public void onChangeFilteredNumberSuccess() { |
Ta-wei Yen | 0bdadcc | 2015-11-03 14:37:44 -0800 | [diff] [blame] | 385 | updateFilteredNumberChanges(); |
Andrew Lee | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public void onChangeFilteredNumberUndo() { |
Ta-wei Yen | 0bdadcc | 2015-11-03 14:37:44 -0800 | [diff] [blame] | 390 | updateFilteredNumberChanges(); |
Andrew Lee | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Ta-wei Yen | 0bdadcc | 2015-11-03 14:37:44 -0800 | [diff] [blame] | 393 | private void updateFilteredNumberChanges() { |
Andrew Lee | 97e333c | 2015-10-29 17:40:27 -0700 | [diff] [blame] | 394 | if (mDetails == null || |
| 395 | !FilteredNumbersUtil.canBlockNumber(this, mNumber, mDetails.countryIso)) { |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 396 | return; |
| 397 | } |
| 398 | |
Andrew Lee | 4805ae0 | 2015-10-28 16:22:39 -0700 | [diff] [blame] | 399 | final boolean success = mFilteredNumberAsyncQueryHandler.isBlockedNumber( |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 400 | new OnCheckBlockedListener() { |
| 401 | @Override |
| 402 | public void onCheckComplete(Integer id) { |
| 403 | mBlockedNumberId = id; |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 404 | updateBlockActionItem(); |
| 405 | } |
Andrew Lee | 4805ae0 | 2015-10-28 16:22:39 -0700 | [diff] [blame] | 406 | }, mNumber, mDetails.countryIso); |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 407 | |
Andrew Lee | 4805ae0 | 2015-10-28 16:22:39 -0700 | [diff] [blame] | 408 | if (!success) { |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 409 | updateBlockActionItem(); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | // Loads and displays the contact photo. |
| 414 | private void updateContactPhoto() { |
| 415 | if (mDetails == null) { |
| 416 | return; |
| 417 | } |
| 418 | |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 419 | final boolean isVoicemailNumber = |
| 420 | PhoneNumberUtil.isVoicemailNumber(mContext, mDetails.accountHandle, mNumber); |
| 421 | final boolean isBusiness = mContactInfoHelper.isBusiness(mDetails.sourceType); |
| 422 | int contactType = ContactPhotoManager.TYPE_DEFAULT; |
| 423 | if (isVoicemailNumber) { |
| 424 | contactType = ContactPhotoManager.TYPE_VOICEMAIL; |
| 425 | } else if (isBusiness) { |
| 426 | contactType = ContactPhotoManager.TYPE_BUSINESS; |
| 427 | } |
| 428 | |
Brandon Maxwell | 36aeec9 | 2015-10-23 12:01:00 -0700 | [diff] [blame] | 429 | final String displayName = TextUtils.isEmpty(mDetails.namePrimary) |
| 430 | ? mDetails.displayNumber : mDetails.namePrimary.toString(); |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 431 | final String lookupKey = mDetails.contactUri == null |
| 432 | ? null : UriUtils.getLookupKeyFromUri(mDetails.contactUri); |
| 433 | |
| 434 | final DefaultImageRequest request = |
| 435 | new DefaultImageRequest(displayName, lookupKey, contactType, true /* isCircular */); |
| 436 | |
| 437 | mQuickContactBadge.assignContactUri(mDetails.contactUri); |
| 438 | mQuickContactBadge.setContentDescription( |
| 439 | mResources.getString(R.string.description_contact_details, displayName)); |
| 440 | |
| 441 | mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, mDetails.photoUri, |
| 442 | false /* darkTheme */, true /* isCircular */, request); |
| 443 | } |
| 444 | |
| 445 | private void updateBlockActionItem() { |
| 446 | if (mBlockedNumberId == null) { |
| 447 | mBlockNumberActionItem.setText(R.string.action_block_number); |
Yorke Lee | 516be4d | 2015-11-09 18:38:51 -0800 | [diff] [blame^] | 448 | mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds( |
Andrew Lee | a6732f7 | 2015-10-19 22:44:06 -0700 | [diff] [blame] | 449 | R.drawable.ic_call_detail_block, 0, 0, 0); |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 450 | } else { |
| 451 | mBlockNumberActionItem.setText(R.string.action_unblock_number); |
Yorke Lee | 516be4d | 2015-11-09 18:38:51 -0800 | [diff] [blame^] | 452 | mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds( |
Andrew Lee | a6732f7 | 2015-10-19 22:44:06 -0700 | [diff] [blame] | 453 | R.drawable.ic_call_detail_unblock, 0, 0, 0); |
Andrew Lee | b67294e | 2015-10-16 12:56:28 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | mBlockNumberActionItem.setVisibility(View.VISIBLE); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 459 | private void closeSystemDialogs() { |
| 460 | sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 461 | } |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 462 | |
| 463 | @NeededForTesting |
| 464 | public boolean hasVoicemail() { |
| 465 | return mVoicemailUri != null; |
| 466 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 467 | } |