blob: 1b2ee23d91bd37520a58330ed3fd24dbfe6d3767 [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 Millar11d628c2009-09-02 08:55:01 -0700961 if (CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(mimetype)
962 || CommonDataKinds.Email.CONTENT_ITEM_TYPE.equals(mimetype)
963 || CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE.equals(mimetype)
964 || CommonDataKinds.Im.CONTENT_ITEM_TYPE.equals(mimetype)) {
965 final boolean isSuperPrimary = entryValues.getAsInteger(
966 Data.IS_SUPER_PRIMARY) != 0;
967
968 if (CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(mimetype)) {
969 // Build phone entries
970 mNumPhoneNumbers++;
971
972 entry.intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
973 Uri.fromParts("tel", entry.data, null));
974 entry.secondaryIntent = new Intent(Intent.ACTION_SENDTO,
975 Uri.fromParts("sms", entry.data, null));
976 entry.data = PhoneNumberUtils.stripSeparators(entry.data);
Evan Millar49714ee2009-09-02 16:42:47 -0700977
978 // If data is empty, don't show it.
979 if (TextUtils.isEmpty(entry.data)) {
980 Log.w(TAG, "empty data for contact method " + id);
981 continue;
982 }
983
Evan Millar11d628c2009-09-02 08:55:01 -0700984 entry.isPrimary = isSuperPrimary;
985 mPhoneEntries.add(entry);
986
987 if (entry.type == CommonDataKinds.Phone.TYPE_MOBILE
988 || mShowSmsLinksForAllPhones) {
989 // Add an SMS entry
990 if (kind.iconAltRes > 0) {
991 entry.secondaryActionIcon = kind.iconAltRes;
992 }
993 }
994 } else if (CommonDataKinds.Email.CONTENT_ITEM_TYPE.equals(mimetype)) {
995 // Build email entries
996 entry.intent = new Intent(Intent.ACTION_SENDTO,
997 Uri.fromParts("mailto", entry.data, null));
998 entry.isPrimary = isSuperPrimary;
999 mEmailEntries.add(entry);
1000 } else if (CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE.
1001 equals(mimetype)) {
1002 // Build postal entries
1003 entry.maxLines = 4;
1004 entry.intent = new Intent(Intent.ACTION_VIEW, uri);
1005 mPostalEntries.add(entry);
1006 } else if (CommonDataKinds.Im.CONTENT_ITEM_TYPE.equals(mimetype)) {
1007 // Build im entries
1008 Object protocolObj = entryValues.getAsInteger(Data.DATA5);
1009 String host = null;
1010
Evan Millar49714ee2009-09-02 16:42:47 -07001011 if (TextUtils.isEmpty(entry.label)) {
Jeff Sharkeyae6c2882009-09-21 23:09:35 -07001012 entry.label = getString(R.string.chat).toLowerCase();
Evan Millar49714ee2009-09-02 16:42:47 -07001013 }
1014
Evan Millar11d628c2009-09-02 08:55:01 -07001015 if (protocolObj instanceof Number) {
1016 int protocol = ((Number) protocolObj).intValue();
Vasu Nori8eecbe62009-09-22 17:23:38 -07001017 host = ContactsUtils.lookupProviderNameFromId(protocol);
Evan Millar11d628c2009-09-02 08:55:01 -07001018 if (protocol == CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK
1019 || protocol == CommonDataKinds.Im.PROTOCOL_MSN) {
1020 entry.maxLabelLines = 2;
1021 }
1022 } else if (protocolObj != null) {
1023 String providerName = (String) protocolObj;
1024 host = providerName.toLowerCase();
1025 }
1026
1027 // Only add the intent if there is a valid host
Vasu Nori8eecbe62009-09-22 17:23:38 -07001028 // host is null for CommonDataKinds.Im.PROTOCOL_CUSTOM
Evan Millar11d628c2009-09-02 08:55:01 -07001029 if (!TextUtils.isEmpty(host)) {
1030 entry.intent = new Intent(Intent.ACTION_SENDTO,
Vasu Nori8eecbe62009-09-22 17:23:38 -07001031 constructImToUrl(host.toLowerCase(), entry.data));
Evan Millar11d628c2009-09-02 08:55:01 -07001032 }
1033 //TODO(emillar) Add in presence info
1034 /*if (!aggCursor.isNull(METHODS_STATUS_COLUMN)) {
1035 entry.presenceIcon = Presence.getPresenceIconResourceId(
1036 aggCursor.getInt(METHODS_STATUS_COLUMN));
1037 entry.status = ...
1038 }*/
1039 mImEntries.add(entry);
1040 }
1041 } else if (CommonDataKinds.Organization.CONTENT_ITEM_TYPE.equals(mimetype)) {
1042 // Build organization entries
1043 mOrganizationEntries.add(entry);
1044 } else if (CommonDataKinds.Note.CONTENT_ITEM_TYPE.equals(mimetype)) {
1045 // Build note entries
1046 entry.id = 0;
1047 entry.uri = null;
1048 entry.intent = null;
1049 entry.maxLines = 10;
1050 mOtherEntries.add(entry);
Jeff Sharkeyab066932009-09-21 09:55:30 -07001051 } else {
1052 // Handle showing custom
1053 entry.intent = new Intent(Intent.ACTION_VIEW, uri);
1054 mOtherEntries.add(entry);
Evan Millar11d628c2009-09-02 08:55:01 -07001055 }
1056
Evan Millar2e1b8af2009-09-24 09:39:21 -07001057 }
1058
1059 if (mSelectedRawContactId != null &&
1060 mSelectedRawContactId == rawContactId
1061 && mEntities.size() > 1) {
1062 ViewEntry entry = new ViewEntry();
1063 entry.mimetype = SPLIT_MIMETYPE;
1064 entry.id = rawContactId;
1065 entry.label = getString(R.string.split_label);
1066 entry.data = getString(R.string.split_explanation);
1067 entry.actionIcon = R.drawable.ic_list_split;
1068 mSplitEntry.add(entry);
1069 }
Evan Millar11d628c2009-09-02 08:55:01 -07001070 // TODO(emillar) Add group entries
1071 // // Build the group entries
1072 // final Uri groupsUri = Uri.withAppendedPath(mUri, GroupMembership.CONTENT_DIRECTORY);
1073 // Cursor groupCursor = mResolver.query(groupsUri, ContactsListActivity.GROUPS_PROJECTION,
1074 // null, null, Groups.DEFAULT_SORT_ORDER);
1075 // if (groupCursor != null) {
1076 // try {
1077 // StringBuilder sb = new StringBuilder();
1078 //
1079 // while (groupCursor.moveToNext()) {
1080 // String systemId = groupCursor.getString(
1081 // ContactsListActivity.GROUPS_COLUMN_INDEX_SYSTEM_ID);
1082 //
1083 // if (systemId != null || Groups.GROUP_MY_CONTACTS.equals(systemId)) {
1084 // continue;
1085 // }
1086 //
1087 // String name = groupCursor.getString(ContactsListActivity.GROUPS_COLUMN_INDEX_NAME);
1088 // if (!TextUtils.isEmpty(name)) {
1089 // if (sb.length() == 0) {
1090 // sb.append(name);
1091 // } else {
1092 // sb.append(getString(R.string.group_list, name));
1093 // }
1094 // }
1095 // }
1096 //
1097 // if (sb.length() > 0) {
1098 // ViewEntry entry = new ViewEntry();
1099 // entry.kind = ContactEntryAdapter.Entry.KIND_GROUP;
1100 // entry.label = getString(R.string.label_groups);
1101 // entry.data = sb.toString();
1102 // entry.intent = new Intent(Intent.ACTION_EDIT, mUri);
1103 //
1104 // // TODO: Add an icon for the groups item.
1105 //
1106 // mGroupEntries.add(entry);
1107 // }
1108 // } finally {
1109 // groupCursor.close();
1110 // }
1111 // }
Evan Millar5c22c3b2009-05-29 11:37:54 -07001112
Evan Millar66388be2009-05-28 15:41:07 -07001113 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001114 }
1115 }
1116
Evan Millar11d628c2009-09-02 08:55:01 -07001117 String buildActionString(DataKind kind, ContentValues values, boolean lowerCase) {
1118 if (kind.actionHeader == null) {
1119 return null;
Jeff Hamilton8350e5b2009-03-24 21:01:34 -07001120 }
Evan Millar11d628c2009-09-02 08:55:01 -07001121 CharSequence actionHeader = kind.actionHeader.inflateUsing(this, values);
1122 if (actionHeader == null) {
1123 return null;
1124 }
1125 return lowerCase ? actionHeader.toString().toLowerCase() : actionHeader.toString();
1126 }
Jeff Hamilton8350e5b2009-03-24 21:01:34 -07001127
Evan Millar11d628c2009-09-02 08:55:01 -07001128 String buildDataString(DataKind kind, ContentValues values) {
1129 if (kind.actionBody == null) {
1130 return null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001131 }
Evan Millar11d628c2009-09-02 08:55:01 -07001132 CharSequence actionBody = kind.actionBody.inflateUsing(this, values);
1133 return actionBody == null ? null : actionBody.toString();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001134 }
Evan Millar5c22c3b2009-05-29 11:37:54 -07001135
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001136 /**
1137 * A basic structure with the data for a contact entry in the list.
1138 */
Evan Millar54a5c9f2009-06-23 17:41:09 -07001139 static class ViewEntry extends ContactEntryAdapter.Entry implements Collapsible<ViewEntry> {
Jeff Sharkeyab066932009-09-21 09:55:30 -07001140 public String resPackageName = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001141 public int actionIcon = -1;
Evan Millar15e514d2009-08-04 10:14:57 -07001142 public boolean isPrimary = false;
1143 public int presenceIcon = -1;
1144 public int secondaryActionIcon = -1;
1145 public Intent intent;
1146 public Intent secondaryIntent = null;
1147 public int status = -1;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001148 public int maxLabelLines = 1;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001149 public ArrayList<Long> ids = new ArrayList<Long>();
1150 public int collapseCount = 0;
1151
1152 public boolean collapseWith(ViewEntry entry) {
1153 // assert equal collapse keys
1154 if (!getCollapseKey().equals(entry.getCollapseKey())) {
1155 return false;
1156 }
1157
1158 // Choose the label associated with the highest type precedence.
1159 if (TypePrecedence.getTypePrecedence(mimetype, type)
1160 > TypePrecedence.getTypePrecedence(entry.mimetype, entry.type)) {
1161 type = entry.type;
1162 label = entry.label;
1163 }
1164
1165 // Choose the max of the maxLines and maxLabelLines values.
1166 maxLines = Math.max(maxLines, entry.maxLines);
1167 maxLabelLines = Math.max(maxLabelLines, entry.maxLabelLines);
1168
1169 // Choose the presence with the highest precedence.
1170 if (Presence.getPresencePrecedence(status)
1171 < Presence.getPresencePrecedence(entry.status)) {
1172 status = entry.status;
1173 }
1174
1175 // If any of the collapsed entries are primary make the whole thing primary.
Evan Millar15e514d2009-08-04 10:14:57 -07001176 isPrimary = entry.isPrimary ? true : isPrimary;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001177
1178 // uri, and contactdId, shouldn't make a difference. Just keep the original.
1179
1180 // Keep track of all the ids that have been collapsed with this one.
1181 ids.add(entry.id);
1182 collapseCount++;
1183 return true;
1184 }
1185
1186 public String getCollapseKey() {
1187 StringBuilder hashSb = new StringBuilder();
1188 hashSb.append(data);
1189 hashSb.append(mimetype);
1190 hashSb.append((intent != null && intent.getAction() != null)
1191 ? intent.getAction() : "");
Evan Millar15e514d2009-08-04 10:14:57 -07001192 hashSb.append((secondaryIntent != null && secondaryIntent.getAction() != null)
1193 ? secondaryIntent.getAction() : "");
Evan Millar54a5c9f2009-06-23 17:41:09 -07001194 hashSb.append(actionIcon);
1195 return hashSb.toString();
1196 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001197 }
1198
Evan Millar15e514d2009-08-04 10:14:57 -07001199 /** Cache of the children views of a row */
1200 static class ViewCache {
1201 public TextView label;
1202 public TextView data;
1203 public ImageView actionIcon;
1204 public ImageView presenceIcon;
1205 public ImageView primaryIcon;
1206 public ImageView secondaryActionButton;
1207 public View secondaryActionDivider;
Evan Millar5c22c3b2009-05-29 11:37:54 -07001208
Evan Millar15e514d2009-08-04 10:14:57 -07001209 // Need to keep track of this too
1210 ViewEntry entry;
1211 }
1212
1213 private final class ViewAdapter extends ContactEntryAdapter<ViewEntry>
1214 implements View.OnClickListener {
1215
Evan Millar5c22c3b2009-05-29 11:37:54 -07001216
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001217 ViewAdapter(Context context, ArrayList<ArrayList<ViewEntry>> sections) {
1218 super(context, sections, SHOW_SEPARATORS);
1219 }
1220
Evan Millar15e514d2009-08-04 10:14:57 -07001221 public void onClick(View v) {
1222 Intent intent = (Intent) v.getTag();
1223 startActivity(intent);
1224 }
1225
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001226 @Override
1227 public View getView(int position, View convertView, ViewGroup parent) {
Evan Millar5c22c3b2009-05-29 11:37:54 -07001228 ViewEntry entry = getEntry(mSections, position, false);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001229 View v;
1230
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001231 ViewCache views;
1232
1233 // Check to see if we can reuse convertView
1234 if (convertView != null) {
1235 v = convertView;
1236 views = (ViewCache) v.getTag();
1237 } else {
1238 // Create a new view if needed
1239 v = mInflater.inflate(R.layout.list_item_text_icons, parent, false);
1240
1241 // Cache the children
1242 views = new ViewCache();
1243 views.label = (TextView) v.findViewById(android.R.id.text1);
1244 views.data = (TextView) v.findViewById(android.R.id.text2);
Evan Millar15e514d2009-08-04 10:14:57 -07001245 views.actionIcon = (ImageView) v.findViewById(R.id.action_icon);
1246 views.primaryIcon = (ImageView) v.findViewById(R.id.primary_icon);
1247 views.presenceIcon = (ImageView) v.findViewById(R.id.presence_icon);
1248 views.secondaryActionButton = (ImageView) v.findViewById(
1249 R.id.secondary_action_button);
1250 views.secondaryActionButton.setOnClickListener(this);
Evan Millar15e514d2009-08-04 10:14:57 -07001251 views.secondaryActionDivider = v.findViewById(R.id.divider);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001252 v.setTag(views);
1253 }
1254
1255 // Update the entry in the view cache
1256 views.entry = entry;
1257
1258 // Bind the data to the view
1259 bindView(v, entry);
1260 return v;
1261 }
1262
1263 @Override
1264 protected View newView(int position, ViewGroup parent) {
1265 // getView() handles this
1266 throw new UnsupportedOperationException();
1267 }
1268
1269 @Override
1270 protected void bindView(View view, ViewEntry entry) {
1271 final Resources resources = mContext.getResources();
1272 ViewCache views = (ViewCache) view.getTag();
1273
1274 // Set the label
1275 TextView label = views.label;
1276 setMaxLines(label, entry.maxLabelLines);
1277 label.setText(entry.label);
1278
1279 // Set the data
1280 TextView data = views.data;
1281 if (data != null) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001282 if (entry.mimetype.equals(Phone.CONTENT_ITEM_TYPE)
Jeff Sharkey49d17b32009-09-07 02:14:21 -07001283 || entry.mimetype.equals(Constants.MIME_SMS_ADDRESS)) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001284 data.setText(PhoneNumberUtils.formatNumber(entry.data));
1285 } else {
1286 data.setText(entry.data);
1287 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001288 setMaxLines(data, entry.maxLines);
1289 }
1290
Evan Millar15e514d2009-08-04 10:14:57 -07001291 // Set the primary icon
1292 views.primaryIcon.setVisibility(entry.isPrimary ? View.VISIBLE : View.GONE);
1293
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001294 // Set the action icon
1295 ImageView action = views.actionIcon;
1296 if (entry.actionIcon != -1) {
Jeff Sharkeyab066932009-09-21 09:55:30 -07001297 Drawable actionIcon;
1298 if (entry.resPackageName != null) {
1299 // Load external resources through PackageManager
1300 actionIcon = mContext.getPackageManager().getDrawable(entry.resPackageName,
1301 entry.actionIcon, null);
1302 } else {
1303 actionIcon = resources.getDrawable(entry.actionIcon);
1304 }
1305 action.setImageDrawable(actionIcon);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001306 action.setVisibility(View.VISIBLE);
1307 } else {
1308 // Things should still line up as if there was an icon, so make it invisible
1309 action.setVisibility(View.INVISIBLE);
1310 }
1311
1312 // Set the presence icon
1313 Drawable presenceIcon = null;
Evan Millar15e514d2009-08-04 10:14:57 -07001314 if (entry.presenceIcon != -1) {
1315 presenceIcon = resources.getDrawable(entry.presenceIcon);
Evan Millar54a5c9f2009-06-23 17:41:09 -07001316 } else if (entry.status != -1) {
1317 presenceIcon = resources.getDrawable(
1318 Presence.getPresenceIconResourceId(entry.status));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001319 }
Evan Millar15e514d2009-08-04 10:14:57 -07001320 ImageView presenceIconView = views.presenceIcon;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001321 if (presenceIcon != null) {
Evan Millar15e514d2009-08-04 10:14:57 -07001322 presenceIconView.setImageDrawable(presenceIcon);
1323 presenceIconView.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001324 } else {
Evan Millar15e514d2009-08-04 10:14:57 -07001325 presenceIconView.setVisibility(View.GONE);
1326 }
1327
1328 // Set the secondary action button
1329 ImageView secondaryActionView = views.secondaryActionButton;
1330 Drawable secondaryActionIcon = null;
1331 if (entry.secondaryActionIcon != -1) {
1332 secondaryActionIcon = resources.getDrawable(entry.secondaryActionIcon);
1333 }
1334 if (entry.secondaryIntent != null && secondaryActionIcon != null) {
1335 secondaryActionView.setImageDrawable(secondaryActionIcon);
1336 secondaryActionView.setTag(entry.secondaryIntent);
1337 secondaryActionView.setVisibility(View.VISIBLE);
1338 views.secondaryActionDivider.setVisibility(View.VISIBLE);
1339 } else {
1340 secondaryActionView.setVisibility(View.GONE);
1341 views.secondaryActionDivider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001342 }
1343 }
1344
1345 private void setMaxLines(TextView textView, int maxLines) {
1346 if (maxLines == 1) {
1347 textView.setSingleLine(true);
1348 textView.setEllipsize(TextUtils.TruncateAt.END);
1349 } else {
1350 textView.setSingleLine(false);
1351 textView.setMaxLines(maxLines);
1352 textView.setEllipsize(null);
1353 }
1354 }
1355 }
1356}