blob: ca17e7ba79a8a9e2b93ff43029d02cd1a454856c [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;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -070021import com.android.internal.telephony.CallerInfo;
22
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;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080040import android.view.KeyEvent;
41import android.view.LayoutInflater;
42import android.view.View;
43import android.view.ViewGroup;
44import android.widget.AdapterView;
45import android.widget.BaseAdapter;
46import android.widget.ImageView;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010047import android.widget.ListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080048import android.widget.TextView;
49import android.widget.Toast;
50
51import java.util.ArrayList;
52import java.util.List;
53
54/**
55 * Displays the details of a specific call log entry.
56 */
57public class CallDetailActivity extends ListActivity implements
58 AdapterView.OnItemClickListener {
59 private static final String TAG = "CallDetail";
60
Flavio Lerdaa024c3f2011-06-10 10:47:07 +010061 /** The views representing the details of a phone call. */
Flavio Lerdaafb93bb2011-07-05 14:46:10 +010062 private PhoneCallDetailsViews mPhoneCallDetailsViews;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010063 private CallTypeHelper mCallTypeHelper;
Flavio Lerdaafb93bb2011-07-05 14:46:10 +010064 private PhoneCallDetailsHelper mPhoneCallDetailsHelper;
Flavio Lerdafb63c432011-07-07 17:16:53 +010065 private View mHomeActionView;
66 private ImageView mMainActionView;
Flavio Lerda9cafe472011-06-08 14:06:13 +010067 private ImageView mContactBackgroundView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080068
69 private String mNumber = null;
Bai Tao09eb04f2010-09-01 15:34:16 +080070 private String mDefaultCountryIso;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070071
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080072 /* package */ LayoutInflater mInflater;
73 /* package */ Resources mResources;
Flavio Lerda9cafe472011-06-08 14:06:13 +010074 /** Helper to load contact photos. */
75 private ContactPhotoManager mContactPhotoManager;
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 Lerda9a208cc2011-07-12 21:05:47 +0100118 mCallTypeHelper = new CallTypeHelper(getResources(),
Flavio Lerda7d7473a2011-07-06 14:21:46 +0100119 getResources().getDrawable(R.drawable.ic_call_log_list_incoming_call),
120 getResources().getDrawable(R.drawable.ic_call_log_list_outgoing_call),
121 getResources().getDrawable(R.drawable.ic_call_log_list_missed_call),
122 getResources().getDrawable(R.drawable.ic_call_log_list_voicemail));
Flavio Lerda9a208cc2011-07-12 21:05:47 +0100123 mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(this, getResources(),
124 getVoicemailNumber(), mCallTypeHelper);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100125 mHomeActionView = findViewById(R.id.action_bar_home);
126 mMainActionView = (ImageView) findViewById(R.id.main_action);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100127 mContactBackgroundView = (ImageView) findViewById(R.id.contact_background);
Bai Tao09eb04f2010-09-01 15:34:16 +0800128 mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100129 mContactPhotoManager = ContactPhotoManager.getInstance(this);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800130 getListView().setOnItemClickListener(this);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100131 mHomeActionView.setOnClickListener(new View.OnClickListener() {
132 @Override
133 public void onClick(View v) {
134 // We want this to start the call log if this activity was not started from the
135 // call log itself.
136 CallDetailActivity.this.finish();
137 }
138 });
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800139 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700140
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800141 @Override
142 public void onResume() {
143 super.onResume();
144 updateData(getIntent().getData());
145 }
146
147 @Override
148 public boolean onKeyDown(int keyCode, KeyEvent event) {
149 switch (keyCode) {
150 case KeyEvent.KEYCODE_CALL: {
151 // Make sure phone isn't already busy before starting direct call
152 TelephonyManager tm = (TelephonyManager)
153 getSystemService(Context.TELEPHONY_SERVICE);
154 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
155 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
156 Uri.fromParts("tel", mNumber, null));
157 startActivity(callIntent);
158 return true;
159 }
160 }
161 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700162
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800163 return super.onKeyDown(keyCode, event);
164 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700165
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800166 /**
167 * Update user interface with details of given call.
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700168 *
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800169 * @param callUri Uri into {@link CallLog.Calls}
170 */
Flavio Lerdaa8956882011-07-09 21:34:38 +0100171 private void updateData(final Uri callUri) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800172 ContentResolver resolver = getContentResolver();
173 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
174 try {
175 if (callCursor != null && callCursor.moveToFirst()) {
176 // Read call log specifics
177 mNumber = callCursor.getString(NUMBER_COLUMN_INDEX);
178 long date = callCursor.getLong(DATE_COLUMN_INDEX);
179 long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
180 int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
Bai Tao09eb04f2010-09-01 15:34:16 +0800181 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
182 if (TextUtils.isEmpty(countryIso)) {
183 countryIso = mDefaultCountryIso;
184 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700185
Flavio Lerda9cafe472011-06-08 14:06:13 +0100186 long photoId = 0L;
187 CharSequence nameText = "";
Flavio Lerdaa024c3f2011-06-10 10:47:07 +0100188 final CharSequence numberText;
189 int numberType = 0;
190 CharSequence numberLabel = "";
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700191 if (mNumber.equals(CallerInfo.UNKNOWN_NUMBER) ||
192 mNumber.equals(CallerInfo.PRIVATE_NUMBER)) {
Flavio Lerdaa024c3f2011-06-10 10:47:07 +0100193 numberText = getString(mNumber.equals(CallerInfo.PRIVATE_NUMBER)
Flavio Lerda9cafe472011-06-08 14:06:13 +0100194 ? R.string.private_num : R.string.unknown);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100195 mMainActionView.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800196 } else {
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700197 // Perform a reverse-phonebook lookup to find the PERSON_ID
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700198 Uri personUri = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700199 Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
200 Uri.encode(mNumber));
Flavio Lerda9cafe472011-06-08 14:06:13 +0100201 Cursor phonesCursor = resolver.query(
202 phoneUri, PHONES_PROJECTION, null, null, null);
Flavio Lerda175b3812011-07-09 20:06:57 +0100203 String candidateNumberText = mNumber;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700204 try {
205 if (phonesCursor != null && phonesCursor.moveToFirst()) {
206 long personId = phonesCursor.getLong(COLUMN_INDEX_ID);
207 personUri = ContentUris.withAppendedId(
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700208 Contacts.CONTENT_URI, personId);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100209 nameText = phonesCursor.getString(COLUMN_INDEX_NAME);
210 photoId = phonesCursor.getLong(COLUMN_INDEX_PHOTO_ID);
Flavio Lerda175b3812011-07-09 20:06:57 +0100211 candidateNumberText = PhoneNumberUtils.formatNumber(
Bai Tao09eb04f2010-09-01 15:34:16 +0800212 phonesCursor.getString(COLUMN_INDEX_NUMBER),
213 phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER),
214 countryIso);
Flavio Lerdaa024c3f2011-06-10 10:47:07 +0100215 numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE);
216 numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL);
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700217 } else {
Flavio Lerda175b3812011-07-09 20:06:57 +0100218 candidateNumberText =
219 PhoneNumberUtils.formatNumber(mNumber, countryIso);
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700220 }
221 } finally {
Flavio Lerda175b3812011-07-09 20:06:57 +0100222 if (phonesCursor != null) phonesCursor.close();
223 numberText = candidateNumberText;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100224 }
225
Flavio Lerdafb63c432011-07-07 17:16:53 +0100226 // Let user view contact details if they exist, otherwise add option
227 // to create new contact from this number.
228 final Intent mainActionIntent;
229 final int mainActionIcon;
230 if (personUri != null) {
231 mainActionIntent = new Intent(Intent.ACTION_VIEW, personUri);
232 mainActionIcon = R.drawable.sym_action_view_contact;
233 } else {
234 mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
235 mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE);
236 mainActionIntent.putExtra(Insert.PHONE, mNumber);
237 mainActionIcon = R.drawable.sym_action_add;
238 }
239
240 mMainActionView.setVisibility(View.VISIBLE);
241 mMainActionView.setImageResource(mainActionIcon);
242 mMainActionView.setOnClickListener(new View.OnClickListener() {
Flavio Lerda9cafe472011-06-08 14:06:13 +0100243 @Override
244 public void onClick(View v) {
Flavio Lerdafb63c432011-07-07 17:16:53 +0100245 startActivity(mainActionIntent);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100246 }
247 });
248
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700249 // Build list of various available actions
250 List<ViewEntry> actions = new ArrayList<ViewEntry>();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700251
Flavio Lerda1a1361f2011-07-09 23:45:32 +0100252 final boolean isSipNumber = PhoneNumberUtils.isUriNumber(mNumber);
253 final Uri numberCallUri;
254 if (isSipNumber) {
255 numberCallUri = Uri.fromParts("sip", mNumber, null);
256 } else {
257 numberCallUri = Uri.fromParts("tel", mNumber, null);
258 }
Flavio Lerdafb63c432011-07-07 17:16:53 +0100259
Flavio Lerda1a1361f2011-07-09 23:45:32 +0100260 actions.add(new ViewEntry(android.R.drawable.sym_action_call,
261 getString(R.string.menu_callNumber, mNumber),
262 new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri)));
263
264 if (!isSipNumber) {
265 Intent smsIntent = new Intent(Intent.ACTION_SENDTO,
266 Uri.fromParts("sms", mNumber, null));
267 actions.add(new ViewEntry(R.drawable.sym_action_sms,
268 getString(R.string.menu_sendTextMessage), smsIntent));
269 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700270
Flavio Lerdaa8956882011-07-09 21:34:38 +0100271 actions.add(new ViewEntry(android.R.drawable.ic_menu_close_clear_cancel,
272 getString(R.string.recentCalls_removeFromRecentList),
273 new View.OnClickListener() {
274 @Override
275 public void onClick(View v) {
276 long id = ContentUris.parseId(callUri);
277 getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
278 Calls._ID + " = ?", new String[]{Long.toString(id)});
279 finish();
280 }
281 }));
282
Flavio Lerda1a1361f2011-07-09 23:45:32 +0100283 if (!isSipNumber) {
284 actions.add(new ViewEntry(android.R.drawable.sym_action_call,
285 getString(R.string.recentCalls_editNumberBeforeCall),
286 new Intent(Intent.ACTION_DIAL, numberCallUri)));
287 }
288
Amith Yamasani8bbe2f22009-03-24 21:24:12 -0700289 ViewAdapter adapter = new ViewAdapter(this, actions);
290 setListAdapter(adapter);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800291 }
Flavio Lerda9a208cc2011-07-12 21:05:47 +0100292 PhoneCallDetails details = new PhoneCallDetails(mNumber, numberText,
293 new int[]{ callType }, duration, date, nameText, numberType, numberLabel);
Flavio Lerda9de38682011-07-08 20:38:07 +0100294 mPhoneCallDetailsHelper.setPhoneCallDetails(mPhoneCallDetailsViews,
Flavio Lerda9a208cc2011-07-12 21:05:47 +0100295 details, false);
296 ListView historyList = (ListView) findViewById(R.id.history);
297 historyList.setAdapter(
298 new CallDetailHistoryAdapter(this, mInflater, mCallTypeHelper,
299 new PhoneCallDetails[]{ details }));
Flavio Lerda9cafe472011-06-08 14:06:13 +0100300
301 loadContactPhotos(photoId);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800302 } else {
303 // Something went wrong reading in our primary data, so we're going to
304 // bail out and show error to users.
305 Toast.makeText(this, R.string.toast_call_detail_error,
306 Toast.LENGTH_SHORT).show();
307 finish();
308 }
309 } finally {
310 if (callCursor != null) {
311 callCursor.close();
312 }
313 }
314 }
315
Flavio Lerda9cafe472011-06-08 14:06:13 +0100316 /** Load the contact photos and places them in the corresponding views. */
317 private void loadContactPhotos(final long photoId) {
Flavio Lerdafb63c432011-07-07 17:16:53 +0100318 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoId);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100319 }
320
Flavio Lerda696e8132011-07-05 19:00:23 +0100321 private String getVoicemailNumber() {
322 TelephonyManager telephonyManager =
323 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
324 return telephonyManager.getVoiceMailNumber();
325 }
326
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800327 static final class ViewEntry {
Flavio Lerdaa8956882011-07-09 21:34:38 +0100328 public final int icon;
329 public final String text;
330 public final Intent intent;
331 public final View.OnClickListener action;
332
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800333 public String label = null;
334 public String number = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700335
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800336 public ViewEntry(int icon, String text, Intent intent) {
337 this.icon = icon;
338 this.text = text;
339 this.intent = intent;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100340 this.action = null;
341 }
342
343 public ViewEntry(int icon, String text, View.OnClickListener listener) {
344 this.icon = icon;
345 this.text = text;
346 this.intent = null;
347 this.action = listener;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800348 }
349 }
350
351 static final class ViewAdapter extends BaseAdapter {
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700352
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800353 private final List<ViewEntry> mActions;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700354
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800355 private final LayoutInflater mInflater;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700356
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800357 public ViewAdapter(Context context, List<ViewEntry> actions) {
358 mActions = actions;
359 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
360 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700361
Flavio Lerda9cafe472011-06-08 14:06:13 +0100362 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800363 public int getCount() {
364 return mActions.size();
365 }
366
Flavio Lerda9cafe472011-06-08 14:06:13 +0100367 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800368 public Object getItem(int position) {
369 return mActions.get(position);
370 }
371
Flavio Lerda9cafe472011-06-08 14:06:13 +0100372 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800373 public long getItemId(int position) {
374 return position;
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 View getView(int position, View convertView, ViewGroup parent) {
379 // Make sure we have a valid convertView to start with
380 if (convertView == null) {
381 convertView = mInflater.inflate(R.layout.call_detail_list_item, parent, false);
382 }
383
384 // Fill action with icon and text.
385 ViewEntry entry = mActions.get(position);
386 convertView.setTag(entry);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700387
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800388 ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
389 TextView text = (TextView) convertView.findViewById(android.R.id.text1);
390
391 icon.setImageResource(entry.icon);
392 text.setText(entry.text);
393
394 View line2 = convertView.findViewById(R.id.line2);
395 boolean numberEmpty = TextUtils.isEmpty(entry.number);
396 boolean labelEmpty = TextUtils.isEmpty(entry.label) || numberEmpty;
397 if (labelEmpty && numberEmpty) {
398 line2.setVisibility(View.GONE);
399 } else {
400 line2.setVisibility(View.VISIBLE);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700401
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800402 TextView label = (TextView) convertView.findViewById(R.id.label);
403 if (labelEmpty) {
404 label.setVisibility(View.GONE);
405 } else {
406 label.setText(entry.label);
407 label.setVisibility(View.VISIBLE);
408 }
409
410 TextView number = (TextView) convertView.findViewById(R.id.number);
411 number.setText(entry.number);
412 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700413
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800414 return convertView;
415 }
416 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700417
Flavio Lerda9cafe472011-06-08 14:06:13 +0100418 @Override
419 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800420 // Handle passing action off to correct handler.
421 if (view.getTag() instanceof ViewEntry) {
422 ViewEntry entry = (ViewEntry) view.getTag();
423 if (entry.intent != null) {
424 startActivity(entry.intent);
Flavio Lerdaa8956882011-07-09 21:34:38 +0100425 } else if (entry.action != null) {
426 entry.action.onClick(view);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800427 }
428 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700429 }
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -0800430
431 @Override
432 public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
433 boolean globalSearch) {
434 if (globalSearch) {
435 super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
436 } else {
437 ContactsSearchManager.startSearch(this, initialQuery);
438 }
439 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800440}