blob: d2c193e228df300542d8c49434d32f11c8c24580 [file] [log] [blame]
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001/*
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
17package com.android.contacts;
18
Flavio Lerda9a208cc2011-07-12 21:05:47 +010019import com.android.contacts.calllog.CallDetailHistoryAdapter;
20import com.android.contacts.calllog.CallTypeHelper;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010021import com.android.contacts.calllog.PhoneNumberHelper;
Hugo Hudsonb002f512011-07-15 17:41:12 +010022import com.android.contacts.voicemail.VoicemailPlaybackFragment;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -070023
Hugo Hudsonb002f512011-07-15 17:41:12 +010024import android.app.FragmentManager;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080025import android.app.ListActivity;
26import android.content.ContentResolver;
27import android.content.ContentUris;
28import android.content.Context;
29import android.content.Intent;
30import android.content.res.Resources;
31import android.database.Cursor;
32import android.net.Uri;
33import android.os.Bundle;
34import android.provider.CallLog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080035import android.provider.CallLog.Calls;
Flavio Lerda9cafe472011-06-08 14:06:13 +010036import android.provider.Contacts.Intents.Insert;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070037import android.provider.ContactsContract.Contacts;
38import android.provider.ContactsContract.PhoneLookup;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080039import android.telephony.PhoneNumberUtils;
40import android.telephony.TelephonyManager;
41import android.text.TextUtils;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010042import android.util.Log;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080043import android.view.KeyEvent;
44import android.view.LayoutInflater;
45import android.view.View;
46import android.view.ViewGroup;
47import android.widget.AdapterView;
48import android.widget.BaseAdapter;
49import android.widget.ImageView;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010050import android.widget.ListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080051import android.widget.TextView;
52import android.widget.Toast;
53
54import java.util.ArrayList;
55import java.util.List;
56
57/**
58 * Displays the details of a specific call log entry.
Flavio Lerda178eeeb2011-07-11 19:51:40 +010059 * <p>
60 * This activity can be either started with the URI of a single call log entry, or with the
61 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080062 */
63public class CallDetailActivity extends ListActivity implements
64 AdapterView.OnItemClickListener {
65 private static final String TAG = "CallDetail";
66
Flavio Lerda178eeeb2011-07-11 19:51:40 +010067 /** A long array extra containing ids of call log entries to display. */
Hugo Hudsonb002f512011-07-15 17:41:12 +010068 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
69 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
70 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
71 /** If we should immediately start playback of the voicemail, this extra will be set to true. */
72 public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK";
Flavio Lerda178eeeb2011-07-11 19:51:40 +010073
Flavio Lerdaa024c3f2011-06-10 10:47:07 +010074 /** The views representing the details of a phone call. */
Flavio Lerdaafb93bb2011-07-05 14:46:10 +010075 private PhoneCallDetailsViews mPhoneCallDetailsViews;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010076 private CallTypeHelper mCallTypeHelper;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010077 private PhoneNumberHelper mPhoneNumberHelper;
Flavio Lerdaafb93bb2011-07-05 14:46:10 +010078 private PhoneCallDetailsHelper mPhoneCallDetailsHelper;
Flavio Lerdafb63c432011-07-07 17:16:53 +010079 private View mHomeActionView;
80 private ImageView mMainActionView;
Flavio Lerda9cafe472011-06-08 14:06:13 +010081 private ImageView mContactBackgroundView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080082
83 private String mNumber = null;
Bai Tao09eb04f2010-09-01 15:34:16 +080084 private String mDefaultCountryIso;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070085
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080086 /* package */ LayoutInflater mInflater;
87 /* package */ Resources mResources;
Flavio Lerda9cafe472011-06-08 14:06:13 +010088 /** Helper to load contact photos. */
89 private ContactPhotoManager mContactPhotoManager;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070090
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080091 static final String[] CALL_LOG_PROJECTION = new String[] {
92 CallLog.Calls.DATE,
93 CallLog.Calls.DURATION,
94 CallLog.Calls.NUMBER,
95 CallLog.Calls.TYPE,
Bai Tao09eb04f2010-09-01 15:34:16 +080096 CallLog.Calls.COUNTRY_ISO,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080097 };
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070098
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080099 static final int DATE_COLUMN_INDEX = 0;
100 static final int DURATION_COLUMN_INDEX = 1;
101 static final int NUMBER_COLUMN_INDEX = 2;
102 static final int CALL_TYPE_COLUMN_INDEX = 3;
Bai Tao09eb04f2010-09-01 15:34:16 +0800103 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700104
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800105 static final String[] PHONES_PROJECTION = new String[] {
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700106 PhoneLookup._ID,
107 PhoneLookup.DISPLAY_NAME,
108 PhoneLookup.TYPE,
109 PhoneLookup.LABEL,
110 PhoneLookup.NUMBER,
Bai Tao09eb04f2010-09-01 15:34:16 +0800111 PhoneLookup.NORMALIZED_NUMBER,
Daniel Lehmann362654a2011-07-17 14:16:47 -0700112 PhoneLookup.PHOTO_URI,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800113 };
114 static final int COLUMN_INDEX_ID = 0;
115 static final int COLUMN_INDEX_NAME = 1;
116 static final int COLUMN_INDEX_TYPE = 2;
117 static final int COLUMN_INDEX_LABEL = 3;
118 static final int COLUMN_INDEX_NUMBER = 4;
Bai Tao09eb04f2010-09-01 15:34:16 +0800119 static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5;
Daniel Lehmann362654a2011-07-17 14:16:47 -0700120 static final int COLUMN_INDEX_PHOTO_URI = 6;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800121
122 @Override
123 protected void onCreate(Bundle icicle) {
124 super.onCreate(icicle);
125
126 setContentView(R.layout.call_detail);
127
128 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
129 mResources = getResources();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700130
Flavio Lerda696e8132011-07-05 19:00:23 +0100131 mPhoneCallDetailsViews = PhoneCallDetailsViews.fromView(getWindow().getDecorView());
Flavio Lerda9a208cc2011-07-12 21:05:47 +0100132 mCallTypeHelper = new CallTypeHelper(getResources(),
Flavio Lerda693d1f82011-07-13 18:20:46 +0100133 getResources().getDrawable(R.drawable.ic_call_incoming_holo_dark),
134 getResources().getDrawable(R.drawable.ic_call_outgoing_holo_dark),
135 getResources().getDrawable(R.drawable.ic_call_missed_holo_dark),
136 getResources().getDrawable(R.drawable.ic_call_voicemail_holo_dark));
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100137 mPhoneNumberHelper = new PhoneNumberHelper(mResources, getVoicemailNumber());
138 mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(this, mResources, mCallTypeHelper,
139 mPhoneNumberHelper);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100140 mHomeActionView = findViewById(R.id.action_bar_home);
141 mMainActionView = (ImageView) findViewById(R.id.main_action);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100142 mContactBackgroundView = (ImageView) findViewById(R.id.contact_background);
Bai Tao09eb04f2010-09-01 15:34:16 +0800143 mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100144 mContactPhotoManager = ContactPhotoManager.getInstance(this);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800145 getListView().setOnItemClickListener(this);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100146 mHomeActionView.setOnClickListener(new View.OnClickListener() {
147 @Override
148 public void onClick(View v) {
149 // We want this to start the call log if this activity was not started from the
150 // call log itself.
151 CallDetailActivity.this.finish();
152 }
153 });
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800154 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700155
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800156 @Override
157 public void onResume() {
158 super.onResume();
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100159 updateData(getCallLogEntryUris());
Hugo Hudsonb002f512011-07-15 17:41:12 +0100160 optionallyHandleVoicemail();
161 }
162
163 /**
164 * Handle voicemail playback or hide voicemail ui.
165 * <p>
166 * If the Intent used to start this Activity contains the suitable extras, then start voicemail
167 * playback. If it doesn't, then hide the voicemail ui.
168 */
169 private void optionallyHandleVoicemail() {
170 FragmentManager manager = getFragmentManager();
171 VoicemailPlaybackFragment fragment = (VoicemailPlaybackFragment) manager.findFragmentById(
172 R.id.voicemail_playback_fragment);
173 Uri voicemailUri = getIntent().getExtras().getParcelable(EXTRA_VOICEMAIL_URI);
174 if (voicemailUri == null) {
175 // No voicemail uri: hide the voicemail fragment.
176 manager.beginTransaction().hide(fragment).commit();
177 } else {
178 // A voicemail: extra tells us if we should start playback or not.
179 boolean startPlayback = getIntent().getExtras().getBoolean(
180 EXTRA_VOICEMAIL_START_PLAYBACK, false);
181 fragment.setVoicemailUri(voicemailUri, startPlayback);
182 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100183 }
184
185 /**
186 * Returns the list of URIs to show.
187 * <p>
188 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
189 * a list of ids in the call log added as an extra on the URI.
190 * <p>
191 * If both are available, the data on the intent takes precedence.
192 */
193 private Uri[] getCallLogEntryUris() {
194 Uri uri = getIntent().getData();
195 if (uri != null) {
196 // If there is a data on the intent, it takes precedence over the extra.
197 return new Uri[]{ uri };
198 }
199 long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
200 Uri[] uris = new Uri[ids.length];
201 for (int index = 0; index < ids.length; ++index) {
202 uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]);
203 }
204 return uris;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800205 }
206
207 @Override
208 public boolean onKeyDown(int keyCode, KeyEvent event) {
209 switch (keyCode) {
210 case KeyEvent.KEYCODE_CALL: {
211 // Make sure phone isn't already busy before starting direct call
212 TelephonyManager tm = (TelephonyManager)
213 getSystemService(Context.TELEPHONY_SERVICE);
214 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
215 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
216 Uri.fromParts("tel", mNumber, null));
217 startActivity(callIntent);
218 return true;
219 }
220 }
221 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700222
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800223 return super.onKeyDown(keyCode, event);
224 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700225
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800226 /**
227 * Update user interface with details of given call.
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700228 *
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100229 * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800230 */
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100231 private void updateData(final Uri... callUris) {
232 // TODO: All phone calls correspond to the same person, so we can make a single lookup.
233 final int numCalls = callUris.length;
234 final PhoneCallDetails[] details = new PhoneCallDetails[numCalls];
235 try {
236 for (int index = 0; index < numCalls; ++index) {
237 details[index] = getPhoneCallDetailsForUri(callUris[index]);
238 }
239 } catch (IllegalArgumentException e) {
240 // Something went wrong reading in our primary data, so we're going to
241 // bail out and show error to users.
242 Log.w(TAG, "invalid URI starting call details", e);
243 Toast.makeText(this, R.string.toast_call_detail_error,
244 Toast.LENGTH_SHORT).show();
245 finish();
246 return;
247 }
248
249 // We know that all calls are from the same number and the same contact, so pick the first.
250 mNumber = details[0].number.toString();
251 final long personId = details[0].personId;
Daniel Lehmann362654a2011-07-17 14:16:47 -0700252 final Uri photoUri = details[0].photoUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100253
254 // Set the details header, based on the first phone call.
255 mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews,
Flavio Lerda76921902011-07-13 21:11:51 +0100256 details[0], false, false);
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100257
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100258 // Cache the details about the phone number.
259 final Uri numberCallUri = mPhoneNumberHelper.getCallUri(mNumber);
260 final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber);
261 final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber);
262 final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber);
263
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100264 // Let user view contact details if they exist, otherwise add option to create new contact
265 // from this number.
266 final Intent mainActionIntent;
267 final int mainActionIcon;
268
269 if (details[0].personId != -1) {
270 Uri personUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, personId);
271 mainActionIntent = new Intent(Intent.ACTION_VIEW, personUri);
272 mainActionIcon = R.drawable.sym_action_view_contact;
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100273 } else if (isVoicemailNumber) {
274 mainActionIntent = null;
275 mainActionIcon = 0;
276 } else if (isSipNumber) {
277 // TODO: This item is currently disabled for SIP addresses, because
278 // the Insert.PHONE extra only works correctly for PSTN numbers.
279 //
280 // To fix this for SIP addresses, we need to:
281 // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if
282 // the current number is a SIP address
283 // - update the contacts UI code to handle Insert.SIP_ADDRESS by
284 // updating the SipAddress field
285 // and then we can remove the "!isSipNumber" check above.
286 mainActionIntent = null;
287 mainActionIcon = 0;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100288 } else {
289 mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
290 mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE);
291 mainActionIntent.putExtra(Insert.PHONE, mNumber);
292 mainActionIcon = R.drawable.sym_action_add;
293 }
294
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100295 if (mainActionIntent == null) {
296 mMainActionView.setVisibility(View.INVISIBLE);
297 } else {
298 mMainActionView.setVisibility(View.VISIBLE);
299 mMainActionView.setImageResource(mainActionIcon);
300 mMainActionView.setOnClickListener(new View.OnClickListener() {
301 @Override
302 public void onClick(View v) {
303 startActivity(mainActionIntent);
304 }
305 });
306 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100307
308 // Build list of various available actions.
309 final List<ViewEntry> actions = new ArrayList<ViewEntry>();
310
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100311 // This action allows to call the number that places the call.
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100312 if (canPlaceCallsTo) {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100313 actions.add(new ViewEntry(android.R.drawable.sym_action_call,
314 getString(R.string.menu_callNumber, mNumber),
315 new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri)));
316 }
317
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100318 // This action allows to send an SMS to the number that placed the call.
319 if (mPhoneNumberHelper.canSendSmsTo(mNumber)) {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100320 Intent smsIntent = new Intent(Intent.ACTION_SENDTO,
321 Uri.fromParts("sms", mNumber, null));
322 actions.add(new ViewEntry(R.drawable.sym_action_sms,
323 getString(R.string.menu_sendTextMessage), smsIntent));
324 }
325
326 // This action deletes all elements in the group from the call log.
327 actions.add(new ViewEntry(android.R.drawable.ic_menu_close_clear_cancel,
328 getString(R.string.recentCalls_removeFromRecentList),
329 new View.OnClickListener() {
330 @Override
331 public void onClick(View v) {
332 StringBuilder callIds = new StringBuilder();
333 for (Uri callUri : callUris) {
334 if (callIds.length() != 0) {
335 callIds.append(",");
336 }
337 callIds.append(ContentUris.parseId(callUri));
338 }
339
340 getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
341 Calls._ID + " IN (" + callIds + ")", null);
342 finish();
343 }
344 }));
345
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100346 if (canPlaceCallsTo && !isSipNumber && !isVoicemailNumber) {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100347 // "Edit the number before calling" is only available for PSTN numbers.
348 actions.add(new ViewEntry(android.R.drawable.sym_action_call,
349 getString(R.string.recentCalls_editNumberBeforeCall),
350 new Intent(Intent.ACTION_DIAL, numberCallUri)));
351 }
352
353 // Set the actions for this phone number.
354 setListAdapter(new ViewAdapter(this, actions));
355
356 ListView historyList = (ListView) findViewById(R.id.history);
357 historyList.setAdapter(
358 new CallDetailHistoryAdapter(this, mInflater, mCallTypeHelper, details));
Daniel Lehmann362654a2011-07-17 14:16:47 -0700359 loadContactPhotos(photoUri);
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100360 }
361
362 /** Return the phone call details for a given call log URI. */
363 private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800364 ContentResolver resolver = getContentResolver();
365 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
366 try {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100367 if (callCursor == null || !callCursor.moveToFirst()) {
368 throw new IllegalArgumentException("Cannot find content: " + callUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800369 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100370
371 // Read call log specifics.
372 String number = callCursor.getString(NUMBER_COLUMN_INDEX);
373 long date = callCursor.getLong(DATE_COLUMN_INDEX);
374 long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
375 int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
376 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
377 if (TextUtils.isEmpty(countryIso)) {
378 countryIso = mDefaultCountryIso;
379 }
380
381 // Formatted phone number.
382 final CharSequence numberText;
383 // Read contact specifics.
384 CharSequence nameText = "";
385 int numberType = 0;
386 CharSequence numberLabel = "";
387 long personId = -1L;
Daniel Lehmann362654a2011-07-17 14:16:47 -0700388 Uri photoUri = null;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100389 // If this is not a regular number, there is no point in looking it up in the contacts.
390 if (!mPhoneNumberHelper.canPlaceCallsTo(number)) {
391 numberText = mPhoneNumberHelper.getDisplayNumber(number, null);
392 } else {
393 // Perform a reverse-phonebook lookup to find the contact details.
394 Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
395 Uri.encode(number));
396 Cursor phonesCursor = resolver.query(phoneUri, PHONES_PROJECTION, null, null, null);
397 String candidateNumberText = number;
398 try {
399 if (phonesCursor != null && phonesCursor.moveToFirst()) {
400 personId = phonesCursor.getLong(COLUMN_INDEX_ID);
401 nameText = phonesCursor.getString(COLUMN_INDEX_NAME);
Daniel Lehmann362654a2011-07-17 14:16:47 -0700402 String photoUriString = phonesCursor.getString(COLUMN_INDEX_PHOTO_URI);
403 photoUri = photoUriString == null ? null : Uri.parse(photoUriString);
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100404 candidateNumberText = PhoneNumberUtils.formatNumber(
405 phonesCursor.getString(COLUMN_INDEX_NUMBER),
406 phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER),
407 countryIso);
408 numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE);
409 numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL);
410 } else {
411 // We could not find this contact in the contacts, just format the phone
412 // number as best as we can. All the other fields will have their default
413 // values.
414 candidateNumberText =
415 PhoneNumberUtils.formatNumber(number, countryIso);
416 }
417 } finally {
418 if (phonesCursor != null) phonesCursor.close();
419 numberText = candidateNumberText;
420 }
421 }
Flavio Lerdacb805e82011-07-18 10:31:44 +0100422 return new PhoneCallDetails(number, numberText,
423 mPhoneNumberHelper.parsePhoneNumber(number, countryIso),
424 new int[]{ callType }, date, duration,
Daniel Lehmann362654a2011-07-17 14:16:47 -0700425 nameText, numberType, numberLabel, personId, photoUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800426 } finally {
427 if (callCursor != null) {
428 callCursor.close();
429 }
430 }
431 }
432
Flavio Lerda9cafe472011-06-08 14:06:13 +0100433 /** Load the contact photos and places them in the corresponding views. */
Daniel Lehmann362654a2011-07-17 14:16:47 -0700434 private void loadContactPhotos(Uri photoUri) {
435 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100436 }
437
Flavio Lerda696e8132011-07-05 19:00:23 +0100438 private String getVoicemailNumber() {
439 TelephonyManager telephonyManager =
440 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
441 return telephonyManager.getVoiceMailNumber();
442 }
443
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800444 static final class ViewEntry {
Flavio Lerdaa8956882011-07-09 21:34:38 +0100445 public final int icon;
446 public final String text;
447 public final Intent intent;
448 public final View.OnClickListener action;
449
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800450 public String label = null;
451 public String number = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700452
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800453 public ViewEntry(int icon, String text, Intent intent) {
454 this.icon = icon;
455 this.text = text;
456 this.intent = intent;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100457 this.action = null;
458 }
459
460 public ViewEntry(int icon, String text, View.OnClickListener listener) {
461 this.icon = icon;
462 this.text = text;
463 this.intent = null;
464 this.action = listener;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800465 }
466 }
467
468 static final class ViewAdapter extends BaseAdapter {
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700469
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800470 private final List<ViewEntry> mActions;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700471
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800472 private final LayoutInflater mInflater;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700473
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800474 public ViewAdapter(Context context, List<ViewEntry> actions) {
475 mActions = actions;
476 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
477 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700478
Flavio Lerda9cafe472011-06-08 14:06:13 +0100479 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800480 public int getCount() {
481 return mActions.size();
482 }
483
Flavio Lerda9cafe472011-06-08 14:06:13 +0100484 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800485 public Object getItem(int position) {
486 return mActions.get(position);
487 }
488
Flavio Lerda9cafe472011-06-08 14:06:13 +0100489 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800490 public long getItemId(int position) {
491 return position;
492 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700493
Flavio Lerda9cafe472011-06-08 14:06:13 +0100494 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800495 public View getView(int position, View convertView, ViewGroup parent) {
496 // Make sure we have a valid convertView to start with
497 if (convertView == null) {
498 convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false);
499 }
500
501 // Fill action with icon and text.
502 ViewEntry entry = mActions.get(position);
503 convertView.setTag(entry);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700504
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800505 ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
506 TextView text = (TextView) convertView.findViewById(android.R.id.text1);
507
508 icon.setImageResource(entry.icon);
509 text.setText(entry.text);
510
511 View line2 = convertView.findViewById(R.id.line2);
512 boolean numberEmpty = TextUtils.isEmpty(entry.number);
513 boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty;
514 if (labelEmpty && numberEmpty) {
515 line2.setVisibility(View.GONE);
516 } else {
517 line2.setVisibility(View.VISIBLE);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700518
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800519 TextView label = (TextView) convertView.findViewById(R.id.label);
520 if (labelEmpty) {
521 label.setVisibility(View.GONE);
522 } else {
523 label.setText(entry.label);
524 label.setVisibility(View.VISIBLE);
525 }
526
527 TextView number = (TextView) convertView.findViewById(R.id.number);
528 number.setText(entry.number);
529 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700530
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800531 return convertView;
532 }
533 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700534
Flavio Lerda9cafe472011-06-08 14:06:13 +0100535 @Override
536 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800537 // Handle passing action off to correct handler.
538 if (view.getTag() instanceof ViewEntry) {
539 ViewEntry entry = (ViewEntry) view.getTag();
540 if (entry.intent != null) {
541 startActivity(entry.intent);
Flavio Lerdaa8956882011-07-09 21:34:38 +0100542 } else if (entry.action != null) {
543 entry.action.onClick(view);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800544 }
545 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700546 }
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -0800547
548 @Override
549 public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
550 boolean globalSearch) {
551 if (globalSearch) {
552 super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
553 } else {
554 ContactsSearchManager.startSearch(this, initialQuery);
555 }
556 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800557}