blob: bbba2c2fbb9f31b2dd6b36a80c327b744b5c19d5 [file] [log] [blame]
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001/*
2 * Copyright (C) 2007 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
Evan Millar54a5c9f2009-06-23 17:41:09 -070019import com.android.contacts.Collapser.Collapsible;
Evan Millar11d628c2009-09-02 08:55:01 -070020import com.android.contacts.ScrollingTabWidget.OnTabSelectionChangedListener;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070021import com.android.contacts.SplitAggregateView.OnContactSelectedListener;
Evan Millar11d628c2009-09-02 08:55:01 -070022import com.android.contacts.model.ContactsSource;
23import com.android.contacts.model.Sources;
24import com.android.contacts.model.ContactsSource.DataKind;
Evan Millar49714ee2009-09-02 16:42:47 -070025import com.android.contacts.model.HardCodedSources.SimpleInflater;
Jeff Sharkey802b2052009-08-04 14:21:06 -070026import com.android.contacts.ui.FastTrackWindow;
Evan Millar11d628c2009-09-02 08:55:01 -070027import com.android.contacts.util.NotifyingAsyncQueryHandler;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080028import com.android.internal.telephony.ITelephony;
Evan Millar11d628c2009-09-02 08:55:01 -070029import com.android.internal.widget.ContactHeaderWidget;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080030
Evan Millar11d628c2009-09-02 08:55:01 -070031import android.app.Activity;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080032import android.app.AlertDialog;
33import android.app.Dialog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080034import android.content.ActivityNotFoundException;
35import android.content.ContentResolver;
36import android.content.ContentUris;
37import android.content.ContentValues;
38import android.content.Context;
39import android.content.DialogInterface;
Evan Millar5f4af702009-08-11 11:12:00 -070040import android.content.Entity;
Evan Millar11d628c2009-09-02 08:55:01 -070041import android.content.EntityIterator;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080042import android.content.Intent;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070043import android.content.DialogInterface.OnClickListener;
Evan Millar11d628c2009-09-02 08:55:01 -070044import android.content.Entity.NamedContentValues;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080045import android.content.pm.PackageManager;
46import android.content.pm.ResolveInfo;
47import android.content.res.Resources;
48import android.database.ContentObserver;
49import android.database.Cursor;
Dmitri Plotnikov3d53ce22009-09-02 08:44:32 -070050import android.database.DatabaseUtils;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080051import android.graphics.drawable.Drawable;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080052import android.net.Uri;
53import android.os.Bundle;
54import android.os.Handler;
55import android.os.RemoteException;
56import android.os.ServiceManager;
Dmitri Plotnikov040dc152009-09-03 15:17:56 -070057import android.provider.BaseColumns;
Dmitri Plotnikov3d53ce22009-09-02 08:44:32 -070058import android.provider.ContactsContract;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070059import android.provider.ContactsContract.AggregationExceptions;
60import android.provider.ContactsContract.CommonDataKinds;
Evan Millar11d628c2009-09-02 08:55:01 -070061import android.provider.ContactsContract.Contacts;
Evan Millar66388be2009-05-28 15:41:07 -070062import android.provider.ContactsContract.Data;
Evan Millar54a5c9f2009-06-23 17:41:09 -070063import android.provider.ContactsContract.Presence;
Dmitri Plotnikov39466592009-07-27 11:23:51 -070064import android.provider.ContactsContract.RawContacts;
Evan Millar54a5c9f2009-06-23 17:41:09 -070065import android.provider.ContactsContract.CommonDataKinds.Phone;
66import android.telephony.PhoneNumberUtils;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080067import android.text.TextUtils;
68import android.util.Log;
Evan Millar11d628c2009-09-02 08:55:01 -070069import android.util.SparseArray;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080070import android.view.ContextMenu;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070071import android.view.ContextThemeWrapper;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080072import android.view.KeyEvent;
Evan Millar11d628c2009-09-02 08:55:01 -070073import android.view.LayoutInflater;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080074import android.view.Menu;
75import android.view.MenuItem;
76import android.view.View;
77import android.view.ViewGroup;
Evan Millar11d628c2009-09-02 08:55:01 -070078import android.view.Window;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080079import android.view.ContextMenu.ContextMenuInfo;
80import android.widget.AdapterView;
Evan Millar7911ff52009-07-21 15:55:18 -070081import android.widget.FrameLayout;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080082import android.widget.ImageView;
83import android.widget.ListView;
84import android.widget.TextView;
85import android.widget.Toast;
86
87import java.util.ArrayList;
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -070088import java.util.Iterator;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080089
90/**
91 * Displays the details of a specific contact.
92 */
Evan Millar11d628c2009-09-02 08:55:01 -070093public class ViewContactActivity extends Activity
Evan Millar7911ff52009-07-21 15:55:18 -070094 implements View.OnCreateContextMenuListener, DialogInterface.OnClickListener,
Evan Millar11d628c2009-09-02 08:55:01 -070095 AdapterView.OnItemClickListener, NotifyingAsyncQueryHandler.AsyncQueryListener,
96 OnTabSelectionChangedListener {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080097 private static final String TAG = "ViewContact";
98 private static final String SHOW_BARCODE_INTENT = "com.google.zxing.client.android.ENCODE";
99
Evan Millar8a79cee2009-08-19 17:20:49 -0700100 public static final String RAW_CONTACT_ID_EXTRA = "rawContactIdExtra";
101
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800102 private static final boolean SHOW_SEPARATORS = false;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800103
104 private static final int DIALOG_CONFIRM_DELETE = 1;
105
Evan Millar8a79cee2009-08-19 17:20:49 -0700106 private static final int REQUEST_JOIN_CONTACT = 1;
107 private static final int REQUEST_EDIT_CONTACT = 2;
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700108
Evan Millar8a79cee2009-08-19 17:20:49 -0700109 public static final int MENU_ITEM_EDIT = 1;
110 public static final int MENU_ITEM_DELETE = 2;
111 public static final int MENU_ITEM_MAKE_DEFAULT = 3;
112 public static final int MENU_ITEM_SHOW_BARCODE = 4;
113 public static final int MENU_ITEM_SPLIT_AGGREGATE = 5;
114 public static final int MENU_ITEM_JOIN_AGGREGATE = 6;
115 public static final int MENU_ITEM_OPTIONS = 7;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800116
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700117 protected Uri mLookupUri;
Evan Millar11d628c2009-09-02 08:55:01 -0700118 private Uri mUri;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800119 private ContentResolver mResolver;
120 private ViewAdapter mAdapter;
121 private int mNumPhoneNumbers = 0;
122
Evan Millar8a79cee2009-08-19 17:20:49 -0700123 private static final long ALL_CONTACTS_ID = -100;
Evan Millar7911ff52009-07-21 15:55:18 -0700124
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700125 /**
Dmitri Plotnikove1cd6792009-07-27 20:28:17 -0700126 * A list of distinct contact IDs included in the current contact.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700127 */
Evan Millar7911ff52009-07-21 15:55:18 -0700128 private ArrayList<Long> mRawContactIds = new ArrayList<Long>();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700129
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800130 /* package */ ArrayList<ViewEntry> mPhoneEntries = new ArrayList<ViewEntry>();
131 /* package */ ArrayList<ViewEntry> mSmsEntries = new ArrayList<ViewEntry>();
132 /* package */ ArrayList<ViewEntry> mEmailEntries = new ArrayList<ViewEntry>();
133 /* package */ ArrayList<ViewEntry> mPostalEntries = new ArrayList<ViewEntry>();
134 /* package */ ArrayList<ViewEntry> mImEntries = new ArrayList<ViewEntry>();
135 /* package */ ArrayList<ViewEntry> mOrganizationEntries = new ArrayList<ViewEntry>();
The Android Open Source Projectcac191e2009-03-18 22:20:27 -0700136 /* package */ ArrayList<ViewEntry> mGroupEntries = new ArrayList<ViewEntry>();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800137 /* package */ ArrayList<ViewEntry> mOtherEntries = new ArrayList<ViewEntry>();
138 /* package */ ArrayList<ArrayList<ViewEntry>> mSections = new ArrayList<ArrayList<ViewEntry>>();
139
140 private Cursor mCursor;
Evan Millar5c22c3b2009-05-29 11:37:54 -0700141
Evan Millar11d628c2009-09-02 08:55:01 -0700142 private SparseArray<Long> mTabRawContactIdMap;
143 protected ScrollingTabWidget mTabWidget;
144 protected ContactHeaderWidget mContactHeaderWidget;
145 private NotifyingAsyncQueryHandler mHandler;
146
147 protected LayoutInflater mInflater;
148
149 //Projection used for the query that determines which tabs to add.
150 protected static final String[] TAB_PROJECTION = new String[] {
151 RawContacts._ID,
152 RawContacts.ACCOUNT_NAME,
153 RawContacts.ACCOUNT_TYPE
154 };
155 protected static final int TAB_CONTACT_ID_COLUMN_INDEX = 0;
156 protected static final int TAB_ACCOUNT_NAME_COLUMN_INDEX = 1;
157 protected static final int TAB_ACCOUNT_TYPE_COLUMN_INDEX = 2;
158
159 protected static final String SELECTED_RAW_CONTACT_ID_KEY = "selectedRawContact";
160 protected Long mSelectedRawContactId = null;
161
162 private static final int TOKEN_QUERY = 0;
163
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800164 private ContentObserver mObserver = new ContentObserver(new Handler()) {
165 @Override
166 public boolean deliverSelfNotifications() {
167 return true;
168 }
169
170 @Override
171 public void onChange(boolean selfChange) {
Evan Millar11d628c2009-09-02 08:55:01 -0700172 if (mCursor != null && !mCursor.isClosed()) {
173 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800174 }
175 }
176 };
177
178 public void onClick(DialogInterface dialog, int which) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700179 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800180 getContentResolver().delete(mUri, null, null);
181 finish();
182 }
183
Evan Millar7911ff52009-07-21 15:55:18 -0700184 private FrameLayout mTabContentLayout;
185 private ListView mListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800186 private boolean mShowSmsLinksForAllPhones;
Evan Millar11d628c2009-09-02 08:55:01 -0700187 private ArrayList<Entity> mEntities = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800188
189 @Override
190 protected void onCreate(Bundle icicle) {
191 super.onCreate(icicle);
192
Evan Millar11d628c2009-09-02 08:55:01 -0700193 final Intent intent = getIntent();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700194 mLookupUri = intent.getData();
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700195
196 mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Evan Millar11d628c2009-09-02 08:55:01 -0700197
198 requestWindowFeature(Window.FEATURE_NO_TITLE);
199 setContentView(R.layout.contact_card_layout);
200
201 mContactHeaderWidget = (ContactHeaderWidget) findViewById(R.id.contact_header_widget);
202 mContactHeaderWidget.showStar(true);
Evan Millar11d628c2009-09-02 08:55:01 -0700203 mContactHeaderWidget.setExcludeMimes(new String[] {
204 Contacts.CONTENT_ITEM_TYPE
205 });
206
207 mTabWidget = (ScrollingTabWidget) findViewById(R.id.tab_widget);
208 mTabWidget.setTabSelectionListener(this);
209 mTabWidget.setVisibility(View.INVISIBLE);
210
211 mTabRawContactIdMap = new SparseArray<Long>();
212
213 mHandler = new NotifyingAsyncQueryHandler(this, this);
214
Evan Millar7911ff52009-07-21 15:55:18 -0700215 mListView = new ListView(this);
216 mListView.setOnCreateContextMenuListener(this);
217 mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
218 mListView.setOnItemClickListener(this);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800219
Evan Millar7911ff52009-07-21 15:55:18 -0700220 mTabContentLayout = (FrameLayout) findViewById(android.R.id.tabcontent);
221 mTabContentLayout.addView(mListView);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800222
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800223 mResolver = getContentResolver();
224
225 // Build the list of sections. The order they're added to mSections dictates the
226 // order they are displayed in the list.
227 mSections.add(mPhoneEntries);
228 mSections.add(mSmsEntries);
229 mSections.add(mEmailEntries);
230 mSections.add(mImEntries);
231 mSections.add(mPostalEntries);
232 mSections.add(mOrganizationEntries);
The Android Open Source Projectcac191e2009-03-18 22:20:27 -0700233 mSections.add(mGroupEntries);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800234 mSections.add(mOtherEntries);
235
236 //TODO Read this value from a preference
237 mShowSmsLinksForAllPhones = true;
238
Evan Millar11d628c2009-09-02 08:55:01 -0700239 startEntityQuery();
240 }
241
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800242 @Override
243 protected void onResume() {
244 super.onResume();
Evan Millar11d628c2009-09-02 08:55:01 -0700245 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800246 }
247
248 @Override
249 protected void onPause() {
250 super.onPause();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700251 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800252 }
253
254 @Override
255 protected void onDestroy() {
256 super.onDestroy();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700257 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800258 }
259
260 @Override
Evan Millar11d628c2009-09-02 08:55:01 -0700261 protected void onRestoreInstanceState(Bundle savedInstanceState) {
262 super.onRestoreInstanceState(savedInstanceState);
263 mSelectedRawContactId = savedInstanceState.getLong(SELECTED_RAW_CONTACT_ID_KEY);
264 }
265
266 @Override
267 protected void onSaveInstanceState(Bundle outState) {
268 super.onSaveInstanceState(outState);
269 outState.putLong(SELECTED_RAW_CONTACT_ID_KEY, mSelectedRawContactId);
270 }
271
272 @Override
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800273 protected Dialog onCreateDialog(int id) {
274 switch (id) {
275 case DIALOG_CONFIRM_DELETE:
276 return new AlertDialog.Builder(this)
277 .setTitle(R.string.deleteConfirmation_title)
278 .setIcon(android.R.drawable.ic_dialog_alert)
279 .setMessage(R.string.deleteConfirmation)
280 .setNegativeButton(android.R.string.cancel, null)
281 .setPositiveButton(android.R.string.ok, this)
282 .setCancelable(false)
283 .create();
284 }
285 return null;
286 }
287
Evan Millar11d628c2009-09-02 08:55:01 -0700288
289 // TAB CODE //
290 /**
291 * Adds a tab for each {@link RawContact} associated with this contact.
292 * Override this method if you want to additional tabs and/or different
293 * tabs for your activity.
294 *
295 * @param entities An {@link ArrayList} of {@link Entity}s of all the RawContacts
296 * associated with the contact being displayed.
297 */
298 protected void bindTabs() {
299 if (mEntities.size() > 1) {
Evan Millar7911ff52009-07-21 15:55:18 -0700300 addAllTab();
301 }
Evan Millar11d628c2009-09-02 08:55:01 -0700302
303 final Sources sources = Sources.getInstance(this);
304
305 for (Entity entity : mEntities) {
306 final String accountType = entity.getEntityValues().
307 getAsString(RawContacts.ACCOUNT_TYPE);
308 final Long rawContactId = entity.getEntityValues().
309 getAsLong(RawContacts._ID);
310
311 // TODO: ensure inflation on background task so we don't block UI thread here
312 final ContactsSource source = sources.getInflatedSource(accountType,
313 ContactsSource.LEVEL_SUMMARY);
314 addTab(rawContactId, ContactsUtils.createTabIndicatorView(mTabWidget.getTabParent(), source));
315 }
316
317 selectInitialTab();
318 mTabWidget.setVisibility(View.VISIBLE);
319 mTabWidget.postInvalidate();
320 }
321
322 /**
323 * Add a tab to be displayed in the {@link ScrollingTabWidget}.
324 *
325 * @param contactId The contact id associated with the tab.
326 * @param view A view to use as the tab indicator.
327 */
328 protected void addTab(long rawContactId, View view) {
329 mTabRawContactIdMap.put(mTabWidget.getTabCount(), rawContactId);
330 mTabWidget.addTab(view);
331 }
332
333
334 protected void clearCurrentTabs() {
335 mTabRawContactIdMap.clear();
336 mTabWidget.removeAllTabs();
337 }
338
339 protected void selectInitialTab() {
340 int selectedTabIndex = 0;
341
342 if (mSelectedRawContactId != null) {
343 selectedTabIndex = getTabIndexForRawContactId(mSelectedRawContactId);
344 if (selectedTabIndex == -1) {
345 // If there was no matching tab, just select the first;
346 selectedTabIndex = 0;
347 }
348 }
349
350 mTabWidget.setCurrentTab(selectedTabIndex);
351 onTabSelectionChanged(selectedTabIndex, false);
352 }
353
Evan Millar7911ff52009-07-21 15:55:18 -0700354 private void addAllTab() {
Evan Millar56d2caa2009-08-20 20:30:12 -0700355 View allTabIndicator = mInflater.inflate(R.layout.all_tab_indicator,
356 mTabWidget.getTabParent(), false);
Evan Millar74660912009-08-19 17:36:33 -0700357 allTabIndicator.getBackground().setDither(true);
Evan Millar7911ff52009-07-21 15:55:18 -0700358 addTab(ALL_CONTACTS_ID, allTabIndicator);
359 }
360
361 public void onTabSelectionChanged(int tabIndex, boolean clicked) {
362 long rawContactId = getTabRawContactId(tabIndex);
Evan Millar8a79cee2009-08-19 17:20:49 -0700363 mSelectedRawContactId = rawContactId;
Evan Millar11d628c2009-09-02 08:55:01 -0700364 bindData();
Evan Millar7911ff52009-07-21 15:55:18 -0700365 }
366
Evan Millar11d628c2009-09-02 08:55:01 -0700367 /**
368 * Return the RawContact id associated with the tab at an index.
369 *
370 * @param index The index of the tab in question.
371 * @return The contactId associated with the tab at the specified index.
372 */
373 protected long getTabRawContactId(int index) {
374 return mTabRawContactIdMap.get(index);
375 }
Evan Millar2c1cc832009-07-13 11:08:06 -0700376
Evan Millar11d628c2009-09-02 08:55:01 -0700377 /**
378 * Return the tab index associated with the RawContact id.
379 *
380 * @param index The index of the tab in question.
381 * @return The contactId associated with the tab at the specified index.
382 */
383 protected int getTabIndexForRawContactId(long rawContactId) {
384 int numTabs = mTabRawContactIdMap.size();
385 for (int i=0; i < numTabs; i++) {
386 if (mTabRawContactIdMap.get(i) == rawContactId) {
387 return i;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800388 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800389 }
Evan Millar11d628c2009-09-02 08:55:01 -0700390 return -1;
391 }
392
393
394 // QUERY CODE //
395 /** {@inheritDoc} */
396 public void onQueryEntitiesComplete(int token, Object cookie, EntityIterator iterator) {
397 try{
398 if (token == TOKEN_QUERY) {
399 clearCurrentTabs();
400 mEntities = readEntities(iterator);
401 bindTabs();
402 bindData();
403 }
404 } finally {
405 if (iterator != null) {
406 iterator.close();
407 }
408 }
409 }
410
411 /** {@inheritDoc} */
412 public void onQueryComplete(int token, Object cookie, Cursor cursor) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700413 // Empty
Evan Millar11d628c2009-09-02 08:55:01 -0700414 }
415
416 private ArrayList<Entity> readEntities(EntityIterator iterator) {
417 ArrayList<Entity> entities = new ArrayList<Entity>();
418 try {
419 while (iterator.hasNext()) {
420 entities.add(iterator.next());
421 }
422 } catch (RemoteException e) {
423 }
424
425 return entities;
426 }
427
428 private void startEntityQuery() {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700429 closeCursor();
430
Dmitri Plotnikov0306bbd2009-09-03 14:37:15 -0700431 mUri = null;
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700432 if (mLookupUri != null) {
433 mLookupUri = Contacts.getLookupUri(getContentResolver(), mLookupUri);
434 if (mLookupUri != null) {
435 mUri = Contacts.lookupContact(getContentResolver(), mLookupUri);
436 }
437 }
438
439 if (mUri == null) {
440
441 // TODO either figure out a way to prevent a flash of black background or
442 // use some other UI than a toast
443 Toast.makeText(this, R.string.invalidContactMessage, Toast.LENGTH_SHORT).show();
444 Log.e(TAG, "invalid contact uri: " + mLookupUri);
445 finish();
446 return;
447 }
448
449 mCursor = mResolver.query(Uri.withAppendedPath(mUri, Contacts.Data.CONTENT_DIRECTORY),
450 new String[] {Contacts.DISPLAY_NAME}, null, null, null);
451 mCursor.registerContentObserver(mObserver);
452
Evan Millar11d628c2009-09-02 08:55:01 -0700453 long contactId = ContentUris.parseId(mUri);
454 mHandler.startQueryEntities(TOKEN_QUERY, null,
455 RawContacts.CONTENT_URI, RawContacts.CONTACT_ID + "=" + contactId, null, null);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700456
457 mContactHeaderWidget.bindFromContactId(ContentUris.parseId(mUri));
458 }
459
460 private void closeCursor() {
461 if (mCursor != null) {
462 mCursor.unregisterContentObserver(mObserver);
463 mCursor.close();
464 mCursor = null;
465 }
Evan Millar11d628c2009-09-02 08:55:01 -0700466 }
467
468 private void bindData() {
469
470 // Build up the contact entries
471 buildEntries();
472
473 // Collapse similar data items in select sections.
474 Collapser.collapseList(mPhoneEntries);
475 Collapser.collapseList(mSmsEntries);
476 Collapser.collapseList(mEmailEntries);
477 Collapser.collapseList(mPostalEntries);
478
479 if (mAdapter == null) {
480 mAdapter = new ViewAdapter(this, mSections);
481 mListView.setAdapter(mAdapter);
482 } else {
483 mAdapter.setSections(mSections, SHOW_SEPARATORS);
484 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800485 }
486
487 @Override
488 public boolean onCreateOptionsMenu(Menu menu) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800489 menu.add(0, MENU_ITEM_DELETE, 0, R.string.menu_deleteContact)
490 .setIcon(android.R.drawable.ic_menu_delete);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700491 menu.add(0, MENU_ITEM_SPLIT_AGGREGATE, 0, R.string.menu_splitAggregate)
492 .setIcon(android.R.drawable.ic_menu_share);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700493 menu.add(0, MENU_ITEM_JOIN_AGGREGATE, 0, R.string.menu_joinAggregate)
494 .setIcon(android.R.drawable.ic_menu_add);
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700495 menu.add(0, MENU_ITEM_OPTIONS, 0, R.string.menu_contactOptions)
496 .setIcon(R.drawable.ic_menu_mark);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800497 return true;
498 }
499
500 @Override
501 public boolean onPrepareOptionsMenu(Menu menu) {
502 super.onPrepareOptionsMenu(menu);
503 // Perform this check each time the menu is about to be shown, because the Barcode Scanner
504 // could be installed or uninstalled at any time.
505 if (isBarcodeScannerInstalled()) {
506 if (menu.findItem(MENU_ITEM_SHOW_BARCODE) == null) {
507 menu.add(0, MENU_ITEM_SHOW_BARCODE, 0, R.string.menu_showBarcode)
508 .setIcon(R.drawable.ic_menu_show_barcode);
509 }
510 } else {
511 menu.removeItem(MENU_ITEM_SHOW_BARCODE);
512 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700513
Evan Millardb5d88c2009-08-28 09:31:57 -0700514 // Only show the edit option if we have a selected tab.
515 if (mSelectedRawContactId != null) {
516 if (menu.findItem(MENU_ITEM_EDIT) == null) {
517 menu.add(0, MENU_ITEM_EDIT, 0, R.string.menu_editContact)
518 .setIcon(android.R.drawable.ic_menu_edit)
519 .setAlphabeticShortcut('e');
520 }
521 } else {
522 menu.removeItem(MENU_ITEM_EDIT);
523 }
524
Evan Millar7911ff52009-07-21 15:55:18 -0700525 boolean isAggregate = mRawContactIds.size() > 1;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700526 menu.findItem(MENU_ITEM_SPLIT_AGGREGATE).setEnabled(isAggregate);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800527 return true;
528 }
529
530 private boolean isBarcodeScannerInstalled() {
531 final Intent intent = new Intent(SHOW_BARCODE_INTENT);
532 ResolveInfo ri = getPackageManager().resolveActivity(intent,
533 PackageManager.MATCH_DEFAULT_ONLY);
534 return ri != null;
535 }
536
537 @Override
538 public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
539 AdapterView.AdapterContextMenuInfo info;
540 try {
541 info = (AdapterView.AdapterContextMenuInfo) menuInfo;
542 } catch (ClassCastException e) {
543 Log.e(TAG, "bad menuInfo", e);
544 return;
545 }
546
547 // This can be null sometimes, don't crash...
548 if (info == null) {
549 Log.e(TAG, "bad menuInfo");
550 return;
551 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700552
Evan Millar45e0ed32009-06-01 16:44:38 -0700553 ViewEntry entry = ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
554 if (entry.mimetype.equals(CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
555 menu.add(0, 0, 0, R.string.menu_call).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700556 menu.add(0, 0, 0, R.string.menu_sendSMS).setIntent(entry.secondaryIntent);
557 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700558 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultNumber);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800559 }
Evan Millar45e0ed32009-06-01 16:44:38 -0700560 } else if (entry.mimetype.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
561 menu.add(0, 0, 0, R.string.menu_sendEmail).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700562 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700563 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultEmail);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800564 }
Jeff Sharkeyc6ad3ab2009-07-21 19:30:15 -0700565 } else if (entry.mimetype.equals(CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700566 menu.add(0, 0, 0, R.string.menu_viewAddress).setIntent(entry.intent);
567 }
568 // TODO(emillar): add back with group support.
569 /* else if (entry.mimetype.equals()) {
570 menu.add(0, 0, 0, R.string.menu_viewGroup).setIntent(entry.intent);
571 } */
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800572 }
573
574 @Override
575 public boolean onOptionsItemSelected(MenuItem item) {
576 switch (item.getItemId()) {
Evan Millar8a79cee2009-08-19 17:20:49 -0700577 case MENU_ITEM_EDIT: {
Evan Millardb5d88c2009-08-28 09:31:57 -0700578 Long rawContactIdToEdit = mSelectedRawContactId;
579 if (rawContactIdToEdit == null) {
580 // This shouldn't be possible. We only show the edit option if
581 // this value is non-null.
582 break;
583 }
Evan Millar8a79cee2009-08-19 17:20:49 -0700584 if (rawContactIdToEdit == ALL_CONTACTS_ID) {
585 // If the "all" tab is selected, edit the next tab.
Evan Millardb5d88c2009-08-28 09:31:57 -0700586 rawContactIdToEdit = getTabRawContactId(mTabWidget.getCurrentTab() + 1);
Evan Millar8a79cee2009-08-19 17:20:49 -0700587 }
588 Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI,
589 rawContactIdToEdit);
590 startActivityForResult(new Intent(Intent.ACTION_EDIT, rawContactUri),
591 REQUEST_EDIT_CONTACT);
592 break;
593 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800594 case MENU_ITEM_DELETE: {
595 // Get confirmation
596 showDialog(DIALOG_CONFIRM_DELETE);
597 return true;
598 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700599
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700600 case MENU_ITEM_SPLIT_AGGREGATE: {
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700601 if (mRawContactIds.size() == 2) {
602 splitContact(mRawContactIds.get(1));
603 } else {
604 showSplitAggregateDialog();
605 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700606 return true;
607 }
608
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700609 case MENU_ITEM_JOIN_AGGREGATE: {
610 showJoinAggregateActivity();
611 return true;
612 }
613
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700614 case MENU_ITEM_OPTIONS: {
615 showOptionsActivity();
616 return true;
617 }
618
Evan Millar66388be2009-05-28 15:41:07 -0700619 // TODO(emillar) Bring this back.
620 /*case MENU_ITEM_SHOW_BARCODE:
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800621 if (mCursor.moveToFirst()) {
622 Intent intent = new Intent(SHOW_BARCODE_INTENT);
623 intent.putExtra("ENCODE_TYPE", "CONTACT_TYPE");
624 Bundle bundle = new Bundle();
Evan Millar66388be2009-05-28 15:41:07 -0700625 String name = mCursor.getString(AGGREGATE_DISPLAY_NAME_COLUMN);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800626 if (!TextUtils.isEmpty(name)) {
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700627 // Correctly handle when section headers are hidden
628 int sepAdjust = SHOW_SEPARATORS ? 1 : 0;
Evan Millar5c22c3b2009-05-29 11:37:54 -0700629
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800630 bundle.putString(Contacts.Intents.Insert.NAME, name);
631 // The 0th ViewEntry in each ArrayList below is a separator item
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700632 int entriesToAdd = Math.min(mPhoneEntries.size() - sepAdjust, PHONE_KEYS.length);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800633 for (int x = 0; x < entriesToAdd; x++) {
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700634 ViewEntry entry = mPhoneEntries.get(x + sepAdjust);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800635 bundle.putString(PHONE_KEYS[x], entry.data);
636 }
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700637 entriesToAdd = Math.min(mEmailEntries.size() - sepAdjust, EMAIL_KEYS.length);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800638 for (int x = 0; x < entriesToAdd; x++) {
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700639 ViewEntry entry = mEmailEntries.get(x + sepAdjust);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800640 bundle.putString(EMAIL_KEYS[x], entry.data);
641 }
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700642 if (mPostalEntries.size() >= 1 + sepAdjust) {
643 ViewEntry entry = mPostalEntries.get(sepAdjust);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800644 bundle.putString(Contacts.Intents.Insert.POSTAL, entry.data);
645 }
646 intent.putExtra("ENCODE_DATA", bundle);
647 try {
648 startActivity(intent);
649 } catch (ActivityNotFoundException e) {
650 // The check in onPrepareOptionsMenu() should make this impossible, but
651 // for safety I'm catching the exception rather than crashing. Ideally
652 // I'd call Menu.removeItem() here too, but I don't see a way to get
653 // the options menu.
654 Log.e(TAG, "Show barcode menu item was clicked but Barcode Scanner " +
655 "was not installed.");
656 }
657 return true;
658 }
659 }
Evan Millar66388be2009-05-28 15:41:07 -0700660 break; */
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800661 }
662 return super.onOptionsItemSelected(item);
663 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700664
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800665 @Override
666 public boolean onContextItemSelected(MenuItem item) {
667 switch (item.getItemId()) {
668 case MENU_ITEM_MAKE_DEFAULT: {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700669 if (makeItemDefault(item)) {
670 return true;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800671 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700672 break;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800673 }
674 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700675
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800676 return super.onContextItemSelected(item);
677 }
678
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700679 private boolean makeItemDefault(MenuItem item) {
680 ViewEntry entry = getViewEntryForMenuItem(item);
681 if (entry == null) {
682 return false;
683 }
684
685 // Update the primary values in the data record.
686 ContentValues values = new ContentValues(2);
687 values.put(Data.IS_PRIMARY, 1);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700688
Evan Millar54a5c9f2009-06-23 17:41:09 -0700689 if (entry.ids.size() > 0) {
690 for (int i = 0; i < entry.ids.size(); i++) {
691 getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI,
692 entry.ids.get(i)),
693 values, null, null);
694 }
695 }
696
697 values.put(Data.IS_SUPER_PRIMARY, 1);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700698 getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, entry.id),
699 values, null, null);
Evan Millar11d628c2009-09-02 08:55:01 -0700700 startEntityQuery();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700701 return true;
702 }
703
704 /**
705 * Shows a dialog that contains a list of all constituent contacts in this aggregate.
706 * The user picks a contact to be split into its own aggregate or clicks Cancel.
707 */
708 private void showSplitAggregateDialog() {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700709 // Wrap this dialog in a specific theme so that list items have correct text color.
710 final ContextThemeWrapper dialogContext =
711 new ContextThemeWrapper(this, android.R.style.Theme_Light);
712 AlertDialog.Builder builder =
713 new AlertDialog.Builder(dialogContext);
714 builder.setTitle(getString(R.string.splitAggregate_title));
715
716 final SplitAggregateView view = new SplitAggregateView(dialogContext, mUri);
717 builder.setView(view);
718
719 builder.setInverseBackgroundForced(true);
720 builder.setCancelable(true);
721 builder.setNegativeButton(android.R.string.cancel,
722 new OnClickListener() {
723 public void onClick(DialogInterface dialog, int which) {
724 dialog.dismiss();
725 }
726 });
727 final AlertDialog dialog = builder.create();
728
729 view.setOnContactSelectedListener(new OnContactSelectedListener() {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700730 public void onContactSelected(long rawContactId) {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700731 dialog.dismiss();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700732 splitContact(rawContactId);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700733 }
734 });
735
736 dialog.show();
737 }
738
739 /**
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700740 * Shows a list of aggregates that can be joined into the currently viewed aggregate.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700741 */
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700742 public void showJoinAggregateActivity() {
743 Intent intent = new Intent(ContactsListActivity.JOIN_AGGREGATE);
744 intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_ID, ContentUris.parseId(mUri));
Evan Millar8a79cee2009-08-19 17:20:49 -0700745 startActivityForResult(intent, REQUEST_JOIN_CONTACT);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700746 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700747
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700748 @Override
749 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
Evan Millar8a79cee2009-08-19 17:20:49 -0700750 switch (requestCode) {
751 case REQUEST_JOIN_CONTACT: {
752 if (resultCode == RESULT_OK && intent != null) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700753 final long contactId = ContentUris.parseId(intent.getData());
754 joinAggregate(contactId);
Evan Millar8a79cee2009-08-19 17:20:49 -0700755 }
756 break;
757 }
758 case REQUEST_EDIT_CONTACT: {
759 if (resultCode == RESULT_OK && intent != null) {
760 long newInitialSelectedRawContactId = intent.getLongExtra(
761 RAW_CONTACT_ID_EXTRA, ALL_CONTACTS_ID);
762 if (newInitialSelectedRawContactId != mSelectedRawContactId) {
763 mSelectedRawContactId = newInitialSelectedRawContactId;
764 selectInitialTab();
765 }
766 }
767 }
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700768 }
769 }
770
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700771 private void splitContact(long rawContactId) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700772 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_SEPARATE);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700773
774 // The split operation may have removed the original aggregate contact, so we need
775 // to requery everything
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700776 Toast.makeText(this, R.string.contactsSplitMessage, Toast.LENGTH_LONG).show();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700777 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700778 }
779
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700780 private void joinAggregate(final long contactId) {
Dmitri Plotnikov39466592009-07-27 11:23:51 -0700781 Cursor c = mResolver.query(RawContacts.CONTENT_URI, new String[] {RawContacts._ID},
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700782 RawContacts.CONTACT_ID + "=" + contactId, null, null);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700783
784 try {
785 while(c.moveToNext()) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700786 long rawContactId = c.getLong(0);
787 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_TOGETHER);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700788 }
789 } finally {
790 c.close();
791 }
792
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700793 Toast.makeText(this, R.string.contactsJoinedMessage, Toast.LENGTH_LONG).show();
794 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700795 }
796
797 /**
798 * Given a contact ID sets an aggregation exception to either join the contact with the
799 * current aggregate or split off.
800 */
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700801 protected void setAggregationException(long rawContactId, int exceptionType) {
Dmitri Plotnikovd09f75c2009-06-16 11:59:22 -0700802 ContentValues values = new ContentValues(3);
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700803 for (long aRawContactId : mRawContactIds) {
804 if (aRawContactId != rawContactId) {
805 values.put(AggregationExceptions.RAW_CONTACT_ID1, aRawContactId);
806 values.put(AggregationExceptions.RAW_CONTACT_ID2, rawContactId);
807 values.put(AggregationExceptions.TYPE, exceptionType);
808 mResolver.update(AggregationExceptions.CONTENT_URI, values, null, null);
809 }
810 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700811 }
812
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700813 private void showOptionsActivity() {
814 final Intent intent = new Intent(this, ContactOptionsActivity.class);
815 intent.setData(mUri);
816 startActivity(intent);
817 }
818
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700819 private ViewEntry getViewEntryForMenuItem(MenuItem item) {
820 AdapterView.AdapterContextMenuInfo info;
821 try {
822 info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
823 } catch (ClassCastException e) {
824 Log.e(TAG, "bad menuInfo", e);
825 return null;
826 }
827
828 return ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
829 }
830
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800831 @Override
832 public boolean onKeyDown(int keyCode, KeyEvent event) {
833 switch (keyCode) {
834 case KeyEvent.KEYCODE_CALL: {
835 try {
836 ITelephony phone = ITelephony.Stub.asInterface(
837 ServiceManager.checkService("phone"));
838 if (phone != null && !phone.isIdle()) {
839 // Skip out and let the key be handled at a higher level
840 break;
841 }
842 } catch (RemoteException re) {
843 // Fall through and try to call the contact
844 }
845
Evan Millar7911ff52009-07-21 15:55:18 -0700846 int index = mListView.getSelectedItemPosition();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800847 if (index != -1) {
848 ViewEntry entry = ViewAdapter.getEntry(mSections, index, SHOW_SEPARATORS);
Evan Millar66388be2009-05-28 15:41:07 -0700849 if (entry.intent.getAction() == Intent.ACTION_CALL_PRIVILEGED) {
850 startActivity(entry.intent);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800851 }
852 } else if (mNumPhoneNumbers != 0) {
853 // There isn't anything selected, call the default number
854 Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, mUri);
855 startActivity(intent);
856 }
857 return true;
858 }
859
860 case KeyEvent.KEYCODE_DEL: {
861 showDialog(DIALOG_CONFIRM_DELETE);
862 return true;
863 }
864 }
865
866 return super.onKeyDown(keyCode, event);
867 }
868
Evan Millar7911ff52009-07-21 15:55:18 -0700869 public void onItemClick(AdapterView parent, View v, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800870 ViewEntry entry = ViewAdapter.getEntry(mSections, position, SHOW_SEPARATORS);
871 if (entry != null) {
872 Intent intent = entry.intent;
873 if (intent != null) {
874 try {
875 startActivity(intent);
876 } catch (ActivityNotFoundException e) {
877 Log.e(TAG, "No activity found for intent: " + intent);
878 signalError();
879 }
880 } else {
881 signalError();
882 }
883 } else {
884 signalError();
885 }
886 }
887
888 /**
889 * Signal an error to the user via a beep, or some other method.
890 */
891 private void signalError() {
892 //TODO: implement this when we have the sonification APIs
893 }
894
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800895 private Uri constructImToUrl(String host, String data) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700896 // don't encode the url, because the Activity Manager can't find using the encoded url
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800897 StringBuilder buf = new StringBuilder("imto://");
898 buf.append(host);
899 buf.append('/');
900 buf.append(data);
901 return Uri.parse(buf.toString());
902 }
903
904 /**
905 * Build up the entries to display on the screen.
Evan Millar5c22c3b2009-05-29 11:37:54 -0700906 *
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800907 * @param personCursor the URI for the contact being displayed
908 */
Evan Millar11d628c2009-09-02 08:55:01 -0700909 private final void buildEntries() {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800910 // Clear out the old entries
911 final int numSections = mSections.size();
912 for (int i = 0; i < numSections; i++) {
913 mSections.get(i).clear();
914 }
915
Evan Millar7911ff52009-07-21 15:55:18 -0700916 mRawContactIds.clear();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700917
Evan Millar11d628c2009-09-02 08:55:01 -0700918 Sources sources = Sources.getInstance(this);
919
Evan Millar66388be2009-05-28 15:41:07 -0700920 // Build up method entries
921 if (mUri != null) {
Evan Millar11d628c2009-09-02 08:55:01 -0700922 for (Entity entity: mEntities) {
923 final ContentValues entValues = entity.getEntityValues();
924 final String accountType = entValues.getAsString(RawContacts.ACCOUNT_TYPE);
Evan Millar7911ff52009-07-21 15:55:18 -0700925 // TODO: entry.contactId should be renamed to entry.rawContactId
Evan Millar11d628c2009-09-02 08:55:01 -0700926 long contactId = entValues.getAsLong(RawContacts._ID);
Evan Millar7911ff52009-07-21 15:55:18 -0700927
Evan Millar11d628c2009-09-02 08:55:01 -0700928 for (NamedContentValues subValue : entity.getSubValues()) {
929 ViewEntry entry = new ViewEntry();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800930
Evan Millar11d628c2009-09-02 08:55:01 -0700931 ContentValues entryValues = subValue.values;
932 final String mimetype = entryValues.getAsString(Data.MIMETYPE);
933 if (mimetype == null || accountType == null) {
Evan Millar66388be2009-05-28 15:41:07 -0700934 continue;
935 }
936
Evan Millar11d628c2009-09-02 08:55:01 -0700937 ContactsSource contactsSource = sources.getInflatedSource(accountType,
938 ContactsSource.LEVEL_MIMETYPES);
939 if (contactsSource == null) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800940 continue;
941 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700942
Evan Millar11d628c2009-09-02 08:55:01 -0700943 DataKind kind = contactsSource.getKindForMimetype(mimetype);
944 if (kind == null) {
945 continue;
946 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800947
Evan Millar11d628c2009-09-02 08:55:01 -0700948 final long id = entryValues.getAsLong(Data._ID);
949 final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, id);
950 entry.contactId = contactId;
951 entry.id = id;
952 entry.uri = uri;
953 entry.mimetype = mimetype;
954 entry.label = buildActionString(kind, entryValues, true);
955 entry.data = buildDataString(kind, entryValues);
956 if (kind.typeColumn != null) {
957 entry.type = entryValues.getAsInteger(kind.typeColumn);
958 }
959 if (kind.iconRes > 0) {
960 entry.actionIcon = kind.iconRes;
961 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800962
Evan Millar11d628c2009-09-02 08:55:01 -0700963 // Don't crash if the data is bogus
Evan Millar66388be2009-05-28 15:41:07 -0700964 if (TextUtils.isEmpty(entry.data)) {
965 Log.w(TAG, "empty data for contact method " + id);
Alex Kennberg87fc3172009-03-28 06:43:06 -0700966 continue;
967 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700968
Evan Millar11d628c2009-09-02 08:55:01 -0700969 if (!mRawContactIds.contains(entry.contactId)) {
970 mRawContactIds.add(entry.contactId);
971 }
972
973 // This performs the tab filtering
974 if (mSelectedRawContactId != null
975 && mSelectedRawContactId != entry.contactId
976 && mSelectedRawContactId != ALL_CONTACTS_ID) {
977 continue;
978 }
979
980 if (CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(mimetype)
981 || CommonDataKinds.Email.CONTENT_ITEM_TYPE.equals(mimetype)
982 || CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE.equals(mimetype)
983 || CommonDataKinds.Im.CONTENT_ITEM_TYPE.equals(mimetype)) {
984 final boolean isSuperPrimary = entryValues.getAsInteger(
985 Data.IS_SUPER_PRIMARY) != 0;
986
987 if (CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(mimetype)) {
988 // Build phone entries
989 mNumPhoneNumbers++;
990
991 entry.intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
992 Uri.fromParts("tel", entry.data, null));
993 entry.secondaryIntent = new Intent(Intent.ACTION_SENDTO,
994 Uri.fromParts("sms", entry.data, null));
995 entry.data = PhoneNumberUtils.stripSeparators(entry.data);
Evan Millar49714ee2009-09-02 16:42:47 -0700996
997 // If data is empty, don't show it.
998 if (TextUtils.isEmpty(entry.data)) {
999 Log.w(TAG, "empty data for contact method " + id);
1000 continue;
1001 }
1002
Evan Millar11d628c2009-09-02 08:55:01 -07001003 entry.isPrimary = isSuperPrimary;
1004 mPhoneEntries.add(entry);
1005
1006 if (entry.type == CommonDataKinds.Phone.TYPE_MOBILE
1007 || mShowSmsLinksForAllPhones) {
1008 // Add an SMS entry
1009 if (kind.iconAltRes > 0) {
1010 entry.secondaryActionIcon = kind.iconAltRes;
1011 }
1012 }
1013 } else if (CommonDataKinds.Email.CONTENT_ITEM_TYPE.equals(mimetype)) {
1014 // Build email entries
1015 entry.intent = new Intent(Intent.ACTION_SENDTO,
1016 Uri.fromParts("mailto", entry.data, null));
Evan Millar49714ee2009-09-02 16:42:47 -07001017 // Temporary hack until we get real label resources for exchange.
1018 if (TextUtils.isEmpty(entry.label)) {
1019 entry.label = getString(R.string.email).toLowerCase();
1020 }
Evan Millar11d628c2009-09-02 08:55:01 -07001021 entry.isPrimary = isSuperPrimary;
1022 mEmailEntries.add(entry);
1023 } else if (CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE.
1024 equals(mimetype)) {
1025 // Build postal entries
1026 entry.maxLines = 4;
1027 entry.intent = new Intent(Intent.ACTION_VIEW, uri);
1028 mPostalEntries.add(entry);
1029 } else if (CommonDataKinds.Im.CONTENT_ITEM_TYPE.equals(mimetype)) {
1030 // Build im entries
1031 Object protocolObj = entryValues.getAsInteger(Data.DATA5);
1032 String host = null;
1033
Evan Millar49714ee2009-09-02 16:42:47 -07001034 if (TextUtils.isEmpty(entry.label)) {
1035 entry.label = getString(R.string.im).toLowerCase();
1036 }
1037
Evan Millar11d628c2009-09-02 08:55:01 -07001038 if (protocolObj instanceof Number) {
1039 int protocol = ((Number) protocolObj).intValue();
1040 host = ContactsUtils.lookupProviderNameFromId(
1041 protocol).toLowerCase();
1042 if (protocol == CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK
1043 || protocol == CommonDataKinds.Im.PROTOCOL_MSN) {
1044 entry.maxLabelLines = 2;
1045 }
1046 } else if (protocolObj != null) {
1047 String providerName = (String) protocolObj;
1048 host = providerName.toLowerCase();
1049 }
1050
1051 // Only add the intent if there is a valid host
1052 if (!TextUtils.isEmpty(host)) {
1053 entry.intent = new Intent(Intent.ACTION_SENDTO,
1054 constructImToUrl(host, entry.data));
1055 }
1056 //TODO(emillar) Add in presence info
1057 /*if (!aggCursor.isNull(METHODS_STATUS_COLUMN)) {
1058 entry.presenceIcon = Presence.getPresenceIconResourceId(
1059 aggCursor.getInt(METHODS_STATUS_COLUMN));
1060 entry.status = ...
1061 }*/
1062 mImEntries.add(entry);
1063 }
1064 } else if (CommonDataKinds.Organization.CONTENT_ITEM_TYPE.equals(mimetype)) {
1065 // Build organization entries
1066 mOrganizationEntries.add(entry);
1067 } else if (CommonDataKinds.Note.CONTENT_ITEM_TYPE.equals(mimetype)) {
1068 // Build note entries
1069 entry.id = 0;
1070 entry.uri = null;
1071 entry.intent = null;
1072 entry.maxLines = 10;
1073 mOtherEntries.add(entry);
1074 }
1075
1076
1077 // TODO(emillar) Add group entries
1078 // // Build the group entries
1079 // final Uri groupsUri = Uri.withAppendedPath(mUri, GroupMembership.CONTENT_DIRECTORY);
1080 // Cursor groupCursor = mResolver.query(groupsUri, ContactsListActivity.GROUPS_PROJECTION,
1081 // null, null, Groups.DEFAULT_SORT_ORDER);
1082 // if (groupCursor != null) {
1083 // try {
1084 // StringBuilder sb = new StringBuilder();
1085 //
1086 // while (groupCursor.moveToNext()) {
1087 // String systemId = groupCursor.getString(
1088 // ContactsListActivity.GROUPS_COLUMN_INDEX_SYSTEM_ID);
1089 //
1090 // if (systemId != null || Groups.GROUP_MY_CONTACTS.equals(systemId)) {
1091 // continue;
1092 // }
1093 //
1094 // String name = groupCursor.getString(ContactsListActivity.GROUPS_COLUMN_INDEX_NAME);
1095 // if (!TextUtils.isEmpty(name)) {
1096 // if (sb.length() == 0) {
1097 // sb.append(name);
1098 // } else {
1099 // sb.append(getString(R.string.group_list, name));
1100 // }
1101 // }
1102 // }
1103 //
1104 // if (sb.length() > 0) {
1105 // ViewEntry entry = new ViewEntry();
1106 // entry.kind = ContactEntryAdapter.Entry.KIND_GROUP;
1107 // entry.label = getString(R.string.label_groups);
1108 // entry.data = sb.toString();
1109 // entry.intent = new Intent(Intent.ACTION_EDIT, mUri);
1110 //
1111 // // TODO: Add an icon for the groups item.
1112 //
1113 // mGroupEntries.add(entry);
1114 // }
1115 // } finally {
1116 // groupCursor.close();
1117 // }
1118 // }
Evan Millar66388be2009-05-28 15:41:07 -07001119 }
Evan Millar5c22c3b2009-05-29 11:37:54 -07001120
Evan Millar66388be2009-05-28 15:41:07 -07001121 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001122 }
1123 }
1124
Evan Millar11d628c2009-09-02 08:55:01 -07001125 String buildActionString(DataKind kind, ContentValues values, boolean lowerCase) {
1126 if (kind.actionHeader == null) {
1127 return null;
Jeff Hamilton8350e5b2009-03-24 21:01:34 -07001128 }
Evan Millar11d628c2009-09-02 08:55:01 -07001129 CharSequence actionHeader = kind.actionHeader.inflateUsing(this, values);
1130 if (actionHeader == null) {
1131 return null;
1132 }
1133 return lowerCase ? actionHeader.toString().toLowerCase() : actionHeader.toString();
1134 }
Jeff Hamilton8350e5b2009-03-24 21:01:34 -07001135
Evan Millar11d628c2009-09-02 08:55:01 -07001136 String buildDataString(DataKind kind, ContentValues values) {
1137 if (kind.actionBody == null) {
1138 return null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001139 }
Evan Millar11d628c2009-09-02 08:55:01 -07001140 CharSequence actionBody = kind.actionBody.inflateUsing(this, values);
1141 return actionBody == null ? null : actionBody.toString();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001142 }
Evan Millar5c22c3b2009-05-29 11:37:54 -07001143
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001144 /**
1145 * A basic structure with the data for a contact entry in the list.
1146 */
Evan Millar54a5c9f2009-06-23 17:41:09 -07001147 static class ViewEntry extends ContactEntryAdapter.Entry implements Collapsible<ViewEntry> {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001148 public int actionIcon = -1;
Evan Millar15e514d2009-08-04 10:14:57 -07001149 public boolean isPrimary = false;
1150 public int presenceIcon = -1;
1151 public int secondaryActionIcon = -1;
1152 public Intent intent;
1153 public Intent secondaryIntent = null;
1154 public int status = -1;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001155 public int maxLabelLines = 1;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001156 public ArrayList<Long> ids = new ArrayList<Long>();
1157 public int collapseCount = 0;
1158
1159 public boolean collapseWith(ViewEntry entry) {
1160 // assert equal collapse keys
1161 if (!getCollapseKey().equals(entry.getCollapseKey())) {
1162 return false;
1163 }
1164
1165 // Choose the label associated with the highest type precedence.
1166 if (TypePrecedence.getTypePrecedence(mimetype, type)
1167 > TypePrecedence.getTypePrecedence(entry.mimetype, entry.type)) {
1168 type = entry.type;
1169 label = entry.label;
1170 }
1171
1172 // Choose the max of the maxLines and maxLabelLines values.
1173 maxLines = Math.max(maxLines, entry.maxLines);
1174 maxLabelLines = Math.max(maxLabelLines, entry.maxLabelLines);
1175
1176 // Choose the presence with the highest precedence.
1177 if (Presence.getPresencePrecedence(status)
1178 < Presence.getPresencePrecedence(entry.status)) {
1179 status = entry.status;
1180 }
1181
1182 // If any of the collapsed entries are primary make the whole thing primary.
Evan Millar15e514d2009-08-04 10:14:57 -07001183 isPrimary = entry.isPrimary ? true : isPrimary;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001184
1185 // uri, and contactdId, shouldn't make a difference. Just keep the original.
1186
1187 // Keep track of all the ids that have been collapsed with this one.
1188 ids.add(entry.id);
1189 collapseCount++;
1190 return true;
1191 }
1192
1193 public String getCollapseKey() {
1194 StringBuilder hashSb = new StringBuilder();
1195 hashSb.append(data);
1196 hashSb.append(mimetype);
1197 hashSb.append((intent != null && intent.getAction() != null)
1198 ? intent.getAction() : "");
Evan Millar15e514d2009-08-04 10:14:57 -07001199 hashSb.append((secondaryIntent != null && secondaryIntent.getAction() != null)
1200 ? secondaryIntent.getAction() : "");
Evan Millar54a5c9f2009-06-23 17:41:09 -07001201 hashSb.append(actionIcon);
1202 return hashSb.toString();
1203 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001204 }
1205
Evan Millar15e514d2009-08-04 10:14:57 -07001206 /** Cache of the children views of a row */
1207 static class ViewCache {
1208 public TextView label;
1209 public TextView data;
1210 public ImageView actionIcon;
1211 public ImageView presenceIcon;
1212 public ImageView primaryIcon;
1213 public ImageView secondaryActionButton;
1214 public View secondaryActionDivider;
Evan Millar5c22c3b2009-05-29 11:37:54 -07001215
Evan Millar15e514d2009-08-04 10:14:57 -07001216 // Need to keep track of this too
1217 ViewEntry entry;
1218 }
1219
1220 private final class ViewAdapter extends ContactEntryAdapter<ViewEntry>
1221 implements View.OnClickListener {
1222
Evan Millar5c22c3b2009-05-29 11:37:54 -07001223
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001224 ViewAdapter(Context context, ArrayList<ArrayList<ViewEntry>> sections) {
1225 super(context, sections, SHOW_SEPARATORS);
1226 }
1227
Evan Millar15e514d2009-08-04 10:14:57 -07001228 public void onClick(View v) {
1229 Intent intent = (Intent) v.getTag();
1230 startActivity(intent);
1231 }
1232
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001233 @Override
1234 public View getView(int position, View convertView, ViewGroup parent) {
Evan Millar5c22c3b2009-05-29 11:37:54 -07001235 ViewEntry entry = getEntry(mSections, position, false);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001236 View v;
1237
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001238 ViewCache views;
1239
1240 // Check to see if we can reuse convertView
1241 if (convertView != null) {
1242 v = convertView;
1243 views = (ViewCache) v.getTag();
1244 } else {
1245 // Create a new view if needed
1246 v = mInflater.inflate(R.layout.list_item_text_icons, parent, false);
1247
1248 // Cache the children
1249 views = new ViewCache();
1250 views.label = (TextView) v.findViewById(android.R.id.text1);
1251 views.data = (TextView) v.findViewById(android.R.id.text2);
Evan Millar15e514d2009-08-04 10:14:57 -07001252 views.actionIcon = (ImageView) v.findViewById(R.id.action_icon);
1253 views.primaryIcon = (ImageView) v.findViewById(R.id.primary_icon);
1254 views.presenceIcon = (ImageView) v.findViewById(R.id.presence_icon);
1255 views.secondaryActionButton = (ImageView) v.findViewById(
1256 R.id.secondary_action_button);
1257 views.secondaryActionButton.setOnClickListener(this);
Evan Millar15e514d2009-08-04 10:14:57 -07001258 views.secondaryActionDivider = v.findViewById(R.id.divider);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001259 v.setTag(views);
1260 }
1261
1262 // Update the entry in the view cache
1263 views.entry = entry;
1264
1265 // Bind the data to the view
1266 bindView(v, entry);
1267 return v;
1268 }
1269
1270 @Override
1271 protected View newView(int position, ViewGroup parent) {
1272 // getView() handles this
1273 throw new UnsupportedOperationException();
1274 }
1275
1276 @Override
1277 protected void bindView(View view, ViewEntry entry) {
1278 final Resources resources = mContext.getResources();
1279 ViewCache views = (ViewCache) view.getTag();
1280
1281 // Set the label
1282 TextView label = views.label;
1283 setMaxLines(label, entry.maxLabelLines);
1284 label.setText(entry.label);
1285
1286 // Set the data
1287 TextView data = views.data;
1288 if (data != null) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001289 if (entry.mimetype.equals(Phone.CONTENT_ITEM_TYPE)
1290 || entry.mimetype.equals(FastTrackWindow.MIME_SMS_ADDRESS)) {
1291 data.setText(PhoneNumberUtils.formatNumber(entry.data));
1292 } else {
1293 data.setText(entry.data);
1294 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001295 setMaxLines(data, entry.maxLines);
1296 }
1297
Evan Millar15e514d2009-08-04 10:14:57 -07001298 // Set the primary icon
1299 views.primaryIcon.setVisibility(entry.isPrimary ? View.VISIBLE : View.GONE);
1300
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001301 // Set the action icon
1302 ImageView action = views.actionIcon;
1303 if (entry.actionIcon != -1) {
1304 action.setImageDrawable(resources.getDrawable(entry.actionIcon));
1305 action.setVisibility(View.VISIBLE);
1306 } else {
1307 // Things should still line up as if there was an icon, so make it invisible
1308 action.setVisibility(View.INVISIBLE);
1309 }
1310
1311 // Set the presence icon
1312 Drawable presenceIcon = null;
Evan Millar15e514d2009-08-04 10:14:57 -07001313 if (entry.presenceIcon != -1) {
1314 presenceIcon = resources.getDrawable(entry.presenceIcon);
Evan Millar54a5c9f2009-06-23 17:41:09 -07001315 } else if (entry.status != -1) {
1316 presenceIcon = resources.getDrawable(
1317 Presence.getPresenceIconResourceId(entry.status));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001318 }
Evan Millar15e514d2009-08-04 10:14:57 -07001319 ImageView presenceIconView = views.presenceIcon;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001320 if (presenceIcon != null) {
Evan Millar15e514d2009-08-04 10:14:57 -07001321 presenceIconView.setImageDrawable(presenceIcon);
1322 presenceIconView.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001323 } else {
Evan Millar15e514d2009-08-04 10:14:57 -07001324 presenceIconView.setVisibility(View.GONE);
1325 }
1326
1327 // Set the secondary action button
1328 ImageView secondaryActionView = views.secondaryActionButton;
1329 Drawable secondaryActionIcon = null;
1330 if (entry.secondaryActionIcon != -1) {
1331 secondaryActionIcon = resources.getDrawable(entry.secondaryActionIcon);
1332 }
1333 if (entry.secondaryIntent != null && secondaryActionIcon != null) {
1334 secondaryActionView.setImageDrawable(secondaryActionIcon);
1335 secondaryActionView.setTag(entry.secondaryIntent);
1336 secondaryActionView.setVisibility(View.VISIBLE);
1337 views.secondaryActionDivider.setVisibility(View.VISIBLE);
1338 } else {
1339 secondaryActionView.setVisibility(View.GONE);
1340 views.secondaryActionDivider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001341 }
1342 }
1343
1344 private void setMaxLines(TextView textView, int maxLines) {
1345 if (maxLines == 1) {
1346 textView.setSingleLine(true);
1347 textView.setEllipsize(TextUtils.TruncateAt.END);
1348 } else {
1349 textView.setSingleLine(false);
1350 textView.setMaxLines(maxLines);
1351 textView.setEllipsize(null);
1352 }
1353 }
1354 }
1355}