blob: 0a967bd1c9f14cb3d76e3893ec3ef6edd81f759d [file] [log] [blame]
Daniel Lehmann4cd94412010-04-08 16:44:36 -07001/*
2 * Copyright (C) 2010 Google Inc.
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.views.detail;
18
19import com.android.contacts.Collapser;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070020import com.android.contacts.ContactOptionsActivity;
21import com.android.contacts.ContactPresenceIconUtil;
22import com.android.contacts.ContactsUtils;
23import com.android.contacts.R;
24import com.android.contacts.TypePrecedence;
25import com.android.contacts.Collapser.Collapsible;
26import com.android.contacts.model.ContactsSource;
27import com.android.contacts.model.Sources;
28import com.android.contacts.model.ContactsSource.DataKind;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070029import com.android.contacts.util.Constants;
30import com.android.contacts.util.DataStatus;
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070031import com.android.contacts.views.ContactLoader;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070032import com.android.internal.telephony.ITelephony;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070033
Daniel Lehmann25a02822010-05-11 15:52:43 -070034import android.app.Activity;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070035import android.app.AlertDialog;
36import android.app.Dialog;
Jeff Hamilton3c462912010-05-15 02:20:01 -050037import android.app.LoaderManagingFragment;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070038import android.content.ActivityNotFoundException;
39import android.content.ContentUris;
40import android.content.ContentValues;
41import android.content.Context;
42import android.content.DialogInterface;
43import android.content.Entity;
44import android.content.Intent;
Jeff Hamilton3c462912010-05-15 02:20:01 -050045import android.content.Loader;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070046import android.content.Entity.NamedContentValues;
47import android.content.res.Resources;
48import android.graphics.drawable.Drawable;
49import android.net.ParseException;
50import android.net.Uri;
51import android.net.WebAddress;
52import android.os.Bundle;
53import android.os.RemoteException;
54import android.os.ServiceManager;
55import android.provider.ContactsContract.CommonDataKinds;
56import android.provider.ContactsContract.Contacts;
57import android.provider.ContactsContract.Data;
58import android.provider.ContactsContract.DisplayNameSources;
59import android.provider.ContactsContract.RawContacts;
60import android.provider.ContactsContract.StatusUpdates;
61import android.provider.ContactsContract.CommonDataKinds.Email;
62import android.provider.ContactsContract.CommonDataKinds.Im;
63import android.provider.ContactsContract.CommonDataKinds.Nickname;
64import android.provider.ContactsContract.CommonDataKinds.Note;
65import android.provider.ContactsContract.CommonDataKinds.Organization;
66import android.provider.ContactsContract.CommonDataKinds.Phone;
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070067import android.provider.ContactsContract.CommonDataKinds.StructuredName;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070068import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
69import android.provider.ContactsContract.CommonDataKinds.Website;
70import android.telephony.PhoneNumberUtils;
71import android.text.TextUtils;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070072import android.util.Log;
73import android.view.ContextMenu;
74import android.view.KeyEvent;
75import android.view.LayoutInflater;
76import android.view.Menu;
77import android.view.MenuInflater;
78import android.view.MenuItem;
79import android.view.View;
80import android.view.ViewGroup;
81import android.view.ContextMenu.ContextMenuInfo;
Daniel Lehmannc2687c32010-04-19 18:20:44 -070082import android.view.View.OnClickListener;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070083import android.view.View.OnCreateContextMenuListener;
84import android.widget.AdapterView;
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070085import android.widget.BaseAdapter;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070086import android.widget.ImageView;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070087import android.widget.ListView;
88import android.widget.TextView;
89import android.widget.Toast;
90import android.widget.AdapterView.OnItemClickListener;
91
92import java.util.ArrayList;
93
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070094public class ContactDetailFragment extends LoaderManagingFragment<ContactLoader.Result>
Daniel Lehmann18f104f2010-05-07 15:41:11 -070095 implements OnCreateContextMenuListener, OnItemClickListener {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070096 private static final String TAG = "ContactDetailFragment";
Daniel Lehmann4cd94412010-04-08 16:44:36 -070097
Daniel Lehmann4cd94412010-04-08 16:44:36 -070098 private static final int MENU_ITEM_MAKE_DEFAULT = 3;
99
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700100 private static final int LOADER_DETAILS = 1;
101
Daniel Lehmann25a02822010-05-11 15:52:43 -0700102 private Context mContext;
103 private Uri mLookupUri;
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700104 private Listener mListener;
Daniel Lehmannc2687c32010-04-19 18:20:44 -0700105
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700106 private ContactLoader.Result mContactData;
107 private ContactDetailHeaderView mHeaderView;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700108 private ListView mListView;
109 private boolean mShowSmsLinksForAllPhones;
110 private ViewAdapter mAdapter;
111 private Uri mPrimaryPhoneUri = null;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700112
113 private int mReadOnlySourcesCnt;
114 private int mWritableSourcesCnt;
115 private boolean mAllRestricted;
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700116 private final ArrayList<Long> mWritableRawContactIds = new ArrayList<Long>();
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700117 private int mNumPhoneNumbers = 0;
118
119 /**
120 * The view shown if the detail list is empty.
121 * We set this to the list view when first bind the adapter, so that it won't be shown while
122 * we're loading data.
123 */
124 private View mEmptyView;
125
126 /**
127 * A list of distinct contact IDs included in the current contact.
128 */
129 private ArrayList<Long> mRawContactIds = new ArrayList<Long>();
130 private ArrayList<ViewEntry> mPhoneEntries = new ArrayList<ViewEntry>();
131 private ArrayList<ViewEntry> mSmsEntries = new ArrayList<ViewEntry>();
132 private ArrayList<ViewEntry> mEmailEntries = new ArrayList<ViewEntry>();
133 private ArrayList<ViewEntry> mPostalEntries = new ArrayList<ViewEntry>();
134 private ArrayList<ViewEntry> mImEntries = new ArrayList<ViewEntry>();
135 private ArrayList<ViewEntry> mNicknameEntries = new ArrayList<ViewEntry>();
136 private ArrayList<ViewEntry> mOrganizationEntries = new ArrayList<ViewEntry>();
137 private ArrayList<ViewEntry> mGroupEntries = new ArrayList<ViewEntry>();
138 private ArrayList<ViewEntry> mOtherEntries = new ArrayList<ViewEntry>();
139 private ArrayList<ArrayList<ViewEntry>> mSections = new ArrayList<ArrayList<ViewEntry>>();
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700140 private LayoutInflater mInflater;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700141
Daniel Lehmann25a02822010-05-11 15:52:43 -0700142 public ContactDetailFragment() {
143 // Explicit constructor for inflation
Daniel Lehmannc2687c32010-04-19 18:20:44 -0700144
145 // Build the list of sections. The order they're added to mSections dictates the
146 // order they are displayed in the list.
147 mSections.add(mPhoneEntries);
148 mSections.add(mSmsEntries);
149 mSections.add(mEmailEntries);
150 mSections.add(mImEntries);
151 mSections.add(mPostalEntries);
152 mSections.add(mNicknameEntries);
153 mSections.add(mOrganizationEntries);
154 mSections.add(mGroupEntries);
155 mSections.add(mOtherEntries);
Daniel Lehmann25a02822010-05-11 15:52:43 -0700156 }
157
158 @Override
159 public void onAttach(Activity activity) {
160 super.onAttach(activity);
161 mContext = activity;
162 }
163
164 @Override
Dianne Hackborn84df2b62010-05-12 19:04:42 -0700165 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700166 final View view = inflater.inflate(R.layout.contact_detail_fragment, container, false);
Daniel Lehmann25a02822010-05-11 15:52:43 -0700167
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700168 mInflater = inflater;
169
170 mHeaderView = (ContactDetailHeaderView) view.findViewById(R.id.contact_header_widget);
171 mHeaderView.showStar(true);
172 mHeaderView.setExcludeMimes(new String[] {
Daniel Lehmann25a02822010-05-11 15:52:43 -0700173 Contacts.CONTENT_ITEM_TYPE
174 });
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700175 mHeaderView.setListener(mHeaderViewListener);
Daniel Lehmann25a02822010-05-11 15:52:43 -0700176
177 mListView = (ListView) view.findViewById(android.R.id.list);
178 mListView.setOnCreateContextMenuListener(this);
179 mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
180 mListView.setOnItemClickListener(this);
181 // Don't set it to mListView yet. We do so later when we bind the adapter.
182 mEmptyView = view.findViewById(android.R.id.empty);
183
Daniel Lehmannc2687c32010-04-19 18:20:44 -0700184 //TODO Read this value from a preference
185 mShowSmsLinksForAllPhones = true;
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700186
Daniel Lehmann25a02822010-05-11 15:52:43 -0700187 return view;
188 }
189
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700190 public void setListener(Listener value) {
191 mListener = value;
Daniel Lehmann25a02822010-05-11 15:52:43 -0700192 }
193
194 public void loadUri(Uri lookupUri) {
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700195 mLookupUri = lookupUri;
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700196 startLoading(LOADER_DETAILS, null);
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700197 }
198
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700199 @Override
200 protected void onInitializeLoaders() {
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700201 }
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700202
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700203 @Override
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700204 protected Loader<ContactLoader.Result> onCreateLoader(int id, Bundle args) {
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700205 switch (id) {
206 case LOADER_DETAILS: {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700207 return new ContactLoader(mContext, mLookupUri);
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700208 }
209 default: {
210 Log.wtf(TAG, "Unknown ID in onCreateLoader: " + id);
211 }
212 }
213 return null;
214 }
215
216 @Override
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700217 protected void onLoadFinished(Loader<ContactLoader.Result> loader,
218 ContactLoader.Result data) {
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700219 final int id = loader.getId();
220 switch (id) {
221 case LOADER_DETAILS:
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700222 if (data == ContactLoader.Result.NOT_FOUND) {
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700223 // Item has been deleted
224 Log.i(TAG, "No contact found. Closing activity");
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700225 mListener.onContactNotFound();
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700226 return;
227 }
228 mContactData = data;
229 bindData();
230 break;
231 default: {
232 Log.wtf(TAG, "Unknown ID in onLoadFinished: " + id);
233 }
234 }
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700235 }
236
237 private void bindData() {
Daniel Lehmannd3e0cdb2010-04-19 13:45:53 -0700238 // Set the header
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700239 mHeaderView.setContactUri(mContactData.getLookupUri());
240 mHeaderView.setDisplayName(mContactData.getDisplayName(),
Daniel Lehmannd3e0cdb2010-04-19 13:45:53 -0700241 mContactData.getPhoneticName());
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700242 mHeaderView.setPhotoId(mContactData.getPhotoId(), mContactData.getLookupUri());
243 mHeaderView.setStared(mContactData.getStarred());
244 mHeaderView.setPresence(mContactData.getPresence());
245 mHeaderView.setStatus(
Daniel Lehmannd3e0cdb2010-04-19 13:45:53 -0700246 mContactData.getStatus(), mContactData.getStatusTimestamp(),
247 mContactData.getStatusLabel(), mContactData.getStatusResPackage());
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700248
249 // Build up the contact entries
250 buildEntries();
251
252 // Collapse similar data items in select sections.
253 Collapser.collapseList(mPhoneEntries);
254 Collapser.collapseList(mSmsEntries);
255 Collapser.collapseList(mEmailEntries);
256 Collapser.collapseList(mPostalEntries);
257 Collapser.collapseList(mImEntries);
258
259 if (mAdapter == null) {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700260 mAdapter = new ViewAdapter();
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700261 mListView.setAdapter(mAdapter);
262 } else {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700263 mAdapter.notifyDataSetChanged();
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700264 }
265 mListView.setEmptyView(mEmptyView);
266 }
267
268 /**
269 * Build up the entries to display on the screen.
270 */
271 private final void buildEntries() {
272 // Clear out the old entries
273 final int numSections = mSections.size();
274 for (int i = 0; i < numSections; i++) {
275 mSections.get(i).clear();
276 }
277
278 mRawContactIds.clear();
279
280 mReadOnlySourcesCnt = 0;
281 mWritableSourcesCnt = 0;
282 mAllRestricted = true;
283 mPrimaryPhoneUri = null;
284 mNumPhoneNumbers = 0;
285
286 mWritableRawContactIds.clear();
287
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700288 // TODO: This should be done in the background thread
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700289 final Sources sources = Sources.getInstance(mContext);
290
291 // Build up method entries
292 if (mContactData == null) {
293 return;
294 }
295
296 for (Entity entity: mContactData.getEntities()) {
297 final ContentValues entValues = entity.getEntityValues();
298 final String accountType = entValues.getAsString(RawContacts.ACCOUNT_TYPE);
299 final long rawContactId = entValues.getAsLong(RawContacts._ID);
300
301 // Mark when this contact has any unrestricted components
302 final boolean isRestricted = entValues.getAsInteger(RawContacts.IS_RESTRICTED) != 0;
303 if (!isRestricted) mAllRestricted = false;
304
305 if (!mRawContactIds.contains(rawContactId)) {
306 mRawContactIds.add(rawContactId);
307 }
308 ContactsSource contactsSource = sources.getInflatedSource(accountType,
309 ContactsSource.LEVEL_SUMMARY);
310 if (contactsSource != null && contactsSource.readOnly) {
311 mReadOnlySourcesCnt += 1;
312 } else {
313 mWritableSourcesCnt += 1;
314 mWritableRawContactIds.add(rawContactId);
315 }
316
317
318 for (NamedContentValues subValue : entity.getSubValues()) {
319 final ContentValues entryValues = subValue.values;
320 entryValues.put(Data.RAW_CONTACT_ID, rawContactId);
321
322 final long dataId = entryValues.getAsLong(Data._ID);
323 final String mimeType = entryValues.getAsString(Data.MIMETYPE);
324 if (mimeType == null) continue;
325
326 final DataKind kind = sources.getKindOrFallback(accountType, mimeType, mContext,
327 ContactsSource.LEVEL_MIMETYPES);
328 if (kind == null) continue;
329
330 final ViewEntry entry = ViewEntry.fromValues(mContext, mimeType, kind,
331 rawContactId, dataId, entryValues);
332
333 final boolean hasData = !TextUtils.isEmpty(entry.data);
334 final boolean isSuperPrimary = entryValues.getAsInteger(
335 Data.IS_SUPER_PRIMARY) != 0;
336
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700337 if (StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)) {
338 // Always ignore the name. It is shown in the header if set
339 } else if (Phone.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700340 // Build phone entries
341 mNumPhoneNumbers++;
342
343 entry.intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
344 Uri.fromParts(Constants.SCHEME_TEL, entry.data, null));
345 entry.secondaryIntent = new Intent(Intent.ACTION_SENDTO,
346 Uri.fromParts(Constants.SCHEME_SMSTO, entry.data, null));
347
348 // Remember super-primary phone
349 if (isSuperPrimary) mPrimaryPhoneUri = entry.uri;
350
351 entry.isPrimary = isSuperPrimary;
352 mPhoneEntries.add(entry);
353
354 if (entry.type == CommonDataKinds.Phone.TYPE_MOBILE
355 || mShowSmsLinksForAllPhones) {
356 // Add an SMS entry
357 if (kind.iconAltRes > 0) {
358 entry.secondaryActionIcon = kind.iconAltRes;
359 }
360 }
361 } else if (Email.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
362 // Build email entries
363 entry.intent = new Intent(Intent.ACTION_SENDTO,
364 Uri.fromParts(Constants.SCHEME_MAILTO, entry.data, null));
365 entry.isPrimary = isSuperPrimary;
366 mEmailEntries.add(entry);
367
368 // When Email rows have status, create additional Im row
369 final DataStatus status = mContactData.getStatuses().get(entry.id);
370 if (status != null) {
371 final String imMime = Im.CONTENT_ITEM_TYPE;
372 final DataKind imKind = sources.getKindOrFallback(accountType,
373 imMime, mContext, ContactsSource.LEVEL_MIMETYPES);
374 final ViewEntry imEntry = ViewEntry.fromValues(mContext,
375 imMime, imKind, rawContactId, dataId, entryValues);
376 imEntry.intent = ContactsUtils.buildImIntent(entryValues);
377 imEntry.applyStatus(status, false);
378 mImEntries.add(imEntry);
379 }
380 } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
381 // Build postal entries
382 entry.maxLines = 4;
383 entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri);
384 mPostalEntries.add(entry);
385 } else if (Im.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
386 // Build IM entries
387 entry.intent = ContactsUtils.buildImIntent(entryValues);
388 if (TextUtils.isEmpty(entry.label)) {
389 entry.label = mContext.getString(R.string.chat).toLowerCase();
390 }
391
392 // Apply presence and status details when available
393 final DataStatus status = mContactData.getStatuses().get(entry.id);
394 if (status != null) {
395 entry.applyStatus(status, false);
396 }
397 mImEntries.add(entry);
398 } else if (Organization.CONTENT_ITEM_TYPE.equals(mimeType) &&
399 (hasData || !TextUtils.isEmpty(entry.label))) {
400 // Build organization entries
401 final boolean isNameRawContact =
402 (mContactData.getNameRawContactId() == rawContactId);
403
404 final boolean duplicatesTitle =
405 isNameRawContact
406 && mContactData.getDisplayNameSource()
407 == DisplayNameSources.ORGANIZATION
408 && (!hasData || TextUtils.isEmpty(entry.label));
409
410 if (!duplicatesTitle) {
411 entry.uri = null;
412
413 if (TextUtils.isEmpty(entry.label)) {
414 entry.label = entry.data;
415 entry.data = "";
416 }
417
418 mOrganizationEntries.add(entry);
419 }
420 } else if (Nickname.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
421 // Build nickname entries
422 final boolean isNameRawContact =
423 (mContactData.getNameRawContactId() == rawContactId);
424
425 final boolean duplicatesTitle =
426 isNameRawContact
427 && mContactData.getDisplayNameSource() == DisplayNameSources.NICKNAME;
428
429 if (!duplicatesTitle) {
430 entry.uri = null;
431 mNicknameEntries.add(entry);
432 }
433 } else if (Note.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
434 // Build note entries
435 entry.uri = null;
436 entry.maxLines = 100;
437 mOtherEntries.add(entry);
438 } else if (Website.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
439 // Build note entries
440 entry.uri = null;
441 entry.maxLines = 10;
442 try {
443 WebAddress webAddress = new WebAddress(entry.data);
444 entry.intent = new Intent(Intent.ACTION_VIEW,
445 Uri.parse(webAddress.toString()));
446 } catch (ParseException e) {
447 Log.e(TAG, "Couldn't parse website: " + entry.data);
448 }
449 mOtherEntries.add(entry);
450 } else {
451 // Handle showing custom rows
452 entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri);
453
454 // Use social summary when requested by external source
455 final DataStatus status = mContactData.getStatuses().get(entry.id);
456 final boolean hasSocial = kind.actionBodySocial && status != null;
457 if (hasSocial) {
458 entry.applyStatus(status, true);
459 }
460
461 if (hasSocial || hasData) {
462 mOtherEntries.add(entry);
463 }
464 }
465 }
466 }
467 }
468
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700469 private static String buildActionString(DataKind kind, ContentValues values,
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700470 boolean lowerCase, Context context) {
471 if (kind.actionHeader == null) {
472 return null;
473 }
474 CharSequence actionHeader = kind.actionHeader.inflateUsing(context, values);
475 if (actionHeader == null) {
476 return null;
477 }
478 return lowerCase ? actionHeader.toString().toLowerCase() : actionHeader.toString();
479 }
480
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700481 private static String buildDataString(DataKind kind, ContentValues values,
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700482 Context context) {
483 if (kind.actionBody == null) {
484 return null;
485 }
486 CharSequence actionBody = kind.actionBody.inflateUsing(context, values);
487 return actionBody == null ? null : actionBody.toString();
488 }
489
490 /**
491 * A basic structure with the data for a contact entry in the list.
492 */
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700493 private static class ViewEntry implements Collapsible<ViewEntry> {
494 // Copied from baseclass
495 public int type = -1;
496 public String label;
497 public String data;
498 public Uri uri;
499 public long id = 0;
500 public int maxLines = 1;
501 public String mimetype;
502
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700503 public Context context = null;
504 public String resPackageName = null;
505 public int actionIcon = -1;
506 public boolean isPrimary = false;
507 public int secondaryActionIcon = -1;
508 public Intent intent;
509 public Intent secondaryIntent = null;
510 public int maxLabelLines = 1;
511 public ArrayList<Long> ids = new ArrayList<Long>();
512 public int collapseCount = 0;
513
514 public int presence = -1;
515
516 public CharSequence footerLine = null;
517
518 private ViewEntry() {
519 }
520
521 /**
522 * Build new {@link ViewEntry} and populate from the given values.
523 */
524 public static ViewEntry fromValues(Context context, String mimeType, DataKind kind,
525 long rawContactId, long dataId, ContentValues values) {
526 final ViewEntry entry = new ViewEntry();
527 entry.context = context;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700528 entry.id = dataId;
529 entry.uri = ContentUris.withAppendedId(Data.CONTENT_URI, entry.id);
530 entry.mimetype = mimeType;
531 entry.label = buildActionString(kind, values, false, context);
532 entry.data = buildDataString(kind, values, context);
533
534 if (kind.typeColumn != null && values.containsKey(kind.typeColumn)) {
535 entry.type = values.getAsInteger(kind.typeColumn);
536 }
537 if (kind.iconRes > 0) {
538 entry.resPackageName = kind.resPackageName;
539 entry.actionIcon = kind.iconRes;
540 }
541
542 return entry;
543 }
544
545 /**
546 * Apply given {@link DataStatus} values over this {@link ViewEntry}
547 *
548 * @param fillData When true, the given status replaces {@link #data}
549 * and {@link #footerLine}. Otherwise only {@link #presence}
550 * is updated.
551 */
552 public ViewEntry applyStatus(DataStatus status, boolean fillData) {
553 presence = status.getPresence();
554 if (fillData && status.isValid()) {
555 this.data = status.getStatus().toString();
556 this.footerLine = status.getTimestampLabel(context);
557 }
558
559 return this;
560 }
561
562 public boolean collapseWith(ViewEntry entry) {
563 // assert equal collapse keys
564 if (!shouldCollapseWith(entry)) {
565 return false;
566 }
567
568 // Choose the label associated with the highest type precedence.
569 if (TypePrecedence.getTypePrecedence(mimetype, type)
570 > TypePrecedence.getTypePrecedence(entry.mimetype, entry.type)) {
571 type = entry.type;
572 label = entry.label;
573 }
574
575 // Choose the max of the maxLines and maxLabelLines values.
576 maxLines = Math.max(maxLines, entry.maxLines);
577 maxLabelLines = Math.max(maxLabelLines, entry.maxLabelLines);
578
579 // Choose the presence with the highest precedence.
580 if (StatusUpdates.getPresencePrecedence(presence)
581 < StatusUpdates.getPresencePrecedence(entry.presence)) {
582 presence = entry.presence;
583 }
584
585 // If any of the collapsed entries are primary make the whole thing primary.
586 isPrimary = entry.isPrimary ? true : isPrimary;
587
588 // uri, and contactdId, shouldn't make a difference. Just keep the original.
589
590 // Keep track of all the ids that have been collapsed with this one.
591 ids.add(entry.id);
592 collapseCount++;
593 return true;
594 }
595
596 public boolean shouldCollapseWith(ViewEntry entry) {
597 if (entry == null) {
598 return false;
599 }
600
601 if (!ContactsUtils.shouldCollapse(context, mimetype, data, entry.mimetype,
602 entry.data)) {
603 return false;
604 }
605
606 if (!TextUtils.equals(mimetype, entry.mimetype)
607 || !ContactsUtils.areIntentActionEqual(intent, entry.intent)
608 || !ContactsUtils.areIntentActionEqual(secondaryIntent, entry.secondaryIntent)
609 || actionIcon != entry.actionIcon) {
610 return false;
611 }
612
613 return true;
614 }
615 }
616
617 /** Cache of the children views of a row */
618 private static class ViewCache {
619 public TextView label;
620 public TextView data;
621 public TextView footer;
622 public ImageView actionIcon;
623 public ImageView presenceIcon;
624 public ImageView primaryIcon;
625 public ImageView secondaryActionButton;
626 public View secondaryActionDivider;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700627 }
628
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700629 private final class ViewAdapter extends BaseAdapter {
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700630 public View getView(int position, View convertView, ViewGroup parent) {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700631 final ViewEntry entry = getEntry(position);
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700632 final View v;
Daniel Lehmannc3a00082010-04-13 13:53:54 -0700633 final ViewCache viewCache;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700634
635 // Check to see if we can reuse convertView
636 if (convertView != null) {
637 v = convertView;
Daniel Lehmannc3a00082010-04-13 13:53:54 -0700638 viewCache = (ViewCache) v.getTag();
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700639 } else {
640 // Create a new view if needed
641 v = mInflater.inflate(R.layout.list_item_text_icons, parent, false);
642
643 // Cache the children
Daniel Lehmannc3a00082010-04-13 13:53:54 -0700644 viewCache = new ViewCache();
645 viewCache.label = (TextView) v.findViewById(android.R.id.text1);
646 viewCache.data = (TextView) v.findViewById(android.R.id.text2);
647 viewCache.footer = (TextView) v.findViewById(R.id.footer);
648 viewCache.actionIcon = (ImageView) v.findViewById(R.id.action_icon);
649 viewCache.primaryIcon = (ImageView) v.findViewById(R.id.primary_icon);
650 viewCache.presenceIcon = (ImageView) v.findViewById(R.id.presence_icon);
651 viewCache.secondaryActionButton = (ImageView) v.findViewById(
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700652 R.id.secondary_action_button);
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700653 viewCache.secondaryActionButton.setOnClickListener(mSecondaryActionClickListener);
Daniel Lehmannc3a00082010-04-13 13:53:54 -0700654 viewCache.secondaryActionDivider = v.findViewById(R.id.divider);
655 v.setTag(viewCache);
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700656 }
657
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700658 // Bind the data to the view
659 bindView(v, entry);
660 return v;
661 }
662
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700663 protected void bindView(View view, ViewEntry entry) {
664 final Resources resources = mContext.getResources();
665 ViewCache views = (ViewCache) view.getTag();
666
667 // Set the label
668 TextView label = views.label;
669 setMaxLines(label, entry.maxLabelLines);
670 label.setText(entry.label);
671
672 // Set the data
673 TextView data = views.data;
674 if (data != null) {
675 if (entry.mimetype.equals(Phone.CONTENT_ITEM_TYPE)
676 || entry.mimetype.equals(Constants.MIME_SMS_ADDRESS)) {
677 data.setText(PhoneNumberUtils.formatNumber(entry.data));
678 } else {
679 data.setText(entry.data);
680 }
681 setMaxLines(data, entry.maxLines);
682 }
683
684 // Set the footer
685 if (!TextUtils.isEmpty(entry.footerLine)) {
686 views.footer.setText(entry.footerLine);
687 views.footer.setVisibility(View.VISIBLE);
688 } else {
689 views.footer.setVisibility(View.GONE);
690 }
691
692 // Set the primary icon
693 views.primaryIcon.setVisibility(entry.isPrimary ? View.VISIBLE : View.GONE);
694
695 // Set the action icon
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700696 final ImageView action = views.actionIcon;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700697 if (entry.actionIcon != -1) {
698 Drawable actionIcon;
699 if (entry.resPackageName != null) {
700 // Load external resources through PackageManager
701 actionIcon = mContext.getPackageManager().getDrawable(entry.resPackageName,
702 entry.actionIcon, null);
703 } else {
704 actionIcon = resources.getDrawable(entry.actionIcon);
705 }
706 action.setImageDrawable(actionIcon);
707 action.setVisibility(View.VISIBLE);
708 } else {
709 // Things should still line up as if there was an icon, so make it invisible
710 action.setVisibility(View.INVISIBLE);
711 }
712
713 // Set the presence icon
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700714 final Drawable presenceIcon = ContactPresenceIconUtil.getPresenceIcon(
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700715 mContext, entry.presence);
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700716 final ImageView presenceIconView = views.presenceIcon;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700717 if (presenceIcon != null) {
718 presenceIconView.setImageDrawable(presenceIcon);
719 presenceIconView.setVisibility(View.VISIBLE);
720 } else {
721 presenceIconView.setVisibility(View.GONE);
722 }
723
724 // Set the secondary action button
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700725 final ImageView secondaryActionView = views.secondaryActionButton;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700726 Drawable secondaryActionIcon = null;
727 if (entry.secondaryActionIcon != -1) {
728 secondaryActionIcon = resources.getDrawable(entry.secondaryActionIcon);
729 }
730 if (entry.secondaryIntent != null && secondaryActionIcon != null) {
731 secondaryActionView.setImageDrawable(secondaryActionIcon);
Daniel Lehmannc3a00082010-04-13 13:53:54 -0700732 secondaryActionView.setTag(entry);
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700733 secondaryActionView.setVisibility(View.VISIBLE);
734 views.secondaryActionDivider.setVisibility(View.VISIBLE);
735 } else {
736 secondaryActionView.setVisibility(View.GONE);
737 views.secondaryActionDivider.setVisibility(View.GONE);
738 }
739 }
740
741 private void setMaxLines(TextView textView, int maxLines) {
742 if (maxLines == 1) {
743 textView.setSingleLine(true);
744 textView.setEllipsize(TextUtils.TruncateAt.END);
745 } else {
746 textView.setSingleLine(false);
747 textView.setMaxLines(maxLines);
748 textView.setEllipsize(null);
749 }
750 }
751
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700752 private OnClickListener mSecondaryActionClickListener = new OnClickListener() {
753 public void onClick(View v) {
754 if (mListener == null) return;
755 if (v == null) return;
756 final ViewEntry entry = (ViewEntry) v.getTag();
757 if (entry == null) return;
758 final Intent intent = entry.secondaryIntent;
759 if (intent == null) return;
760 mListener.onItemClicked(intent);
761 }
762 };
763
764 public int getCount() {
765 int count = 0;
766 final int numSections = mSections.size();
767 for (int i = 0; i < numSections; i++) {
768 final ArrayList<ViewEntry> section = mSections.get(i);
769 count += section.size();
770 }
771 return count;
772 }
773
774 public Object getItem(int position) {
775 return getEntry(position);
776 }
777
778 public long getItemId(int position) {
779 final ViewEntry entry = getEntry(position);
780 if (entry != null) {
781 return entry.id;
782 } else {
783 return -1;
784 }
785 }
786
787 private ViewEntry getEntry(int position) {
788 final int numSections = mSections.size();
789 for (int i = 0; i < numSections; i++) {
790 final ArrayList<ViewEntry> section = mSections.get(i);
791 final int sectionSize = section.size();
792 if (position < sectionSize) {
793 return section.get(position);
794 }
795 position -= sectionSize;
796 }
797 return null;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700798 }
799 }
800
801 public boolean onCreateOptionsMenu(Menu menu, final MenuInflater inflater) {
802 inflater.inflate(R.menu.view, menu);
803 return true;
804 }
805
806 public boolean onPrepareOptionsMenu(Menu menu) {
807 // Only allow edit when we have at least one raw_contact id
808 final boolean hasRawContact = (mRawContactIds.size() > 0);
809 menu.findItem(R.id.menu_edit).setEnabled(hasRawContact);
810
811 // Only allow share when unrestricted contacts available
812 menu.findItem(R.id.menu_share).setEnabled(!mAllRestricted);
813
814 return true;
815 }
816
817 public boolean onOptionsItemSelected(MenuItem item) {
818 switch (item.getItemId()) {
819 case R.id.menu_edit: {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700820 mListener.onEditRequested(mLookupUri);
821 break;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700822 }
823 case R.id.menu_delete: {
824 showDeleteConfirmationDialog();
825 return true;
826 }
827 case R.id.menu_options: {
828 final Intent intent = new Intent(mContext, ContactOptionsActivity.class);
829 intent.setData(mContactData.getLookupUri());
830 mContext.startActivity(intent);
831 return true;
832 }
833 case R.id.menu_share: {
834 if (mAllRestricted) return false;
835
836 final String lookupKey = mContactData.getLookupKey();
837 final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
838
839 final Intent intent = new Intent(Intent.ACTION_SEND);
840 intent.setType(Contacts.CONTENT_VCARD_TYPE);
841 intent.putExtra(Intent.EXTRA_STREAM, shareUri);
842
843 // Launch chooser to share contact via
844 final CharSequence chooseTitle = mContext.getText(R.string.share_via);
845 final Intent chooseIntent = Intent.createChooser(intent, chooseTitle);
846
847 try {
848 mContext.startActivity(chooseIntent);
849 } catch (ActivityNotFoundException ex) {
850 Toast.makeText(mContext, R.string.share_error, Toast.LENGTH_SHORT).show();
851 }
852 return true;
853 }
854 }
855 return false;
856 }
857
858 private void showDeleteConfirmationDialog() {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700859 final int id;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700860 if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700861 id = R.id.detail_dialog_confirm_readonly_delete;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700862 } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700863 id = R.id.detail_dialog_confirm_readonly_hide;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700864 } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700865 id = R.id.detail_dialog_confirm_multiple_delete;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700866 } else {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700867 id = R.id.detail_dialog_confirm_delete;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700868 }
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700869 if (mListener != null) mListener.onDialogRequested(id, null);
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700870 }
871
872 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
873 AdapterView.AdapterContextMenuInfo info;
874 try {
875 info = (AdapterView.AdapterContextMenuInfo) menuInfo;
876 } catch (ClassCastException e) {
877 Log.e(TAG, "bad menuInfo", e);
878 return;
879 }
880
881 // This can be null sometimes, don't crash...
882 if (info == null) {
883 Log.e(TAG, "bad menuInfo");
884 return;
885 }
886
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700887 final ViewEntry entry = mAdapter.getEntry(info.position);
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700888 menu.setHeaderTitle(R.string.contactOptionsTitle);
889 if (entry.mimetype.equals(CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
890 menu.add(0, 0, 0, R.string.menu_call).setIntent(entry.intent);
891 menu.add(0, 0, 0, R.string.menu_sendSMS).setIntent(entry.secondaryIntent);
892 if (!entry.isPrimary) {
893 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultNumber);
894 }
895 } else if (entry.mimetype.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
896 menu.add(0, 0, 0, R.string.menu_sendEmail).setIntent(entry.intent);
897 if (!entry.isPrimary) {
898 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultEmail);
899 }
900 } else if (entry.mimetype.equals(CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)) {
901 menu.add(0, 0, 0, R.string.menu_viewAddress).setIntent(entry.intent);
902 }
903 }
904
905 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700906 if (mListener == null) return;
907 final ViewEntry entry = mAdapter.getEntry(position);
Daniel Lehmannc3a00082010-04-13 13:53:54 -0700908 if (entry == null) return;
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700909 final Intent intent = entry.intent;
910 if (intent == null) return;
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700911 mListener.onItemClicked(intent);
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700912 }
913
914 private final DialogInterface.OnClickListener mDeleteListener =
915 new DialogInterface.OnClickListener() {
916 public void onClick(DialogInterface dialog, int which) {
917 mContext.getContentResolver().delete(mContactData.getLookupUri(), null, null);
918 }
919 };
920
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700921 public Dialog onCreateDialog(int id, Bundle bundle) {
922 switch (id) {
923 case R.id.detail_dialog_confirm_delete:
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700924 return new AlertDialog.Builder(mContext)
925 .setTitle(R.string.deleteConfirmation_title)
926 .setIcon(android.R.drawable.ic_dialog_alert)
927 .setMessage(R.string.deleteConfirmation)
928 .setNegativeButton(android.R.string.cancel, null)
929 .setPositiveButton(android.R.string.ok, mDeleteListener)
930 .setCancelable(false)
931 .create();
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700932 case R.id.detail_dialog_confirm_readonly_delete:
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700933 return new AlertDialog.Builder(mContext)
934 .setTitle(R.string.deleteConfirmation_title)
935 .setIcon(android.R.drawable.ic_dialog_alert)
936 .setMessage(R.string.readOnlyContactDeleteConfirmation)
937 .setNegativeButton(android.R.string.cancel, null)
938 .setPositiveButton(android.R.string.ok, mDeleteListener)
939 .setCancelable(false)
940 .create();
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700941 case R.id.detail_dialog_confirm_multiple_delete:
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700942 return new AlertDialog.Builder(mContext)
943 .setTitle(R.string.deleteConfirmation_title)
944 .setIcon(android.R.drawable.ic_dialog_alert)
945 .setMessage(R.string.multipleContactDeleteConfirmation)
946 .setNegativeButton(android.R.string.cancel, null)
947 .setPositiveButton(android.R.string.ok, mDeleteListener)
948 .setCancelable(false)
949 .create();
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700950 case R.id.detail_dialog_confirm_readonly_hide: {
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700951 return new AlertDialog.Builder(mContext)
952 .setTitle(R.string.deleteConfirmation_title)
953 .setIcon(android.R.drawable.ic_dialog_alert)
954 .setMessage(R.string.readOnlyContactWarning)
955 .setPositiveButton(android.R.string.ok, mDeleteListener)
956 .create();
957 }
958 default:
Daniel Lehmann18f104f2010-05-07 15:41:11 -0700959 return null;
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700960 }
961 }
962
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700963 public boolean onContextItemSelected(MenuItem item) {
964 switch (item.getItemId()) {
965 case MENU_ITEM_MAKE_DEFAULT: {
966 if (makeItemDefault(item)) {
967 return true;
968 }
969 break;
970 }
971 }
972
973 return false;
974 }
975
976 private boolean makeItemDefault(MenuItem item) {
977 ViewEntry entry = getViewEntryForMenuItem(item);
978 if (entry == null) {
979 return false;
980 }
981
982 // Update the primary values in the data record.
983 ContentValues values = new ContentValues(1);
984 values.put(Data.IS_SUPER_PRIMARY, 1);
985
986 mContext.getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, entry.id),
987 values, null, null);
988 return true;
989 }
990
991 private ViewEntry getViewEntryForMenuItem(MenuItem item) {
992 AdapterView.AdapterContextMenuInfo info;
993 try {
994 info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
995 } catch (ClassCastException e) {
996 Log.e(TAG, "bad menuInfo", e);
997 return null;
998 }
999
Daniel Lehmanncdef2b62010-06-06 18:25:49 -07001000 return mAdapter.getEntry(info.position);
Daniel Lehmann4cd94412010-04-08 16:44:36 -07001001 }
1002
Daniel Lehmann4cd94412010-04-08 16:44:36 -07001003 public boolean onKeyDown(int keyCode, KeyEvent event) {
1004 switch (keyCode) {
1005 case KeyEvent.KEYCODE_CALL: {
1006 try {
1007 ITelephony phone = ITelephony.Stub.asInterface(
1008 ServiceManager.checkService("phone"));
1009 if (phone != null && !phone.isIdle()) {
1010 // Skip out and let the key be handled at a higher level
1011 break;
1012 }
1013 } catch (RemoteException re) {
1014 // Fall through and try to call the contact
1015 }
1016
1017 int index = mListView.getSelectedItemPosition();
1018 if (index != -1) {
Daniel Lehmanncdef2b62010-06-06 18:25:49 -07001019 final ViewEntry entry = mAdapter.getEntry(index);
Daniel Lehmann4cd94412010-04-08 16:44:36 -07001020 if (entry != null &&
1021 entry.intent.getAction() == Intent.ACTION_CALL_PRIVILEGED) {
1022 mContext.startActivity(entry.intent);
1023 return true;
1024 }
1025 } else if (mPrimaryPhoneUri != null) {
1026 // There isn't anything selected, call the default number
1027 final Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
1028 mPrimaryPhoneUri);
1029 mContext.startActivity(intent);
1030 return true;
1031 }
1032 return false;
1033 }
1034
1035 case KeyEvent.KEYCODE_DEL: {
1036 showDeleteConfirmationDialog();
1037 return true;
1038 }
1039 }
1040
Daniel Lehmannc2687c32010-04-19 18:20:44 -07001041 return false;
Daniel Lehmann4cd94412010-04-08 16:44:36 -07001042 }
Daniel Lehmann18f104f2010-05-07 15:41:11 -07001043
Daniel Lehmanncdef2b62010-06-06 18:25:49 -07001044 private ContactDetailHeaderView.Listener mHeaderViewListener =
1045 new ContactDetailHeaderView.Listener() {
1046 public void onDisplayNameClick(View view) {
1047 }
1048
1049 public void onEditClicked() {
1050 if (mListener != null) mListener.onEditRequested(mLookupUri);
1051 }
1052
1053 public void onPhotoClick(View view) {
1054 }
1055 };
1056
1057
1058 public static interface Listener {
Daniel Lehmann18f104f2010-05-07 15:41:11 -07001059 /**
1060 * Contact was not found, so somehow close this fragment.
1061 */
Daniel Lehmanncdef2b62010-06-06 18:25:49 -07001062 public void onContactNotFound();
Daniel Lehmann18f104f2010-05-07 15:41:11 -07001063
1064 /**
1065 * User decided to go to Edit-Mode
1066 */
Daniel Lehmanncdef2b62010-06-06 18:25:49 -07001067 public void onEditRequested(Uri lookupUri);
Daniel Lehmann18f104f2010-05-07 15:41:11 -07001068
1069 /**
1070 * User clicked a single item (e.g. mail)
1071 */
Daniel Lehmanncdef2b62010-06-06 18:25:49 -07001072 public void onItemClicked(Intent intent);
1073
1074 /**
1075 * Show a dialog using the globally unique id
1076 */
1077 public void onDialogRequested(int id, Bundle bundle);
Daniel Lehmann18f104f2010-05-07 15:41:11 -07001078 }
Daniel Lehmann4cd94412010-04-08 16:44:36 -07001079}