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