The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [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.contacts; |
| 18 | |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 19 | import com.android.contacts.calllog.CallDetailHistoryAdapter; |
| 20 | import com.android.contacts.calllog.CallTypeHelper; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 21 | import com.android.contacts.calllog.PhoneNumberHelper; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 22 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 23 | import android.app.ListActivity; |
| 24 | import android.content.ContentResolver; |
| 25 | import android.content.ContentUris; |
| 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
| 28 | import android.content.res.Resources; |
| 29 | import android.database.Cursor; |
| 30 | import android.net.Uri; |
| 31 | import android.os.Bundle; |
| 32 | import android.provider.CallLog; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 33 | import android.provider.CallLog.Calls; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 34 | import android.provider.Contacts.Intents.Insert; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 35 | import android.provider.ContactsContract.Contacts; |
| 36 | import android.provider.ContactsContract.PhoneLookup; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 37 | import android.telephony.PhoneNumberUtils; |
| 38 | import android.telephony.TelephonyManager; |
| 39 | import android.text.TextUtils; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 40 | import android.util.Log; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 41 | import android.view.KeyEvent; |
| 42 | import android.view.LayoutInflater; |
| 43 | import android.view.View; |
| 44 | import android.view.ViewGroup; |
| 45 | import android.widget.AdapterView; |
| 46 | import android.widget.BaseAdapter; |
| 47 | import android.widget.ImageView; |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 48 | import android.widget.ListView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 49 | import android.widget.TextView; |
| 50 | import android.widget.Toast; |
| 51 | |
| 52 | import java.util.ArrayList; |
| 53 | import java.util.List; |
| 54 | |
| 55 | /** |
| 56 | * Displays the details of a specific call log entry. |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 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. |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 60 | */ |
| 61 | public class CallDetailActivity extends ListActivity implements |
| 62 | AdapterView.OnItemClickListener { |
| 63 | private static final String TAG = "CallDetail"; |
| 64 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 65 | /** A long array extra containing ids of call log entries to display. */ |
| 66 | public static final String EXTRA_CALL_LOG_IDS = "com.android.contacts.CALL_LOG_IDS"; |
| 67 | |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 68 | /** The views representing the details of a phone call. */ |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame] | 69 | private PhoneCallDetailsViews mPhoneCallDetailsViews; |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 70 | private CallTypeHelper mCallTypeHelper; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 71 | private PhoneNumberHelper mPhoneNumberHelper; |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame] | 72 | private PhoneCallDetailsHelper mPhoneCallDetailsHelper; |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 73 | private View mHomeActionView; |
| 74 | private ImageView mMainActionView; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 75 | private ImageView mContactBackgroundView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 76 | |
| 77 | private String mNumber = null; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 78 | private String mDefaultCountryIso; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 79 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 80 | /* package */ LayoutInflater mInflater; |
| 81 | /* package */ Resources mResources; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 82 | /** Helper to load contact photos. */ |
| 83 | private ContactPhotoManager mContactPhotoManager; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 84 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 85 | static final String[] CALL_LOG_PROJECTION = new String[] { |
| 86 | CallLog.Calls.DATE, |
| 87 | CallLog.Calls.DURATION, |
| 88 | CallLog.Calls.NUMBER, |
| 89 | CallLog.Calls.TYPE, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 90 | CallLog.Calls.COUNTRY_ISO, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 91 | }; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 92 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 93 | static final int DATE_COLUMN_INDEX = 0; |
| 94 | static final int DURATION_COLUMN_INDEX = 1; |
| 95 | static final int NUMBER_COLUMN_INDEX = 2; |
| 96 | static final int CALL_TYPE_COLUMN_INDEX = 3; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 97 | static final int COUNTRY_ISO_COLUMN_INDEX = 4; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 98 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 99 | static final String[] PHONES_PROJECTION = new String[] { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 100 | PhoneLookup._ID, |
| 101 | PhoneLookup.DISPLAY_NAME, |
| 102 | PhoneLookup.TYPE, |
| 103 | PhoneLookup.LABEL, |
| 104 | PhoneLookup.NUMBER, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 105 | PhoneLookup.NORMALIZED_NUMBER, |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 106 | PhoneLookup.PHOTO_ID, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 107 | }; |
| 108 | static final int COLUMN_INDEX_ID = 0; |
| 109 | static final int COLUMN_INDEX_NAME = 1; |
| 110 | static final int COLUMN_INDEX_TYPE = 2; |
| 111 | static final int COLUMN_INDEX_LABEL = 3; |
| 112 | static final int COLUMN_INDEX_NUMBER = 4; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 113 | static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 114 | static final int COLUMN_INDEX_PHOTO_ID = 6; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 115 | |
| 116 | @Override |
| 117 | protected void onCreate(Bundle icicle) { |
| 118 | super.onCreate(icicle); |
| 119 | |
| 120 | setContentView(R.layout.call_detail); |
| 121 | |
| 122 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 123 | mResources = getResources(); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 124 | |
Flavio Lerda | 696e813 | 2011-07-05 19:00:23 +0100 | [diff] [blame] | 125 | mPhoneCallDetailsViews = PhoneCallDetailsViews.fromView(getWindow().getDecorView()); |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 126 | mCallTypeHelper = new CallTypeHelper(getResources(), |
Flavio Lerda | 693d1f8 | 2011-07-13 18:20:46 +0100 | [diff] [blame] | 127 | getResources().getDrawable(R.drawable.ic_call_incoming_holo_dark), |
| 128 | getResources().getDrawable(R.drawable.ic_call_outgoing_holo_dark), |
| 129 | getResources().getDrawable(R.drawable.ic_call_missed_holo_dark), |
| 130 | getResources().getDrawable(R.drawable.ic_call_voicemail_holo_dark)); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 131 | mPhoneNumberHelper = new PhoneNumberHelper(mResources, getVoicemailNumber()); |
| 132 | mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(this, mResources, mCallTypeHelper, |
| 133 | mPhoneNumberHelper); |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 134 | mHomeActionView = findViewById(R.id.action_bar_home); |
| 135 | mMainActionView = (ImageView) findViewById(R.id.main_action); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 136 | mContactBackgroundView = (ImageView) findViewById(R.id.contact_background); |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 137 | mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 138 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 139 | getListView().setOnItemClickListener(this); |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 140 | mHomeActionView.setOnClickListener(new View.OnClickListener() { |
| 141 | @Override |
| 142 | public void onClick(View v) { |
| 143 | // We want this to start the call log if this activity was not started from the |
| 144 | // call log itself. |
| 145 | CallDetailActivity.this.finish(); |
| 146 | } |
| 147 | }); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 148 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 149 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 150 | @Override |
| 151 | public void onResume() { |
| 152 | super.onResume(); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 153 | updateData(getCallLogEntryUris()); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Returns the list of URIs to show. |
| 158 | * <p> |
| 159 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 160 | * a list of ids in the call log added as an extra on the URI. |
| 161 | * <p> |
| 162 | * If both are available, the data on the intent takes precedence. |
| 163 | */ |
| 164 | private Uri[] getCallLogEntryUris() { |
| 165 | Uri uri = getIntent().getData(); |
| 166 | if (uri != null) { |
| 167 | // If there is a data on the intent, it takes precedence over the extra. |
| 168 | return new Uri[]{ uri }; |
| 169 | } |
| 170 | long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 171 | Uri[] uris = new Uri[ids.length]; |
| 172 | for (int index = 0; index < ids.length; ++index) { |
| 173 | uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]); |
| 174 | } |
| 175 | return uris; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 180 | switch (keyCode) { |
| 181 | case KeyEvent.KEYCODE_CALL: { |
| 182 | // Make sure phone isn't already busy before starting direct call |
| 183 | TelephonyManager tm = (TelephonyManager) |
| 184 | getSystemService(Context.TELEPHONY_SERVICE); |
| 185 | if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { |
| 186 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
| 187 | Uri.fromParts("tel", mNumber, null)); |
| 188 | startActivity(callIntent); |
| 189 | return true; |
| 190 | } |
| 191 | } |
| 192 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 193 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 194 | return super.onKeyDown(keyCode, event); |
| 195 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 196 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 197 | /** |
| 198 | * Update user interface with details of given call. |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 199 | * |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 200 | * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 201 | */ |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 202 | private void updateData(final Uri... callUris) { |
| 203 | // TODO: All phone calls correspond to the same person, so we can make a single lookup. |
| 204 | final int numCalls = callUris.length; |
| 205 | final PhoneCallDetails[] details = new PhoneCallDetails[numCalls]; |
| 206 | try { |
| 207 | for (int index = 0; index < numCalls; ++index) { |
| 208 | details[index] = getPhoneCallDetailsForUri(callUris[index]); |
| 209 | } |
| 210 | } catch (IllegalArgumentException e) { |
| 211 | // Something went wrong reading in our primary data, so we're going to |
| 212 | // bail out and show error to users. |
| 213 | Log.w(TAG, "invalid URI starting call details", e); |
| 214 | Toast.makeText(this, R.string.toast_call_detail_error, |
| 215 | Toast.LENGTH_SHORT).show(); |
| 216 | finish(); |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | // We know that all calls are from the same number and the same contact, so pick the first. |
| 221 | mNumber = details[0].number.toString(); |
| 222 | final long personId = details[0].personId; |
| 223 | final long photoId = details[0].photoId; |
| 224 | |
| 225 | // Set the details header, based on the first phone call. |
| 226 | mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews, |
| 227 | details[0], false); |
| 228 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 229 | // Cache the details about the phone number. |
| 230 | final Uri numberCallUri = mPhoneNumberHelper.getCallUri(mNumber); |
| 231 | final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber); |
| 232 | final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber); |
| 233 | final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber); |
| 234 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 235 | // Let user view contact details if they exist, otherwise add option to create new contact |
| 236 | // from this number. |
| 237 | final Intent mainActionIntent; |
| 238 | final int mainActionIcon; |
| 239 | |
| 240 | if (details[0].personId != -1) { |
| 241 | Uri personUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, personId); |
| 242 | mainActionIntent = new Intent(Intent.ACTION_VIEW, personUri); |
| 243 | mainActionIcon = R.drawable.sym_action_view_contact; |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 244 | } else if (isVoicemailNumber) { |
| 245 | mainActionIntent = null; |
| 246 | mainActionIcon = 0; |
| 247 | } else if (isSipNumber) { |
| 248 | // TODO: This item is currently disabled for SIP addresses, because |
| 249 | // the Insert.PHONE extra only works correctly for PSTN numbers. |
| 250 | // |
| 251 | // To fix this for SIP addresses, we need to: |
| 252 | // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if |
| 253 | // the current number is a SIP address |
| 254 | // - update the contacts UI code to handle Insert.SIP_ADDRESS by |
| 255 | // updating the SipAddress field |
| 256 | // and then we can remove the "!isSipNumber" check above. |
| 257 | mainActionIntent = null; |
| 258 | mainActionIcon = 0; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 259 | } else { |
| 260 | mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 261 | mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 262 | mainActionIntent.putExtra(Insert.PHONE, mNumber); |
| 263 | mainActionIcon = R.drawable.sym_action_add; |
| 264 | } |
| 265 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 266 | if (mainActionIntent == null) { |
| 267 | mMainActionView.setVisibility(View.INVISIBLE); |
| 268 | } else { |
| 269 | mMainActionView.setVisibility(View.VISIBLE); |
| 270 | mMainActionView.setImageResource(mainActionIcon); |
| 271 | mMainActionView.setOnClickListener(new View.OnClickListener() { |
| 272 | @Override |
| 273 | public void onClick(View v) { |
| 274 | startActivity(mainActionIntent); |
| 275 | } |
| 276 | }); |
| 277 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 278 | |
| 279 | // Build list of various available actions. |
| 280 | final List<ViewEntry> actions = new ArrayList<ViewEntry>(); |
| 281 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 282 | // This action allows to call the number that places the call. |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 283 | if (canPlaceCallsTo) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 284 | actions.add(new ViewEntry(android.R.drawable.sym_action_call, |
| 285 | getString(R.string.menu_callNumber, mNumber), |
| 286 | new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri))); |
| 287 | } |
| 288 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 289 | // This action allows to send an SMS to the number that placed the call. |
| 290 | if (mPhoneNumberHelper.canSendSmsTo(mNumber)) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 291 | Intent smsIntent = new Intent(Intent.ACTION_SENDTO, |
| 292 | Uri.fromParts("sms", mNumber, null)); |
| 293 | actions.add(new ViewEntry(R.drawable.sym_action_sms, |
| 294 | getString(R.string.menu_sendTextMessage), smsIntent)); |
| 295 | } |
| 296 | |
| 297 | // This action deletes all elements in the group from the call log. |
| 298 | actions.add(new ViewEntry(android.R.drawable.ic_menu_close_clear_cancel, |
| 299 | getString(R.string.recentCalls_removeFromRecentList), |
| 300 | new View.OnClickListener() { |
| 301 | @Override |
| 302 | public void onClick(View v) { |
| 303 | StringBuilder callIds = new StringBuilder(); |
| 304 | for (Uri callUri : callUris) { |
| 305 | if (callIds.length() != 0) { |
| 306 | callIds.append(","); |
| 307 | } |
| 308 | callIds.append(ContentUris.parseId(callUri)); |
| 309 | } |
| 310 | |
| 311 | getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL, |
| 312 | Calls._ID + " IN (" + callIds + ")", null); |
| 313 | finish(); |
| 314 | } |
| 315 | })); |
| 316 | |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 317 | if (canPlaceCallsTo && !isSipNumber && !isVoicemailNumber) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 318 | // "Edit the number before calling" is only available for PSTN numbers. |
| 319 | actions.add(new ViewEntry(android.R.drawable.sym_action_call, |
| 320 | getString(R.string.recentCalls_editNumberBeforeCall), |
| 321 | new Intent(Intent.ACTION_DIAL, numberCallUri))); |
| 322 | } |
| 323 | |
| 324 | // Set the actions for this phone number. |
| 325 | setListAdapter(new ViewAdapter(this, actions)); |
| 326 | |
| 327 | ListView historyList = (ListView) findViewById(R.id.history); |
| 328 | historyList.setAdapter( |
| 329 | new CallDetailHistoryAdapter(this, mInflater, mCallTypeHelper, details)); |
| 330 | loadContactPhotos(photoId); |
| 331 | } |
| 332 | |
| 333 | /** Return the phone call details for a given call log URI. */ |
| 334 | private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 335 | ContentResolver resolver = getContentResolver(); |
| 336 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 337 | try { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 338 | if (callCursor == null || !callCursor.moveToFirst()) { |
| 339 | throw new IllegalArgumentException("Cannot find content: " + callUri); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 340 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 341 | |
| 342 | // Read call log specifics. |
| 343 | String number = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 344 | long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 345 | long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 346 | int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
| 347 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 348 | if (TextUtils.isEmpty(countryIso)) { |
| 349 | countryIso = mDefaultCountryIso; |
| 350 | } |
| 351 | |
| 352 | // Formatted phone number. |
| 353 | final CharSequence numberText; |
| 354 | // Read contact specifics. |
| 355 | CharSequence nameText = ""; |
| 356 | int numberType = 0; |
| 357 | CharSequence numberLabel = ""; |
| 358 | long personId = -1L; |
| 359 | long photoId = 0L; |
| 360 | // If this is not a regular number, there is no point in looking it up in the contacts. |
| 361 | if (!mPhoneNumberHelper.canPlaceCallsTo(number)) { |
| 362 | numberText = mPhoneNumberHelper.getDisplayNumber(number, null); |
| 363 | } else { |
| 364 | // Perform a reverse-phonebook lookup to find the contact details. |
| 365 | Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, |
| 366 | Uri.encode(number)); |
| 367 | Cursor phonesCursor = resolver.query(phoneUri, PHONES_PROJECTION, null, null, null); |
| 368 | String candidateNumberText = number; |
| 369 | try { |
| 370 | if (phonesCursor != null && phonesCursor.moveToFirst()) { |
| 371 | personId = phonesCursor.getLong(COLUMN_INDEX_ID); |
| 372 | nameText = phonesCursor.getString(COLUMN_INDEX_NAME); |
| 373 | photoId = phonesCursor.getLong(COLUMN_INDEX_PHOTO_ID); |
| 374 | candidateNumberText = PhoneNumberUtils.formatNumber( |
| 375 | phonesCursor.getString(COLUMN_INDEX_NUMBER), |
| 376 | phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER), |
| 377 | countryIso); |
| 378 | numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE); |
| 379 | numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL); |
| 380 | } else { |
| 381 | // We could not find this contact in the contacts, just format the phone |
| 382 | // number as best as we can. All the other fields will have their default |
| 383 | // values. |
| 384 | candidateNumberText = |
| 385 | PhoneNumberUtils.formatNumber(number, countryIso); |
| 386 | } |
| 387 | } finally { |
| 388 | if (phonesCursor != null) phonesCursor.close(); |
| 389 | numberText = candidateNumberText; |
| 390 | } |
| 391 | } |
| 392 | return new PhoneCallDetails(number, numberText, new int[]{ callType }, date, duration, |
| 393 | nameText, numberType, numberLabel, personId, photoId); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 394 | } finally { |
| 395 | if (callCursor != null) { |
| 396 | callCursor.close(); |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 401 | /** Load the contact photos and places them in the corresponding views. */ |
| 402 | private void loadContactPhotos(final long photoId) { |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 403 | mContactPhotoManager.loadPhoto(mContactBackgroundView, photoId); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 404 | } |
| 405 | |
Flavio Lerda | 696e813 | 2011-07-05 19:00:23 +0100 | [diff] [blame] | 406 | private String getVoicemailNumber() { |
| 407 | TelephonyManager telephonyManager = |
| 408 | (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 409 | return telephonyManager.getVoiceMailNumber(); |
| 410 | } |
| 411 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 412 | static final class ViewEntry { |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 413 | public final int icon; |
| 414 | public final String text; |
| 415 | public final Intent intent; |
| 416 | public final View.OnClickListener action; |
| 417 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 418 | public String label = null; |
| 419 | public String number = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 420 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 421 | public ViewEntry(int icon, String text, Intent intent) { |
| 422 | this.icon = icon; |
| 423 | this.text = text; |
| 424 | this.intent = intent; |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 425 | this.action = null; |
| 426 | } |
| 427 | |
| 428 | public ViewEntry(int icon, String text, View.OnClickListener listener) { |
| 429 | this.icon = icon; |
| 430 | this.text = text; |
| 431 | this.intent = null; |
| 432 | this.action = listener; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
| 436 | static final class ViewAdapter extends BaseAdapter { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 437 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 438 | private final List<ViewEntry> mActions; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 439 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 440 | private final LayoutInflater mInflater; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 441 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 442 | public ViewAdapter(Context context, List<ViewEntry> actions) { |
| 443 | mActions = actions; |
| 444 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 445 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 446 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 447 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 448 | public int getCount() { |
| 449 | return mActions.size(); |
| 450 | } |
| 451 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 452 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 453 | public Object getItem(int position) { |
| 454 | return mActions.get(position); |
| 455 | } |
| 456 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 457 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 458 | public long getItemId(int position) { |
| 459 | return position; |
| 460 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 461 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 462 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 463 | public View getView(int position, View convertView, ViewGroup parent) { |
| 464 | // Make sure we have a valid convertView to start with |
| 465 | if (convertView == null) { |
| 466 | convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false); |
| 467 | } |
| 468 | |
| 469 | // Fill action with icon and text. |
| 470 | ViewEntry entry = mActions.get(position); |
| 471 | convertView.setTag(entry); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 472 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 473 | ImageView icon = (ImageView) convertView.findViewById(R.id.icon); |
| 474 | TextView text = (TextView) convertView.findViewById(android.R.id.text1); |
| 475 | |
| 476 | icon.setImageResource(entry.icon); |
| 477 | text.setText(entry.text); |
| 478 | |
| 479 | View line2 = convertView.findViewById(R.id.line2); |
| 480 | boolean numberEmpty = TextUtils.isEmpty(entry.number); |
| 481 | boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty; |
| 482 | if (labelEmpty && numberEmpty) { |
| 483 | line2.setVisibility(View.GONE); |
| 484 | } else { |
| 485 | line2.setVisibility(View.VISIBLE); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 486 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 487 | TextView label = (TextView) convertView.findViewById(R.id.label); |
| 488 | if (labelEmpty) { |
| 489 | label.setVisibility(View.GONE); |
| 490 | } else { |
| 491 | label.setText(entry.label); |
| 492 | label.setVisibility(View.VISIBLE); |
| 493 | } |
| 494 | |
| 495 | TextView number = (TextView) convertView.findViewById(R.id.number); |
| 496 | number.setText(entry.number); |
| 497 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 498 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 499 | return convertView; |
| 500 | } |
| 501 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 502 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 503 | @Override |
| 504 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 505 | // Handle passing action off to correct handler. |
| 506 | if (view.getTag() instanceof ViewEntry) { |
| 507 | ViewEntry entry = (ViewEntry) view.getTag(); |
| 508 | if (entry.intent != null) { |
| 509 | startActivity(entry.intent); |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 510 | } else if (entry.action != null) { |
| 511 | entry.action.onClick(view); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 512 | } |
| 513 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 514 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 515 | |
| 516 | @Override |
| 517 | public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, |
| 518 | boolean globalSearch) { |
| 519 | if (globalSearch) { |
| 520 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 521 | } else { |
| 522 | ContactsSearchManager.startSearch(this, initialQuery); |
| 523 | } |
| 524 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 525 | } |