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 | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 19 | import com.android.contacts.format.FormatUtils; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 20 | import com.android.internal.telephony.CallerInfo; |
| 21 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 22 | import android.app.ListActivity; |
| 23 | import android.content.ContentResolver; |
| 24 | import android.content.ContentUris; |
| 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.content.res.Resources; |
| 28 | import android.database.Cursor; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 29 | import android.graphics.Typeface; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 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; |
| 35 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 36 | import android.provider.ContactsContract.Contacts; |
| 37 | import android.provider.ContactsContract.PhoneLookup; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 38 | import android.telephony.PhoneNumberUtils; |
| 39 | import android.telephony.TelephonyManager; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 40 | import android.text.Spanned; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 41 | import android.text.TextUtils; |
| 42 | import android.text.format.DateUtils; |
| 43 | import android.view.KeyEvent; |
| 44 | import android.view.LayoutInflater; |
| 45 | import android.view.View; |
| 46 | import android.view.ViewGroup; |
| 47 | import android.widget.AdapterView; |
| 48 | import android.widget.BaseAdapter; |
| 49 | import android.widget.ImageView; |
| 50 | import android.widget.TextView; |
| 51 | import android.widget.Toast; |
| 52 | |
| 53 | import java.util.ArrayList; |
| 54 | import java.util.List; |
| 55 | |
| 56 | /** |
| 57 | * Displays the details of a specific call log entry. |
| 58 | */ |
| 59 | public class CallDetailActivity extends ListActivity implements |
| 60 | AdapterView.OnItemClickListener { |
| 61 | private static final String TAG = "CallDetail"; |
| 62 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 63 | private TextView mNameView; |
| 64 | private TextView mCallTypeView; |
| 65 | private TextView mNumberView; |
| 66 | private TextView mCallTimeView; |
| 67 | private TextView mCallDurationView; |
| 68 | private View mCallActionView; |
| 69 | private ImageView mContactPhotoView; |
| 70 | private ImageView mContactBackgroundView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 71 | |
| 72 | private String mNumber = null; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 73 | private String mDefaultCountryIso; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 74 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 75 | /* package */ LayoutInflater mInflater; |
| 76 | /* package */ Resources mResources; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 77 | /** Helper to load contact photos. */ |
| 78 | private ContactPhotoManager mContactPhotoManager; |
| 79 | /** Attached to the call action button in the UI. */ |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 80 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 81 | static final String[] CALL_LOG_PROJECTION = new String[] { |
| 82 | CallLog.Calls.DATE, |
| 83 | CallLog.Calls.DURATION, |
| 84 | CallLog.Calls.NUMBER, |
| 85 | CallLog.Calls.TYPE, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 86 | CallLog.Calls.COUNTRY_ISO, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 87 | }; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 88 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 89 | static final int DATE_COLUMN_INDEX = 0; |
| 90 | static final int DURATION_COLUMN_INDEX = 1; |
| 91 | static final int NUMBER_COLUMN_INDEX = 2; |
| 92 | static final int CALL_TYPE_COLUMN_INDEX = 3; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 93 | static final int COUNTRY_ISO_COLUMN_INDEX = 4; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 94 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 95 | static final String[] PHONES_PROJECTION = new String[] { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 96 | PhoneLookup._ID, |
| 97 | PhoneLookup.DISPLAY_NAME, |
| 98 | PhoneLookup.TYPE, |
| 99 | PhoneLookup.LABEL, |
| 100 | PhoneLookup.NUMBER, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 101 | PhoneLookup.NORMALIZED_NUMBER, |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 102 | PhoneLookup.PHOTO_ID, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 103 | }; |
| 104 | static final int COLUMN_INDEX_ID = 0; |
| 105 | static final int COLUMN_INDEX_NAME = 1; |
| 106 | static final int COLUMN_INDEX_TYPE = 2; |
| 107 | static final int COLUMN_INDEX_LABEL = 3; |
| 108 | static final int COLUMN_INDEX_NUMBER = 4; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 109 | static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 110 | static final int COLUMN_INDEX_PHOTO_ID = 6; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 111 | |
| 112 | @Override |
| 113 | protected void onCreate(Bundle icicle) { |
| 114 | super.onCreate(icicle); |
| 115 | |
| 116 | setContentView(R.layout.call_detail); |
| 117 | |
| 118 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 119 | mResources = getResources(); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 120 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 121 | mNameView = (TextView) findViewById(R.id.name); |
| 122 | mCallTypeView = (TextView) findViewById(R.id.call_type); |
| 123 | mNumberView = (TextView) findViewById(R.id.number); |
| 124 | mCallActionView = findViewById(R.id.call); |
| 125 | mContactPhotoView = (ImageView) findViewById(R.id.contact_photo); |
| 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); |
| 132 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 133 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 134 | @Override |
| 135 | public void onResume() { |
| 136 | super.onResume(); |
| 137 | updateData(getIntent().getData()); |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 142 | switch (keyCode) { |
| 143 | case KeyEvent.KEYCODE_CALL: { |
| 144 | // Make sure phone isn't already busy before starting direct call |
| 145 | TelephonyManager tm = (TelephonyManager) |
| 146 | getSystemService(Context.TELEPHONY_SERVICE); |
| 147 | if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { |
| 148 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
| 149 | Uri.fromParts("tel", mNumber, null)); |
| 150 | startActivity(callIntent); |
| 151 | return true; |
| 152 | } |
| 153 | } |
| 154 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 155 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 156 | return super.onKeyDown(keyCode, event); |
| 157 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 158 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 159 | /** |
| 160 | * Update user interface with details of given call. |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 161 | * |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 162 | * @param callUri Uri into {@link CallLog.Calls} |
| 163 | */ |
| 164 | private void updateData(Uri callUri) { |
| 165 | ContentResolver resolver = getContentResolver(); |
| 166 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 167 | try { |
| 168 | if (callCursor != null && callCursor.moveToFirst()) { |
| 169 | // Read call log specifics |
| 170 | mNumber = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 171 | long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 172 | long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 173 | int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 174 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 175 | if (TextUtils.isEmpty(countryIso)) { |
| 176 | countryIso = mDefaultCountryIso; |
| 177 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 178 | // Pull out string in format [relative], [date] |
| 179 | CharSequence dateClause = DateUtils.formatDateRange(this, date, date, |
| 180 | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | |
| 181 | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 182 | mCallTimeView.setText(dateClause); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 183 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 184 | // Set the duration |
| 185 | if (callType == Calls.MISSED_TYPE) { |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 186 | mCallDurationView.setVisibility(View.GONE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 187 | } else { |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 188 | mCallDurationView.setVisibility(View.VISIBLE); |
| 189 | mCallDurationView.setText(formatDuration(duration)); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 190 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 191 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 192 | CharSequence shortDateText = |
| 193 | DateUtils.getRelativeTimeSpanString(date, |
| 194 | System.currentTimeMillis(), |
| 195 | DateUtils.MINUTE_IN_MILLIS, |
| 196 | DateUtils.FORMAT_ABBREV_RELATIVE); |
| 197 | |
| 198 | CharSequence callTypeText = ""; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 199 | switch (callType) { |
| 200 | case Calls.INCOMING_TYPE: |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 201 | callTypeText = getString(R.string.type_incoming); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 202 | break; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 203 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 204 | case Calls.OUTGOING_TYPE: |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 205 | callTypeText = getString(R.string.type_outgoing); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 206 | break; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 207 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 208 | case Calls.MISSED_TYPE: |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 209 | callTypeText = getString(R.string.type_missed); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 210 | break; |
| 211 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 212 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 213 | mCallTypeView.setText( |
| 214 | getString(R.string.call_type_and_date, |
| 215 | FormatUtils.applyStyleToSpan(Typeface.BOLD, |
| 216 | callTypeText, 0, callTypeText.length(), |
| 217 | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE), |
| 218 | shortDateText)); |
| 219 | |
| 220 | long photoId = 0L; |
| 221 | CharSequence nameText = ""; |
| 222 | CharSequence numberText = ""; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 223 | if (mNumber.equals(CallerInfo.UNKNOWN_NUMBER) || |
| 224 | mNumber.equals(CallerInfo.PRIVATE_NUMBER)) { |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 225 | nameText = getString(mNumber.equals(CallerInfo.PRIVATE_NUMBER) |
| 226 | ? R.string.private_num : R.string.unknown); |
| 227 | numberText = ""; |
| 228 | mCallActionView.setVisibility(View.GONE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 229 | } else { |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 230 | // Perform a reverse-phonebook lookup to find the PERSON_ID |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 231 | CharSequence callLabel = null; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 232 | Uri personUri = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 233 | Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, |
| 234 | Uri.encode(mNumber)); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 235 | Cursor phonesCursor = resolver.query( |
| 236 | phoneUri, PHONES_PROJECTION, null, null, null); |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 237 | try { |
| 238 | if (phonesCursor != null && phonesCursor.moveToFirst()) { |
| 239 | long personId = phonesCursor.getLong(COLUMN_INDEX_ID); |
| 240 | personUri = ContentUris.withAppendedId( |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 241 | Contacts.CONTENT_URI, personId); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 242 | nameText = phonesCursor.getString(COLUMN_INDEX_NAME); |
| 243 | photoId = phonesCursor.getLong(COLUMN_INDEX_PHOTO_ID); |
Sang-il, Lee | 177c77f | 2010-03-09 20:37:19 +0900 | [diff] [blame] | 244 | mNumber = PhoneNumberUtils.formatNumber( |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 245 | phonesCursor.getString(COLUMN_INDEX_NUMBER), |
| 246 | phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER), |
| 247 | countryIso); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 248 | callLabel = Phone.getTypeLabel(getResources(), |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 249 | phonesCursor.getInt(COLUMN_INDEX_TYPE), |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 250 | phonesCursor.getString(COLUMN_INDEX_LABEL)); |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 251 | } else { |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 252 | mNumber = PhoneNumberUtils.formatNumber(mNumber, countryIso); |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 253 | } |
| 254 | } finally { |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 255 | if (phonesCursor != null) phonesCursor.close(); |
| 256 | } |
| 257 | |
| 258 | mCallActionView.setVisibility(View.VISIBLE); |
| 259 | mCallActionView.setOnClickListener(new View.OnClickListener() { |
| 260 | @Override |
| 261 | public void onClick(View v) { |
| 262 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
| 263 | Uri.fromParts("tel", mNumber, null)); |
| 264 | startActivity(callIntent); |
| 265 | } |
| 266 | }); |
| 267 | |
| 268 | if (callLabel != null) { |
| 269 | numberText = FormatUtils.applyStyleToSpan(Typeface.BOLD, |
| 270 | callLabel + " " + mNumber, 0, |
| 271 | callLabel.length(), |
| 272 | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 273 | } else { |
| 274 | numberText = mNumber; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 275 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 276 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 277 | // Build list of various available actions |
| 278 | List<ViewEntry> actions = new ArrayList<ViewEntry>(); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 279 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 280 | Intent smsIntent = new Intent(Intent.ACTION_SENDTO, |
| 281 | Uri.fromParts("sms", mNumber, null)); |
| 282 | actions.add(new ViewEntry(R.drawable.sym_action_sms, |
| 283 | getString(R.string.menu_sendTextMessage), smsIntent)); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 284 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 285 | // Let user view contact details if they exist, otherwise add option |
| 286 | // to create new contact from this number. |
| 287 | if (personUri != null) { |
| 288 | Intent viewIntent = new Intent(Intent.ACTION_VIEW, personUri); |
| 289 | actions.add(new ViewEntry(R.drawable.sym_action_view_contact, |
| 290 | getString(R.string.menu_viewContact), viewIntent)); |
| 291 | } else { |
| 292 | Intent createIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 293 | createIntent.setType(Contacts.CONTENT_ITEM_TYPE); |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 294 | createIntent.putExtra(Insert.PHONE, mNumber); |
| 295 | actions.add(new ViewEntry(R.drawable.sym_action_add, |
| 296 | getString(R.string.recentCalls_addToContact), createIntent)); |
| 297 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 298 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 299 | ViewAdapter adapter = new ViewAdapter(this, actions); |
| 300 | setListAdapter(adapter); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 301 | } |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 302 | mNameView.setText(nameText); |
| 303 | mNumberView.setText(numberText); |
| 304 | |
| 305 | loadContactPhotos(photoId); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 306 | } else { |
| 307 | // Something went wrong reading in our primary data, so we're going to |
| 308 | // bail out and show error to users. |
| 309 | Toast.makeText(this, R.string.toast_call_detail_error, |
| 310 | Toast.LENGTH_SHORT).show(); |
| 311 | finish(); |
| 312 | } |
| 313 | } finally { |
| 314 | if (callCursor != null) { |
| 315 | callCursor.close(); |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 320 | /** Load the contact photos and places them in the corresponding views. */ |
| 321 | private void loadContactPhotos(final long photoId) { |
| 322 | // There seem to be a limitation in the ContactPhotoManager that does not allow requesting |
| 323 | // two photos at once. |
| 324 | // TODO: Figure out the problem with ContactPhotoManager and remove this nonsense. |
| 325 | mContactPhotoView.post(new Runnable() { |
| 326 | @Override |
| 327 | public void run() { |
| 328 | mContactPhotoManager.loadPhoto(mContactPhotoView, photoId); |
| 329 | mContactPhotoView.postDelayed(new Runnable() { |
| 330 | @Override |
| 331 | public void run() { |
| 332 | mContactPhotoManager.loadPhoto(mContactBackgroundView, photoId); |
| 333 | } |
| 334 | }, 100); |
| 335 | } |
| 336 | }); |
| 337 | } |
| 338 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 339 | private String formatDuration(long elapsedSeconds) { |
| 340 | long minutes = 0; |
| 341 | long seconds = 0; |
| 342 | |
| 343 | if (elapsedSeconds >= 60) { |
| 344 | minutes = elapsedSeconds / 60; |
| 345 | elapsedSeconds -= minutes * 60; |
| 346 | } |
| 347 | seconds = elapsedSeconds; |
| 348 | |
| 349 | return getString(R.string.callDetailsDurationFormat, minutes, seconds); |
| 350 | } |
| 351 | |
| 352 | static final class ViewEntry { |
| 353 | public int icon = -1; |
| 354 | public String text = null; |
| 355 | public Intent intent = null; |
| 356 | public String label = null; |
| 357 | public String number = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 358 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 359 | public ViewEntry(int icon, String text, Intent intent) { |
| 360 | this.icon = icon; |
| 361 | this.text = text; |
| 362 | this.intent = intent; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | static final class ViewAdapter extends BaseAdapter { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 367 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 368 | private final List<ViewEntry> mActions; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 369 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 370 | private final LayoutInflater mInflater; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 371 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 372 | public ViewAdapter(Context context, List<ViewEntry> actions) { |
| 373 | mActions = actions; |
| 374 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 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 int getCount() { |
| 379 | return mActions.size(); |
| 380 | } |
| 381 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 382 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 383 | public Object getItem(int position) { |
| 384 | return mActions.get(position); |
| 385 | } |
| 386 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 387 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 388 | public long getItemId(int position) { |
| 389 | return position; |
| 390 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 391 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 392 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 393 | public View getView(int position, View convertView, ViewGroup parent) { |
| 394 | // Make sure we have a valid convertView to start with |
| 395 | if (convertView == null) { |
| 396 | convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false); |
| 397 | } |
| 398 | |
| 399 | // Fill action with icon and text. |
| 400 | ViewEntry entry = mActions.get(position); |
| 401 | convertView.setTag(entry); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 402 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 403 | ImageView icon = (ImageView) convertView.findViewById(R.id.icon); |
| 404 | TextView text = (TextView) convertView.findViewById(android.R.id.text1); |
| 405 | |
| 406 | icon.setImageResource(entry.icon); |
| 407 | text.setText(entry.text); |
| 408 | |
| 409 | View line2 = convertView.findViewById(R.id.line2); |
| 410 | boolean numberEmpty = TextUtils.isEmpty(entry.number); |
| 411 | boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty; |
| 412 | if (labelEmpty && numberEmpty) { |
| 413 | line2.setVisibility(View.GONE); |
| 414 | } else { |
| 415 | line2.setVisibility(View.VISIBLE); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 416 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 417 | TextView label = (TextView) convertView.findViewById(R.id.label); |
| 418 | if (labelEmpty) { |
| 419 | label.setVisibility(View.GONE); |
| 420 | } else { |
| 421 | label.setText(entry.label); |
| 422 | label.setVisibility(View.VISIBLE); |
| 423 | } |
| 424 | |
| 425 | TextView number = (TextView) convertView.findViewById(R.id.number); |
| 426 | number.setText(entry.number); |
| 427 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 428 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 429 | return convertView; |
| 430 | } |
| 431 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 432 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame^] | 433 | @Override |
| 434 | 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] | 435 | // Handle passing action off to correct handler. |
| 436 | if (view.getTag() instanceof ViewEntry) { |
| 437 | ViewEntry entry = (ViewEntry) view.getTag(); |
| 438 | if (entry.intent != null) { |
| 439 | startActivity(entry.intent); |
| 440 | } |
| 441 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 442 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 443 | |
| 444 | @Override |
| 445 | public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, |
| 446 | boolean globalSearch) { |
| 447 | if (globalSearch) { |
| 448 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 449 | } else { |
| 450 | ContactsSearchManager.startSearch(this, initialQuery); |
| 451 | } |
| 452 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 453 | } |