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; |
| 64 | private View mCallActionView; |
| 65 | private ImageView mContactPhotoView; |
| 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 | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 117 | mPhoneCallDetailsViews = new PhoneCallDetailsViews(getWindow().getDecorView()); |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame^] | 118 | mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 119 | mCallActionView = findViewById(R.id.call); |
| 120 | mContactPhotoView = (ImageView) findViewById(R.id.contact_photo); |
| 121 | mContactBackgroundView = (ImageView) findViewById(R.id.contact_background); |
| 122 | mCallTimeView = (TextView) findViewById(R.id.time); |
| 123 | mCallDurationView = (TextView) findViewById(R.id.duration); |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 124 | mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 125 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 126 | getListView().setOnItemClickListener(this); |
| 127 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 128 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 129 | @Override |
| 130 | public void onResume() { |
| 131 | super.onResume(); |
| 132 | updateData(getIntent().getData()); |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 137 | switch (keyCode) { |
| 138 | case KeyEvent.KEYCODE_CALL: { |
| 139 | // Make sure phone isn't already busy before starting direct call |
| 140 | TelephonyManager tm = (TelephonyManager) |
| 141 | getSystemService(Context.TELEPHONY_SERVICE); |
| 142 | if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { |
| 143 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
| 144 | Uri.fromParts("tel", mNumber, null)); |
| 145 | startActivity(callIntent); |
| 146 | return true; |
| 147 | } |
| 148 | } |
| 149 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 150 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 151 | return super.onKeyDown(keyCode, event); |
| 152 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 153 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 154 | /** |
| 155 | * Update user interface with details of given call. |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 156 | * |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 157 | * @param callUri Uri into {@link CallLog.Calls} |
| 158 | */ |
| 159 | private void updateData(Uri callUri) { |
| 160 | ContentResolver resolver = getContentResolver(); |
| 161 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 162 | try { |
| 163 | if (callCursor != null && callCursor.moveToFirst()) { |
| 164 | // Read call log specifics |
| 165 | mNumber = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 166 | long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 167 | long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 168 | int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 169 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 170 | if (TextUtils.isEmpty(countryIso)) { |
| 171 | countryIso = mDefaultCountryIso; |
| 172 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 173 | // Pull out string in format [relative], [date] |
| 174 | CharSequence dateClause = DateUtils.formatDateRange(this, date, date, |
| 175 | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | |
| 176 | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 177 | mCallTimeView.setText(dateClause); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 178 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 179 | // Set the duration |
| 180 | if (callType == Calls.MISSED_TYPE) { |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 181 | mCallDurationView.setVisibility(View.GONE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 182 | } else { |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 183 | mCallDurationView.setVisibility(View.VISIBLE); |
| 184 | mCallDurationView.setText(formatDuration(duration)); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 185 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 186 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 187 | long photoId = 0L; |
| 188 | CharSequence nameText = ""; |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 189 | final CharSequence numberText; |
| 190 | int numberType = 0; |
| 191 | CharSequence numberLabel = ""; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 192 | if (mNumber.equals(CallerInfo.UNKNOWN_NUMBER) || |
| 193 | mNumber.equals(CallerInfo.PRIVATE_NUMBER)) { |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 194 | numberText = getString(mNumber.equals(CallerInfo.PRIVATE_NUMBER) |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 195 | ? R.string.private_num : R.string.unknown); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 196 | mCallActionView.setVisibility(View.GONE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 197 | } else { |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 198 | // Perform a reverse-phonebook lookup to find the PERSON_ID |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 199 | Uri personUri = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 200 | Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, |
| 201 | Uri.encode(mNumber)); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 202 | Cursor phonesCursor = resolver.query( |
| 203 | phoneUri, PHONES_PROJECTION, null, null, null); |
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); |
Sang-il, Lee | 177c77f | 2010-03-09 20:37:19 +0900 | [diff] [blame] | 211 | mNumber = 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 { |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 218 | mNumber = PhoneNumberUtils.formatNumber(mNumber, countryIso); |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 219 | } |
| 220 | } finally { |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 221 | if (phonesCursor != null) phonesCursor.close(); |
| 222 | } |
Flavio Lerda | a024c3f | 2011-06-10 10:47:07 +0100 | [diff] [blame] | 223 | numberText = mNumber; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 224 | |
| 225 | mCallActionView.setVisibility(View.VISIBLE); |
| 226 | mCallActionView.setOnClickListener(new View.OnClickListener() { |
| 227 | @Override |
| 228 | public void onClick(View v) { |
| 229 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
| 230 | Uri.fromParts("tel", mNumber, null)); |
| 231 | startActivity(callIntent); |
| 232 | } |
| 233 | }); |
| 234 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 235 | // Build list of various available actions |
| 236 | List<ViewEntry> actions = new ArrayList<ViewEntry>(); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 237 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 238 | Intent smsIntent = new Intent(Intent.ACTION_SENDTO, |
| 239 | Uri.fromParts("sms", mNumber, null)); |
| 240 | actions.add(new ViewEntry(R.drawable.sym_action_sms, |
| 241 | getString(R.string.menu_sendTextMessage), smsIntent)); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 242 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 243 | // Let user view contact details if they exist, otherwise add option |
| 244 | // to create new contact from this number. |
| 245 | if (personUri != null) { |
| 246 | Intent viewIntent = new Intent(Intent.ACTION_VIEW, personUri); |
| 247 | actions.add(new ViewEntry(R.drawable.sym_action_view_contact, |
| 248 | getString(R.string.menu_viewContact), viewIntent)); |
| 249 | } else { |
| 250 | Intent createIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 251 | createIntent.setType(Contacts.CONTENT_ITEM_TYPE); |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 252 | createIntent.putExtra(Insert.PHONE, mNumber); |
| 253 | actions.add(new ViewEntry(R.drawable.sym_action_add, |
| 254 | getString(R.string.recentCalls_addToContact), createIntent)); |
| 255 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 256 | |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 257 | ViewAdapter adapter = new ViewAdapter(this, actions); |
| 258 | setListAdapter(adapter); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 259 | } |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame^] | 260 | mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews, getResources(), |
| 261 | date, callType, nameText, numberText, numberType, numberLabel); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 262 | |
| 263 | loadContactPhotos(photoId); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 264 | } else { |
| 265 | // Something went wrong reading in our primary data, so we're going to |
| 266 | // bail out and show error to users. |
| 267 | Toast.makeText(this, R.string.toast_call_detail_error, |
| 268 | Toast.LENGTH_SHORT).show(); |
| 269 | finish(); |
| 270 | } |
| 271 | } finally { |
| 272 | if (callCursor != null) { |
| 273 | callCursor.close(); |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 278 | /** Load the contact photos and places them in the corresponding views. */ |
| 279 | private void loadContactPhotos(final long photoId) { |
| 280 | // There seem to be a limitation in the ContactPhotoManager that does not allow requesting |
| 281 | // two photos at once. |
| 282 | // TODO: Figure out the problem with ContactPhotoManager and remove this nonsense. |
| 283 | mContactPhotoView.post(new Runnable() { |
| 284 | @Override |
| 285 | public void run() { |
| 286 | mContactPhotoManager.loadPhoto(mContactPhotoView, photoId); |
| 287 | mContactPhotoView.postDelayed(new Runnable() { |
| 288 | @Override |
| 289 | public void run() { |
| 290 | mContactPhotoManager.loadPhoto(mContactBackgroundView, photoId); |
| 291 | } |
| 292 | }, 100); |
| 293 | } |
| 294 | }); |
| 295 | } |
| 296 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 297 | private String formatDuration(long elapsedSeconds) { |
| 298 | long minutes = 0; |
| 299 | long seconds = 0; |
| 300 | |
| 301 | if (elapsedSeconds >= 60) { |
| 302 | minutes = elapsedSeconds / 60; |
| 303 | elapsedSeconds -= minutes * 60; |
| 304 | } |
| 305 | seconds = elapsedSeconds; |
| 306 | |
| 307 | return getString(R.string.callDetailsDurationFormat, minutes, seconds); |
| 308 | } |
| 309 | |
| 310 | static final class ViewEntry { |
| 311 | public int icon = -1; |
| 312 | public String text = null; |
| 313 | public Intent intent = null; |
| 314 | public String label = null; |
| 315 | public String number = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 316 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 317 | public ViewEntry(int icon, String text, Intent intent) { |
| 318 | this.icon = icon; |
| 319 | this.text = text; |
| 320 | this.intent = intent; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | static final class ViewAdapter extends BaseAdapter { |
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 | private final List<ViewEntry> mActions; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 327 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 328 | private final LayoutInflater mInflater; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 329 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 330 | public ViewAdapter(Context context, List<ViewEntry> actions) { |
| 331 | mActions = actions; |
| 332 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 333 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 334 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 335 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 336 | public int getCount() { |
| 337 | return mActions.size(); |
| 338 | } |
| 339 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 340 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 341 | public Object getItem(int position) { |
| 342 | return mActions.get(position); |
| 343 | } |
| 344 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 345 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 346 | public long getItemId(int position) { |
| 347 | return position; |
| 348 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 349 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 350 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 351 | public View getView(int position, View convertView, ViewGroup parent) { |
| 352 | // Make sure we have a valid convertView to start with |
| 353 | if (convertView == null) { |
| 354 | convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false); |
| 355 | } |
| 356 | |
| 357 | // Fill action with icon and text. |
| 358 | ViewEntry entry = mActions.get(position); |
| 359 | convertView.setTag(entry); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 360 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 361 | ImageView icon = (ImageView) convertView.findViewById(R.id.icon); |
| 362 | TextView text = (TextView) convertView.findViewById(android.R.id.text1); |
| 363 | |
| 364 | icon.setImageResource(entry.icon); |
| 365 | text.setText(entry.text); |
| 366 | |
| 367 | View line2 = convertView.findViewById(R.id.line2); |
| 368 | boolean numberEmpty = TextUtils.isEmpty(entry.number); |
| 369 | boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty; |
| 370 | if (labelEmpty && numberEmpty) { |
| 371 | line2.setVisibility(View.GONE); |
| 372 | } else { |
| 373 | line2.setVisibility(View.VISIBLE); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 374 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 375 | TextView label = (TextView) convertView.findViewById(R.id.label); |
| 376 | if (labelEmpty) { |
| 377 | label.setVisibility(View.GONE); |
| 378 | } else { |
| 379 | label.setText(entry.label); |
| 380 | label.setVisibility(View.VISIBLE); |
| 381 | } |
| 382 | |
| 383 | TextView number = (TextView) convertView.findViewById(R.id.number); |
| 384 | number.setText(entry.number); |
| 385 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 386 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 387 | return convertView; |
| 388 | } |
| 389 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 390 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 391 | @Override |
| 392 | 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] | 393 | // Handle passing action off to correct handler. |
| 394 | if (view.getTag() instanceof ViewEntry) { |
| 395 | ViewEntry entry = (ViewEntry) view.getTag(); |
| 396 | if (entry.intent != null) { |
| 397 | startActivity(entry.intent); |
| 398 | } |
| 399 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 400 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 401 | |
| 402 | @Override |
| 403 | public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, |
| 404 | boolean globalSearch) { |
| 405 | if (globalSearch) { |
| 406 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 407 | } else { |
| 408 | ContactsSearchManager.startSearch(this, initialQuery); |
| 409 | } |
| 410 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 411 | } |