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 | */ |
| 172 | private void updateData(Uri callUri) { |
| 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); |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 217 | try { |
| 218 | if (phonesCursor != null && phonesCursor.moveToFirst()) { |
| 219 | long personId = phonesCursor.getLong(COLUMN_INDEX_ID); |
| 220 | personUri = ContentUris.withAppendedId( |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 221 | Contacts.CONTENT_URI, personId); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 222 | nameText = phonesCursor.getString(COLUMN_INDEX_NAME); |
| 223 | photoId = phonesCursor.getLong(COLUMN_INDEX_PHOTO_ID); |
Sang-il, Lee | 177c77f | 2010-03-09 20:37:19 +0900 | [diff] [blame] | 224 | mNumber = PhoneNumberUtils.formatNumber( |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 225 | phonesCursor.getString(COLUMN_INDEX_NUMBER), |
| 226 | phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER), |
| 227 | countryIso); |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 228 | numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE); |
| 229 | numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL); |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 230 | } else { |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 231 | mNumber = PhoneNumberUtils.formatNumber(mNumber, countryIso); |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 232 | } |
| 233 | } finally { |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 234 | if (phonesCursor != null) phonesCursor.close(); |
| 235 | } |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 236 | numberText = mNumber; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 237 | |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame^] | 238 | // Let user view contact details if they exist, otherwise add option |
| 239 | // to create new contact from this number. |
| 240 | final Intent mainActionIntent; |
| 241 | final int mainActionIcon; |
| 242 | if (personUri != null) { |
| 243 | mainActionIntent = new Intent(Intent.ACTION_VIEW, personUri); |
| 244 | mainActionIcon = R.drawable.sym_action_view_contact; |
| 245 | } else { |
| 246 | mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 247 | mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 248 | mainActionIntent.putExtra(Insert.PHONE, mNumber); |
| 249 | mainActionIcon = R.drawable.sym_action_add; |
| 250 | } |
| 251 | |
| 252 | mMainActionView.setVisibility(View.VISIBLE); |
| 253 | mMainActionView.setImageResource(mainActionIcon); |
| 254 | mMainActionView.setOnClickListener(new View.OnClickListener() { |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 255 | @Override |
| 256 | public void onClick(View v) { |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame^] | 257 | startActivity(mainActionIntent); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 258 | } |
| 259 | }); |
| 260 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 261 | // Build list of various available actions |
| 262 | List<ViewEntry> actions = new ArrayList<ViewEntry>(); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 263 | |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame^] | 264 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
| 265 | Uri.fromParts("tel", mNumber, null)); |
| 266 | actions.add(new ViewEntry(android.R.drawable.sym_action_call, |
| 267 | getString(R.string.menu_callNumber, mNumber), callIntent)); |
| 268 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 269 | Intent smsIntent = new Intent(Intent.ACTION_SENDTO, |
| 270 | Uri.fromParts("sms", mNumber, null)); |
| 271 | actions.add(new ViewEntry(R.drawable.sym_action_sms, |
| 272 | getString(R.string.menu_sendTextMessage), smsIntent)); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 273 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 274 | ViewAdapter adapter = new ViewAdapter(this, actions); |
| 275 | setListAdapter(adapter); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 276 | } |
Flavio Lerda | d72bf8a | 2011-07-05 16:00:09 +0100 | [diff] [blame] | 277 | mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews, date, callType, |
| 278 | nameText, numberText, numberType, numberLabel); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 279 | |
| 280 | loadContactPhotos(photoId); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 281 | } else { |
| 282 | // Something went wrong reading in our primary data, so we're going to |
| 283 | // bail out and show error to users. |
| 284 | Toast.makeText(this, R.string.toast_call_detail_error, |
| 285 | Toast.LENGTH_SHORT).show(); |
| 286 | finish(); |
| 287 | } |
| 288 | } finally { |
| 289 | if (callCursor != null) { |
| 290 | callCursor.close(); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 295 | /** Load the contact photos and places them in the corresponding views. */ |
| 296 | private void loadContactPhotos(final long photoId) { |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame^] | 297 | mContactPhotoManager.loadPhoto(mContactBackgroundView, photoId); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 298 | } |
| 299 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 300 | private String formatDuration(long elapsedSeconds) { |
| 301 | long minutes = 0; |
| 302 | long seconds = 0; |
| 303 | |
| 304 | if (elapsedSeconds >= 60) { |
| 305 | minutes = elapsedSeconds / 60; |
| 306 | elapsedSeconds -= minutes * 60; |
| 307 | } |
| 308 | seconds = elapsedSeconds; |
| 309 | |
| 310 | return getString(R.string.callDetailsDurationFormat, minutes, seconds); |
| 311 | } |
| 312 | |
Flavio Lerda | 696e813 | 2011-07-05 19:00:23 +0100 | [diff] [blame] | 313 | private String getVoicemailNumber() { |
| 314 | TelephonyManager telephonyManager = |
| 315 | (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 316 | return telephonyManager.getVoiceMailNumber(); |
| 317 | } |
| 318 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 319 | static final class ViewEntry { |
| 320 | public int icon = -1; |
| 321 | public String text = null; |
| 322 | public Intent intent = null; |
| 323 | public String label = null; |
| 324 | public String number = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 325 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 326 | public ViewEntry(int icon, String text, Intent intent) { |
| 327 | this.icon = icon; |
| 328 | this.text = text; |
| 329 | this.intent = intent; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | static final class ViewAdapter extends BaseAdapter { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 334 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 335 | private final List<ViewEntry> mActions; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 336 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 337 | private final LayoutInflater mInflater; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 338 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 339 | public ViewAdapter(Context context, List<ViewEntry> actions) { |
| 340 | mActions = actions; |
| 341 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 342 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 343 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 344 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 345 | public int getCount() { |
| 346 | return mActions.size(); |
| 347 | } |
| 348 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 349 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 350 | public Object getItem(int position) { |
| 351 | return mActions.get(position); |
| 352 | } |
| 353 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 354 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 355 | public long getItemId(int position) { |
| 356 | return position; |
| 357 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 358 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 359 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 360 | public View getView(int position, View convertView, ViewGroup parent) { |
| 361 | // Make sure we have a valid convertView to start with |
| 362 | if (convertView == null) { |
| 363 | convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false); |
| 364 | } |
| 365 | |
| 366 | // Fill action with icon and text. |
| 367 | ViewEntry entry = mActions.get(position); |
| 368 | convertView.setTag(entry); |
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 | ImageView icon = (ImageView) convertView.findViewById(R.id.icon); |
| 371 | TextView text = (TextView) convertView.findViewById(android.R.id.text1); |
| 372 | |
| 373 | icon.setImageResource(entry.icon); |
| 374 | text.setText(entry.text); |
| 375 | |
| 376 | View line2 = convertView.findViewById(R.id.line2); |
| 377 | boolean numberEmpty = TextUtils.isEmpty(entry.number); |
| 378 | boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty; |
| 379 | if (labelEmpty && numberEmpty) { |
| 380 | line2.setVisibility(View.GONE); |
| 381 | } else { |
| 382 | line2.setVisibility(View.VISIBLE); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 383 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 384 | TextView label = (TextView) convertView.findViewById(R.id.label); |
| 385 | if (labelEmpty) { |
| 386 | label.setVisibility(View.GONE); |
| 387 | } else { |
| 388 | label.setText(entry.label); |
| 389 | label.setVisibility(View.VISIBLE); |
| 390 | } |
| 391 | |
| 392 | TextView number = (TextView) convertView.findViewById(R.id.number); |
| 393 | number.setText(entry.number); |
| 394 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 395 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 396 | return convertView; |
| 397 | } |
| 398 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 399 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 400 | @Override |
| 401 | 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] | 402 | // Handle passing action off to correct handler. |
| 403 | if (view.getTag() instanceof ViewEntry) { |
| 404 | ViewEntry entry = (ViewEntry) view.getTag(); |
| 405 | if (entry.intent != null) { |
| 406 | startActivity(entry.intent); |
| 407 | } |
| 408 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 409 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 410 | |
| 411 | @Override |
| 412 | public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, |
| 413 | boolean globalSearch) { |
| 414 | if (globalSearch) { |
| 415 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 416 | } else { |
| 417 | ContactsSearchManager.startSearch(this, initialQuery); |
| 418 | } |
| 419 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 420 | } |