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; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 21 | import com.android.internal.telephony.CallerInfo; |
| 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; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 40 | import android.view.KeyEvent; |
| 41 | import android.view.LayoutInflater; |
| 42 | import android.view.View; |
| 43 | import android.view.ViewGroup; |
| 44 | import android.widget.AdapterView; |
| 45 | import android.widget.BaseAdapter; |
| 46 | import android.widget.ImageView; |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 47 | import android.widget.ListView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 48 | import android.widget.TextView; |
| 49 | import android.widget.Toast; |
| 50 | |
| 51 | import java.util.ArrayList; |
| 52 | import java.util.List; |
| 53 | |
| 54 | /** |
| 55 | * Displays the details of a specific call log entry. |
| 56 | */ |
| 57 | public class CallDetailActivity extends ListActivity implements |
| 58 | AdapterView.OnItemClickListener { |
| 59 | private static final String TAG = "CallDetail"; |
| 60 | |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 61 | /** The views representing the details of a phone call. */ |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame] | 62 | private PhoneCallDetailsViews mPhoneCallDetailsViews; |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 63 | private CallTypeHelper mCallTypeHelper; |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame] | 64 | private PhoneCallDetailsHelper mPhoneCallDetailsHelper; |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 65 | private View mHomeActionView; |
| 66 | private ImageView mMainActionView; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 67 | private ImageView mContactBackgroundView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 68 | |
| 69 | private String mNumber = null; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 70 | private String mDefaultCountryIso; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 71 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 72 | /* package */ LayoutInflater mInflater; |
| 73 | /* package */ Resources mResources; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 74 | /** Helper to load contact photos. */ |
| 75 | private ContactPhotoManager mContactPhotoManager; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 76 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 77 | static final String[] CALL_LOG_PROJECTION = new String[] { |
| 78 | CallLog.Calls.DATE, |
| 79 | CallLog.Calls.DURATION, |
| 80 | CallLog.Calls.NUMBER, |
| 81 | CallLog.Calls.TYPE, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 82 | CallLog.Calls.COUNTRY_ISO, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 83 | }; |
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 int DATE_COLUMN_INDEX = 0; |
| 86 | static final int DURATION_COLUMN_INDEX = 1; |
| 87 | static final int NUMBER_COLUMN_INDEX = 2; |
| 88 | static final int CALL_TYPE_COLUMN_INDEX = 3; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 89 | static final int COUNTRY_ISO_COLUMN_INDEX = 4; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 90 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 91 | static final String[] PHONES_PROJECTION = new String[] { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 92 | PhoneLookup._ID, |
| 93 | PhoneLookup.DISPLAY_NAME, |
| 94 | PhoneLookup.TYPE, |
| 95 | PhoneLookup.LABEL, |
| 96 | PhoneLookup.NUMBER, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 97 | PhoneLookup.NORMALIZED_NUMBER, |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 98 | PhoneLookup.PHOTO_ID, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 99 | }; |
| 100 | static final int COLUMN_INDEX_ID = 0; |
| 101 | static final int COLUMN_INDEX_NAME = 1; |
| 102 | static final int COLUMN_INDEX_TYPE = 2; |
| 103 | static final int COLUMN_INDEX_LABEL = 3; |
| 104 | static final int COLUMN_INDEX_NUMBER = 4; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 105 | static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 106 | static final int COLUMN_INDEX_PHOTO_ID = 6; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 107 | |
| 108 | @Override |
| 109 | protected void onCreate(Bundle icicle) { |
| 110 | super.onCreate(icicle); |
| 111 | |
| 112 | setContentView(R.layout.call_detail); |
| 113 | |
| 114 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 115 | mResources = getResources(); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 116 | |
Flavio Lerda | 696e813 | 2011-07-05 19:00:23 +0100 | [diff] [blame] | 117 | mPhoneCallDetailsViews = PhoneCallDetailsViews.fromView(getWindow().getDecorView()); |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 118 | mCallTypeHelper = new CallTypeHelper(getResources(), |
Flavio Lerda | 7d7473a | 2011-07-06 14:21:46 +0100 | [diff] [blame] | 119 | getResources().getDrawable(R.drawable.ic_call_log_list_incoming_call), |
| 120 | getResources().getDrawable(R.drawable.ic_call_log_list_outgoing_call), |
| 121 | getResources().getDrawable(R.drawable.ic_call_log_list_missed_call), |
| 122 | getResources().getDrawable(R.drawable.ic_call_log_list_voicemail)); |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 123 | mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(this, getResources(), |
| 124 | getVoicemailNumber(), mCallTypeHelper); |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 125 | mHomeActionView = findViewById(R.id.action_bar_home); |
| 126 | mMainActionView = (ImageView) findViewById(R.id.main_action); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 127 | mContactBackgroundView = (ImageView) findViewById(R.id.contact_background); |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 128 | mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 129 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 130 | getListView().setOnItemClickListener(this); |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 131 | mHomeActionView.setOnClickListener(new View.OnClickListener() { |
| 132 | @Override |
| 133 | public void onClick(View v) { |
| 134 | // We want this to start the call log if this activity was not started from the |
| 135 | // call log itself. |
| 136 | CallDetailActivity.this.finish(); |
| 137 | } |
| 138 | }); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 139 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 140 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 141 | @Override |
| 142 | public void onResume() { |
| 143 | super.onResume(); |
| 144 | updateData(getIntent().getData()); |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 149 | switch (keyCode) { |
| 150 | case KeyEvent.KEYCODE_CALL: { |
| 151 | // Make sure phone isn't already busy before starting direct call |
| 152 | TelephonyManager tm = (TelephonyManager) |
| 153 | getSystemService(Context.TELEPHONY_SERVICE); |
| 154 | if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { |
| 155 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
| 156 | Uri.fromParts("tel", mNumber, null)); |
| 157 | startActivity(callIntent); |
| 158 | return true; |
| 159 | } |
| 160 | } |
| 161 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 162 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 163 | return super.onKeyDown(keyCode, event); |
| 164 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 165 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 166 | /** |
| 167 | * Update user interface with details of given call. |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 168 | * |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 169 | * @param callUri Uri into {@link CallLog.Calls} |
| 170 | */ |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 171 | private void updateData(final Uri callUri) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 172 | ContentResolver resolver = getContentResolver(); |
| 173 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 174 | try { |
| 175 | if (callCursor != null && callCursor.moveToFirst()) { |
| 176 | // Read call log specifics |
| 177 | mNumber = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 178 | long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 179 | long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 180 | int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 181 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 182 | if (TextUtils.isEmpty(countryIso)) { |
| 183 | countryIso = mDefaultCountryIso; |
| 184 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 185 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 186 | long photoId = 0L; |
| 187 | CharSequence nameText = ""; |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 188 | final CharSequence numberText; |
| 189 | int numberType = 0; |
| 190 | CharSequence numberLabel = ""; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 191 | if (mNumber.equals(CallerInfo.UNKNOWN_NUMBER) || |
| 192 | mNumber.equals(CallerInfo.PRIVATE_NUMBER)) { |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 193 | numberText = getString(mNumber.equals(CallerInfo.PRIVATE_NUMBER) |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 194 | ? R.string.private_num : R.string.unknown); |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 195 | mMainActionView.setVisibility(View.GONE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 196 | } else { |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 197 | // Perform a reverse-phonebook lookup to find the PERSON_ID |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 198 | Uri personUri = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 199 | Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, |
| 200 | Uri.encode(mNumber)); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 201 | Cursor phonesCursor = resolver.query( |
| 202 | phoneUri, PHONES_PROJECTION, null, null, null); |
Flavio Lerda | 175b381 | 2011-07-09 20:06:57 +0100 | [diff] [blame] | 203 | String candidateNumberText = mNumber; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 204 | try { |
| 205 | if (phonesCursor != null && phonesCursor.moveToFirst()) { |
| 206 | long personId = phonesCursor.getLong(COLUMN_INDEX_ID); |
| 207 | personUri = ContentUris.withAppendedId( |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 208 | Contacts.CONTENT_URI, personId); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 209 | nameText = phonesCursor.getString(COLUMN_INDEX_NAME); |
| 210 | photoId = phonesCursor.getLong(COLUMN_INDEX_PHOTO_ID); |
Flavio Lerda | 175b381 | 2011-07-09 20:06:57 +0100 | [diff] [blame] | 211 | candidateNumberText = PhoneNumberUtils.formatNumber( |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 212 | phonesCursor.getString(COLUMN_INDEX_NUMBER), |
| 213 | phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER), |
| 214 | countryIso); |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 215 | numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE); |
| 216 | numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL); |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 217 | } else { |
Flavio Lerda | 175b381 | 2011-07-09 20:06:57 +0100 | [diff] [blame] | 218 | candidateNumberText = |
| 219 | PhoneNumberUtils.formatNumber(mNumber, countryIso); |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 220 | } |
| 221 | } finally { |
Flavio Lerda | 175b381 | 2011-07-09 20:06:57 +0100 | [diff] [blame] | 222 | if (phonesCursor != null) phonesCursor.close(); |
| 223 | numberText = candidateNumberText; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 224 | } |
| 225 | |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 226 | // Let user view contact details if they exist, otherwise add option |
| 227 | // to create new contact from this number. |
| 228 | final Intent mainActionIntent; |
| 229 | final int mainActionIcon; |
| 230 | if (personUri != null) { |
| 231 | mainActionIntent = new Intent(Intent.ACTION_VIEW, personUri); |
| 232 | mainActionIcon = R.drawable.sym_action_view_contact; |
| 233 | } else { |
| 234 | mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 235 | mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 236 | mainActionIntent.putExtra(Insert.PHONE, mNumber); |
| 237 | mainActionIcon = R.drawable.sym_action_add; |
| 238 | } |
| 239 | |
| 240 | mMainActionView.setVisibility(View.VISIBLE); |
| 241 | mMainActionView.setImageResource(mainActionIcon); |
| 242 | mMainActionView.setOnClickListener(new View.OnClickListener() { |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 243 | @Override |
| 244 | public void onClick(View v) { |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 245 | startActivity(mainActionIntent); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 246 | } |
| 247 | }); |
| 248 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 249 | // Build list of various available actions |
| 250 | List<ViewEntry> actions = new ArrayList<ViewEntry>(); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 251 | |
Flavio Lerda | 1a1361f | 2011-07-09 23:45:32 +0100 | [diff] [blame] | 252 | final boolean isSipNumber = PhoneNumberUtils.isUriNumber(mNumber); |
| 253 | final Uri numberCallUri; |
| 254 | if (isSipNumber) { |
| 255 | numberCallUri = Uri.fromParts("sip", mNumber, null); |
| 256 | } else { |
| 257 | numberCallUri = Uri.fromParts("tel", mNumber, null); |
| 258 | } |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 259 | |
Flavio Lerda | 1a1361f | 2011-07-09 23:45:32 +0100 | [diff] [blame] | 260 | actions.add(new ViewEntry(android.R.drawable.sym_action_call, |
| 261 | getString(R.string.menu_callNumber, mNumber), |
| 262 | new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri))); |
| 263 | |
| 264 | if (!isSipNumber) { |
| 265 | Intent smsIntent = new Intent(Intent.ACTION_SENDTO, |
| 266 | Uri.fromParts("sms", mNumber, null)); |
| 267 | actions.add(new ViewEntry(R.drawable.sym_action_sms, |
| 268 | getString(R.string.menu_sendTextMessage), smsIntent)); |
| 269 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 270 | |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 271 | actions.add(new ViewEntry(android.R.drawable.ic_menu_close_clear_cancel, |
| 272 | getString(R.string.recentCalls_removeFromRecentList), |
| 273 | new View.OnClickListener() { |
| 274 | @Override |
| 275 | public void onClick(View v) { |
| 276 | long id = ContentUris.parseId(callUri); |
| 277 | getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL, |
| 278 | Calls._ID + " = ?", new String[]{Long.toString(id)}); |
| 279 | finish(); |
| 280 | } |
| 281 | })); |
| 282 | |
Flavio Lerda | 1a1361f | 2011-07-09 23:45:32 +0100 | [diff] [blame] | 283 | if (!isSipNumber) { |
| 284 | actions.add(new ViewEntry(android.R.drawable.sym_action_call, |
| 285 | getString(R.string.recentCalls_editNumberBeforeCall), |
| 286 | new Intent(Intent.ACTION_DIAL, numberCallUri))); |
| 287 | } |
| 288 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 289 | ViewAdapter adapter = new ViewAdapter(this, actions); |
| 290 | setListAdapter(adapter); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 291 | } |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 292 | PhoneCallDetails details = new PhoneCallDetails(mNumber, numberText, |
| 293 | new int[]{ callType }, duration, date, nameText, numberType, numberLabel); |
Flavio Lerda | 9de3868 | 2011-07-08 20:38:07 +0100 | [diff] [blame] | 294 | mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews, |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 295 | details, false); |
| 296 | ListView historyList = (ListView) findViewById(R.id.history); |
| 297 | historyList.setAdapter( |
| 298 | new CallDetailHistoryAdapter(this, mInflater, mCallTypeHelper, |
| 299 | new PhoneCallDetails[]{ details })); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 300 | |
| 301 | loadContactPhotos(photoId); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 302 | } else { |
| 303 | // Something went wrong reading in our primary data, so we're going to |
| 304 | // bail out and show error to users. |
| 305 | Toast.makeText(this, R.string.toast_call_detail_error, |
| 306 | Toast.LENGTH_SHORT).show(); |
| 307 | finish(); |
| 308 | } |
| 309 | } finally { |
| 310 | if (callCursor != null) { |
| 311 | callCursor.close(); |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 316 | /** Load the contact photos and places them in the corresponding views. */ |
| 317 | private void loadContactPhotos(final long photoId) { |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 318 | mContactPhotoManager.loadPhoto(mContactBackgroundView, photoId); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 319 | } |
| 320 | |
Flavio Lerda | 696e813 | 2011-07-05 19:00:23 +0100 | [diff] [blame] | 321 | private String getVoicemailNumber() { |
| 322 | TelephonyManager telephonyManager = |
| 323 | (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 324 | return telephonyManager.getVoiceMailNumber(); |
| 325 | } |
| 326 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 327 | static final class ViewEntry { |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 328 | public final int icon; |
| 329 | public final String text; |
| 330 | public final Intent intent; |
| 331 | public final View.OnClickListener action; |
| 332 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 333 | public String label = null; |
| 334 | public String number = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 335 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 336 | public ViewEntry(int icon, String text, Intent intent) { |
| 337 | this.icon = icon; |
| 338 | this.text = text; |
| 339 | this.intent = intent; |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 340 | this.action = null; |
| 341 | } |
| 342 | |
| 343 | public ViewEntry(int icon, String text, View.OnClickListener listener) { |
| 344 | this.icon = icon; |
| 345 | this.text = text; |
| 346 | this.intent = null; |
| 347 | this.action = listener; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
| 351 | static final class ViewAdapter extends BaseAdapter { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 352 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 353 | private final List<ViewEntry> mActions; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 354 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 355 | private final LayoutInflater mInflater; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 356 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 357 | public ViewAdapter(Context context, List<ViewEntry> actions) { |
| 358 | mActions = actions; |
| 359 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 360 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 361 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 362 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 363 | public int getCount() { |
| 364 | return mActions.size(); |
| 365 | } |
| 366 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 367 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 368 | public Object getItem(int position) { |
| 369 | return mActions.get(position); |
| 370 | } |
| 371 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 372 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 373 | public long getItemId(int position) { |
| 374 | return position; |
| 375 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 376 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 377 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 378 | public View getView(int position, View convertView, ViewGroup parent) { |
| 379 | // Make sure we have a valid convertView to start with |
| 380 | if (convertView == null) { |
| 381 | convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false); |
| 382 | } |
| 383 | |
| 384 | // Fill action with icon and text. |
| 385 | ViewEntry entry = mActions.get(position); |
| 386 | convertView.setTag(entry); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 387 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 388 | ImageView icon = (ImageView) convertView.findViewById(R.id.icon); |
| 389 | TextView text = (TextView) convertView.findViewById(android.R.id.text1); |
| 390 | |
| 391 | icon.setImageResource(entry.icon); |
| 392 | text.setText(entry.text); |
| 393 | |
| 394 | View line2 = convertView.findViewById(R.id.line2); |
| 395 | boolean numberEmpty = TextUtils.isEmpty(entry.number); |
| 396 | boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty; |
| 397 | if (labelEmpty && numberEmpty) { |
| 398 | line2.setVisibility(View.GONE); |
| 399 | } else { |
| 400 | line2.setVisibility(View.VISIBLE); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 401 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 402 | TextView label = (TextView) convertView.findViewById(R.id.label); |
| 403 | if (labelEmpty) { |
| 404 | label.setVisibility(View.GONE); |
| 405 | } else { |
| 406 | label.setText(entry.label); |
| 407 | label.setVisibility(View.VISIBLE); |
| 408 | } |
| 409 | |
| 410 | TextView number = (TextView) convertView.findViewById(R.id.number); |
| 411 | number.setText(entry.number); |
| 412 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 413 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 414 | return convertView; |
| 415 | } |
| 416 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 417 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 418 | @Override |
| 419 | 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] | 420 | // Handle passing action off to correct handler. |
| 421 | if (view.getTag() instanceof ViewEntry) { |
| 422 | ViewEntry entry = (ViewEntry) view.getTag(); |
| 423 | if (entry.intent != null) { |
| 424 | startActivity(entry.intent); |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 425 | } else if (entry.action != null) { |
| 426 | entry.action.onClick(view); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 427 | } |
| 428 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 429 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 430 | |
| 431 | @Override |
| 432 | public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, |
| 433 | boolean globalSearch) { |
| 434 | if (globalSearch) { |
| 435 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 436 | } else { |
| 437 | ContactsSearchManager.startSearch(this, initialQuery); |
| 438 | } |
| 439 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 440 | } |