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; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 31 | import android.util.Log; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 32 | import android.view.LayoutInflater; |
| 33 | import android.view.Menu; |
| 34 | import android.view.MenuItem; |
Yorke Lee | 0b45897 | 2015-09-18 12:55:30 -0700 | [diff] [blame] | 35 | import android.view.MotionEvent; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 36 | import android.view.View; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 37 | import android.widget.ListView; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 38 | import android.widget.QuickContactBadge; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 39 | import android.widget.TextView; |
| 40 | import android.widget.Toast; |
| 41 | |
Brian Attwell | 8204324 | 2015-02-03 14:13:58 -0800 | [diff] [blame] | 42 | import com.android.contacts.common.CallUtil; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 43 | import com.android.contacts.common.ClipboardUtils; |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 44 | import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; |
| 45 | import com.android.contacts.common.ContactPhotoManager; |
| 46 | import com.android.contacts.common.GeoUtil; |
| 47 | import com.android.contacts.common.interactions.TouchPointManager; |
| 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; |
Yorke Lee | f44e517 | 2015-10-01 17:16:43 -0700 | [diff] [blame] | 52 | import com.android.dialer.onboard.OnboardingActivity; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 53 | import com.android.dialer.calllog.CallLogAsyncTaskUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 54 | import com.android.dialer.calllog.CallTypeHelper; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 55 | import com.android.dialer.calllog.ContactInfoHelper; |
Nancy Chen | b2eebaf | 2014-07-21 13:41:36 -0700 | [diff] [blame] | 56 | import com.android.dialer.calllog.PhoneAccountUtils; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 57 | import com.android.dialer.database.FilteredNumberAsyncQueryHandler; |
| 58 | import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; |
| 59 | import com.android.dialer.filterednumber.FilterNumberDialogFragment; |
| 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 | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame^] | 74 | FilterNumberDialogFragment.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]; |
| 109 | mNumber = TextUtils.isEmpty(mDetails.number) ? |
| 110 | null : mDetails.number.toString(); |
| 111 | mDisplayNumber = mDetails.displayNumber; |
| 112 | final int numberPresentation = mDetails.numberPresentation; |
| 113 | final Uri contactUri = mDetails.contactUri; |
| 114 | final Uri photoUri = mDetails.photoUri; |
| 115 | final PhoneAccountHandle accountHandle = mDetails.accountHandle; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 116 | |
| 117 | // Cache the details about the phone number. |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 118 | mIsVoicemailNumber = |
Andrew Lee | d3f6a6c | 2015-06-25 16:53:56 -0700 | [diff] [blame] | 119 | PhoneNumberUtil.isVoicemailNumber(mContext, accountHandle, mNumber); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 120 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 121 | final CharSequence callLocationOrType = getNumberTypeOrLocation(mDetails); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 122 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 123 | final CharSequence displayNumber = mDetails.displayNumber; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 124 | final String displayNumberStr = mBidiFormatter.unicodeWrap( |
| 125 | displayNumber.toString(), TextDirectionHeuristics.LTR); |
| 126 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 127 | if (!TextUtils.isEmpty(mDetails.name)) { |
| 128 | mCallerName.setText(mDetails.name); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 129 | mCallerNumber.setText(callLocationOrType + " " + displayNumberStr); |
| 130 | } else { |
| 131 | mCallerName.setText(displayNumberStr); |
| 132 | if (!TextUtils.isEmpty(callLocationOrType)) { |
| 133 | mCallerNumber.setText(callLocationOrType); |
| 134 | mCallerNumber.setVisibility(View.VISIBLE); |
| 135 | } else { |
| 136 | mCallerNumber.setVisibility(View.GONE); |
| 137 | } |
| 138 | } |
| 139 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 140 | String accountLabel = PhoneAccountUtils.getAccountLabel(mContext, accountHandle); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 141 | if (!TextUtils.isEmpty(accountLabel)) { |
| 142 | mAccountLabel.setText(accountLabel); |
| 143 | mAccountLabel.setVisibility(View.VISIBLE); |
| 144 | } else { |
| 145 | mAccountLabel.setVisibility(View.GONE); |
| 146 | } |
| 147 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 148 | final boolean canPlaceCallsTo = |
| 149 | PhoneNumberUtil.canPlaceCallsTo(mNumber, mDetails.numberPresentation); |
| 150 | mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); |
| 151 | |
| 152 | final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber); |
| 153 | final boolean showEditNumberBeforeCallAction = |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 154 | canPlaceCallsTo && !isSipNumber && !mIsVoicemailNumber; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 155 | mEditBeforeCallActionItem.setVisibility( |
| 156 | showEditNumberBeforeCallAction ? View.VISIBLE : View.GONE); |
| 157 | |
| 158 | final boolean showReportAction = mContactInfoHelper.canReportAsInvalid( |
| 159 | mDetails.sourceType, mDetails.objectId); |
| 160 | mReportActionItem.setVisibility( |
| 161 | showReportAction ? View.VISIBLE : View.GONE); |
| 162 | |
| 163 | updateBlockActionItem(); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 164 | invalidateOptionsMenu(); |
| 165 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 166 | mHistoryList.setAdapter( |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 167 | new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details)); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 168 | |
| 169 | String lookupKey = contactUri == null ? null |
Tyler Gunn | 18b4a2e | 2015-08-05 08:18:37 -0700 | [diff] [blame] | 170 | : UriUtils.getLookupKeyFromUri(contactUri); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 171 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 172 | final boolean isBusiness = mContactInfoHelper.isBusiness(mDetails.sourceType); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 173 | |
| 174 | final int contactType = |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 175 | mIsVoicemailNumber ? ContactPhotoManager.TYPE_VOICEMAIL : |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 176 | isBusiness ? ContactPhotoManager.TYPE_BUSINESS : |
| 177 | ContactPhotoManager.TYPE_DEFAULT; |
| 178 | |
| 179 | String nameForDefaultImage; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 180 | if (TextUtils.isEmpty(mDetails.name)) { |
| 181 | nameForDefaultImage = mDetails.displayNumber; |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 182 | } else { |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 183 | nameForDefaultImage = mDetails.name.toString(); |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | loadContactPhotos( |
| 187 | contactUri, photoUri, nameForDefaultImage, lookupKey, contactType); |
| 188 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Determines the location geocode text for a call, or the phone number type |
| 193 | * (if available). |
| 194 | * |
| 195 | * @param details The call details. |
| 196 | * @return The phone number type or location. |
| 197 | */ |
| 198 | private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) { |
| 199 | if (!TextUtils.isEmpty(details.name)) { |
| 200 | return Phone.getTypeLabel(mResources, details.numberType, |
| 201 | details.numberLabel); |
| 202 | } else { |
| 203 | return details.geocode; |
| 204 | } |
| 205 | } |
| 206 | }; |
| 207 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 208 | private Context mContext; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 209 | private ContactInfoHelper mContactInfoHelper; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 210 | private CallTypeHelper mCallTypeHelper; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 211 | private ContactPhotoManager mContactPhotoManager; |
| 212 | private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler; |
| 213 | private BidiFormatter mBidiFormatter = BidiFormatter.getInstance(); |
| 214 | private LayoutInflater mInflater; |
| 215 | private Resources mResources; |
| 216 | |
| 217 | private PhoneCallDetails mDetails; |
| 218 | protected String mNumber; |
| 219 | private Uri mVoicemailUri; |
| 220 | private boolean mIsVoicemailNumber; |
| 221 | private String mDefaultCountryIso; |
| 222 | private String mDisplayNumber; |
| 223 | |
| 224 | private ListView mHistoryList; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 225 | private QuickContactBadge mQuickContactBadge; |
| 226 | private TextView mCallerName; |
| 227 | private TextView mCallerNumber; |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 228 | private TextView mAccountLabel; |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 229 | private View mCallButton; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 230 | |
Andrew Lee | f549abc | 2015-10-12 12:50:55 -0700 | [diff] [blame] | 231 | private TextView mBlockNumberActionItem; |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 232 | private View mEditBeforeCallActionItem; |
| 233 | private View mReportActionItem; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 234 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 235 | private Integer mBlockedNumberId; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 236 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 237 | @Override |
| 238 | protected void onCreate(Bundle icicle) { |
| 239 | super.onCreate(icicle); |
| 240 | |
Yorke Lee | f44e517 | 2015-10-01 17:16:43 -0700 | [diff] [blame] | 241 | if (OnboardingActivity.shouldStartOnboardingActivity(this)) { |
| 242 | OnboardingActivity.startOnboardingActivity(this); |
| 243 | finish(); |
| 244 | } |
| 245 | |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 246 | mContext = this; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 247 | mResources = getResources(); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 248 | mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 249 | mCallTypeHelper = new CallTypeHelper(getResources()); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 250 | mFilteredNumberAsyncQueryHandler = |
| 251 | new FilteredNumberAsyncQueryHandler(getContentResolver()); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 252 | |
| 253 | mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
| 254 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 255 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
| 256 | |
| 257 | setContentView(R.layout.call_detail); |
| 258 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 259 | |
| 260 | mHistoryList = (ListView) findViewById(R.id.history); |
| 261 | mHistoryList.addHeaderView(mInflater.inflate(R.layout.call_detail_header, null)); |
| 262 | mHistoryList.addFooterView( |
| 263 | mInflater.inflate(R.layout.call_detail_footer, null), null, false); |
Andrew Lee | afdd8b9 | 2015-10-05 17:57:40 -0700 | [diff] [blame] | 264 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 265 | mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo); |
| 266 | mQuickContactBadge.setOverlay(null); |
Brian Attwell | 74eb4ec | 2015-02-25 22:31:22 -0800 | [diff] [blame] | 267 | mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE); |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 268 | mCallerName = (TextView) findViewById(R.id.caller_name); |
| 269 | mCallerNumber = (TextView) findViewById(R.id.caller_number); |
Nancy Chen | 1970263 | 2014-07-25 13:23:16 -0700 | [diff] [blame] | 270 | mAccountLabel = (TextView) findViewById(R.id.phone_account_label); |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 271 | mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 272 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
Yorke Lee | 7151398 | 2015-02-25 20:23:53 -0800 | [diff] [blame] | 273 | |
Yorke Lee | e3a2d13 | 2015-09-14 16:52:08 -0700 | [diff] [blame] | 274 | mCallButton = findViewById(R.id.call_back_button); |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 275 | mCallButton.setOnClickListener(new View.OnClickListener() { |
| 276 | @Override |
| 277 | public void onClick(View view) { |
Yorke Lee | c8d6e16 | 2015-09-14 18:43:27 -0700 | [diff] [blame] | 278 | mContext.startActivity( |
| 279 | new CallIntentBuilder(mNumber) |
| 280 | .setCallInitiationType(LogState.INITIATION_CALL_DETAILS) |
| 281 | .build()); |
Andrew Lee | e177fe6 | 2015-06-05 13:01:09 -0700 | [diff] [blame] | 282 | } |
| 283 | }); |
| 284 | |
Andrew Lee | f549abc | 2015-10-12 12:50:55 -0700 | [diff] [blame] | 285 | mBlockNumberActionItem = (TextView) findViewById(R.id.call_detail_action_block); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 286 | mBlockNumberActionItem.setOnClickListener(this); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 287 | mEditBeforeCallActionItem = findViewById(R.id.call_detail_action_edit_before_call); |
| 288 | mEditBeforeCallActionItem.setOnClickListener(this); |
| 289 | mReportActionItem = findViewById(R.id.call_detail_action_report); |
| 290 | mReportActionItem.setOnClickListener(this); |
| 291 | |
| 292 | View copyActionItem = findViewById(R.id.call_detail_action_copy); |
| 293 | copyActionItem.setOnClickListener(this); |
Yorke Lee | 257b6f2 | 2014-07-31 14:16:44 -0700 | [diff] [blame] | 294 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 295 | if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) { |
| 296 | closeSystemDialogs(); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | @Override |
| 301 | public void onResume() { |
| 302 | super.onResume(); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 303 | getCallDetails(); |
| 304 | } |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 305 | |
Yorke Lee | 0b45897 | 2015-09-18 12:55:30 -0700 | [diff] [blame] | 306 | @Override |
| 307 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 308 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 309 | TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); |
| 310 | } |
| 311 | return super.dispatchTouchEvent(ev); |
| 312 | } |
| 313 | |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 314 | public void getCallDetails() { |
Andrew Lee | 7c461dc | 2015-05-15 10:18:45 -0700 | [diff] [blame] | 315 | CallLogAsyncTaskUtil.getCallDetails(this, getCallLogEntryUris(), mCallLogAsyncTaskListener); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 318 | /** |
| 319 | * Returns the list of URIs to show. |
| 320 | * <p> |
| 321 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 322 | * a list of ids in the call log added as an extra on the URI. |
| 323 | * <p> |
| 324 | * If both are available, the data on the intent takes precedence. |
| 325 | */ |
| 326 | private Uri[] getCallLogEntryUris() { |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 327 | final Uri uri = getIntent().getData(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 328 | if (uri != null) { |
| 329 | // If there is a data on the intent, it takes precedence over the extra. |
| 330 | return new Uri[]{ uri }; |
| 331 | } |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 332 | final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 333 | final int numIds = ids == null ? 0 : ids.length; |
| 334 | final Uri[] uris = new Uri[numIds]; |
| 335 | for (int index = 0; index < numIds; ++index) { |
Yorke Lee | 4aece95 | 2015-05-02 22:22:54 -0700 | [diff] [blame] | 336 | uris[index] = ContentUris.withAppendedId( |
| 337 | TelecomUtil.getCallLogUri(CallDetailActivity.this), ids[index]); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 338 | } |
| 339 | return uris; |
| 340 | } |
| 341 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 342 | /** Load the contact photos and places them in the corresponding views. */ |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 343 | private void loadContactPhotos(Uri contactUri, Uri photoUri, String displayName, |
| 344 | String lookupKey, int contactType) { |
| 345 | |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 346 | final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 347 | contactType, true /* isCircular */); |
| 348 | |
| 349 | mQuickContactBadge.assignContactUri(contactUri); |
| 350 | mQuickContactBadge.setContentDescription( |
| 351 | mResources.getString(R.string.description_contact_details, displayName)); |
| 352 | |
| 353 | mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, photoUri, |
| 354 | false /* darkTheme */, true /* isCircular */, request); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 357 | @Override |
| 358 | public boolean onCreateOptionsMenu(Menu menu) { |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 359 | final MenuItem deleteMenuItem = menu.add( |
| 360 | Menu.NONE, |
| 361 | R.id.call_detail_delete_menu_item, |
| 362 | Menu.NONE, |
| 363 | R.string.call_details_delete); |
| 364 | deleteMenuItem.setIcon(R.drawable.ic_delete_24dp); |
| 365 | deleteMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); |
| 366 | deleteMenuItem.setOnMenuItemClickListener(this); |
| 367 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 368 | return super.onCreateOptionsMenu(menu); |
| 369 | } |
| 370 | |
| 371 | @Override |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 372 | public boolean onMenuItemClick(MenuItem item) { |
| 373 | switch (item.getItemId()) { |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 374 | case R.id.call_detail_delete_menu_item: |
| 375 | if (hasVoicemail()) { |
| 376 | CallLogAsyncTaskUtil.deleteVoicemail( |
| 377 | this, mVoicemailUri, mCallLogAsyncTaskListener); |
| 378 | } else { |
| 379 | final StringBuilder callIds = new StringBuilder(); |
| 380 | for (Uri callUri : getCallLogEntryUris()) { |
| 381 | if (callIds.length() != 0) { |
| 382 | callIds.append(","); |
| 383 | } |
| 384 | callIds.append(ContentUris.parseId(callUri)); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 385 | } |
Andrew Lee | 7b127d4 | 2015-09-30 18:24:48 -0700 | [diff] [blame] | 386 | CallLogAsyncTaskUtil.deleteCalls( |
| 387 | this, callIds.toString(), mCallLogAsyncTaskListener); |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 388 | } |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 389 | break; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 390 | } |
Andrew Lee | 2f05af3 | 2015-06-09 15:59:47 -0700 | [diff] [blame] | 391 | return true; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 394 | @Override |
| 395 | public void onClick(View view) { |
| 396 | switch(view.getId()) { |
| 397 | case R.id.call_detail_action_block: |
Andrew Lee | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame^] | 398 | FilterNumberDialogFragment.show( |
| 399 | mBlockedNumberId, |
| 400 | null /* normalizedNumber */, |
| 401 | mNumber, |
| 402 | null /* countryIso */, |
| 403 | mDisplayNumber, |
| 404 | R.id.call_detail, |
| 405 | getFragmentManager(), |
| 406 | this); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 407 | break; |
| 408 | case R.id.call_detail_action_copy: |
| 409 | ClipboardUtils.copyText(mContext, null, mNumber, true); |
| 410 | break; |
| 411 | case R.id.call_detail_action_edit_before_call: |
| 412 | Intent dialIntent = new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber)); |
| 413 | DialerUtils.startActivityWithErrorToast(mContext, dialIntent); |
| 414 | break; |
| 415 | default: |
| 416 | Log.wtf(TAG, "Unexpected onClick event from " + view); |
| 417 | break; |
| 418 | } |
| 419 | } |
| 420 | |
Andrew Lee | 8d0847c | 2015-10-13 13:07:58 -0700 | [diff] [blame^] | 421 | @Override |
| 422 | public void onChangeFilteredNumberSuccess() { |
| 423 | updateBlockActionItem(); |
| 424 | } |
| 425 | |
| 426 | @Override |
| 427 | public void onChangeFilteredNumberUndo() { |
| 428 | updateBlockActionItem(); |
| 429 | } |
| 430 | |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 431 | private void updateBlockActionItem() { |
| 432 | if (mDetails == null) { |
| 433 | return; |
| 434 | } |
| 435 | |
| 436 | mFilteredNumberAsyncQueryHandler.startBlockedQuery(new OnCheckBlockedListener() { |
| 437 | @Override |
| 438 | public void onCheckComplete(Integer id) { |
| 439 | mBlockedNumberId = id; |
| 440 | if (mBlockedNumberId == null) { |
Andrew Lee | f549abc | 2015-10-12 12:50:55 -0700 | [diff] [blame] | 441 | mBlockNumberActionItem.setText(R.string.action_block_number); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 442 | } else { |
Andrew Lee | f549abc | 2015-10-12 12:50:55 -0700 | [diff] [blame] | 443 | mBlockNumberActionItem.setText(R.string.action_unblock_number); |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | mBlockNumberActionItem.setVisibility(View.VISIBLE); |
| 447 | } |
| 448 | }, null, mNumber, mDetails.countryIso); |
| 449 | } |
| 450 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 451 | private void closeSystemDialogs() { |
| 452 | sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 453 | } |
Andrew Lee | bf9cca2 | 2015-10-05 13:43:54 -0700 | [diff] [blame] | 454 | |
| 455 | @NeededForTesting |
| 456 | public boolean hasVoicemail() { |
| 457 | return mVoicemailUri != null; |
| 458 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 459 | } |