blob: e014938781ac93ca16dbb0e45e171370b2522d1d [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;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -070022
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080023import android.app.ListActivity;
24import android.content.ContentResolver;
25import android.content.ContentUris;
26import android.content.Context;
27import android.content.Intent;
28import android.content.res.Resources;
29import android.database.Cursor;
30import android.net.Uri;
31import android.os.Bundle;
32import android.provider.CallLog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080033import android.provider.CallLog.Calls;
Flavio Lerda9cafe472011-06-08 14:06:13 +010034import android.provider.Contacts.Intents.Insert;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070035import android.provider.ContactsContract.Contacts;
36import android.provider.ContactsContract.PhoneLookup;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080037import android.telephony.PhoneNumberUtils;
38import android.telephony.TelephonyManager;
39import android.text.TextUtils;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010040import android.util.Log;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080041import android.view.KeyEvent;
42import android.view.LayoutInflater;
43import android.view.View;
44import android.view.ViewGroup;
45import android.widget.AdapterView;
46import android.widget.BaseAdapter;
47import android.widget.ImageView;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010048import android.widget.ListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080049import android.widget.TextView;
50import android.widget.Toast;
51
52import java.util.ArrayList;
53import java.util.List;
54
55/**
56 * Displays the details of a specific call log entry.
Flavio Lerda178eeeb2011-07-11 19:51:40 +010057 * <p>
58 * This activity can be either started with the URI of a single call log entry, or with the
59 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080060 */
61public class CallDetailActivity extends ListActivity implements
62 AdapterView.OnItemClickListener {
63 private static final String TAG = "CallDetail";
64
Flavio Lerda178eeeb2011-07-11 19:51:40 +010065 /** A long array extra containing ids of call log entries to display. */
66 public static final String EXTRA_CALL_LOG_IDS = "com.android.contacts.CALL_LOG_IDS";
67
Flavio Lerdaa024c3f2011-06-10 10:47:07 +010068 /** The views representing the details of a phone call. */
Flavio Lerdaafb93bb2011-07-05 14:46:10 +010069 private PhoneCallDetailsViews mPhoneCallDetailsViews;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010070 private CallTypeHelper mCallTypeHelper;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010071 private PhoneNumberHelper mPhoneNumberHelper;
Flavio Lerdaafb93bb2011-07-05 14:46:10 +010072 private PhoneCallDetailsHelper mPhoneCallDetailsHelper;
Flavio Lerdafb63c432011-07-07 17:16:53 +010073 private View mHomeActionView;
74 private ImageView mMainActionView;
Flavio Lerda9cafe472011-06-08 14:06:13 +010075 private ImageView mContactBackgroundView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080076
77 private String mNumber = null;
Bai Tao09eb04f2010-09-01 15:34:16 +080078 private String mDefaultCountryIso;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070079
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080080 /* package */ LayoutInflater mInflater;
81 /* package */ Resources mResources;
Flavio Lerda9cafe472011-06-08 14:06:13 +010082 /** Helper to load contact photos. */
83 private ContactPhotoManager mContactPhotoManager;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070084
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080085 static final String[] CALL_LOG_PROJECTION = new String[] {
86 CallLog.Calls.DATE,
87 CallLog.Calls.DURATION,
88 CallLog.Calls.NUMBER,
89 CallLog.Calls.TYPE,
Bai Tao09eb04f2010-09-01 15:34:16 +080090 CallLog.Calls.COUNTRY_ISO,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080091 };
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070092
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080093 static final int DATE_COLUMN_INDEX = 0;
94 static final int DURATION_COLUMN_INDEX = 1;
95 static final int NUMBER_COLUMN_INDEX = 2;
96 static final int CALL_TYPE_COLUMN_INDEX = 3;
Bai Tao09eb04f2010-09-01 15:34:16 +080097 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070098
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080099 static final String[] PHONES_PROJECTION = new String[] {
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700100 PhoneLookup._ID,
101 PhoneLookup.DISPLAY_NAME,
102 PhoneLookup.TYPE,
103 PhoneLookup.LABEL,
104 PhoneLookup.NUMBER,
Bai Tao09eb04f2010-09-01 15:34:16 +0800105 PhoneLookup.NORMALIZED_NUMBER,
Daniel Lehmann362654a2011-07-17 14:16:47 -0700106 PhoneLookup.PHOTO_URI,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800107 };
108 static final int COLUMN_INDEX_ID = 0;
109 static final int COLUMN_INDEX_NAME = 1;
110 static final int COLUMN_INDEX_TYPE = 2;
111 static final int COLUMN_INDEX_LABEL = 3;
112 static final int COLUMN_INDEX_NUMBER = 4;
Bai Tao09eb04f2010-09-01 15:34:16 +0800113 static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5;
Daniel Lehmann362654a2011-07-17 14:16:47 -0700114 static final int COLUMN_INDEX_PHOTO_URI = 6;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800115
116 @Override
117 protected void onCreate(Bundle icicle) {
118 super.onCreate(icicle);
119
120 setContentView(R.layout.call_detail);
121
122 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
123 mResources = getResources();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700124
Flavio Lerda696e8132011-07-05 19:00:23 +0100125 mPhoneCallDetailsViews = PhoneCallDetailsViews.fromView(getWindow().getDecorView());
Flavio Lerda9a208cc2011-07-12 21:05:47 +0100126 mCallTypeHelper = new CallTypeHelper(getResources(),
Flavio Lerda693d1f82011-07-13 18:20:46 +0100127 getResources().getDrawable(R.drawable.ic_call_incoming_holo_dark),
128 getResources().getDrawable(R.drawable.ic_call_outgoing_holo_dark),
129 getResources().getDrawable(R.drawable.ic_call_missed_holo_dark),
130 getResources().getDrawable(R.drawable.ic_call_voicemail_holo_dark));
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100131 mPhoneNumberHelper = new PhoneNumberHelper(mResources, getVoicemailNumber());
132 mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(this, mResources, mCallTypeHelper,
133 mPhoneNumberHelper);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100134 mHomeActionView = findViewById(R.id.action_bar_home);
135 mMainActionView = (ImageView) findViewById(R.id.main_action);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100136 mContactBackgroundView = (ImageView) findViewById(R.id.contact_background);
Bai Tao09eb04f2010-09-01 15:34:16 +0800137 mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100138 mContactPhotoManager = ContactPhotoManager.getInstance(this);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800139 getListView().setOnItemClickListener(this);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100140 mHomeActionView.setOnClickListener(new View.OnClickListener() {
141 @Override
142 public void onClick(View v) {
143 // We want this to start the call log if this activity was not started from the
144 // call log itself.
145 CallDetailActivity.this.finish();
146 }
147 });
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800148 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700149
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800150 @Override
151 public void onResume() {
152 super.onResume();
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100153 updateData(getCallLogEntryUris());
154 }
155
156 /**
157 * Returns the list of URIs to show.
158 * <p>
159 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
160 * a list of ids in the call log added as an extra on the URI.
161 * <p>
162 * If both are available, the data on the intent takes precedence.
163 */
164 private Uri[] getCallLogEntryUris() {
165 Uri uri = getIntent().getData();
166 if (uri != null) {
167 // If there is a data on the intent, it takes precedence over the extra.
168 return new Uri[]{ uri };
169 }
170 long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
171 Uri[] uris = new Uri[ids.length];
172 for (int index = 0; index < ids.length; ++index) {
173 uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]);
174 }
175 return uris;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800176 }
177
178 @Override
179 public boolean onKeyDown(int keyCode, KeyEvent event) {
180 switch (keyCode) {
181 case KeyEvent.KEYCODE_CALL: {
182 // Make sure phone isn't already busy before starting direct call
183 TelephonyManager tm = (TelephonyManager)
184 getSystemService(Context.TELEPHONY_SERVICE);
185 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
186 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
187 Uri.fromParts("tel", mNumber, null));
188 startActivity(callIntent);
189 return true;
190 }
191 }
192 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700193
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800194 return super.onKeyDown(keyCode, event);
195 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700196
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800197 /**
198 * Update user interface with details of given call.
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700199 *
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100200 * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800201 */
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100202 private void updateData(final Uri... callUris) {
203 // TODO: All phone calls correspond to the same person, so we can make a single lookup.
204 final int numCalls = callUris.length;
205 final PhoneCallDetails[] details = new PhoneCallDetails[numCalls];
206 try {
207 for (int index = 0; index < numCalls; ++index) {
208 details[index] = getPhoneCallDetailsForUri(callUris[index]);
209 }
210 } catch (IllegalArgumentException e) {
211 // Something went wrong reading in our primary data, so we're going to
212 // bail out and show error to users.
213 Log.w(TAG, "invalid URI starting call details", e);
214 Toast.makeText(this, R.string.toast_call_detail_error,
215 Toast.LENGTH_SHORT).show();
216 finish();
217 return;
218 }
219
220 // We know that all calls are from the same number and the same contact, so pick the first.
221 mNumber = details[0].number.toString();
222 final long personId = details[0].personId;
Daniel Lehmann362654a2011-07-17 14:16:47 -0700223 final Uri photoUri = details[0].photoUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100224
225 // Set the details header, based on the first phone call.
226 mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews,
Flavio Lerda76921902011-07-13 21:11:51 +0100227 details[0], false, false);
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100228
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100229 // Cache the details about the phone number.
230 final Uri numberCallUri = mPhoneNumberHelper.getCallUri(mNumber);
231 final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber);
232 final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber);
233 final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber);
234
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100235 // Let user view contact details if they exist, otherwise add option to create new contact
236 // from this number.
237 final Intent mainActionIntent;
238 final int mainActionIcon;
239
240 if (details[0].personId != -1) {
241 Uri personUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, personId);
242 mainActionIntent = new Intent(Intent.ACTION_VIEW, personUri);
243 mainActionIcon = R.drawable.sym_action_view_contact;
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100244 } else if (isVoicemailNumber) {
245 mainActionIntent = null;
246 mainActionIcon = 0;
247 } else if (isSipNumber) {
248 // TODO: This item is currently disabled for SIP addresses, because
249 // the Insert.PHONE extra only works correctly for PSTN numbers.
250 //
251 // To fix this for SIP addresses, we need to:
252 // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if
253 // the current number is a SIP address
254 // - update the contacts UI code to handle Insert.SIP_ADDRESS by
255 // updating the SipAddress field
256 // and then we can remove the "!isSipNumber" check above.
257 mainActionIntent = null;
258 mainActionIcon = 0;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100259 } else {
260 mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
261 mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE);
262 mainActionIntent.putExtra(Insert.PHONE, mNumber);
263 mainActionIcon = R.drawable.sym_action_add;
264 }
265
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100266 if (mainActionIntent == null) {
267 mMainActionView.setVisibility(View.INVISIBLE);
268 } else {
269 mMainActionView.setVisibility(View.VISIBLE);
270 mMainActionView.setImageResource(mainActionIcon);
271 mMainActionView.setOnClickListener(new View.OnClickListener() {
272 @Override
273 public void onClick(View v) {
274 startActivity(mainActionIntent);
275 }
276 });
277 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100278
279 // Build list of various available actions.
280 final List<ViewEntry> actions = new ArrayList<ViewEntry>();
281
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100282 // This action allows to call the number that places the call.
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100283 if (canPlaceCallsTo) {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100284 actions.add(new ViewEntry(android.R.drawable.sym_action_call,
285 getString(R.string.menu_callNumber, mNumber),
286 new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri)));
287 }
288
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100289 // This action allows to send an SMS to the number that placed the call.
290 if (mPhoneNumberHelper.canSendSmsTo(mNumber)) {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100291 Intent smsIntent = new Intent(Intent.ACTION_SENDTO,
292 Uri.fromParts("sms", mNumber, null));
293 actions.add(new ViewEntry(R.drawable.sym_action_sms,
294 getString(R.string.menu_sendTextMessage), smsIntent));
295 }
296
297 // This action deletes all elements in the group from the call log.
298 actions.add(new ViewEntry(android.R.drawable.ic_menu_close_clear_cancel,
299 getString(R.string.recentCalls_removeFromRecentList),
300 new View.OnClickListener() {
301 @Override
302 public void onClick(View v) {
303 StringBuilder callIds = new StringBuilder();
304 for (Uri callUri : callUris) {
305 if (callIds.length() != 0) {
306 callIds.append(",");
307 }
308 callIds.append(ContentUris.parseId(callUri));
309 }
310
311 getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
312 Calls._ID + " IN (" + callIds + ")", null);
313 finish();
314 }
315 }));
316
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100317 if (canPlaceCallsTo && !isSipNumber && !isVoicemailNumber) {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100318 // "Edit the number before calling" is only available for PSTN numbers.
319 actions.add(new ViewEntry(android.R.drawable.sym_action_call,
320 getString(R.string.recentCalls_editNumberBeforeCall),
321 new Intent(Intent.ACTION_DIAL, numberCallUri)));
322 }
323
324 // Set the actions for this phone number.
325 setListAdapter(new ViewAdapter(this, actions));
326
327 ListView historyList = (ListView) findViewById(R.id.history);
328 historyList.setAdapter(
329 new CallDetailHistoryAdapter(this, mInflater, mCallTypeHelper, details));
Daniel Lehmann362654a2011-07-17 14:16:47 -0700330 loadContactPhotos(photoUri);
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100331 }
332
333 /** Return the phone call details for a given call log URI. */
334 private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800335 ContentResolver resolver = getContentResolver();
336 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
337 try {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100338 if (callCursor == null || !callCursor.moveToFirst()) {
339 throw new IllegalArgumentException("Cannot find content: " + callUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800340 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100341
342 // Read call log specifics.
343 String number = callCursor.getString(NUMBER_COLUMN_INDEX);
344 long date = callCursor.getLong(DATE_COLUMN_INDEX);
345 long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
346 int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
347 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
348 if (TextUtils.isEmpty(countryIso)) {
349 countryIso = mDefaultCountryIso;
350 }
351
352 // Formatted phone number.
353 final CharSequence numberText;
354 // Read contact specifics.
355 CharSequence nameText = "";
356 int numberType = 0;
357 CharSequence numberLabel = "";
358 long personId = -1L;
Daniel Lehmann362654a2011-07-17 14:16:47 -0700359 Uri photoUri = null;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100360 // If this is not a regular number, there is no point in looking it up in the contacts.
361 if (!mPhoneNumberHelper.canPlaceCallsTo(number)) {
362 numberText = mPhoneNumberHelper.getDisplayNumber(number, null);
363 } else {
364 // Perform a reverse-phonebook lookup to find the contact details.
365 Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
366 Uri.encode(number));
367 Cursor phonesCursor = resolver.query(phoneUri, PHONES_PROJECTION, null, null, null);
368 String candidateNumberText = number;
369 try {
370 if (phonesCursor != null && phonesCursor.moveToFirst()) {
371 personId = phonesCursor.getLong(COLUMN_INDEX_ID);
372 nameText = phonesCursor.getString(COLUMN_INDEX_NAME);
Daniel Lehmann362654a2011-07-17 14:16:47 -0700373 String photoUriString = phonesCursor.getString(COLUMN_INDEX_PHOTO_URI);
374 photoUri = photoUriString == null ? null : Uri.parse(photoUriString);
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100375 candidateNumberText = PhoneNumberUtils.formatNumber(
376 phonesCursor.getString(COLUMN_INDEX_NUMBER),
377 phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER),
378 countryIso);
379 numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE);
380 numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL);
381 } else {
382 // We could not find this contact in the contacts, just format the phone
383 // number as best as we can. All the other fields will have their default
384 // values.
385 candidateNumberText =
386 PhoneNumberUtils.formatNumber(number, countryIso);
387 }
388 } finally {
389 if (phonesCursor != null) phonesCursor.close();
390 numberText = candidateNumberText;
391 }
392 }
393 return new PhoneCallDetails(number, numberText, new int[]{ callType }, date, duration,
Daniel Lehmann362654a2011-07-17 14:16:47 -0700394 nameText, numberType, numberLabel, personId, photoUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800395 } finally {
396 if (callCursor != null) {
397 callCursor.close();
398 }
399 }
400 }
401
Flavio Lerda9cafe472011-06-08 14:06:13 +0100402 /** Load the contact photos and places them in the corresponding views. */
Daniel Lehmann362654a2011-07-17 14:16:47 -0700403 private void loadContactPhotos(Uri photoUri) {
404 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100405 }
406
Flavio Lerda696e8132011-07-05 19:00:23 +0100407 private String getVoicemailNumber() {
408 TelephonyManager telephonyManager =
409 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
410 return telephonyManager.getVoiceMailNumber();
411 }
412
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800413 static final class ViewEntry {
Flavio Lerdaa8956882011-07-09 21:34:38 +0100414 public final int icon;
415 public final String text;
416 public final Intent intent;
417 public final View.OnClickListener action;
418
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800419 public String label = null;
420 public String number = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700421
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800422 public ViewEntry(int icon, String text, Intent intent) {
423 this.icon = icon;
424 this.text = text;
425 this.intent = intent;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100426 this.action = null;
427 }
428
429 public ViewEntry(int icon, String text, View.OnClickListener listener) {
430 this.icon = icon;
431 this.text = text;
432 this.intent = null;
433 this.action = listener;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800434 }
435 }
436
437 static final class ViewAdapter extends BaseAdapter {
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700438
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800439 private final List<ViewEntry> mActions;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700440
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800441 private final LayoutInflater mInflater;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700442
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800443 public ViewAdapter(Context context, List<ViewEntry> actions) {
444 mActions = actions;
445 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
446 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700447
Flavio Lerda9cafe472011-06-08 14:06:13 +0100448 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800449 public int getCount() {
450 return mActions.size();
451 }
452
Flavio Lerda9cafe472011-06-08 14:06:13 +0100453 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800454 public Object getItem(int position) {
455 return mActions.get(position);
456 }
457
Flavio Lerda9cafe472011-06-08 14:06:13 +0100458 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800459 public long getItemId(int position) {
460 return position;
461 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700462
Flavio Lerda9cafe472011-06-08 14:06:13 +0100463 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800464 public View getView(int position, View convertView, ViewGroup parent) {
465 // Make sure we have a valid convertView to start with
466 if (convertView == null) {
467 convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false);
468 }
469
470 // Fill action with icon and text.
471 ViewEntry entry = mActions.get(position);
472 convertView.setTag(entry);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700473
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800474 ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
475 TextView text = (TextView) convertView.findViewById(android.R.id.text1);
476
477 icon.setImageResource(entry.icon);
478 text.setText(entry.text);
479
480 View line2 = convertView.findViewById(R.id.line2);
481 boolean numberEmpty = TextUtils.isEmpty(entry.number);
482 boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty;
483 if (labelEmpty && numberEmpty) {
484 line2.setVisibility(View.GONE);
485 } else {
486 line2.setVisibility(View.VISIBLE);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700487
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800488 TextView label = (TextView) convertView.findViewById(R.id.label);
489 if (labelEmpty) {
490 label.setVisibility(View.GONE);
491 } else {
492 label.setText(entry.label);
493 label.setVisibility(View.VISIBLE);
494 }
495
496 TextView number = (TextView) convertView.findViewById(R.id.number);
497 number.setText(entry.number);
498 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700499
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800500 return convertView;
501 }
502 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700503
Flavio Lerda9cafe472011-06-08 14:06:13 +0100504 @Override
505 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800506 // Handle passing action off to correct handler.
507 if (view.getTag() instanceof ViewEntry) {
508 ViewEntry entry = (ViewEntry) view.getTag();
509 if (entry.intent != null) {
510 startActivity(entry.intent);
Flavio Lerdaa8956882011-07-09 21:34:38 +0100511 } else if (entry.action != null) {
512 entry.action.onClick(view);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800513 }
514 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700515 }
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -0800516
517 @Override
518 public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
519 boolean globalSearch) {
520 if (globalSearch) {
521 super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
522 } else {
523 ContactsSearchManager.startSearch(this, initialQuery);
524 }
525 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800526}