blob: 0931e3d760312e869c009b068c76d00a80b8391f [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 Lerda9cafe472011-06-08 14:06:13 +010019import com.android.contacts.format.FormatUtils;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -070020import com.android.internal.telephony.CallerInfo;
21
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080022import android.app.ListActivity;
23import android.content.ContentResolver;
24import android.content.ContentUris;
25import android.content.Context;
26import android.content.Intent;
27import android.content.res.Resources;
28import android.database.Cursor;
Flavio Lerda9cafe472011-06-08 14:06:13 +010029import android.graphics.Typeface;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080030import 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;
35import android.provider.ContactsContract.CommonDataKinds.Phone;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070036import android.provider.ContactsContract.Contacts;
37import android.provider.ContactsContract.PhoneLookup;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080038import android.telephony.PhoneNumberUtils;
39import android.telephony.TelephonyManager;
Flavio Lerda9cafe472011-06-08 14:06:13 +010040import android.text.Spanned;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080041import android.text.TextUtils;
42import android.text.format.DateUtils;
43import 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;
50import android.widget.TextView;
51import android.widget.Toast;
52
53import java.util.ArrayList;
54import java.util.List;
55
56/**
57 * Displays the details of a specific call log entry.
58 */
59public class CallDetailActivity extends ListActivity implements
60 AdapterView.OnItemClickListener {
61 private static final String TAG = "CallDetail";
62
Flavio Lerda9cafe472011-06-08 14:06:13 +010063 private TextView mNameView;
64 private TextView mCallTypeView;
65 private TextView mNumberView;
66 private TextView mCallTimeView;
67 private TextView mCallDurationView;
68 private View mCallActionView;
69 private ImageView mContactPhotoView;
70 private ImageView mContactBackgroundView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080071
72 private String mNumber = null;
Bai Tao09eb04f2010-09-01 15:34:16 +080073 private String mDefaultCountryIso;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070074
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080075 /* package */ LayoutInflater mInflater;
76 /* package */ Resources mResources;
Flavio Lerda9cafe472011-06-08 14:06:13 +010077 /** Helper to load contact photos. */
78 private ContactPhotoManager mContactPhotoManager;
79 /** Attached to the call action button in the UI. */
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070080
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080081 static final String[] CALL_LOG_PROJECTION = new String[] {
82 CallLog.Calls.DATE,
83 CallLog.Calls.DURATION,
84 CallLog.Calls.NUMBER,
85 CallLog.Calls.TYPE,
Bai Tao09eb04f2010-09-01 15:34:16 +080086 CallLog.Calls.COUNTRY_ISO,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080087 };
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070088
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080089 static final int DATE_COLUMN_INDEX = 0;
90 static final int DURATION_COLUMN_INDEX = 1;
91 static final int NUMBER_COLUMN_INDEX = 2;
92 static final int CALL_TYPE_COLUMN_INDEX = 3;
Bai Tao09eb04f2010-09-01 15:34:16 +080093 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070094
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080095 static final String[] PHONES_PROJECTION = new String[] {
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070096 PhoneLookup._ID,
97 PhoneLookup.DISPLAY_NAME,
98 PhoneLookup.TYPE,
99 PhoneLookup.LABEL,
100 PhoneLookup.NUMBER,
Bai Tao09eb04f2010-09-01 15:34:16 +0800101 PhoneLookup.NORMALIZED_NUMBER,
Flavio Lerda9cafe472011-06-08 14:06:13 +0100102 PhoneLookup.PHOTO_ID,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800103 };
104 static final int COLUMN_INDEX_ID = 0;
105 static final int COLUMN_INDEX_NAME = 1;
106 static final int COLUMN_INDEX_TYPE = 2;
107 static final int COLUMN_INDEX_LABEL = 3;
108 static final int COLUMN_INDEX_NUMBER = 4;
Bai Tao09eb04f2010-09-01 15:34:16 +0800109 static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100110 static final int COLUMN_INDEX_PHOTO_ID = 6;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800111
112 @Override
113 protected void onCreate(Bundle icicle) {
114 super.onCreate(icicle);
115
116 setContentView(R.layout.call_detail);
117
118 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
119 mResources = getResources();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700120
Flavio Lerda9cafe472011-06-08 14:06:13 +0100121 mNameView = (TextView) findViewById(R.id.name);
122 mCallTypeView = (TextView) findViewById(R.id.call_type);
123 mNumberView = (TextView) findViewById(R.id.number);
124 mCallActionView = findViewById(R.id.call);
125 mContactPhotoView = (ImageView) findViewById(R.id.contact_photo);
126 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);
132 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700133
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800134 @Override
135 public void onResume() {
136 super.onResume();
137 updateData(getIntent().getData());
138 }
139
140 @Override
141 public boolean onKeyDown(int keyCode, KeyEvent event) {
142 switch (keyCode) {
143 case KeyEvent.KEYCODE_CALL: {
144 // Make sure phone isn't already busy before starting direct call
145 TelephonyManager tm = (TelephonyManager)
146 getSystemService(Context.TELEPHONY_SERVICE);
147 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
148 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
149 Uri.fromParts("tel", mNumber, null));
150 startActivity(callIntent);
151 return true;
152 }
153 }
154 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700155
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800156 return super.onKeyDown(keyCode, event);
157 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700158
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800159 /**
160 * Update user interface with details of given call.
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700161 *
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800162 * @param callUri Uri into {@link CallLog.Calls}
163 */
164 private void updateData(Uri callUri) {
165 ContentResolver resolver = getContentResolver();
166 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
167 try {
168 if (callCursor != null && callCursor.moveToFirst()) {
169 // Read call log specifics
170 mNumber = callCursor.getString(NUMBER_COLUMN_INDEX);
171 long date = callCursor.getLong(DATE_COLUMN_INDEX);
172 long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
173 int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
Bai Tao09eb04f2010-09-01 15:34:16 +0800174 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
175 if (TextUtils.isEmpty(countryIso)) {
176 countryIso = mDefaultCountryIso;
177 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800178 // Pull out string in format [relative], [date]
179 CharSequence dateClause = DateUtils.formatDateRange(this, date, date,
180 DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE |
181 DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100182 mCallTimeView.setText(dateClause);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700183
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800184 // Set the duration
185 if (callType == Calls.MISSED_TYPE) {
Flavio Lerda9cafe472011-06-08 14:06:13 +0100186 mCallDurationView.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800187 } else {
Flavio Lerda9cafe472011-06-08 14:06:13 +0100188 mCallDurationView.setVisibility(View.VISIBLE);
189 mCallDurationView.setText(formatDuration(duration));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800190 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700191
Flavio Lerda9cafe472011-06-08 14:06:13 +0100192 CharSequence shortDateText =
193 DateUtils.getRelativeTimeSpanString(date,
194 System.currentTimeMillis(),
195 DateUtils.MINUTE_IN_MILLIS,
196 DateUtils.FORMAT_ABBREV_RELATIVE);
197
198 CharSequence callTypeText = "";
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800199 switch (callType) {
200 case Calls.INCOMING_TYPE:
Flavio Lerda9cafe472011-06-08 14:06:13 +0100201 callTypeText = getString(R.string.type_incoming);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800202 break;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700203
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800204 case Calls.OUTGOING_TYPE:
Flavio Lerda9cafe472011-06-08 14:06:13 +0100205 callTypeText = getString(R.string.type_outgoing);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800206 break;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700207
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800208 case Calls.MISSED_TYPE:
Flavio Lerda9cafe472011-06-08 14:06:13 +0100209 callTypeText = getString(R.string.type_missed);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800210 break;
211 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700212
Flavio Lerda9cafe472011-06-08 14:06:13 +0100213 mCallTypeView.setText(
214 getString(R.string.call_type_and_date,
215 FormatUtils.applyStyleToSpan(Typeface.BOLD,
216 callTypeText, 0, callTypeText.length(),
217 Spanned.SPAN_EXCLUSIVE_EXCLUSIVE),
218 shortDateText));
219
220 long photoId = 0L;
221 CharSequence nameText = "";
222 CharSequence numberText = "";
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700223 if (mNumber.equals(CallerInfo.UNKNOWN_NUMBER) ||
224 mNumber.equals(CallerInfo.PRIVATE_NUMBER)) {
Flavio Lerda9cafe472011-06-08 14:06:13 +0100225 nameText = getString(mNumber.equals(CallerInfo.PRIVATE_NUMBER)
226 ? R.string.private_num : R.string.unknown);
227 numberText = "";
228 mCallActionView.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800229 } else {
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700230 // Perform a reverse-phonebook lookup to find the PERSON_ID
Flavio Lerda9cafe472011-06-08 14:06:13 +0100231 CharSequence callLabel = null;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700232 Uri personUri = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700233 Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
234 Uri.encode(mNumber));
Flavio Lerda9cafe472011-06-08 14:06:13 +0100235 Cursor phonesCursor = resolver.query(
236 phoneUri, PHONES_PROJECTION, null, null, null);
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700237 try {
238 if (phonesCursor != null && phonesCursor.moveToFirst()) {
239 long personId = phonesCursor.getLong(COLUMN_INDEX_ID);
240 personUri = ContentUris.withAppendedId(
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700241 Contacts.CONTENT_URI, personId);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100242 nameText = phonesCursor.getString(COLUMN_INDEX_NAME);
243 photoId = phonesCursor.getLong(COLUMN_INDEX_PHOTO_ID);
Sang-il, Lee177c77f2010-03-09 20:37:19 +0900244 mNumber = PhoneNumberUtils.formatNumber(
Bai Tao09eb04f2010-09-01 15:34:16 +0800245 phonesCursor.getString(COLUMN_INDEX_NUMBER),
246 phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER),
247 countryIso);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100248 callLabel = Phone.getTypeLabel(getResources(),
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700249 phonesCursor.getInt(COLUMN_INDEX_TYPE),
Flavio Lerda9cafe472011-06-08 14:06:13 +0100250 phonesCursor.getString(COLUMN_INDEX_LABEL));
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700251 } else {
Bai Tao09eb04f2010-09-01 15:34:16 +0800252 mNumber = PhoneNumberUtils.formatNumber(mNumber, countryIso);
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700253 }
254 } finally {
Flavio Lerda9cafe472011-06-08 14:06:13 +0100255 if (phonesCursor != null) phonesCursor.close();
256 }
257
258 mCallActionView.setVisibility(View.VISIBLE);
259 mCallActionView.setOnClickListener(new View.OnClickListener() {
260 @Override
261 public void onClick(View v) {
262 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
263 Uri.fromParts("tel", mNumber, null));
264 startActivity(callIntent);
265 }
266 });
267
268 if (callLabel != null) {
269 numberText = FormatUtils.applyStyleToSpan(Typeface.BOLD,
270 callLabel + " " + mNumber, 0,
271 callLabel.length(),
272 Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
273 } else {
274 numberText = mNumber;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700275 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700276
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700277 // Build list of various available actions
278 List<ViewEntry> actions = new ArrayList<ViewEntry>();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700279
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700280 Intent smsIntent = new Intent(Intent.ACTION_SENDTO,
281 Uri.fromParts("sms", mNumber, null));
282 actions.add(new ViewEntry(R.drawable.sym_action_sms,
283 getString(R.string.menu_sendTextMessage), smsIntent));
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700284
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700285 // Let user view contact details if they exist, otherwise add option
286 // to create new contact from this number.
287 if (personUri != null) {
288 Intent viewIntent = new Intent(Intent.ACTION_VIEW, personUri);
289 actions.add(new ViewEntry(R.drawable.sym_action_view_contact,
290 getString(R.string.menu_viewContact), viewIntent));
291 } else {
292 Intent createIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700293 createIntent.setType(Contacts.CONTENT_ITEM_TYPE);
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700294 createIntent.putExtra(Insert.PHONE, mNumber);
295 actions.add(new ViewEntry(R.drawable.sym_action_add,
296 getString(R.string.recentCalls_addToContact), createIntent));
297 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700298
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700299 ViewAdapter adapter = new ViewAdapter(this, actions);
300 setListAdapter(adapter);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800301 }
Flavio Lerda9cafe472011-06-08 14:06:13 +0100302 mNameView.setText(nameText);
303 mNumberView.setText(numberText);
304
305 loadContactPhotos(photoId);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800306 } else {
307 // Something went wrong reading in our primary data, so we're going to
308 // bail out and show error to users.
309 Toast.makeText(this, R.string.toast_call_detail_error,
310 Toast.LENGTH_SHORT).show();
311 finish();
312 }
313 } finally {
314 if (callCursor != null) {
315 callCursor.close();
316 }
317 }
318 }
319
Flavio Lerda9cafe472011-06-08 14:06:13 +0100320 /** Load the contact photos and places them in the corresponding views. */
321 private void loadContactPhotos(final long photoId) {
322 // There seem to be a limitation in the ContactPhotoManager that does not allow requesting
323 // two photos at once.
324 // TODO: Figure out the problem with ContactPhotoManager and remove this nonsense.
325 mContactPhotoView.post(new Runnable() {
326 @Override
327 public void run() {
328 mContactPhotoManager.loadPhoto(mContactPhotoView, photoId);
329 mContactPhotoView.postDelayed(new Runnable() {
330 @Override
331 public void run() {
332 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoId);
333 }
334 }, 100);
335 }
336 });
337 }
338
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800339 private String formatDuration(long elapsedSeconds) {
340 long minutes = 0;
341 long seconds = 0;
342
343 if (elapsedSeconds >= 60) {
344 minutes = elapsedSeconds / 60;
345 elapsedSeconds -= minutes * 60;
346 }
347 seconds = elapsedSeconds;
348
349 return getString(R.string.callDetailsDurationFormat, minutes, seconds);
350 }
351
352 static final class ViewEntry {
353 public int icon = -1;
354 public String text = null;
355 public Intent intent = null;
356 public String label = null;
357 public String number = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700358
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800359 public ViewEntry(int icon, String text, Intent intent) {
360 this.icon = icon;
361 this.text = text;
362 this.intent = intent;
363 }
364 }
365
366 static final class ViewAdapter extends BaseAdapter {
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700367
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800368 private final List<ViewEntry> mActions;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700369
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800370 private final LayoutInflater mInflater;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700371
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800372 public ViewAdapter(Context context, List<ViewEntry> actions) {
373 mActions = actions;
374 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
375 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700376
Flavio Lerda9cafe472011-06-08 14:06:13 +0100377 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800378 public int getCount() {
379 return mActions.size();
380 }
381
Flavio Lerda9cafe472011-06-08 14:06:13 +0100382 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800383 public Object getItem(int position) {
384 return mActions.get(position);
385 }
386
Flavio Lerda9cafe472011-06-08 14:06:13 +0100387 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800388 public long getItemId(int position) {
389 return position;
390 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700391
Flavio Lerda9cafe472011-06-08 14:06:13 +0100392 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800393 public View getView(int position, View convertView, ViewGroup parent) {
394 // Make sure we have a valid convertView to start with
395 if (convertView == null) {
396 convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false);
397 }
398
399 // Fill action with icon and text.
400 ViewEntry entry = mActions.get(position);
401 convertView.setTag(entry);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700402
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800403 ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
404 TextView text = (TextView) convertView.findViewById(android.R.id.text1);
405
406 icon.setImageResource(entry.icon);
407 text.setText(entry.text);
408
409 View line2 = convertView.findViewById(R.id.line2);
410 boolean numberEmpty = TextUtils.isEmpty(entry.number);
411 boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty;
412 if (labelEmpty && numberEmpty) {
413 line2.setVisibility(View.GONE);
414 } else {
415 line2.setVisibility(View.VISIBLE);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700416
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800417 TextView label = (TextView) convertView.findViewById(R.id.label);
418 if (labelEmpty) {
419 label.setVisibility(View.GONE);
420 } else {
421 label.setText(entry.label);
422 label.setVisibility(View.VISIBLE);
423 }
424
425 TextView number = (TextView) convertView.findViewById(R.id.number);
426 number.setText(entry.number);
427 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700428
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800429 return convertView;
430 }
431 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700432
Flavio Lerda9cafe472011-06-08 14:06:13 +0100433 @Override
434 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800435 // Handle passing action off to correct handler.
436 if (view.getTag() instanceof ViewEntry) {
437 ViewEntry entry = (ViewEntry) view.getTag();
438 if (entry.intent != null) {
439 startActivity(entry.intent);
440 }
441 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700442 }
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -0800443
444 @Override
445 public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
446 boolean globalSearch) {
447 if (globalSearch) {
448 super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
449 } else {
450 ContactsSearchManager.startSearch(this, initialQuery);
451 }
452 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800453}