blob: 138ce25d2b2a1fdec2e88d51af16fe2be8e5b488 [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
Amith Yamasani8bbe2f22009-03-24 21:24:12 -070019import com.android.internal.telephony.CallerInfo;
20
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080021import android.app.ListActivity;
22import android.content.ContentResolver;
23import android.content.ContentUris;
24import android.content.Context;
25import android.content.Intent;
26import android.content.res.Resources;
27import android.database.Cursor;
28import android.net.Uri;
29import android.os.Bundle;
30import android.provider.CallLog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080031import android.provider.CallLog.Calls;
Flavio Lerda9cafe472011-06-08 14:06:13 +010032import android.provider.Contacts.Intents.Insert;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070033import android.provider.ContactsContract.Contacts;
34import android.provider.ContactsContract.PhoneLookup;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080035import android.telephony.PhoneNumberUtils;
36import android.telephony.TelephonyManager;
37import android.text.TextUtils;
38import android.text.format.DateUtils;
39import android.view.KeyEvent;
40import android.view.LayoutInflater;
41import android.view.View;
42import android.view.ViewGroup;
43import android.widget.AdapterView;
44import android.widget.BaseAdapter;
45import android.widget.ImageView;
46import android.widget.TextView;
47import android.widget.Toast;
48
49import java.util.ArrayList;
50import java.util.List;
51
52/**
53 * Displays the details of a specific call log entry.
54 */
55public class CallDetailActivity extends ListActivity implements
56 AdapterView.OnItemClickListener {
57 private static final String TAG = "CallDetail";
58
Flavio Lerdaa024c3f2011-06-10 10:47:07 +010059 /** The views representing the details of a phone call. */
Flavio Lerdaafb93bb2011-07-05 14:46:10 +010060 private PhoneCallDetailsViews mPhoneCallDetailsViews;
61 private PhoneCallDetailsHelper mPhoneCallDetailsHelper;
Flavio Lerda9cafe472011-06-08 14:06:13 +010062 private TextView mCallTimeView;
63 private TextView mCallDurationView;
Flavio Lerdafb63c432011-07-07 17:16:53 +010064 private View mHomeActionView;
65 private ImageView mMainActionView;
Flavio Lerda9cafe472011-06-08 14:06:13 +010066 private ImageView mContactBackgroundView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080067
68 private String mNumber = null;
Bai Tao09eb04f2010-09-01 15:34:16 +080069 private String mDefaultCountryIso;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070070
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080071 /* package */ LayoutInflater mInflater;
72 /* package */ Resources mResources;
Flavio Lerda9cafe472011-06-08 14:06:13 +010073 /** Helper to load contact photos. */
74 private ContactPhotoManager mContactPhotoManager;
75 /** Attached to the call action button in the UI. */
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070076
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080077 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 Tao09eb04f2010-09-01 15:34:16 +080082 CallLog.Calls.COUNTRY_ISO,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080083 };
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070084
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080085 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 Tao09eb04f2010-09-01 15:34:16 +080089 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070090
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080091 static final String[] PHONES_PROJECTION = new String[] {
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070092 PhoneLookup._ID,
93 PhoneLookup.DISPLAY_NAME,
94 PhoneLookup.TYPE,
95 PhoneLookup.LABEL,
96 PhoneLookup.NUMBER,
Bai Tao09eb04f2010-09-01 15:34:16 +080097 PhoneLookup.NORMALIZED_NUMBER,
Flavio Lerda9cafe472011-06-08 14:06:13 +010098 PhoneLookup.PHOTO_ID,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080099 };
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 Tao09eb04f2010-09-01 15:34:16 +0800105 static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100106 static final int COLUMN_INDEX_PHOTO_ID = 6;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800107
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 Plotnikovd0d776d2009-08-19 17:38:04 -0700116
Flavio Lerda696e8132011-07-05 19:00:23 +0100117 mPhoneCallDetailsViews = PhoneCallDetailsViews.fromView(getWindow().getDecorView());
Flavio Lerda7d7473a2011-07-06 14:21:46 +0100118 mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(this, getResources(),
119 getVoicemailNumber(),
120 getResources().getDrawable(R.drawable.ic_call_log_list_incoming_call),
121 getResources().getDrawable(R.drawable.ic_call_log_list_outgoing_call),
122 getResources().getDrawable(R.drawable.ic_call_log_list_missed_call),
123 getResources().getDrawable(R.drawable.ic_call_log_list_voicemail));
Flavio Lerdafb63c432011-07-07 17:16:53 +0100124 mHomeActionView = findViewById(R.id.action_bar_home);
125 mMainActionView = (ImageView) findViewById(R.id.main_action);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100126 mContactBackgroundView = (ImageView) findViewById(R.id.contact_background);
127 mCallTimeView = (TextView) findViewById(R.id.time);
128 mCallDurationView = (TextView) findViewById(R.id.duration);
Bai Tao09eb04f2010-09-01 15:34:16 +0800129 mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100130 mContactPhotoManager = ContactPhotoManager.getInstance(this);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800131 getListView().setOnItemClickListener(this);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100132 mHomeActionView.setOnClickListener(new View.OnClickListener() {
133 @Override
134 public void onClick(View v) {
135 // We want this to start the call log if this activity was not started from the
136 // call log itself.
137 CallDetailActivity.this.finish();
138 }
139 });
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800140 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700141
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800142 @Override
143 public void onResume() {
144 super.onResume();
145 updateData(getIntent().getData());
146 }
147
148 @Override
149 public boolean onKeyDown(int keyCode, KeyEvent event) {
150 switch (keyCode) {
151 case KeyEvent.KEYCODE_CALL: {
152 // Make sure phone isn't already busy before starting direct call
153 TelephonyManager tm = (TelephonyManager)
154 getSystemService(Context.TELEPHONY_SERVICE);
155 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
156 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
157 Uri.fromParts("tel", mNumber, null));
158 startActivity(callIntent);
159 return true;
160 }
161 }
162 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700163
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800164 return super.onKeyDown(keyCode, event);
165 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700166
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800167 /**
168 * Update user interface with details of given call.
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700169 *
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800170 * @param callUri Uri into {@link CallLog.Calls}
171 */
Flavio Lerdaa8956882011-07-09 21:34:38 +0100172 private void updateData(final Uri callUri) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800173 ContentResolver resolver = getContentResolver();
174 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
175 try {
176 if (callCursor != null && callCursor.moveToFirst()) {
177 // Read call log specifics
178 mNumber = callCursor.getString(NUMBER_COLUMN_INDEX);
179 long date = callCursor.getLong(DATE_COLUMN_INDEX);
180 long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
181 int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
Bai Tao09eb04f2010-09-01 15:34:16 +0800182 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
183 if (TextUtils.isEmpty(countryIso)) {
184 countryIso = mDefaultCountryIso;
185 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800186 // Pull out string in format [relative], [date]
187 CharSequence dateClause = DateUtils.formatDateRange(this, date, date,
188 DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE |
189 DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100190 mCallTimeView.setText(dateClause);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700191
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800192 // Set the duration
193 if (callType == Calls.MISSED_TYPE) {
Flavio Lerda9cafe472011-06-08 14:06:13 +0100194 mCallDurationView.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800195 } else {
Flavio Lerda9cafe472011-06-08 14:06:13 +0100196 mCallDurationView.setVisibility(View.VISIBLE);
197 mCallDurationView.setText(formatDuration(duration));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800198 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700199
Flavio Lerda9cafe472011-06-08 14:06:13 +0100200 long photoId = 0L;
201 CharSequence nameText = "";
Flavio Lerdaa024c3f2011-06-10 10:47:07 +0100202 final CharSequence numberText;
203 int numberType = 0;
204 CharSequence numberLabel = "";
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700205 if (mNumber.equals(CallerInfo.UNKNOWN_NUMBER) ||
206 mNumber.equals(CallerInfo.PRIVATE_NUMBER)) {
Flavio Lerdaa024c3f2011-06-10 10:47:07 +0100207 numberText = getString(mNumber.equals(CallerInfo.PRIVATE_NUMBER)
Flavio Lerda9cafe472011-06-08 14:06:13 +0100208 ? R.string.private_num : R.string.unknown);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100209 mMainActionView.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800210 } else {
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700211 // Perform a reverse-phonebook lookup to find the PERSON_ID
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700212 Uri personUri = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700213 Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
214 Uri.encode(mNumber));
Flavio Lerda9cafe472011-06-08 14:06:13 +0100215 Cursor phonesCursor = resolver.query(
216 phoneUri, PHONES_PROJECTION, null, null, null);
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700217 try {
218 if (phonesCursor != null && phonesCursor.moveToFirst()) {
219 long personId = phonesCursor.getLong(COLUMN_INDEX_ID);
220 personUri = ContentUris.withAppendedId(
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700221 Contacts.CONTENT_URI, personId);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100222 nameText = phonesCursor.getString(COLUMN_INDEX_NAME);
223 photoId = phonesCursor.getLong(COLUMN_INDEX_PHOTO_ID);
Sang-il, Lee177c77f2010-03-09 20:37:19 +0900224 mNumber = PhoneNumberUtils.formatNumber(
Bai Tao09eb04f2010-09-01 15:34:16 +0800225 phonesCursor.getString(COLUMN_INDEX_NUMBER),
226 phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER),
227 countryIso);
Flavio Lerdaa024c3f2011-06-10 10:47:07 +0100228 numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE);
229 numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL);
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700230 } else {
Bai Tao09eb04f2010-09-01 15:34:16 +0800231 mNumber = PhoneNumberUtils.formatNumber(mNumber, countryIso);
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700232 }
233 } finally {
Flavio Lerda9cafe472011-06-08 14:06:13 +0100234 if (phonesCursor != null) phonesCursor.close();
235 }
Flavio Lerdaa024c3f2011-06-10 10:47:07 +0100236 numberText = mNumber;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100237
Flavio Lerdafb63c432011-07-07 17:16:53 +0100238 // Let user view contact details if they exist, otherwise add option
239 // to create new contact from this number.
240 final Intent mainActionIntent;
241 final int mainActionIcon;
242 if (personUri != null) {
243 mainActionIntent = new Intent(Intent.ACTION_VIEW, personUri);
244 mainActionIcon = R.drawable.sym_action_view_contact;
245 } else {
246 mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
247 mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE);
248 mainActionIntent.putExtra(Insert.PHONE, mNumber);
249 mainActionIcon = R.drawable.sym_action_add;
250 }
251
252 mMainActionView.setVisibility(View.VISIBLE);
253 mMainActionView.setImageResource(mainActionIcon);
254 mMainActionView.setOnClickListener(new View.OnClickListener() {
Flavio Lerda9cafe472011-06-08 14:06:13 +0100255 @Override
256 public void onClick(View v) {
Flavio Lerdafb63c432011-07-07 17:16:53 +0100257 startActivity(mainActionIntent);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100258 }
259 });
260
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700261 // Build list of various available actions
262 List<ViewEntry> actions = new ArrayList<ViewEntry>();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700263
Flavio Lerdafb63c432011-07-07 17:16:53 +0100264 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
265 Uri.fromParts("tel", mNumber, null));
266 actions.add(new ViewEntry(android.R.drawable.sym_action_call,
267 getString(R.string.menu_callNumber, mNumber), callIntent));
268
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700269 Intent smsIntent = new Intent(Intent.ACTION_SENDTO,
270 Uri.fromParts("sms", mNumber, null));
271 actions.add(new ViewEntry(R.drawable.sym_action_sms,
272 getString(R.string.menu_sendTextMessage), smsIntent));
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700273
Flavio Lerdaa8956882011-07-09 21:34:38 +0100274 actions.add(new ViewEntry(android.R.drawable.ic_menu_close_clear_cancel,
275 getString(R.string.recentCalls_removeFromRecentList),
276 new View.OnClickListener() {
277 @Override
278 public void onClick(View v) {
279 long id = ContentUris.parseId(callUri);
280 getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
281 Calls._ID + " = ?", new String[]{Long.toString(id)});
282 finish();
283 }
284 }));
285
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700286 ViewAdapter adapter = new ViewAdapter(this, actions);
287 setListAdapter(adapter);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800288 }
Flavio Lerdad72bf8a2011-07-05 16:00:09 +0100289 mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews, date, callType,
290 nameText, numberText, numberType, numberLabel);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100291
292 loadContactPhotos(photoId);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800293 } else {
294 // Something went wrong reading in our primary data, so we're going to
295 // bail out and show error to users.
296 Toast.makeText(this, R.string.toast_call_detail_error,
297 Toast.LENGTH_SHORT).show();
298 finish();
299 }
300 } finally {
301 if (callCursor != null) {
302 callCursor.close();
303 }
304 }
305 }
306
Flavio Lerda9cafe472011-06-08 14:06:13 +0100307 /** Load the contact photos and places them in the corresponding views. */
308 private void loadContactPhotos(final long photoId) {
Flavio Lerdafb63c432011-07-07 17:16:53 +0100309 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoId);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100310 }
311
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800312 private String formatDuration(long elapsedSeconds) {
313 long minutes = 0;
314 long seconds = 0;
315
316 if (elapsedSeconds >= 60) {
317 minutes = elapsedSeconds / 60;
318 elapsedSeconds -= minutes * 60;
319 }
320 seconds = elapsedSeconds;
321
322 return getString(R.string.callDetailsDurationFormat, minutes, seconds);
323 }
324
Flavio Lerda696e8132011-07-05 19:00:23 +0100325 private String getVoicemailNumber() {
326 TelephonyManager telephonyManager =
327 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
328 return telephonyManager.getVoiceMailNumber();
329 }
330
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800331 static final class ViewEntry {
Flavio Lerdaa8956882011-07-09 21:34:38 +0100332 public final int icon;
333 public final String text;
334 public final Intent intent;
335 public final View.OnClickListener action;
336
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800337 public String label = null;
338 public String number = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700339
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800340 public ViewEntry(int icon, String text, Intent intent) {
341 this.icon = icon;
342 this.text = text;
343 this.intent = intent;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100344 this.action = null;
345 }
346
347 public ViewEntry(int icon, String text, View.OnClickListener listener) {
348 this.icon = icon;
349 this.text = text;
350 this.intent = null;
351 this.action = listener;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800352 }
353 }
354
355 static final class ViewAdapter extends BaseAdapter {
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700356
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800357 private final List<ViewEntry> mActions;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700358
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800359 private final LayoutInflater mInflater;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700360
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800361 public ViewAdapter(Context context, List<ViewEntry> actions) {
362 mActions = actions;
363 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
364 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700365
Flavio Lerda9cafe472011-06-08 14:06:13 +0100366 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800367 public int getCount() {
368 return mActions.size();
369 }
370
Flavio Lerda9cafe472011-06-08 14:06:13 +0100371 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800372 public Object getItem(int position) {
373 return mActions.get(position);
374 }
375
Flavio Lerda9cafe472011-06-08 14:06:13 +0100376 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800377 public long getItemId(int position) {
378 return position;
379 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700380
Flavio Lerda9cafe472011-06-08 14:06:13 +0100381 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800382 public View getView(int position, View convertView, ViewGroup parent) {
383 // Make sure we have a valid convertView to start with
384 if (convertView == null) {
385 convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false);
386 }
387
388 // Fill action with icon and text.
389 ViewEntry entry = mActions.get(position);
390 convertView.setTag(entry);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700391
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800392 ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
393 TextView text = (TextView) convertView.findViewById(android.R.id.text1);
394
395 icon.setImageResource(entry.icon);
396 text.setText(entry.text);
397
398 View line2 = convertView.findViewById(R.id.line2);
399 boolean numberEmpty = TextUtils.isEmpty(entry.number);
400 boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty;
401 if (labelEmpty && numberEmpty) {
402 line2.setVisibility(View.GONE);
403 } else {
404 line2.setVisibility(View.VISIBLE);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700405
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800406 TextView label = (TextView) convertView.findViewById(R.id.label);
407 if (labelEmpty) {
408 label.setVisibility(View.GONE);
409 } else {
410 label.setText(entry.label);
411 label.setVisibility(View.VISIBLE);
412 }
413
414 TextView number = (TextView) convertView.findViewById(R.id.number);
415 number.setText(entry.number);
416 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700417
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800418 return convertView;
419 }
420 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700421
Flavio Lerda9cafe472011-06-08 14:06:13 +0100422 @Override
423 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800424 // Handle passing action off to correct handler.
425 if (view.getTag() instanceof ViewEntry) {
426 ViewEntry entry = (ViewEntry) view.getTag();
427 if (entry.intent != null) {
428 startActivity(entry.intent);
Flavio Lerdaa8956882011-07-09 21:34:38 +0100429 } else if (entry.action != null) {
430 entry.action.onClick(view);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800431 }
432 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700433 }
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -0800434
435 @Override
436 public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
437 boolean globalSearch) {
438 if (globalSearch) {
439 super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
440 } else {
441 ContactsSearchManager.startSearch(this, initialQuery);
442 }
443 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800444}