blob: bf5d8aacb6fa809ddb702716cba8f90f1ce14178 [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,
Flavio Lerda9cafe472011-06-08 14:06:13 +0100106 PhoneLookup.PHOTO_ID,
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;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100114 static final int COLUMN_INDEX_PHOTO_ID = 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 Lerda7d7473a2011-07-06 14:21:46 +0100127 getResources().getDrawable(R.drawable.ic_call_log_list_incoming_call),
128 getResources().getDrawable(R.drawable.ic_call_log_list_outgoing_call),
129 getResources().getDrawable(R.drawable.ic_call_log_list_missed_call),
130 getResources().getDrawable(R.drawable.ic_call_log_list_voicemail));
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;
223 final long photoId = details[0].photoId;
224
225 // Set the details header, based on the first phone call.
226 mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews,
227 details[0], false);
228
229 // Let user view contact details if they exist, otherwise add option to create new contact
230 // from this number.
231 final Intent mainActionIntent;
232 final int mainActionIcon;
233
234 if (details[0].personId != -1) {
235 Uri personUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, personId);
236 mainActionIntent = new Intent(Intent.ACTION_VIEW, personUri);
237 mainActionIcon = R.drawable.sym_action_view_contact;
238 } else {
239 mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
240 mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE);
241 mainActionIntent.putExtra(Insert.PHONE, mNumber);
242 mainActionIcon = R.drawable.sym_action_add;
243 }
244
245 mMainActionView.setVisibility(View.VISIBLE);
246 mMainActionView.setImageResource(mainActionIcon);
247 mMainActionView.setOnClickListener(new View.OnClickListener() {
248 @Override
249 public void onClick(View v) {
250 startActivity(mainActionIntent);
251 }
252 });
253
254 // Build list of various available actions.
255 final List<ViewEntry> actions = new ArrayList<ViewEntry>();
256
257 final boolean isSipNumber = PhoneNumberUtils.isUriNumber(mNumber);
258 final Uri numberCallUri = mPhoneNumberHelper.getCallUri(mNumber);
259
260 // This action allows to call the number that places the call.
261 if (mPhoneNumberHelper.canPlaceCallsTo(mNumber)) {
262 actions.add(new ViewEntry(android.R.drawable.sym_action_call,
263 getString(R.string.menu_callNumber, mNumber),
264 new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri)));
265 }
266
267 if (!isSipNumber) {
268 // SMS is only available for PSTN numbers.
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));
273 }
274
275 // This action deletes all elements in the group from the call log.
276 actions.add(new ViewEntry(android.R.drawable.ic_menu_close_clear_cancel,
277 getString(R.string.recentCalls_removeFromRecentList),
278 new View.OnClickListener() {
279 @Override
280 public void onClick(View v) {
281 StringBuilder callIds = new StringBuilder();
282 for (Uri callUri : callUris) {
283 if (callIds.length() != 0) {
284 callIds.append(",");
285 }
286 callIds.append(ContentUris.parseId(callUri));
287 }
288
289 getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
290 Calls._ID + " IN (" + callIds + ")", null);
291 finish();
292 }
293 }));
294
295 if (!isSipNumber) {
296 // "Edit the number before calling" is only available for PSTN numbers.
297 actions.add(new ViewEntry(android.R.drawable.sym_action_call,
298 getString(R.string.recentCalls_editNumberBeforeCall),
299 new Intent(Intent.ACTION_DIAL, numberCallUri)));
300 }
301
302 // Set the actions for this phone number.
303 setListAdapter(new ViewAdapter(this, actions));
304
305 ListView historyList = (ListView) findViewById(R.id.history);
306 historyList.setAdapter(
307 new CallDetailHistoryAdapter(this, mInflater, mCallTypeHelper, details));
308 loadContactPhotos(photoId);
309 }
310
311 /** Return the phone call details for a given call log URI. */
312 private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800313 ContentResolver resolver = getContentResolver();
314 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
315 try {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100316 if (callCursor == null || !callCursor.moveToFirst()) {
317 throw new IllegalArgumentException("Cannot find content: " + callUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800318 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100319
320 // Read call log specifics.
321 String number = callCursor.getString(NUMBER_COLUMN_INDEX);
322 long date = callCursor.getLong(DATE_COLUMN_INDEX);
323 long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
324 int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
325 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
326 if (TextUtils.isEmpty(countryIso)) {
327 countryIso = mDefaultCountryIso;
328 }
329
330 // Formatted phone number.
331 final CharSequence numberText;
332 // Read contact specifics.
333 CharSequence nameText = "";
334 int numberType = 0;
335 CharSequence numberLabel = "";
336 long personId = -1L;
337 long photoId = 0L;
338 // If this is not a regular number, there is no point in looking it up in the contacts.
339 if (!mPhoneNumberHelper.canPlaceCallsTo(number)) {
340 numberText = mPhoneNumberHelper.getDisplayNumber(number, null);
341 } else {
342 // Perform a reverse-phonebook lookup to find the contact details.
343 Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
344 Uri.encode(number));
345 Cursor phonesCursor = resolver.query(phoneUri, PHONES_PROJECTION, null, null, null);
346 String candidateNumberText = number;
347 try {
348 if (phonesCursor != null && phonesCursor.moveToFirst()) {
349 personId = phonesCursor.getLong(COLUMN_INDEX_ID);
350 nameText = phonesCursor.getString(COLUMN_INDEX_NAME);
351 photoId = phonesCursor.getLong(COLUMN_INDEX_PHOTO_ID);
352 candidateNumberText = PhoneNumberUtils.formatNumber(
353 phonesCursor.getString(COLUMN_INDEX_NUMBER),
354 phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER),
355 countryIso);
356 numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE);
357 numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL);
358 } else {
359 // We could not find this contact in the contacts, just format the phone
360 // number as best as we can. All the other fields will have their default
361 // values.
362 candidateNumberText =
363 PhoneNumberUtils.formatNumber(number, countryIso);
364 }
365 } finally {
366 if (phonesCursor != null) phonesCursor.close();
367 numberText = candidateNumberText;
368 }
369 }
370 return new PhoneCallDetails(number, numberText, new int[]{ callType }, date, duration,
371 nameText, numberType, numberLabel, personId, photoId);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800372 } finally {
373 if (callCursor != null) {
374 callCursor.close();
375 }
376 }
377 }
378
Flavio Lerda9cafe472011-06-08 14:06:13 +0100379 /** Load the contact photos and places them in the corresponding views. */
380 private void loadContactPhotos(final long photoId) {
Flavio Lerdafb63c432011-07-07 17:16:53 +0100381 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoId);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100382 }
383
Flavio Lerda696e8132011-07-05 19:00:23 +0100384 private String getVoicemailNumber() {
385 TelephonyManager telephonyManager =
386 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
387 return telephonyManager.getVoiceMailNumber();
388 }
389
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800390 static final class ViewEntry {
Flavio Lerdaa8956882011-07-09 21:34:38 +0100391 public final int icon;
392 public final String text;
393 public final Intent intent;
394 public final View.OnClickListener action;
395
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800396 public String label = null;
397 public String number = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700398
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800399 public ViewEntry(int icon, String text, Intent intent) {
400 this.icon = icon;
401 this.text = text;
402 this.intent = intent;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100403 this.action = null;
404 }
405
406 public ViewEntry(int icon, String text, View.OnClickListener listener) {
407 this.icon = icon;
408 this.text = text;
409 this.intent = null;
410 this.action = listener;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800411 }
412 }
413
414 static final class ViewAdapter extends BaseAdapter {
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700415
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800416 private final List<ViewEntry> mActions;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700417
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800418 private final LayoutInflater mInflater;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700419
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800420 public ViewAdapter(Context context, List<ViewEntry> actions) {
421 mActions = actions;
422 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
423 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700424
Flavio Lerda9cafe472011-06-08 14:06:13 +0100425 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800426 public int getCount() {
427 return mActions.size();
428 }
429
Flavio Lerda9cafe472011-06-08 14:06:13 +0100430 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800431 public Object getItem(int position) {
432 return mActions.get(position);
433 }
434
Flavio Lerda9cafe472011-06-08 14:06:13 +0100435 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800436 public long getItemId(int position) {
437 return position;
438 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700439
Flavio Lerda9cafe472011-06-08 14:06:13 +0100440 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800441 public View getView(int position, View convertView, ViewGroup parent) {
442 // Make sure we have a valid convertView to start with
443 if (convertView == null) {
444 convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false);
445 }
446
447 // Fill action with icon and text.
448 ViewEntry entry = mActions.get(position);
449 convertView.setTag(entry);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700450
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800451 ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
452 TextView text = (TextView) convertView.findViewById(android.R.id.text1);
453
454 icon.setImageResource(entry.icon);
455 text.setText(entry.text);
456
457 View line2 = convertView.findViewById(R.id.line2);
458 boolean numberEmpty = TextUtils.isEmpty(entry.number);
459 boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty;
460 if (labelEmpty && numberEmpty) {
461 line2.setVisibility(View.GONE);
462 } else {
463 line2.setVisibility(View.VISIBLE);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700464
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800465 TextView label = (TextView) convertView.findViewById(R.id.label);
466 if (labelEmpty) {
467 label.setVisibility(View.GONE);
468 } else {
469 label.setText(entry.label);
470 label.setVisibility(View.VISIBLE);
471 }
472
473 TextView number = (TextView) convertView.findViewById(R.id.number);
474 number.setText(entry.number);
475 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700476
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800477 return convertView;
478 }
479 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700480
Flavio Lerda9cafe472011-06-08 14:06:13 +0100481 @Override
482 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800483 // Handle passing action off to correct handler.
484 if (view.getTag() instanceof ViewEntry) {
485 ViewEntry entry = (ViewEntry) view.getTag();
486 if (entry.intent != null) {
487 startActivity(entry.intent);
Flavio Lerdaa8956882011-07-09 21:34:38 +0100488 } else if (entry.action != null) {
489 entry.action.onClick(view);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800490 }
491 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700492 }
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -0800493
494 @Override
495 public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
496 boolean globalSearch) {
497 if (globalSearch) {
498 super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
499 } else {
500 ContactsSearchManager.startSearch(this, initialQuery);
501 }
502 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800503}