blob: 77b69c3823fca67ac659928dc12720f4315e58e5 [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;
Jeff Sharkey49d17b32009-09-07 02:14:21 -070025import com.android.contacts.util.Constants;
Evan Millar11d628c2009-09-02 08:55:01 -070026import com.android.contacts.util.NotifyingAsyncQueryHandler;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080027import com.android.internal.telephony.ITelephony;
Evan Millar11d628c2009-09-02 08:55:01 -070028import com.android.internal.widget.ContactHeaderWidget;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080029
Evan Millar11d628c2009-09-02 08:55:01 -070030import android.app.Activity;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080031import android.app.AlertDialog;
32import android.app.Dialog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080033import android.content.ActivityNotFoundException;
34import android.content.ContentResolver;
35import android.content.ContentUris;
36import android.content.ContentValues;
37import android.content.Context;
38import android.content.DialogInterface;
Evan Millar5f4af702009-08-11 11:12:00 -070039import android.content.Entity;
Evan Millar11d628c2009-09-02 08:55:01 -070040import android.content.EntityIterator;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080041import android.content.Intent;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070042import android.content.DialogInterface.OnClickListener;
Evan Millar11d628c2009-09-02 08:55:01 -070043import android.content.Entity.NamedContentValues;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080044import android.content.res.Resources;
45import android.database.ContentObserver;
46import android.database.Cursor;
47import android.graphics.drawable.Drawable;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080048import android.net.Uri;
49import android.os.Bundle;
50import android.os.Handler;
51import android.os.RemoteException;
52import android.os.ServiceManager;
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -070053import android.provider.ContactsContract;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070054import android.provider.ContactsContract.AggregationExceptions;
55import android.provider.ContactsContract.CommonDataKinds;
Evan Millar11d628c2009-09-02 08:55:01 -070056import android.provider.ContactsContract.Contacts;
Evan Millar66388be2009-05-28 15:41:07 -070057import android.provider.ContactsContract.Data;
Evan Millar54a5c9f2009-06-23 17:41:09 -070058import android.provider.ContactsContract.Presence;
Dmitri Plotnikov39466592009-07-27 11:23:51 -070059import android.provider.ContactsContract.RawContacts;
Evan Millar54a5c9f2009-06-23 17:41:09 -070060import android.provider.ContactsContract.CommonDataKinds.Phone;
61import android.telephony.PhoneNumberUtils;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080062import android.text.TextUtils;
63import android.util.Log;
Evan Millar11d628c2009-09-02 08:55:01 -070064import android.util.SparseArray;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080065import android.view.ContextMenu;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070066import android.view.ContextThemeWrapper;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080067import android.view.KeyEvent;
Evan Millar11d628c2009-09-02 08:55:01 -070068import android.view.LayoutInflater;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080069import android.view.Menu;
Jeff Sharkey49d17b32009-09-07 02:14:21 -070070import android.view.MenuInflater;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080071import android.view.MenuItem;
72import android.view.View;
73import android.view.ViewGroup;
Evan Millar11d628c2009-09-02 08:55:01 -070074import android.view.Window;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080075import android.view.ContextMenu.ContextMenuInfo;
Evan Millar2e1b8af2009-09-24 09:39:21 -070076import android.view.animation.Animation;
77import android.view.animation.AnimationUtils;
78import android.view.animation.TranslateAnimation;
79import android.view.animation.Animation.AnimationListener;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080080import 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;
Evan Millar2e1b8af2009-09-24 09:39:21 -070083import android.widget.LinearLayout;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080084import android.widget.ListView;
85import android.widget.TextView;
86import android.widget.Toast;
87
88import java.util.ArrayList;
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 Millar2e1b8af2009-09-24 09:39:21 -070095 AdapterView.OnItemClickListener, NotifyingAsyncQueryHandler.AsyncQueryListener,
96 OnTabSelectionChangedListener {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080097 private static final String TAG = "ViewContact";
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080098
Evan Millar8a79cee2009-08-19 17:20:49 -070099 public static final String RAW_CONTACT_ID_EXTRA = "rawContactIdExtra";
100
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800101 private static final boolean SHOW_SEPARATORS = false;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800102
103 private static final int DIALOG_CONFIRM_DELETE = 1;
104
Evan Millar8a79cee2009-08-19 17:20:49 -0700105 private static final int REQUEST_JOIN_CONTACT = 1;
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700106
Evan Millar8a79cee2009-08-19 17:20:49 -0700107 public static final int MENU_ITEM_MAKE_DEFAULT = 3;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800108
Evan Millar2e1b8af2009-09-24 09:39:21 -0700109 private static final String SPLIT_MIMETYPE = "split_mimetype";
110
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700111 protected Uri mLookupUri;
Evan Millar11d628c2009-09-02 08:55:01 -0700112 private Uri mUri;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800113 private ContentResolver mResolver;
114 private ViewAdapter mAdapter;
115 private int mNumPhoneNumbers = 0;
116
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700117 /**
Dmitri Plotnikove1cd6792009-07-27 20:28:17 -0700118 * A list of distinct contact IDs included in the current contact.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700119 */
Evan Millar7911ff52009-07-21 15:55:18 -0700120 private ArrayList<Long> mRawContactIds = new ArrayList<Long>();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700121
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800122 /* package */ ArrayList<ViewEntry> mPhoneEntries = new ArrayList<ViewEntry>();
123 /* package */ ArrayList<ViewEntry> mSmsEntries = new ArrayList<ViewEntry>();
124 /* package */ ArrayList<ViewEntry> mEmailEntries = new ArrayList<ViewEntry>();
125 /* package */ ArrayList<ViewEntry> mPostalEntries = new ArrayList<ViewEntry>();
126 /* package */ ArrayList<ViewEntry> mImEntries = new ArrayList<ViewEntry>();
127 /* package */ ArrayList<ViewEntry> mOrganizationEntries = new ArrayList<ViewEntry>();
The Android Open Source Projectcac191e2009-03-18 22:20:27 -0700128 /* package */ ArrayList<ViewEntry> mGroupEntries = new ArrayList<ViewEntry>();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800129 /* package */ ArrayList<ViewEntry> mOtherEntries = new ArrayList<ViewEntry>();
Evan Millar2e1b8af2009-09-24 09:39:21 -0700130 /* package */ ArrayList<ViewEntry> mSplitEntry = new ArrayList<ViewEntry>();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800131 /* package */ ArrayList<ArrayList<ViewEntry>> mSections = new ArrayList<ArrayList<ViewEntry>>();
132
133 private Cursor mCursor;
Evan Millar5c22c3b2009-05-29 11:37:54 -0700134
Evan Millar11d628c2009-09-02 08:55:01 -0700135 private SparseArray<Long> mTabRawContactIdMap;
136 protected ScrollingTabWidget mTabWidget;
137 protected ContactHeaderWidget mContactHeaderWidget;
Evan Millar2e1b8af2009-09-24 09:39:21 -0700138 protected View mBelowHeader;
139 protected View mBufferView;
Evan Millar11d628c2009-09-02 08:55:01 -0700140 private NotifyingAsyncQueryHandler mHandler;
141
142 protected LayoutInflater mInflater;
143
144 //Projection used for the query that determines which tabs to add.
145 protected static final String[] TAB_PROJECTION = new String[] {
146 RawContacts._ID,
147 RawContacts.ACCOUNT_NAME,
148 RawContacts.ACCOUNT_TYPE
149 };
150 protected static final int TAB_CONTACT_ID_COLUMN_INDEX = 0;
151 protected static final int TAB_ACCOUNT_NAME_COLUMN_INDEX = 1;
152 protected static final int TAB_ACCOUNT_TYPE_COLUMN_INDEX = 2;
153
154 protected static final String SELECTED_RAW_CONTACT_ID_KEY = "selectedRawContact";
155 protected Long mSelectedRawContactId = null;
156
157 private static final int TOKEN_QUERY = 0;
158
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800159 private ContentObserver mObserver = new ContentObserver(new Handler()) {
160 @Override
161 public boolean deliverSelfNotifications() {
162 return true;
163 }
164
165 @Override
166 public void onChange(boolean selfChange) {
Evan Millar11d628c2009-09-02 08:55:01 -0700167 if (mCursor != null && !mCursor.isClosed()) {
168 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800169 }
170 }
171 };
172
173 public void onClick(DialogInterface dialog, int which) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700174 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800175 getContentResolver().delete(mUri, null, null);
176 finish();
177 }
178
Evan Millar7911ff52009-07-21 15:55:18 -0700179 private FrameLayout mTabContentLayout;
180 private ListView mListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800181 private boolean mShowSmsLinksForAllPhones;
Evan Millar11d628c2009-09-02 08:55:01 -0700182 private ArrayList<Entity> mEntities = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800183
Evan Millar2e1b8af2009-09-24 09:39:21 -0700184 private boolean mTabsVisible;
185
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800186 @Override
187 protected void onCreate(Bundle icicle) {
188 super.onCreate(icicle);
189
Evan Millar11d628c2009-09-02 08:55:01 -0700190 final Intent intent = getIntent();
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -0700191 Uri data = intent.getData();
192 String authority = data.getAuthority();
193 if (ContactsContract.AUTHORITY.equals(authority)) {
194 mLookupUri = data;
195 } else if (android.provider.Contacts.AUTHORITY.equals(authority)) {
196 final long rawContactId = ContentUris.parseId(data);
197 mLookupUri = RawContacts.getContactLookupUri(getContentResolver(),
198 ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700199
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -0700200 }
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700201 mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Evan Millar11d628c2009-09-02 08:55:01 -0700202
203 requestWindowFeature(Window.FEATURE_NO_TITLE);
204 setContentView(R.layout.contact_card_layout);
205
206 mContactHeaderWidget = (ContactHeaderWidget) findViewById(R.id.contact_header_widget);
207 mContactHeaderWidget.showStar(true);
Evan Millar11d628c2009-09-02 08:55:01 -0700208 mContactHeaderWidget.setExcludeMimes(new String[] {
209 Contacts.CONTENT_ITEM_TYPE
210 });
211
212 mTabWidget = (ScrollingTabWidget) findViewById(R.id.tab_widget);
Evan Millar2e1b8af2009-09-24 09:39:21 -0700213 mTabWidget.setTabSelectionListener(this);
Evan Millar85863112009-09-21 14:35:18 -0700214 mTabWidget.setVisibility(View.GONE);
Evan Millar2e1b8af2009-09-24 09:39:21 -0700215 mTabsVisible = false;
216
217 mBelowHeader = findViewById(R.id.below_header);
Evan Millar11d628c2009-09-02 08:55:01 -0700218
219 mTabRawContactIdMap = new SparseArray<Long>();
220
221 mHandler = new NotifyingAsyncQueryHandler(this, this);
222
Evan Millar7911ff52009-07-21 15:55:18 -0700223 mListView = new ListView(this);
224 mListView.setOnCreateContextMenuListener(this);
225 mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
226 mListView.setOnItemClickListener(this);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800227
Evan Millar7911ff52009-07-21 15:55:18 -0700228 mTabContentLayout = (FrameLayout) findViewById(android.R.id.tabcontent);
229 mTabContentLayout.addView(mListView);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800230
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800231 mResolver = getContentResolver();
232
233 // Build the list of sections. The order they're added to mSections dictates the
234 // order they are displayed in the list.
235 mSections.add(mPhoneEntries);
236 mSections.add(mSmsEntries);
237 mSections.add(mEmailEntries);
238 mSections.add(mImEntries);
239 mSections.add(mPostalEntries);
240 mSections.add(mOrganizationEntries);
The Android Open Source Projectcac191e2009-03-18 22:20:27 -0700241 mSections.add(mGroupEntries);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800242 mSections.add(mOtherEntries);
Evan Millar2e1b8af2009-09-24 09:39:21 -0700243 mSections.add(mSplitEntry);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800244
245 //TODO Read this value from a preference
246 mShowSmsLinksForAllPhones = true;
Evan Millar11d628c2009-09-02 08:55:01 -0700247 }
248
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800249 @Override
250 protected void onResume() {
251 super.onResume();
Evan Millar2e1b8af2009-09-24 09:39:21 -0700252 showTabs(false, false /*no animation*/);
Evan Millar11d628c2009-09-02 08:55:01 -0700253 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800254 }
255
256 @Override
257 protected void onPause() {
258 super.onPause();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700259 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800260 }
261
262 @Override
263 protected void onDestroy() {
264 super.onDestroy();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700265 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800266 }
267
268 @Override
269 protected Dialog onCreateDialog(int id) {
270 switch (id) {
271 case DIALOG_CONFIRM_DELETE:
272 return new AlertDialog.Builder(this)
273 .setTitle(R.string.deleteConfirmation_title)
274 .setIcon(android.R.drawable.ic_dialog_alert)
275 .setMessage(R.string.deleteConfirmation)
276 .setNegativeButton(android.R.string.cancel, null)
277 .setPositiveButton(android.R.string.ok, this)
278 .setCancelable(false)
279 .create();
280 }
281 return null;
282 }
283
Evan Millar11d628c2009-09-02 08:55:01 -0700284
285 // TAB CODE //
286 /**
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700287 * Adds a tab for each {@link RawContacts} associated with this contact.
Evan Millar11d628c2009-09-02 08:55:01 -0700288 * Override this method if you want to additional tabs and/or different
289 * tabs for your activity.
Evan Millar11d628c2009-09-02 08:55:01 -0700290 */
Evan Millar2e1b8af2009-09-24 09:39:21 -0700291 protected void bindTabs() {
292 final Sources sources = Sources.getInstance(this);
293
294 for (Entity entity : mEntities) {
295 final String accountType = entity.getEntityValues().
296 getAsString(RawContacts.ACCOUNT_TYPE);
297 final Long rawContactId = entity.getEntityValues().
298 getAsLong(RawContacts._ID);
299
300 // TODO: ensure inflation on background task so we don't block UI thread here
301 final ContactsSource source = sources.getInflatedSource(accountType,
302 ContactsSource.LEVEL_SUMMARY);
303 addTab(rawContactId, ContactsUtils.createTabIndicatorView(mTabWidget.getTabParent(),
304 source));
305 }
306 }
307
308 /**
309 * Add a tab to be displayed in the {@link ScrollingTabWidget}.
310 *
311 * @param rawContactId The contact id associated with the tab.
312 * @param view A view to use as the tab indicator.
313 */
314 protected void addTab(long rawContactId, View view) {
315 mTabRawContactIdMap.put(mTabWidget.getTabCount(), rawContactId);
316 mTabWidget.addTab(view);
317 }
318
319
320 protected void clearCurrentTabs() {
321 mTabRawContactIdMap.clear();
322 mTabWidget.removeAllTabs();
323 }
324
325 protected void selectInitialTab() {
326 int selectedTabIndex = 0;
327
328 if (mSelectedRawContactId != null) {
329 selectedTabIndex = getTabIndexForRawContactId(mSelectedRawContactId);
330 if (selectedTabIndex == -1) {
331 // If there was no matching tab, just select the first;
332 selectedTabIndex = 0;
333 }
334 }
335
336 mTabWidget.setCurrentTab(selectedTabIndex);
337 onTabSelectionChanged(selectedTabIndex, false);
338 }
339
340 public void onTabSelectionChanged(int tabIndex, boolean clicked) {
341 Long rawContactId = getTabRawContactId(tabIndex);
342 if (rawContactId != null) {
343 mSelectedRawContactId = rawContactId;
344 bindData();
345 }
346 }
347
348 /**
349 * Return the RawContact id associated with the tab at an index.
350 *
351 * @param index The index of the tab in question.
352 * @return The contactId associated with the tab at the specified index.
353 */
354 protected Long getTabRawContactId(int index) {
355 return mTabRawContactIdMap.get(index);
356 }
357
358 /**
359 * Return the tab index associated with the RawContact id.
360 *
361 * @param index The index of the tab in question.
362 * @return The contactId associated with the tab at the specified index.
363 */
364 protected int getTabIndexForRawContactId(long rawContactId) {
365 int numTabs = mTabRawContactIdMap.size();
366 for (int i=0; i < numTabs; i++) {
367 if (mTabRawContactIdMap.get(i) == rawContactId) {
368 return i;
369 }
370 }
371 return -1;
372 }
373
374 protected void showTabs(boolean show, boolean animate) {
375 if (mTabsVisible == show) {
376 return;
377 }
378
379 float tabHeight = getResources().getDimension(R.dimen.tab_height);
380 if (show) {
381 if (animate) {
382 TranslateAnimation showAnimation = new TranslateAnimation(
383 Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0,
384 Animation.ABSOLUTE, -tabHeight, Animation.ABSOLUTE, 0);
385 showAnimation.setDuration(getResources().getInteger(
386 android.R.integer.config_longAnimTime));
387
388 showAnimation.setAnimationListener(new AnimationListener() {
389 public void onAnimationEnd(Animation animation) {
390 selectInitialTab();
391 bindData();
392 }
393
394 public void onAnimationRepeat(Animation animation) {
395 }
396
397 public void onAnimationStart(Animation animation) {
398 }
399
400 });
401
402 mBelowHeader.startAnimation(showAnimation);
403 }
404 mTabWidget.setVisibility(View.VISIBLE);
405 mTabsVisible = true;
406 clearCurrentTabs();
407 bindTabs();
408 if (!animate) {
409 selectInitialTab();
410 bindData();
411 }
412 } else {
413 if (animate) {
414 TranslateAnimation hideTabsAnimation = new TranslateAnimation(
415 Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0,
416 Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -tabHeight);
417 hideTabsAnimation.setDuration(getResources().getInteger(
418 android.R.integer.config_longAnimTime));
419 hideTabsAnimation.setAnimationListener(new AnimationListener() {
420 public void onAnimationEnd(Animation animation) {
421 bindData();
422 }
423
424 public void onAnimationRepeat(Animation animation) {
425 }
426
427 public void onAnimationStart(Animation animation) {
428 }
429
430 });
431
432 TranslateAnimation hideListAnimation = new TranslateAnimation(
433 Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0,
434 Animation.ABSOLUTE, tabHeight, Animation.ABSOLUTE, 0);
435 hideListAnimation.setDuration(getResources().getInteger(
436 android.R.integer.config_longAnimTime));
437
438
439 mTabWidget.startAnimation(hideTabsAnimation);
440 mTabContentLayout.startAnimation(hideListAnimation);
441 }
442 mTabWidget.setVisibility(View.GONE);
443 mTabsVisible = false;
444 mSelectedRawContactId = null;
445 if (!animate) {
446 bindData();
447 }
448 }
449 }
Evan Millar11d628c2009-09-02 08:55:01 -0700450
451
452 // QUERY CODE //
453 /** {@inheritDoc} */
454 public void onQueryEntitiesComplete(int token, Object cookie, EntityIterator iterator) {
455 try{
456 if (token == TOKEN_QUERY) {
Evan Millar11d628c2009-09-02 08:55:01 -0700457 mEntities = readEntities(iterator);
Evan Millar85863112009-09-21 14:35:18 -0700458 // Show the aggregate badge if this contact is aggregated.
Evan Millarcc87fb92009-09-22 15:27:47 -0700459 boolean isAggregate = mEntities.size() > 1;
460 mContactHeaderWidget.showAggregateBadge(isAggregate);
Evan Millar2e1b8af2009-09-24 09:39:21 -0700461 if (mTabsVisible) {
462 clearCurrentTabs();
463 bindTabs();
464 selectInitialTab();
465 }
Evan Millar85863112009-09-21 14:35:18 -0700466 bindData();
Evan Millar11d628c2009-09-02 08:55:01 -0700467 }
468 } finally {
469 if (iterator != null) {
470 iterator.close();
471 }
472 }
473 }
474
475 /** {@inheritDoc} */
476 public void onQueryComplete(int token, Object cookie, Cursor cursor) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700477 // Empty
Evan Millar11d628c2009-09-02 08:55:01 -0700478 }
479
480 private ArrayList<Entity> readEntities(EntityIterator iterator) {
481 ArrayList<Entity> entities = new ArrayList<Entity>();
482 try {
483 while (iterator.hasNext()) {
484 entities.add(iterator.next());
485 }
486 } catch (RemoteException e) {
487 }
488
489 return entities;
490 }
491
492 private void startEntityQuery() {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700493 closeCursor();
494
Dmitri Plotnikov0306bbd2009-09-03 14:37:15 -0700495 mUri = null;
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700496 if (mLookupUri != null) {
497 mLookupUri = Contacts.getLookupUri(getContentResolver(), mLookupUri);
498 if (mLookupUri != null) {
499 mUri = Contacts.lookupContact(getContentResolver(), mLookupUri);
500 }
501 }
502
503 if (mUri == null) {
504
505 // TODO either figure out a way to prevent a flash of black background or
506 // use some other UI than a toast
507 Toast.makeText(this, R.string.invalidContactMessage, Toast.LENGTH_SHORT).show();
508 Log.e(TAG, "invalid contact uri: " + mLookupUri);
509 finish();
510 return;
511 }
512
513 mCursor = mResolver.query(Uri.withAppendedPath(mUri, Contacts.Data.CONTENT_DIRECTORY),
514 new String[] {Contacts.DISPLAY_NAME}, null, null, null);
515 mCursor.registerContentObserver(mObserver);
516
Evan Millar11d628c2009-09-02 08:55:01 -0700517 long contactId = ContentUris.parseId(mUri);
518 mHandler.startQueryEntities(TOKEN_QUERY, null,
519 RawContacts.CONTENT_URI, RawContacts.CONTACT_ID + "=" + contactId, null, null);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700520
Evan Millar9b1a1242009-09-16 10:26:10 -0700521 mContactHeaderWidget.bindFromContactLookupUri(mLookupUri);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700522 }
523
524 private void closeCursor() {
525 if (mCursor != null) {
526 mCursor.unregisterContentObserver(mObserver);
527 mCursor.close();
528 mCursor = null;
529 }
Evan Millar11d628c2009-09-02 08:55:01 -0700530 }
531
532 private void bindData() {
533
534 // Build up the contact entries
535 buildEntries();
536
537 // Collapse similar data items in select sections.
538 Collapser.collapseList(mPhoneEntries);
539 Collapser.collapseList(mSmsEntries);
540 Collapser.collapseList(mEmailEntries);
541 Collapser.collapseList(mPostalEntries);
542
543 if (mAdapter == null) {
544 mAdapter = new ViewAdapter(this, mSections);
545 mListView.setAdapter(mAdapter);
546 } else {
547 mAdapter.setSections(mSections, SHOW_SEPARATORS);
548 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800549 }
550
551 @Override
552 public boolean onCreateOptionsMenu(Menu menu) {
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700553 super.onCreateOptionsMenu(menu);
554
555 final MenuInflater inflater = getMenuInflater();
556 inflater.inflate(R.menu.view, menu);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800557 return true;
558 }
559
560 @Override
561 public boolean onPrepareOptionsMenu(Menu menu) {
562 super.onPrepareOptionsMenu(menu);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700563
Evan Millar2e1b8af2009-09-24 09:39:21 -0700564 // If tabWidget is not shown enable "show sources", otherwise
565 // enable "hide sources"
566 if (mTabsVisible) {
567 menu.findItem(R.id.menu_show_sources).setVisible(false);
568 menu.findItem(R.id.menu_hide_sources).setVisible(true);
569 } else {
570 menu.findItem(R.id.menu_show_sources).setVisible(true);
571 menu.findItem(R.id.menu_hide_sources).setVisible(false);
572 }
573
Evan Millar51514db2009-09-22 11:42:35 -0700574 // Only allow edit when we have at least one raw_contact id
575 final boolean hasRawContact = (mRawContactIds.size() > 0);
Evan Millar2e1b8af2009-09-24 09:39:21 -0700576 menu.findItem(R.id.menu_edit).setEnabled(hasRawContact);
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700577
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800578 return true;
579 }
580
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800581 @Override
582 public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
583 AdapterView.AdapterContextMenuInfo info;
584 try {
585 info = (AdapterView.AdapterContextMenuInfo) menuInfo;
586 } catch (ClassCastException e) {
587 Log.e(TAG, "bad menuInfo", e);
588 return;
589 }
590
591 // This can be null sometimes, don't crash...
592 if (info == null) {
593 Log.e(TAG, "bad menuInfo");
594 return;
595 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700596
Evan Millar45e0ed32009-06-01 16:44:38 -0700597 ViewEntry entry = ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
598 if (entry.mimetype.equals(CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
599 menu.add(0, 0, 0, R.string.menu_call).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700600 menu.add(0, 0, 0, R.string.menu_sendSMS).setIntent(entry.secondaryIntent);
601 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700602 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultNumber);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800603 }
Evan Millar45e0ed32009-06-01 16:44:38 -0700604 } else if (entry.mimetype.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
605 menu.add(0, 0, 0, R.string.menu_sendEmail).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700606 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700607 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultEmail);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800608 }
Jeff Sharkeyc6ad3ab2009-07-21 19:30:15 -0700609 } else if (entry.mimetype.equals(CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700610 menu.add(0, 0, 0, R.string.menu_viewAddress).setIntent(entry.intent);
611 }
612 // TODO(emillar): add back with group support.
613 /* else if (entry.mimetype.equals()) {
614 menu.add(0, 0, 0, R.string.menu_viewGroup).setIntent(entry.intent);
615 } */
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800616 }
617
618 @Override
619 public boolean onOptionsItemSelected(MenuItem item) {
620 switch (item.getItemId()) {
Evan Millar2e1b8af2009-09-24 09:39:21 -0700621 case R.id.menu_show_sources: {
622 showTabs(true, true /*animate*/);
623 break;
624 }
625 case R.id.menu_hide_sources: {
626 showTabs(false, true /*animate*/);
627 break;
628 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700629 case R.id.menu_edit: {
Evan Millar2e1b8af2009-09-24 09:39:21 -0700630 Long rawContactIdToEdit = mSelectedRawContactId;
631 if (rawContactIdToEdit == null) {
632 if (mRawContactIds.size() > 0) {
633 rawContactIdToEdit = mRawContactIds.get(0);
634 } else {
635 // There is no rawContact to edit.
636 break;
637 }
Evan Millardb5d88c2009-08-28 09:31:57 -0700638 }
Evan Millar2e1b8af2009-09-24 09:39:21 -0700639 Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI,
640 rawContactIdToEdit);
641 startActivity(new Intent(Intent.ACTION_EDIT, rawContactUri));
Evan Millar8a79cee2009-08-19 17:20:49 -0700642 break;
643 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700644 case R.id.menu_delete: {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800645 // Get confirmation
646 showDialog(DIALOG_CONFIRM_DELETE);
647 return true;
648 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700649 case R.id.menu_join: {
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700650 showJoinAggregateActivity();
651 return true;
652 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700653 case R.id.menu_options: {
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700654 showOptionsActivity();
655 return true;
656 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700657 case R.id.menu_share: {
658 final Intent intent = new Intent(Intent.ACTION_SEND);
659 intent.setType(Contacts.CONTENT_ITEM_TYPE);
660 intent.putExtra(Intent.EXTRA_STREAM, mLookupUri);
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700661
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700662 // Launch chooser to share contact via
663 final CharSequence chooseTitle = getText(R.string.share_via);
664 final Intent chooseIntent = Intent.createChooser(intent, chooseTitle);
Evan Millar5c22c3b2009-05-29 11:37:54 -0700665
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700666 try {
667 startActivity(chooseIntent);
668 } catch (ActivityNotFoundException ex) {
669 Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800670 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700671 return true;
672 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800673 }
674 return super.onOptionsItemSelected(item);
675 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700676
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800677 @Override
678 public boolean onContextItemSelected(MenuItem item) {
679 switch (item.getItemId()) {
680 case MENU_ITEM_MAKE_DEFAULT: {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700681 if (makeItemDefault(item)) {
682 return true;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800683 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700684 break;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800685 }
686 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700687
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800688 return super.onContextItemSelected(item);
689 }
690
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700691 private boolean makeItemDefault(MenuItem item) {
692 ViewEntry entry = getViewEntryForMenuItem(item);
693 if (entry == null) {
694 return false;
695 }
696
697 // Update the primary values in the data record.
Evan Millar14fecb62009-09-09 09:23:12 -0700698 ContentValues values = new ContentValues(1);
Evan Millar54a5c9f2009-06-23 17:41:09 -0700699 values.put(Data.IS_SUPER_PRIMARY, 1);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700700 getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, entry.id),
701 values, null, null);
Evan Millar11d628c2009-09-02 08:55:01 -0700702 startEntityQuery();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700703 return true;
704 }
705
706 /**
707 * Shows a dialog that contains a list of all constituent contacts in this aggregate.
708 * The user picks a contact to be split into its own aggregate or clicks Cancel.
709 */
710 private void showSplitAggregateDialog() {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700711 // Wrap this dialog in a specific theme so that list items have correct text color.
712 final ContextThemeWrapper dialogContext =
713 new ContextThemeWrapper(this, android.R.style.Theme_Light);
714 AlertDialog.Builder builder =
715 new AlertDialog.Builder(dialogContext);
716 builder.setTitle(getString(R.string.splitAggregate_title));
717
718 final SplitAggregateView view = new SplitAggregateView(dialogContext, mUri);
719 builder.setView(view);
720
721 builder.setInverseBackgroundForced(true);
722 builder.setCancelable(true);
723 builder.setNegativeButton(android.R.string.cancel,
724 new OnClickListener() {
725 public void onClick(DialogInterface dialog, int which) {
726 dialog.dismiss();
727 }
728 });
729 final AlertDialog dialog = builder.create();
730
731 view.setOnContactSelectedListener(new OnContactSelectedListener() {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700732 public void onContactSelected(long rawContactId) {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700733 dialog.dismiss();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700734 splitContact(rawContactId);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700735 }
736 });
737
738 dialog.show();
739 }
740
741 /**
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700742 * Shows a list of aggregates that can be joined into the currently viewed aggregate.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700743 */
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700744 public void showJoinAggregateActivity() {
745 Intent intent = new Intent(ContactsListActivity.JOIN_AGGREGATE);
746 intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_ID, ContentUris.parseId(mUri));
Evan Millar8a79cee2009-08-19 17:20:49 -0700747 startActivityForResult(intent, REQUEST_JOIN_CONTACT);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700748 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700749
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700750 @Override
751 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
Evan Millar2e1b8af2009-09-24 09:39:21 -0700752 if (requestCode == REQUEST_JOIN_CONTACT) {
753 if (resultCode == RESULT_OK && intent != null) {
754 final long contactId = ContentUris.parseId(intent.getData());
755 joinAggregate(contactId);
Evan Millar8a79cee2009-08-19 17:20:49 -0700756 }
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700757 }
758 }
759
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700760 private void splitContact(long rawContactId) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700761 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_SEPARATE);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700762
763 // The split operation may have removed the original aggregate contact, so we need
764 // to requery everything
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700765 Toast.makeText(this, R.string.contactsSplitMessage, Toast.LENGTH_LONG).show();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700766 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700767 }
768
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700769 private void joinAggregate(final long contactId) {
Dmitri Plotnikov39466592009-07-27 11:23:51 -0700770 Cursor c = mResolver.query(RawContacts.CONTENT_URI, new String[] {RawContacts._ID},
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700771 RawContacts.CONTACT_ID + "=" + contactId, null, null);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700772
773 try {
774 while(c.moveToNext()) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700775 long rawContactId = c.getLong(0);
776 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_TOGETHER);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700777 }
778 } finally {
779 c.close();
780 }
781
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700782 Toast.makeText(this, R.string.contactsJoinedMessage, Toast.LENGTH_LONG).show();
783 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700784 }
785
786 /**
787 * Given a contact ID sets an aggregation exception to either join the contact with the
788 * current aggregate or split off.
789 */
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700790 protected void setAggregationException(long rawContactId, int exceptionType) {
Dmitri Plotnikovd09f75c2009-06-16 11:59:22 -0700791 ContentValues values = new ContentValues(3);
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700792 for (long aRawContactId : mRawContactIds) {
793 if (aRawContactId != rawContactId) {
794 values.put(AggregationExceptions.RAW_CONTACT_ID1, aRawContactId);
795 values.put(AggregationExceptions.RAW_CONTACT_ID2, rawContactId);
796 values.put(AggregationExceptions.TYPE, exceptionType);
797 mResolver.update(AggregationExceptions.CONTENT_URI, values, null, null);
798 }
799 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700800 }
801
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700802 private void showOptionsActivity() {
803 final Intent intent = new Intent(this, ContactOptionsActivity.class);
804 intent.setData(mUri);
805 startActivity(intent);
806 }
807
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700808 private ViewEntry getViewEntryForMenuItem(MenuItem item) {
809 AdapterView.AdapterContextMenuInfo info;
810 try {
811 info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
812 } catch (ClassCastException e) {
813 Log.e(TAG, "bad menuInfo", e);
814 return null;
815 }
816
817 return ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
818 }
819
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800820 @Override
821 public boolean onKeyDown(int keyCode, KeyEvent event) {
822 switch (keyCode) {
823 case KeyEvent.KEYCODE_CALL: {
824 try {
825 ITelephony phone = ITelephony.Stub.asInterface(
826 ServiceManager.checkService("phone"));
827 if (phone != null && !phone.isIdle()) {
828 // Skip out and let the key be handled at a higher level
829 break;
830 }
831 } catch (RemoteException re) {
832 // Fall through and try to call the contact
833 }
834
Evan Millar7911ff52009-07-21 15:55:18 -0700835 int index = mListView.getSelectedItemPosition();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800836 if (index != -1) {
837 ViewEntry entry = ViewAdapter.getEntry(mSections, index, SHOW_SEPARATORS);
Evan Millar66388be2009-05-28 15:41:07 -0700838 if (entry.intent.getAction() == Intent.ACTION_CALL_PRIVILEGED) {
839 startActivity(entry.intent);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800840 }
841 } else if (mNumPhoneNumbers != 0) {
842 // There isn't anything selected, call the default number
843 Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, mUri);
844 startActivity(intent);
845 }
846 return true;
847 }
848
849 case KeyEvent.KEYCODE_DEL: {
850 showDialog(DIALOG_CONFIRM_DELETE);
851 return true;
852 }
853 }
854
855 return super.onKeyDown(keyCode, event);
856 }
857
Evan Millar7911ff52009-07-21 15:55:18 -0700858 public void onItemClick(AdapterView parent, View v, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800859 ViewEntry entry = ViewAdapter.getEntry(mSections, position, SHOW_SEPARATORS);
860 if (entry != null) {
861 Intent intent = entry.intent;
Evan Millar2e1b8af2009-09-24 09:39:21 -0700862 if (entry.mimetype == SPLIT_MIMETYPE) {
863 splitContact(entry.id);
864 } else if (intent != null) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800865 try {
866 startActivity(intent);
867 } catch (ActivityNotFoundException e) {
868 Log.e(TAG, "No activity found for intent: " + intent);
869 signalError();
870 }
871 } else {
872 signalError();
873 }
874 } else {
875 signalError();
876 }
877 }
878
879 /**
880 * Signal an error to the user via a beep, or some other method.
881 */
882 private void signalError() {
883 //TODO: implement this when we have the sonification APIs
884 }
885
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800886 private Uri constructImToUrl(String host, String data) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700887 // 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 -0800888 StringBuilder buf = new StringBuilder("imto://");
889 buf.append(host);
890 buf.append('/');
891 buf.append(data);
892 return Uri.parse(buf.toString());
893 }
894
895 /**
896 * Build up the entries to display on the screen.
Evan Millar5c22c3b2009-05-29 11:37:54 -0700897 *
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800898 * @param personCursor the URI for the contact being displayed
899 */
Evan Millar11d628c2009-09-02 08:55:01 -0700900 private final void buildEntries() {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800901 // Clear out the old entries
902 final int numSections = mSections.size();
903 for (int i = 0; i < numSections; i++) {
904 mSections.get(i).clear();
905 }
906
Evan Millar7911ff52009-07-21 15:55:18 -0700907 mRawContactIds.clear();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700908
Evan Millar11d628c2009-09-02 08:55:01 -0700909 Sources sources = Sources.getInstance(this);
910
Evan Millar66388be2009-05-28 15:41:07 -0700911 // Build up method entries
912 if (mUri != null) {
Evan Millar11d628c2009-09-02 08:55:01 -0700913 for (Entity entity: mEntities) {
914 final ContentValues entValues = entity.getEntityValues();
915 final String accountType = entValues.getAsString(RawContacts.ACCOUNT_TYPE);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700916 final long rawContactId = entValues.getAsLong(RawContacts._ID);
Evan Millar7911ff52009-07-21 15:55:18 -0700917
Dmitri Plotnikov2a8cef02009-09-23 19:01:15 -0700918 if (!mRawContactIds.contains(rawContactId)) {
919 mRawContactIds.add(rawContactId);
920 }
921
Evan Millar2e1b8af2009-09-24 09:39:21 -0700922 // This performs the tab filtering
923 if (mSelectedRawContactId != null && mSelectedRawContactId != rawContactId) {
924 continue;
925 }
Evan Millar66210452009-09-21 10:53:43 -0700926
Evan Millar11d628c2009-09-02 08:55:01 -0700927 for (NamedContentValues subValue : entity.getSubValues()) {
928 ViewEntry entry = new ViewEntry();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800929
Jeff Sharkeyab066932009-09-21 09:55:30 -0700930 final ContentValues entryValues = subValue.values;
931 entryValues.put(Data.RAW_CONTACT_ID, rawContactId);
932
Evan Millar11d628c2009-09-02 08:55:01 -0700933 final String mimetype = entryValues.getAsString(Data.MIMETYPE);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700934 if (mimetype == null) continue;
Evan Millar66388be2009-05-28 15:41:07 -0700935
Jeff Sharkeyab066932009-09-21 09:55:30 -0700936 final DataKind kind = sources.getKindOrFallback(accountType, mimetype, this,
Evan Millar11d628c2009-09-02 08:55:01 -0700937 ContactsSource.LEVEL_MIMETYPES);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700938 if (kind == null) continue;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800939
Evan Millar11d628c2009-09-02 08:55:01 -0700940 final long id = entryValues.getAsLong(Data._ID);
941 final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, id);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700942 entry.contactId = rawContactId;
Evan Millar11d628c2009-09-02 08:55:01 -0700943 entry.id = id;
944 entry.uri = uri;
945 entry.mimetype = mimetype;
Daisuke Miyakawa999db912009-09-17 15:55:15 -0700946 entry.label = buildActionString(kind, entryValues, false);
Evan Millar11d628c2009-09-02 08:55:01 -0700947 entry.data = buildDataString(kind, entryValues);
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700948 if (kind.typeColumn != null && entryValues.containsKey(kind.typeColumn)) {
Evan Millar11d628c2009-09-02 08:55:01 -0700949 entry.type = entryValues.getAsInteger(kind.typeColumn);
950 }
951 if (kind.iconRes > 0) {
Jeff Sharkeyab066932009-09-21 09:55:30 -0700952 entry.resPackageName = kind.resPackageName;
Evan Millar11d628c2009-09-02 08:55:01 -0700953 entry.actionIcon = kind.iconRes;
954 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800955
Evan Millar11d628c2009-09-02 08:55:01 -0700956 // Don't crash if the data is bogus
Evan Millar66388be2009-05-28 15:41:07 -0700957 if (TextUtils.isEmpty(entry.data)) {
Alex Kennberg87fc3172009-03-28 06:43:06 -0700958 continue;
959 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700960
Evan Millarff04a272009-09-26 15:23:37 -0700961 final boolean isSuperPrimary = entryValues.getAsInteger(
962 Data.IS_SUPER_PRIMARY) != 0;
Evan Millar11d628c2009-09-02 08:55:01 -0700963
Evan Millarff04a272009-09-26 15:23:37 -0700964 if (CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(mimetype)) {
965 // Build phone entries
966 mNumPhoneNumbers++;
Evan Millar11d628c2009-09-02 08:55:01 -0700967
Evan Millarff04a272009-09-26 15:23:37 -0700968 entry.intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
969 Uri.fromParts("tel", entry.data, null));
970 entry.secondaryIntent = new Intent(Intent.ACTION_SENDTO,
971 Uri.fromParts("sms", entry.data, null));
972 entry.data = PhoneNumberUtils.stripSeparators(entry.data);
Evan Millar49714ee2009-09-02 16:42:47 -0700973
Evan Millarff04a272009-09-26 15:23:37 -0700974 entry.isPrimary = isSuperPrimary;
975 mPhoneEntries.add(entry);
976
977 if (entry.type == CommonDataKinds.Phone.TYPE_MOBILE
978 || mShowSmsLinksForAllPhones) {
979 // Add an SMS entry
980 if (kind.iconAltRes > 0) {
981 entry.secondaryActionIcon = kind.iconAltRes;
Evan Millar49714ee2009-09-02 16:42:47 -0700982 }
Evan Millarff04a272009-09-26 15:23:37 -0700983 }
984 } else if (CommonDataKinds.Email.CONTENT_ITEM_TYPE.equals(mimetype)) {
985 // Build email entries
986 entry.intent = new Intent(Intent.ACTION_SENDTO,
987 Uri.fromParts("mailto", entry.data, null));
988 entry.isPrimary = isSuperPrimary;
989 mEmailEntries.add(entry);
990 } else if (CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE.
991 equals(mimetype)) {
992 // Build postal entries
993 entry.maxLines = 4;
994 entry.intent = new Intent(Intent.ACTION_VIEW, uri);
995 mPostalEntries.add(entry);
996 } else if (CommonDataKinds.Im.CONTENT_ITEM_TYPE.equals(mimetype)) {
997 // Build im entries
998 Object protocolObj = entryValues.getAsInteger(CommonDataKinds.Im.PROTOCOL);
999 String host = null;
Evan Millar49714ee2009-09-02 16:42:47 -07001000
Evan Millarff04a272009-09-26 15:23:37 -07001001 if (TextUtils.isEmpty(entry.label)) {
1002 entry.label = getString(R.string.chat).toLowerCase();
1003 }
Evan Millar11d628c2009-09-02 08:55:01 -07001004
Evan Millarff04a272009-09-26 15:23:37 -07001005 if (protocolObj instanceof Number) {
1006 int protocol = ((Number) protocolObj).intValue();
1007 host = ContactsUtils.lookupProviderNameFromId(protocol);
1008 if (protocol == CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK
1009 || protocol == CommonDataKinds.Im.PROTOCOL_MSN) {
1010 entry.maxLabelLines = 2;
Evan Millar11d628c2009-09-02 08:55:01 -07001011 }
Evan Millarff04a272009-09-26 15:23:37 -07001012 } else if (protocolObj != null) {
1013 String providerName = (String) protocolObj;
1014 host = providerName.toLowerCase();
1015 }
1016
1017 // Only add the intent if there is a valid host
1018 // host is null for CommonDataKinds.Im.PROTOCOL_CUSTOM
1019 if (!TextUtils.isEmpty(host)) {
Evan Millar11d628c2009-09-02 08:55:01 -07001020 entry.intent = new Intent(Intent.ACTION_SENDTO,
Evan Millarff04a272009-09-26 15:23:37 -07001021 constructImToUrl(host.toLowerCase(), entry.data));
1022 }
1023 //TODO(emillar) Add in presence info
Evan Millar11d628c2009-09-02 08:55:01 -07001024 /*if (!aggCursor.isNull(METHODS_STATUS_COLUMN)) {
1025 entry.presenceIcon = Presence.getPresenceIconResourceId(
1026 aggCursor.getInt(METHODS_STATUS_COLUMN));
1027 entry.status = ...
1028 }*/
Evan Millarff04a272009-09-26 15:23:37 -07001029 mImEntries.add(entry);
1030 } else if (CommonDataKinds.Organization.CONTENT_ITEM_TYPE.equals(mimetype)
1031 || CommonDataKinds.Nickname.CONTENT_ITEM_TYPE.equals(mimetype)) {
1032 // Build organization and note entries
1033 entry.uri = null;
Evan Millar11d628c2009-09-02 08:55:01 -07001034 mOrganizationEntries.add(entry);
1035 } else if (CommonDataKinds.Note.CONTENT_ITEM_TYPE.equals(mimetype)) {
1036 // Build note entries
Evan Millar11d628c2009-09-02 08:55:01 -07001037 entry.uri = null;
Evan Millar11d628c2009-09-02 08:55:01 -07001038 entry.maxLines = 10;
1039 mOtherEntries.add(entry);
Jeff Sharkeyab066932009-09-21 09:55:30 -07001040 } else {
1041 // Handle showing custom
Evan Millarff04a272009-09-26 15:23:37 -07001042 entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri);
Jeff Sharkeyab066932009-09-21 09:55:30 -07001043 mOtherEntries.add(entry);
Evan Millar11d628c2009-09-02 08:55:01 -07001044 }
1045
Evan Millar2e1b8af2009-09-24 09:39:21 -07001046 }
1047
1048 if (mSelectedRawContactId != null &&
1049 mSelectedRawContactId == rawContactId
1050 && mEntities.size() > 1) {
1051 ViewEntry entry = new ViewEntry();
1052 entry.mimetype = SPLIT_MIMETYPE;
1053 entry.id = rawContactId;
1054 entry.label = getString(R.string.split_label);
1055 entry.data = getString(R.string.split_explanation);
1056 entry.actionIcon = R.drawable.ic_list_split;
1057 mSplitEntry.add(entry);
1058 }
Evan Millar11d628c2009-09-02 08:55:01 -07001059 // TODO(emillar) Add group entries
1060 // // Build the group entries
1061 // final Uri groupsUri = Uri.withAppendedPath(mUri, GroupMembership.CONTENT_DIRECTORY);
1062 // Cursor groupCursor = mResolver.query(groupsUri, ContactsListActivity.GROUPS_PROJECTION,
1063 // null, null, Groups.DEFAULT_SORT_ORDER);
1064 // if (groupCursor != null) {
1065 // try {
1066 // StringBuilder sb = new StringBuilder();
1067 //
1068 // while (groupCursor.moveToNext()) {
1069 // String systemId = groupCursor.getString(
1070 // ContactsListActivity.GROUPS_COLUMN_INDEX_SYSTEM_ID);
1071 //
1072 // if (systemId != null || Groups.GROUP_MY_CONTACTS.equals(systemId)) {
1073 // continue;
1074 // }
1075 //
1076 // String name = groupCursor.getString(ContactsListActivity.GROUPS_COLUMN_INDEX_NAME);
1077 // if (!TextUtils.isEmpty(name)) {
1078 // if (sb.length() == 0) {
1079 // sb.append(name);
1080 // } else {
1081 // sb.append(getString(R.string.group_list, name));
1082 // }
1083 // }
1084 // }
1085 //
1086 // if (sb.length() > 0) {
1087 // ViewEntry entry = new ViewEntry();
1088 // entry.kind = ContactEntryAdapter.Entry.KIND_GROUP;
1089 // entry.label = getString(R.string.label_groups);
1090 // entry.data = sb.toString();
1091 // entry.intent = new Intent(Intent.ACTION_EDIT, mUri);
1092 //
1093 // // TODO: Add an icon for the groups item.
1094 //
1095 // mGroupEntries.add(entry);
1096 // }
1097 // } finally {
1098 // groupCursor.close();
1099 // }
1100 // }
Evan Millar5c22c3b2009-05-29 11:37:54 -07001101
Evan Millar66388be2009-05-28 15:41:07 -07001102 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001103 }
1104 }
1105
Evan Millar11d628c2009-09-02 08:55:01 -07001106 String buildActionString(DataKind kind, ContentValues values, boolean lowerCase) {
1107 if (kind.actionHeader == null) {
1108 return null;
Jeff Hamilton8350e5b2009-03-24 21:01:34 -07001109 }
Evan Millar11d628c2009-09-02 08:55:01 -07001110 CharSequence actionHeader = kind.actionHeader.inflateUsing(this, values);
1111 if (actionHeader == null) {
1112 return null;
1113 }
1114 return lowerCase ? actionHeader.toString().toLowerCase() : actionHeader.toString();
1115 }
Jeff Hamilton8350e5b2009-03-24 21:01:34 -07001116
Evan Millar11d628c2009-09-02 08:55:01 -07001117 String buildDataString(DataKind kind, ContentValues values) {
1118 if (kind.actionBody == null) {
1119 return null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001120 }
Evan Millar11d628c2009-09-02 08:55:01 -07001121 CharSequence actionBody = kind.actionBody.inflateUsing(this, values);
1122 return actionBody == null ? null : actionBody.toString();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001123 }
Evan Millar5c22c3b2009-05-29 11:37:54 -07001124
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001125 /**
1126 * A basic structure with the data for a contact entry in the list.
1127 */
Evan Millar54a5c9f2009-06-23 17:41:09 -07001128 static class ViewEntry extends ContactEntryAdapter.Entry implements Collapsible<ViewEntry> {
Jeff Sharkeyab066932009-09-21 09:55:30 -07001129 public String resPackageName = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001130 public int actionIcon = -1;
Evan Millar15e514d2009-08-04 10:14:57 -07001131 public boolean isPrimary = false;
1132 public int presenceIcon = -1;
1133 public int secondaryActionIcon = -1;
1134 public Intent intent;
1135 public Intent secondaryIntent = null;
1136 public int status = -1;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001137 public int maxLabelLines = 1;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001138 public ArrayList<Long> ids = new ArrayList<Long>();
1139 public int collapseCount = 0;
1140
1141 public boolean collapseWith(ViewEntry entry) {
1142 // assert equal collapse keys
1143 if (!getCollapseKey().equals(entry.getCollapseKey())) {
1144 return false;
1145 }
1146
1147 // Choose the label associated with the highest type precedence.
1148 if (TypePrecedence.getTypePrecedence(mimetype, type)
1149 > TypePrecedence.getTypePrecedence(entry.mimetype, entry.type)) {
1150 type = entry.type;
1151 label = entry.label;
1152 }
1153
1154 // Choose the max of the maxLines and maxLabelLines values.
1155 maxLines = Math.max(maxLines, entry.maxLines);
1156 maxLabelLines = Math.max(maxLabelLines, entry.maxLabelLines);
1157
1158 // Choose the presence with the highest precedence.
1159 if (Presence.getPresencePrecedence(status)
1160 < Presence.getPresencePrecedence(entry.status)) {
1161 status = entry.status;
1162 }
1163
1164 // If any of the collapsed entries are primary make the whole thing primary.
Evan Millar15e514d2009-08-04 10:14:57 -07001165 isPrimary = entry.isPrimary ? true : isPrimary;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001166
1167 // uri, and contactdId, shouldn't make a difference. Just keep the original.
1168
1169 // Keep track of all the ids that have been collapsed with this one.
1170 ids.add(entry.id);
1171 collapseCount++;
1172 return true;
1173 }
1174
1175 public String getCollapseKey() {
1176 StringBuilder hashSb = new StringBuilder();
1177 hashSb.append(data);
1178 hashSb.append(mimetype);
1179 hashSb.append((intent != null && intent.getAction() != null)
1180 ? intent.getAction() : "");
Evan Millar15e514d2009-08-04 10:14:57 -07001181 hashSb.append((secondaryIntent != null && secondaryIntent.getAction() != null)
1182 ? secondaryIntent.getAction() : "");
Evan Millar54a5c9f2009-06-23 17:41:09 -07001183 hashSb.append(actionIcon);
1184 return hashSb.toString();
1185 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001186 }
1187
Evan Millar15e514d2009-08-04 10:14:57 -07001188 /** Cache of the children views of a row */
1189 static class ViewCache {
1190 public TextView label;
1191 public TextView data;
1192 public ImageView actionIcon;
1193 public ImageView presenceIcon;
1194 public ImageView primaryIcon;
1195 public ImageView secondaryActionButton;
1196 public View secondaryActionDivider;
Evan Millar5c22c3b2009-05-29 11:37:54 -07001197
Evan Millar15e514d2009-08-04 10:14:57 -07001198 // Need to keep track of this too
1199 ViewEntry entry;
1200 }
1201
1202 private final class ViewAdapter extends ContactEntryAdapter<ViewEntry>
1203 implements View.OnClickListener {
1204
Evan Millar5c22c3b2009-05-29 11:37:54 -07001205
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001206 ViewAdapter(Context context, ArrayList<ArrayList<ViewEntry>> sections) {
1207 super(context, sections, SHOW_SEPARATORS);
1208 }
1209
Evan Millar15e514d2009-08-04 10:14:57 -07001210 public void onClick(View v) {
1211 Intent intent = (Intent) v.getTag();
1212 startActivity(intent);
1213 }
1214
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001215 @Override
1216 public View getView(int position, View convertView, ViewGroup parent) {
Evan Millar5c22c3b2009-05-29 11:37:54 -07001217 ViewEntry entry = getEntry(mSections, position, false);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001218 View v;
1219
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001220 ViewCache views;
1221
1222 // Check to see if we can reuse convertView
1223 if (convertView != null) {
1224 v = convertView;
1225 views = (ViewCache) v.getTag();
1226 } else {
1227 // Create a new view if needed
1228 v = mInflater.inflate(R.layout.list_item_text_icons, parent, false);
1229
1230 // Cache the children
1231 views = new ViewCache();
1232 views.label = (TextView) v.findViewById(android.R.id.text1);
1233 views.data = (TextView) v.findViewById(android.R.id.text2);
Evan Millar15e514d2009-08-04 10:14:57 -07001234 views.actionIcon = (ImageView) v.findViewById(R.id.action_icon);
1235 views.primaryIcon = (ImageView) v.findViewById(R.id.primary_icon);
1236 views.presenceIcon = (ImageView) v.findViewById(R.id.presence_icon);
1237 views.secondaryActionButton = (ImageView) v.findViewById(
1238 R.id.secondary_action_button);
1239 views.secondaryActionButton.setOnClickListener(this);
Evan Millar15e514d2009-08-04 10:14:57 -07001240 views.secondaryActionDivider = v.findViewById(R.id.divider);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001241 v.setTag(views);
1242 }
1243
1244 // Update the entry in the view cache
1245 views.entry = entry;
1246
1247 // Bind the data to the view
1248 bindView(v, entry);
1249 return v;
1250 }
1251
1252 @Override
1253 protected View newView(int position, ViewGroup parent) {
1254 // getView() handles this
1255 throw new UnsupportedOperationException();
1256 }
1257
1258 @Override
1259 protected void bindView(View view, ViewEntry entry) {
1260 final Resources resources = mContext.getResources();
1261 ViewCache views = (ViewCache) view.getTag();
1262
1263 // Set the label
1264 TextView label = views.label;
1265 setMaxLines(label, entry.maxLabelLines);
1266 label.setText(entry.label);
1267
1268 // Set the data
1269 TextView data = views.data;
1270 if (data != null) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001271 if (entry.mimetype.equals(Phone.CONTENT_ITEM_TYPE)
Jeff Sharkey49d17b32009-09-07 02:14:21 -07001272 || entry.mimetype.equals(Constants.MIME_SMS_ADDRESS)) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001273 data.setText(PhoneNumberUtils.formatNumber(entry.data));
1274 } else {
1275 data.setText(entry.data);
1276 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001277 setMaxLines(data, entry.maxLines);
1278 }
1279
Evan Millar15e514d2009-08-04 10:14:57 -07001280 // Set the primary icon
1281 views.primaryIcon.setVisibility(entry.isPrimary ? View.VISIBLE : View.GONE);
1282
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001283 // Set the action icon
1284 ImageView action = views.actionIcon;
1285 if (entry.actionIcon != -1) {
Jeff Sharkeyab066932009-09-21 09:55:30 -07001286 Drawable actionIcon;
1287 if (entry.resPackageName != null) {
1288 // Load external resources through PackageManager
1289 actionIcon = mContext.getPackageManager().getDrawable(entry.resPackageName,
1290 entry.actionIcon, null);
1291 } else {
1292 actionIcon = resources.getDrawable(entry.actionIcon);
1293 }
1294 action.setImageDrawable(actionIcon);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001295 action.setVisibility(View.VISIBLE);
1296 } else {
1297 // Things should still line up as if there was an icon, so make it invisible
1298 action.setVisibility(View.INVISIBLE);
1299 }
1300
1301 // Set the presence icon
1302 Drawable presenceIcon = null;
Evan Millar15e514d2009-08-04 10:14:57 -07001303 if (entry.presenceIcon != -1) {
1304 presenceIcon = resources.getDrawable(entry.presenceIcon);
Evan Millar54a5c9f2009-06-23 17:41:09 -07001305 } else if (entry.status != -1) {
1306 presenceIcon = resources.getDrawable(
1307 Presence.getPresenceIconResourceId(entry.status));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001308 }
Evan Millar15e514d2009-08-04 10:14:57 -07001309 ImageView presenceIconView = views.presenceIcon;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001310 if (presenceIcon != null) {
Evan Millar15e514d2009-08-04 10:14:57 -07001311 presenceIconView.setImageDrawable(presenceIcon);
1312 presenceIconView.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001313 } else {
Evan Millar15e514d2009-08-04 10:14:57 -07001314 presenceIconView.setVisibility(View.GONE);
1315 }
1316
1317 // Set the secondary action button
1318 ImageView secondaryActionView = views.secondaryActionButton;
1319 Drawable secondaryActionIcon = null;
1320 if (entry.secondaryActionIcon != -1) {
1321 secondaryActionIcon = resources.getDrawable(entry.secondaryActionIcon);
1322 }
1323 if (entry.secondaryIntent != null && secondaryActionIcon != null) {
1324 secondaryActionView.setImageDrawable(secondaryActionIcon);
1325 secondaryActionView.setTag(entry.secondaryIntent);
1326 secondaryActionView.setVisibility(View.VISIBLE);
1327 views.secondaryActionDivider.setVisibility(View.VISIBLE);
1328 } else {
1329 secondaryActionView.setVisibility(View.GONE);
1330 views.secondaryActionDivider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001331 }
1332 }
1333
1334 private void setMaxLines(TextView textView, int maxLines) {
1335 if (maxLines == 1) {
1336 textView.setSingleLine(true);
1337 textView.setEllipsize(TextUtils.TruncateAt.END);
1338 } else {
1339 textView.setSingleLine(false);
1340 textView.setMaxLines(maxLines);
1341 textView.setEllipsize(null);
1342 }
1343 }
1344 }
1345}