blob: 69c1f89b8b4a6f975bc856dfa767fcb1c6f4d47d [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.model.ContactsSource;
21import com.android.contacts.model.Sources;
22import com.android.contacts.model.ContactsSource.DataKind;
Evan Millardf181202009-09-30 15:15:51 -070023import com.android.contacts.ui.EditContactActivity;
Jeff Sharkey49d17b32009-09-07 02:14:21 -070024import com.android.contacts.util.Constants;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070025import com.android.contacts.util.DataStatus;
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;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070029import com.google.android.collect.Lists;
30import com.google.android.collect.Maps;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080031
Evan Millar11d628c2009-09-02 08:55:01 -070032import android.app.Activity;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080033import android.app.AlertDialog;
34import android.app.Dialog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080035import android.content.ActivityNotFoundException;
36import android.content.ContentResolver;
37import android.content.ContentUris;
38import android.content.ContentValues;
39import android.content.Context;
40import android.content.DialogInterface;
Evan Millar5f4af702009-08-11 11:12:00 -070041import android.content.Entity;
Evan Millar11d628c2009-09-02 08:55:01 -070042import android.content.EntityIterator;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080043import android.content.Intent;
Evan Millar11d628c2009-09-02 08:55:01 -070044import android.content.Entity.NamedContentValues;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080045import android.content.res.Resources;
46import android.database.ContentObserver;
47import android.database.Cursor;
48import android.graphics.drawable.Drawable;
Evan Millar951fa9c2009-10-26 14:57:43 -070049import android.net.ParseException;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080050import android.net.Uri;
Evan Millar951fa9c2009-10-26 14:57:43 -070051import android.net.WebAddress;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080052import android.os.Bundle;
53import android.os.Handler;
54import android.os.RemoteException;
55import android.os.ServiceManager;
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -070056import android.provider.ContactsContract;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070057import android.provider.ContactsContract.AggregationExceptions;
58import android.provider.ContactsContract.CommonDataKinds;
Evan Millar11d628c2009-09-02 08:55:01 -070059import android.provider.ContactsContract.Contacts;
Evan Millar66388be2009-05-28 15:41:07 -070060import android.provider.ContactsContract.Data;
Dmitri Plotnikov39466592009-07-27 11:23:51 -070061import android.provider.ContactsContract.RawContacts;
Dmitri Plotnikov160e9da2009-09-30 23:48:12 -070062import android.provider.ContactsContract.StatusUpdates;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070063import android.provider.ContactsContract.CommonDataKinds.Email;
64import android.provider.ContactsContract.CommonDataKinds.Im;
65import android.provider.ContactsContract.CommonDataKinds.Nickname;
66import android.provider.ContactsContract.CommonDataKinds.Note;
67import android.provider.ContactsContract.CommonDataKinds.Organization;
Evan Millar54a5c9f2009-06-23 17:41:09 -070068import android.provider.ContactsContract.CommonDataKinds.Phone;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070069import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
Evan Millar951fa9c2009-10-26 14:57:43 -070070import android.provider.ContactsContract.CommonDataKinds.Website;
Evan Millar54a5c9f2009-06-23 17:41:09 -070071import android.telephony.PhoneNumberUtils;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080072import android.text.TextUtils;
73import android.util.Log;
74import android.view.ContextMenu;
75import android.view.KeyEvent;
Evan Millar11d628c2009-09-02 08:55:01 -070076import android.view.LayoutInflater;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080077import android.view.Menu;
Jeff Sharkey49d17b32009-09-07 02:14:21 -070078import android.view.MenuInflater;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080079import android.view.MenuItem;
80import android.view.View;
81import android.view.ViewGroup;
Evan Millar11d628c2009-09-02 08:55:01 -070082import android.view.Window;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080083import android.view.ContextMenu.ContextMenuInfo;
84import android.widget.AdapterView;
Evan Millar7911ff52009-07-21 15:55:18 -070085import android.widget.FrameLayout;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080086import android.widget.ImageView;
87import android.widget.ListView;
Evan Millarcdeea942009-10-07 11:47:35 -070088import android.widget.ScrollView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080089import android.widget.TextView;
90import android.widget.Toast;
91
92import java.util.ArrayList;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070093import java.util.HashMap;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080094
95/**
96 * Displays the details of a specific contact.
97 */
Evan Millar11d628c2009-09-02 08:55:01 -070098public class ViewContactActivity extends Activity
Evan Millar7911ff52009-07-21 15:55:18 -070099 implements View.OnCreateContextMenuListener, DialogInterface.OnClickListener,
Evan Millardf181202009-09-30 15:15:51 -0700100 AdapterView.OnItemClickListener, NotifyingAsyncQueryHandler.AsyncQueryListener {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800101 private static final String TAG = "ViewContact";
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800102
103 private static final boolean SHOW_SEPARATORS = false;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800104
105 private static final int DIALOG_CONFIRM_DELETE = 1;
Megha Joshid5afd8a2009-09-22 09:38:41 -0700106 private static final int DIALOG_CONFIRM_READONLY_DELETE = 2;
107 private static final int DIALOG_CONFIRM_MULTIPLE_DELETE = 3;
Megha Joshic508bd82009-10-01 17:31:49 -0700108 private static final int DIALOG_CONFIRM_READONLY_HIDE = 4;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800109
Evan Millar8a79cee2009-08-19 17:20:49 -0700110 private static final int REQUEST_JOIN_CONTACT = 1;
Evan Millar9cd81242009-09-26 16:02:31 -0700111 private static final int REQUEST_EDIT_CONTACT = 2;
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700112
Evan Millar8a79cee2009-08-19 17:20:49 -0700113 public static final int MENU_ITEM_MAKE_DEFAULT = 3;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800114
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700115 protected Uri mLookupUri;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800116 private ContentResolver mResolver;
117 private ViewAdapter mAdapter;
118 private int mNumPhoneNumbers = 0;
119
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700120 /**
Dmitri Plotnikove1cd6792009-07-27 20:28:17 -0700121 * A list of distinct contact IDs included in the current contact.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700122 */
Evan Millar7911ff52009-07-21 15:55:18 -0700123 private ArrayList<Long> mRawContactIds = new ArrayList<Long>();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700124
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800125 /* package */ ArrayList<ViewEntry> mPhoneEntries = new ArrayList<ViewEntry>();
126 /* package */ ArrayList<ViewEntry> mSmsEntries = new ArrayList<ViewEntry>();
127 /* package */ ArrayList<ViewEntry> mEmailEntries = new ArrayList<ViewEntry>();
128 /* package */ ArrayList<ViewEntry> mPostalEntries = new ArrayList<ViewEntry>();
129 /* package */ ArrayList<ViewEntry> mImEntries = new ArrayList<ViewEntry>();
130 /* package */ ArrayList<ViewEntry> mOrganizationEntries = new ArrayList<ViewEntry>();
The Android Open Source Projectcac191e2009-03-18 22:20:27 -0700131 /* package */ ArrayList<ViewEntry> mGroupEntries = new ArrayList<ViewEntry>();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800132 /* package */ ArrayList<ViewEntry> mOtherEntries = new ArrayList<ViewEntry>();
133 /* package */ ArrayList<ArrayList<ViewEntry>> mSections = new ArrayList<ArrayList<ViewEntry>>();
134
135 private Cursor mCursor;
Evan Millar5c22c3b2009-05-29 11:37:54 -0700136
Evan Millar11d628c2009-09-02 08:55:01 -0700137 protected ContactHeaderWidget mContactHeaderWidget;
138 private NotifyingAsyncQueryHandler mHandler;
139
140 protected LayoutInflater mInflater;
141
Megha Joshid5afd8a2009-09-22 09:38:41 -0700142 protected int mReadOnlySourcesCnt;
143 protected int mWritableSourcesCnt;
144 protected ArrayList<Long> mWritableRawContactIds = new ArrayList<Long>();
Evan Millar11d628c2009-09-02 08:55:01 -0700145
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700146 private static final int TOKEN_ENTITIES = 0;
147 private static final int TOKEN_STATUSES = 1;
148
149 private boolean mHasEntities = false;
150 private boolean mHasStatuses = false;
151
152 private ArrayList<Entity> mEntities = Lists.newArrayList();
153 private HashMap<Long, DataStatus> mStatuses = Maps.newHashMap();
Evan Millar11d628c2009-09-02 08:55:01 -0700154
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800155 private ContentObserver mObserver = new ContentObserver(new Handler()) {
156 @Override
157 public boolean deliverSelfNotifications() {
158 return true;
159 }
160
161 @Override
162 public void onChange(boolean selfChange) {
Evan Millar11d628c2009-09-02 08:55:01 -0700163 if (mCursor != null && !mCursor.isClosed()) {
164 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800165 }
166 }
167 };
168
169 public void onClick(DialogInterface dialog, int which) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700170 closeCursor();
Megha Joshic508bd82009-10-01 17:31:49 -0700171 getContentResolver().delete(mLookupUri, null, null);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800172 finish();
173 }
174
Evan Millar7911ff52009-07-21 15:55:18 -0700175 private ListView mListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800176 private boolean mShowSmsLinksForAllPhones;
177
178 @Override
179 protected void onCreate(Bundle icicle) {
180 super.onCreate(icicle);
181
Evan Millar11d628c2009-09-02 08:55:01 -0700182 final Intent intent = getIntent();
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -0700183 Uri data = intent.getData();
184 String authority = data.getAuthority();
185 if (ContactsContract.AUTHORITY.equals(authority)) {
186 mLookupUri = data;
187 } else if (android.provider.Contacts.AUTHORITY.equals(authority)) {
188 final long rawContactId = ContentUris.parseId(data);
189 mLookupUri = RawContacts.getContactLookupUri(getContentResolver(),
190 ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700191
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -0700192 }
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700193 mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Evan Millar11d628c2009-09-02 08:55:01 -0700194
195 requestWindowFeature(Window.FEATURE_NO_TITLE);
196 setContentView(R.layout.contact_card_layout);
197
198 mContactHeaderWidget = (ContactHeaderWidget) findViewById(R.id.contact_header_widget);
199 mContactHeaderWidget.showStar(true);
Evan Millar11d628c2009-09-02 08:55:01 -0700200 mContactHeaderWidget.setExcludeMimes(new String[] {
201 Contacts.CONTENT_ITEM_TYPE
202 });
203
Evan Millar11d628c2009-09-02 08:55:01 -0700204 mHandler = new NotifyingAsyncQueryHandler(this, this);
205
Evan Millarcdeea942009-10-07 11:47:35 -0700206 mListView = (ListView) findViewById(R.id.contact_data);
Evan Millar7911ff52009-07-21 15:55:18 -0700207 mListView.setOnCreateContextMenuListener(this);
208 mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
209 mListView.setOnItemClickListener(this);
Evan Millarcdeea942009-10-07 11:47:35 -0700210 mListView.setEmptyView((ScrollView) findViewById(android.R.id.empty));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800211
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800212 mResolver = getContentResolver();
213
214 // Build the list of sections. The order they're added to mSections dictates the
215 // order they are displayed in the list.
216 mSections.add(mPhoneEntries);
217 mSections.add(mSmsEntries);
218 mSections.add(mEmailEntries);
219 mSections.add(mImEntries);
220 mSections.add(mPostalEntries);
221 mSections.add(mOrganizationEntries);
The Android Open Source Projectcac191e2009-03-18 22:20:27 -0700222 mSections.add(mGroupEntries);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800223 mSections.add(mOtherEntries);
224
225 //TODO Read this value from a preference
226 mShowSmsLinksForAllPhones = true;
Evan Millar11d628c2009-09-02 08:55:01 -0700227 }
228
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800229 @Override
230 protected void onResume() {
231 super.onResume();
Evan Millar11d628c2009-09-02 08:55:01 -0700232 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800233 }
234
235 @Override
236 protected void onPause() {
237 super.onPause();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700238 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800239 }
240
241 @Override
242 protected void onDestroy() {
243 super.onDestroy();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700244 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800245 }
246
247 @Override
248 protected Dialog onCreateDialog(int id) {
249 switch (id) {
250 case DIALOG_CONFIRM_DELETE:
251 return new AlertDialog.Builder(this)
252 .setTitle(R.string.deleteConfirmation_title)
253 .setIcon(android.R.drawable.ic_dialog_alert)
254 .setMessage(R.string.deleteConfirmation)
255 .setNegativeButton(android.R.string.cancel, null)
256 .setPositiveButton(android.R.string.ok, this)
257 .setCancelable(false)
258 .create();
Megha Joshid5afd8a2009-09-22 09:38:41 -0700259 case DIALOG_CONFIRM_READONLY_DELETE:
260 return new AlertDialog.Builder(this)
261 .setTitle(R.string.deleteConfirmation_title)
262 .setIcon(android.R.drawable.ic_dialog_alert)
263 .setMessage(R.string.readOnlyContactDeleteConfirmation)
264 .setNegativeButton(android.R.string.cancel, null)
265 .setPositiveButton(android.R.string.ok, this)
266 .setCancelable(false)
267 .create();
268 case DIALOG_CONFIRM_MULTIPLE_DELETE:
269 return new AlertDialog.Builder(this)
270 .setTitle(R.string.deleteConfirmation_title)
271 .setIcon(android.R.drawable.ic_dialog_alert)
272 .setMessage(R.string.multipleContactDeleteConfirmation)
273 .setNegativeButton(android.R.string.cancel, null)
274 .setPositiveButton(android.R.string.ok, this)
275 .setCancelable(false)
276 .create();
Evan Millarcdeea942009-10-07 11:47:35 -0700277 case DIALOG_CONFIRM_READONLY_HIDE: {
Megha Joshic508bd82009-10-01 17:31:49 -0700278 return new AlertDialog.Builder(this)
279 .setTitle(R.string.deleteConfirmation_title)
280 .setIcon(android.R.drawable.ic_dialog_alert)
281 .setMessage(R.string.readOnlyContactWarning)
282 .setPositiveButton(android.R.string.ok, this)
Evan Millarcdeea942009-10-07 11:47:35 -0700283 .create();
Megha Joshic508bd82009-10-01 17:31:49 -0700284 }
285
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800286 }
287 return null;
288 }
289
Evan Millar11d628c2009-09-02 08:55:01 -0700290 // QUERY CODE //
291 /** {@inheritDoc} */
292 public void onQueryEntitiesComplete(int token, Object cookie, EntityIterator iterator) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700293 try {
294 // Read incoming entities and consider binding
295 readEntities(iterator);
296 considerBindData();
Evan Millar11d628c2009-09-02 08:55:01 -0700297 } finally {
298 if (iterator != null) {
299 iterator.close();
300 }
301 }
302 }
303
304 /** {@inheritDoc} */
305 public void onQueryComplete(int token, Object cookie, Cursor cursor) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700306 try {
307 // Read available social rows and consider binding
308 readStatuses(cursor);
309 considerBindData();
310 } finally {
311 if (cursor != null) {
312 cursor.close();
313 }
314 }
Evan Millar11d628c2009-09-02 08:55:01 -0700315 }
316
Evan Millar6a61a1a2009-09-29 14:00:43 -0700317 private long getRefreshedContactId() {
318 Uri freshContactUri = Contacts.lookupContact(getContentResolver(), mLookupUri);
319 if (freshContactUri != null) {
320 return ContentUris.parseId(freshContactUri);
321 }
322 return -1;
323 }
324
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700325 /**
326 * Read from the given {@link EntityIterator} to build internal set of
327 * {@link #mEntities} for data display.
328 */
329 private synchronized void readEntities(EntityIterator iterator) {
330 mEntities.clear();
Evan Millar11d628c2009-09-02 08:55:01 -0700331 try {
332 while (iterator.hasNext()) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700333 mEntities.add(iterator.next());
Evan Millar11d628c2009-09-02 08:55:01 -0700334 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700335 mHasEntities = true;
Evan Millar11d628c2009-09-02 08:55:01 -0700336 } catch (RemoteException e) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700337 Log.w(TAG, "Problem reading contact data: " + e.toString());
Evan Millar11d628c2009-09-02 08:55:01 -0700338 }
Evan Millar11d628c2009-09-02 08:55:01 -0700339 }
340
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700341 /**
342 * Read from the given {@link Cursor} and build a set of {@link DataStatus}
343 * objects to match any valid statuses found.
344 */
345 private synchronized void readStatuses(Cursor cursor) {
346 mStatuses.clear();
347
348 // Walk found statuses, creating internal row for each
349 while (cursor.moveToNext()) {
350 final DataStatus status = new DataStatus(cursor);
351 final long dataId = cursor.getLong(StatusQuery._ID);
352 mStatuses.put(dataId, status);
353 }
354
355 mHasStatuses = true;
356 }
357
358 private synchronized void startEntityQuery() {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700359 closeCursor();
360
Evan Millar6a61a1a2009-09-29 14:00:43 -0700361 Uri uri = null;
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700362 if (mLookupUri != null) {
363 mLookupUri = Contacts.getLookupUri(getContentResolver(), mLookupUri);
364 if (mLookupUri != null) {
Evan Millar6a61a1a2009-09-29 14:00:43 -0700365 uri = Contacts.lookupContact(getContentResolver(), mLookupUri);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700366 }
367 }
368
Evan Millar6a61a1a2009-09-29 14:00:43 -0700369 if (uri == null) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700370
371 // TODO either figure out a way to prevent a flash of black background or
372 // use some other UI than a toast
373 Toast.makeText(this, R.string.invalidContactMessage, Toast.LENGTH_SHORT).show();
374 Log.e(TAG, "invalid contact uri: " + mLookupUri);
375 finish();
376 return;
377 }
378
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700379 final Uri dataUri = Uri.withAppendedPath(uri, Contacts.Data.CONTENT_DIRECTORY);
380
381 // Keep stub cursor open on side to watch for change events
382 mCursor = mResolver.query(dataUri,
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700383 new String[] {Contacts.DISPLAY_NAME}, null, null, null);
384 mCursor.registerContentObserver(mObserver);
385
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700386 final long contactId = ContentUris.parseId(uri);
387
388 // Clear flags and start queries to data and status
389 mHasEntities = false;
390 mHasStatuses = false;
391
392 mHandler.startQueryEntities(TOKEN_ENTITIES, null, RawContacts.CONTENT_URI,
393 RawContacts.CONTACT_ID + "=" + contactId, null, null);
394 mHandler.startQuery(TOKEN_STATUSES, null, dataUri, StatusQuery.PROJECTION,
395 StatusUpdates.PRESENCE + " IS NOT NULL OR " + StatusUpdates.STATUS
396 + " IS NOT NULL", null, null);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700397
Evan Millar9b1a1242009-09-16 10:26:10 -0700398 mContactHeaderWidget.bindFromContactLookupUri(mLookupUri);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700399 }
400
401 private void closeCursor() {
402 if (mCursor != null) {
403 mCursor.unregisterContentObserver(mObserver);
404 mCursor.close();
405 mCursor = null;
406 }
Evan Millar11d628c2009-09-02 08:55:01 -0700407 }
408
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700409 /**
410 * Consider binding views after any of several background queries has
411 * completed. We check internal flags and only bind when all data has
412 * arrived.
413 */
414 private void considerBindData() {
415 if (mHasEntities && mHasStatuses) {
416 bindData();
417 }
418 }
419
Evan Millar11d628c2009-09-02 08:55:01 -0700420 private void bindData() {
421
422 // Build up the contact entries
423 buildEntries();
424
425 // Collapse similar data items in select sections.
426 Collapser.collapseList(mPhoneEntries);
427 Collapser.collapseList(mSmsEntries);
428 Collapser.collapseList(mEmailEntries);
429 Collapser.collapseList(mPostalEntries);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700430 Collapser.collapseList(mImEntries);
Evan Millar11d628c2009-09-02 08:55:01 -0700431
432 if (mAdapter == null) {
433 mAdapter = new ViewAdapter(this, mSections);
434 mListView.setAdapter(mAdapter);
435 } else {
436 mAdapter.setSections(mSections, SHOW_SEPARATORS);
437 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800438 }
439
440 @Override
441 public boolean onCreateOptionsMenu(Menu menu) {
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700442 super.onCreateOptionsMenu(menu);
443
444 final MenuInflater inflater = getMenuInflater();
445 inflater.inflate(R.menu.view, menu);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800446 return true;
447 }
448
449 @Override
450 public boolean onPrepareOptionsMenu(Menu menu) {
451 super.onPrepareOptionsMenu(menu);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700452
Evan Millar51514db2009-09-22 11:42:35 -0700453 // Only allow edit when we have at least one raw_contact id
454 final boolean hasRawContact = (mRawContactIds.size() > 0);
Evan Millar2e1b8af2009-09-24 09:39:21 -0700455 menu.findItem(R.id.menu_edit).setEnabled(hasRawContact);
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700456
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800457 return true;
458 }
459
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800460 @Override
461 public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
462 AdapterView.AdapterContextMenuInfo info;
463 try {
464 info = (AdapterView.AdapterContextMenuInfo) menuInfo;
465 } catch (ClassCastException e) {
466 Log.e(TAG, "bad menuInfo", e);
467 return;
468 }
469
470 // This can be null sometimes, don't crash...
471 if (info == null) {
472 Log.e(TAG, "bad menuInfo");
473 return;
474 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700475
Evan Millar45e0ed32009-06-01 16:44:38 -0700476 ViewEntry entry = ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
Neel Parekha8fb68a2009-09-25 18:05:18 -0700477 menu.setHeaderTitle(R.string.contactOptionsTitle);
Evan Millar45e0ed32009-06-01 16:44:38 -0700478 if (entry.mimetype.equals(CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
479 menu.add(0, 0, 0, R.string.menu_call).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700480 menu.add(0, 0, 0, R.string.menu_sendSMS).setIntent(entry.secondaryIntent);
481 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700482 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultNumber);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800483 }
Evan Millar45e0ed32009-06-01 16:44:38 -0700484 } else if (entry.mimetype.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
485 menu.add(0, 0, 0, R.string.menu_sendEmail).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700486 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700487 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultEmail);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800488 }
Jeff Sharkeyc6ad3ab2009-07-21 19:30:15 -0700489 } else if (entry.mimetype.equals(CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700490 menu.add(0, 0, 0, R.string.menu_viewAddress).setIntent(entry.intent);
491 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800492 }
493
494 @Override
495 public boolean onOptionsItemSelected(MenuItem item) {
496 switch (item.getItemId()) {
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700497 case R.id.menu_edit: {
Evan Millardf181202009-09-30 15:15:51 -0700498 Long rawContactIdToEdit = null;
499 if (mRawContactIds.size() > 0) {
500 rawContactIdToEdit = mRawContactIds.get(0);
501 } else {
502 // There is no rawContact to edit.
503 break;
Evan Millardb5d88c2009-08-28 09:31:57 -0700504 }
Evan Millar2e1b8af2009-09-24 09:39:21 -0700505 Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI,
506 rawContactIdToEdit);
Evan Millar9cd81242009-09-26 16:02:31 -0700507 startActivityForResult(new Intent(Intent.ACTION_EDIT, rawContactUri),
508 REQUEST_EDIT_CONTACT);
Evan Millar8a79cee2009-08-19 17:20:49 -0700509 break;
510 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700511 case R.id.menu_delete: {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800512 // Get confirmation
Evan Millarcdeea942009-10-07 11:47:35 -0700513 if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) {
Megha Joshid5afd8a2009-09-22 09:38:41 -0700514 showDialog(DIALOG_CONFIRM_READONLY_DELETE);
Evan Millarcdeea942009-10-07 11:47:35 -0700515 } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
Megha Joshic508bd82009-10-01 17:31:49 -0700516 showDialog(DIALOG_CONFIRM_READONLY_HIDE);
Evan Millarcdeea942009-10-07 11:47:35 -0700517 } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
518 showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE);
519 } else {
520 showDialog(DIALOG_CONFIRM_DELETE);
521 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800522 return true;
523 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700524 case R.id.menu_join: {
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700525 showJoinAggregateActivity();
526 return true;
527 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700528 case R.id.menu_options: {
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700529 showOptionsActivity();
530 return true;
531 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700532 case R.id.menu_share: {
Jeff Sharkey93049312009-09-27 17:28:13 -0700533 // TODO: Keep around actual LOOKUP_KEY, or formalize method of extracting
534 final String lookupKey = mLookupUri.getPathSegments().get(2);
535 final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
536
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700537 final Intent intent = new Intent(Intent.ACTION_SEND);
Jeff Sharkey93049312009-09-27 17:28:13 -0700538 intent.setType(Contacts.CONTENT_VCARD_TYPE);
539 intent.putExtra(Intent.EXTRA_STREAM, shareUri);
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700540
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700541 // Launch chooser to share contact via
542 final CharSequence chooseTitle = getText(R.string.share_via);
543 final Intent chooseIntent = Intent.createChooser(intent, chooseTitle);
Evan Millar5c22c3b2009-05-29 11:37:54 -0700544
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700545 try {
546 startActivity(chooseIntent);
547 } catch (ActivityNotFoundException ex) {
548 Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800549 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700550 return true;
551 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800552 }
553 return super.onOptionsItemSelected(item);
554 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700555
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800556 @Override
557 public boolean onContextItemSelected(MenuItem item) {
558 switch (item.getItemId()) {
559 case MENU_ITEM_MAKE_DEFAULT: {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700560 if (makeItemDefault(item)) {
561 return true;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800562 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700563 break;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800564 }
565 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700566
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800567 return super.onContextItemSelected(item);
568 }
569
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700570 private boolean makeItemDefault(MenuItem item) {
571 ViewEntry entry = getViewEntryForMenuItem(item);
572 if (entry == null) {
573 return false;
574 }
575
576 // Update the primary values in the data record.
Evan Millar14fecb62009-09-09 09:23:12 -0700577 ContentValues values = new ContentValues(1);
Evan Millar54a5c9f2009-06-23 17:41:09 -0700578 values.put(Data.IS_SUPER_PRIMARY, 1);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700579 getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, entry.id),
580 values, null, null);
Evan Millar11d628c2009-09-02 08:55:01 -0700581 startEntityQuery();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700582 return true;
583 }
584
585 /**
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700586 * Shows a list of aggregates that can be joined into the currently viewed aggregate.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700587 */
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700588 public void showJoinAggregateActivity() {
Evan Millar6a61a1a2009-09-29 14:00:43 -0700589 long freshId = getRefreshedContactId();
590 if (freshId > 0) {
591 String displayName = null;
592 if (mCursor.moveToFirst()) {
593 displayName = mCursor.getString(0);
594 }
595 Intent intent = new Intent(ContactsListActivity.JOIN_AGGREGATE);
596 intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_ID, freshId);
597 if (displayName != null) {
598 intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_NAME, displayName);
599 }
600 startActivityForResult(intent, REQUEST_JOIN_CONTACT);
Dmitri Plotnikova5cfca32009-09-29 18:13:08 -0700601 }
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700602 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700603
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700604 @Override
605 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
Evan Millar2e1b8af2009-09-24 09:39:21 -0700606 if (requestCode == REQUEST_JOIN_CONTACT) {
607 if (resultCode == RESULT_OK && intent != null) {
608 final long contactId = ContentUris.parseId(intent.getData());
609 joinAggregate(contactId);
Evan Millar8a79cee2009-08-19 17:20:49 -0700610 }
Evan Millar9cd81242009-09-26 16:02:31 -0700611 } else if (requestCode == REQUEST_EDIT_CONTACT) {
Evan Millardf181202009-09-30 15:15:51 -0700612 if (resultCode == EditContactActivity.RESULT_CLOSE_VIEW_ACTIVITY) {
613 finish();
Jeff Hamilton5297c6a2009-10-01 02:22:33 -0700614 } else if (resultCode == Activity.RESULT_OK) {
Dmitri Plotnikov160e9da2009-09-30 23:48:12 -0700615 mLookupUri = intent.getData();
616 if (mLookupUri == null) {
617 finish();
618 }
Evan Millardf181202009-09-30 15:15:51 -0700619 }
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700620 }
621 }
622
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700623 private void splitContact(long rawContactId) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700624 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_SEPARATE);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700625
626 // The split operation may have removed the original aggregate contact, so we need
627 // to requery everything
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700628 Toast.makeText(this, R.string.contactsSplitMessage, Toast.LENGTH_LONG).show();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700629 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700630 }
631
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700632 private void joinAggregate(final long contactId) {
Dmitri Plotnikov39466592009-07-27 11:23:51 -0700633 Cursor c = mResolver.query(RawContacts.CONTENT_URI, new String[] {RawContacts._ID},
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700634 RawContacts.CONTACT_ID + "=" + contactId, null, null);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700635
636 try {
637 while(c.moveToNext()) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700638 long rawContactId = c.getLong(0);
639 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_TOGETHER);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700640 }
641 } finally {
642 c.close();
643 }
644
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700645 Toast.makeText(this, R.string.contactsJoinedMessage, Toast.LENGTH_LONG).show();
646 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700647 }
648
649 /**
650 * Given a contact ID sets an aggregation exception to either join the contact with the
651 * current aggregate or split off.
652 */
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700653 protected void setAggregationException(long rawContactId, int exceptionType) {
Dmitri Plotnikovd09f75c2009-06-16 11:59:22 -0700654 ContentValues values = new ContentValues(3);
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700655 for (long aRawContactId : mRawContactIds) {
656 if (aRawContactId != rawContactId) {
657 values.put(AggregationExceptions.RAW_CONTACT_ID1, aRawContactId);
658 values.put(AggregationExceptions.RAW_CONTACT_ID2, rawContactId);
659 values.put(AggregationExceptions.TYPE, exceptionType);
660 mResolver.update(AggregationExceptions.CONTENT_URI, values, null, null);
661 }
662 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700663 }
664
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700665 private void showOptionsActivity() {
666 final Intent intent = new Intent(this, ContactOptionsActivity.class);
Evan Millar6a61a1a2009-09-29 14:00:43 -0700667 intent.setData(mLookupUri);
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700668 startActivity(intent);
669 }
670
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700671 private ViewEntry getViewEntryForMenuItem(MenuItem item) {
672 AdapterView.AdapterContextMenuInfo info;
673 try {
674 info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
675 } catch (ClassCastException e) {
676 Log.e(TAG, "bad menuInfo", e);
677 return null;
678 }
679
680 return ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
681 }
682
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800683 @Override
684 public boolean onKeyDown(int keyCode, KeyEvent event) {
685 switch (keyCode) {
686 case KeyEvent.KEYCODE_CALL: {
687 try {
688 ITelephony phone = ITelephony.Stub.asInterface(
689 ServiceManager.checkService("phone"));
690 if (phone != null && !phone.isIdle()) {
691 // Skip out and let the key be handled at a higher level
692 break;
693 }
694 } catch (RemoteException re) {
695 // Fall through and try to call the contact
696 }
697
Evan Millar7911ff52009-07-21 15:55:18 -0700698 int index = mListView.getSelectedItemPosition();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800699 if (index != -1) {
700 ViewEntry entry = ViewAdapter.getEntry(mSections, index, SHOW_SEPARATORS);
Evan Millar66388be2009-05-28 15:41:07 -0700701 if (entry.intent.getAction() == Intent.ACTION_CALL_PRIVILEGED) {
702 startActivity(entry.intent);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800703 }
704 } else if (mNumPhoneNumbers != 0) {
705 // There isn't anything selected, call the default number
Evan Millar6a61a1a2009-09-29 14:00:43 -0700706 long freshContactId = getRefreshedContactId();
707 if (freshContactId > 0) {
708 Uri hardContacUri = ContentUris.withAppendedId(
709 Contacts.CONTENT_URI, freshContactId);
710 Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, hardContacUri);
711 startActivity(intent);
712 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800713 }
714 return true;
715 }
716
717 case KeyEvent.KEYCODE_DEL: {
Evan Millarcdeea942009-10-07 11:47:35 -0700718 if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) {
Megha Joshid5afd8a2009-09-22 09:38:41 -0700719 showDialog(DIALOG_CONFIRM_READONLY_DELETE);
Evan Millarcdeea942009-10-07 11:47:35 -0700720 } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
Megha Joshic508bd82009-10-01 17:31:49 -0700721 showDialog(DIALOG_CONFIRM_READONLY_HIDE);
Evan Millarcdeea942009-10-07 11:47:35 -0700722 } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
723 showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE);
724 } else {
725 showDialog(DIALOG_CONFIRM_DELETE);
726 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800727 return true;
728 }
729 }
730
731 return super.onKeyDown(keyCode, event);
732 }
733
Evan Millar7911ff52009-07-21 15:55:18 -0700734 public void onItemClick(AdapterView parent, View v, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800735 ViewEntry entry = ViewAdapter.getEntry(mSections, position, SHOW_SEPARATORS);
736 if (entry != null) {
737 Intent intent = entry.intent;
Evan Millardf181202009-09-30 15:15:51 -0700738 if (intent != null) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800739 try {
740 startActivity(intent);
741 } catch (ActivityNotFoundException e) {
742 Log.e(TAG, "No activity found for intent: " + intent);
743 signalError();
744 }
745 } else {
746 signalError();
747 }
748 } else {
749 signalError();
750 }
751 }
752
753 /**
754 * Signal an error to the user via a beep, or some other method.
755 */
756 private void signalError() {
757 //TODO: implement this when we have the sonification APIs
758 }
759
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800760 /**
761 * Build up the entries to display on the screen.
Evan Millar5c22c3b2009-05-29 11:37:54 -0700762 *
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800763 * @param personCursor the URI for the contact being displayed
764 */
Evan Millar11d628c2009-09-02 08:55:01 -0700765 private final void buildEntries() {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800766 // Clear out the old entries
767 final int numSections = mSections.size();
768 for (int i = 0; i < numSections; i++) {
769 mSections.get(i).clear();
770 }
771
Evan Millar7911ff52009-07-21 15:55:18 -0700772 mRawContactIds.clear();
Megha Joshid5afd8a2009-09-22 09:38:41 -0700773 mReadOnlySourcesCnt = 0;
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700774 mWritableSourcesCnt = 0;
Megha Joshid5afd8a2009-09-22 09:38:41 -0700775 mWritableRawContactIds.clear();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700776
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700777 final Context context = this;
778 final Sources sources = Sources.getInstance(context);
Evan Millar11d628c2009-09-02 08:55:01 -0700779
Evan Millar66388be2009-05-28 15:41:07 -0700780 // Build up method entries
Evan Millar6a61a1a2009-09-29 14:00:43 -0700781 if (mLookupUri != null) {
Evan Millar11d628c2009-09-02 08:55:01 -0700782 for (Entity entity: mEntities) {
783 final ContentValues entValues = entity.getEntityValues();
784 final String accountType = entValues.getAsString(RawContacts.ACCOUNT_TYPE);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700785 final long rawContactId = entValues.getAsLong(RawContacts._ID);
Evan Millar7911ff52009-07-21 15:55:18 -0700786
Dmitri Plotnikov2a8cef02009-09-23 19:01:15 -0700787 if (!mRawContactIds.contains(rawContactId)) {
788 mRawContactIds.add(rawContactId);
789 }
Megha Joshic508bd82009-10-01 17:31:49 -0700790 ContactsSource contactsSource = sources.getInflatedSource(accountType,
791 ContactsSource.LEVEL_SUMMARY);
792 if (contactsSource != null && contactsSource.readOnly) {
793 mReadOnlySourcesCnt += 1;
794 } else {
795 mWritableSourcesCnt += 1;
Evan Millarcdeea942009-10-07 11:47:35 -0700796 mWritableRawContactIds.add(rawContactId);
797 }
Megha Joshic508bd82009-10-01 17:31:49 -0700798
Dmitri Plotnikov2a8cef02009-09-23 19:01:15 -0700799
Evan Millar11d628c2009-09-02 08:55:01 -0700800 for (NamedContentValues subValue : entity.getSubValues()) {
Jeff Sharkeyab066932009-09-21 09:55:30 -0700801 final ContentValues entryValues = subValue.values;
802 entryValues.put(Data.RAW_CONTACT_ID, rawContactId);
803
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700804 final long dataId = entryValues.getAsLong(Data._ID);
805 final String mimeType = entryValues.getAsString(Data.MIMETYPE);
806 if (mimeType == null) continue;
Evan Millar66388be2009-05-28 15:41:07 -0700807
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700808 final DataKind kind = sources.getKindOrFallback(accountType, mimeType, this,
Evan Millar11d628c2009-09-02 08:55:01 -0700809 ContactsSource.LEVEL_MIMETYPES);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700810 if (kind == null) continue;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800811
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700812 final ViewEntry entry = ViewEntry.fromValues(context, mimeType, kind,
813 rawContactId, dataId, entryValues);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800814
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700815 final boolean hasData = !TextUtils.isEmpty(entry.data);
Evan Millarff04a272009-09-26 15:23:37 -0700816 final boolean isSuperPrimary = entryValues.getAsInteger(
817 Data.IS_SUPER_PRIMARY) != 0;
Evan Millar11d628c2009-09-02 08:55:01 -0700818
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700819 if (Phone.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700820 // Build phone entries
821 mNumPhoneNumbers++;
Evan Millar11d628c2009-09-02 08:55:01 -0700822
Evan Millarff04a272009-09-26 15:23:37 -0700823 entry.intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700824 Uri.fromParts(Constants.SCHEME_TEL, entry.data, null));
Evan Millarff04a272009-09-26 15:23:37 -0700825 entry.secondaryIntent = new Intent(Intent.ACTION_SENDTO,
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700826 Uri.fromParts(Constants.SCHEME_SMSTO, entry.data, null));
Evan Millar49714ee2009-09-02 16:42:47 -0700827
Evan Millarff04a272009-09-26 15:23:37 -0700828 entry.isPrimary = isSuperPrimary;
829 mPhoneEntries.add(entry);
830
831 if (entry.type == CommonDataKinds.Phone.TYPE_MOBILE
832 || mShowSmsLinksForAllPhones) {
833 // Add an SMS entry
834 if (kind.iconAltRes > 0) {
835 entry.secondaryActionIcon = kind.iconAltRes;
Evan Millar49714ee2009-09-02 16:42:47 -0700836 }
Evan Millarff04a272009-09-26 15:23:37 -0700837 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700838 } else if (Email.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700839 // Build email entries
840 entry.intent = new Intent(Intent.ACTION_SENDTO,
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700841 Uri.fromParts(Constants.SCHEME_MAILTO, entry.data, null));
Evan Millarff04a272009-09-26 15:23:37 -0700842 entry.isPrimary = isSuperPrimary;
843 mEmailEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700844
845 // When Email rows have status, create additional Im row
846 final DataStatus status = mStatuses.get(entry.id);
847 if (status != null) {
848 final String imMime = Im.CONTENT_ITEM_TYPE;
849 final DataKind imKind = sources.getKindOrFallback(accountType,
850 imMime, this, ContactsSource.LEVEL_MIMETYPES);
851 final ViewEntry imEntry = ViewEntry.fromValues(context,
852 imMime, imKind, rawContactId, dataId, entryValues);
853 imEntry.intent = ContactsUtils.buildImIntent(entryValues);
854 imEntry.applyStatus(status, false);
855 mImEntries.add(imEntry);
856 }
857 } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700858 // Build postal entries
859 entry.maxLines = 4;
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700860 entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri);
Evan Millarff04a272009-09-26 15:23:37 -0700861 mPostalEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700862 } else if (Im.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
863 // Build IM entries
864 entry.intent = ContactsUtils.buildImIntent(entryValues);
Evan Millarff04a272009-09-26 15:23:37 -0700865 if (TextUtils.isEmpty(entry.label)) {
866 entry.label = getString(R.string.chat).toLowerCase();
867 }
Evan Millar11d628c2009-09-02 08:55:01 -0700868
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700869 // Apply presence and status details when available
870 final DataStatus status = mStatuses.get(entry.id);
871 if (status != null) {
872 entry.applyStatus(status, false);
Evan Millarff04a272009-09-26 15:23:37 -0700873 }
Evan Millarff04a272009-09-26 15:23:37 -0700874 mImEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700875 } else if ((Organization.CONTENT_ITEM_TYPE.equals(mimeType)
876 || Nickname.CONTENT_ITEM_TYPE.equals(mimeType)) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700877 // Build organization and note entries
878 entry.uri = null;
Evan Millar11d628c2009-09-02 08:55:01 -0700879 mOrganizationEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700880 } else if (Note.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millar11d628c2009-09-02 08:55:01 -0700881 // Build note entries
Evan Millar11d628c2009-09-02 08:55:01 -0700882 entry.uri = null;
Evan Millar11d628c2009-09-02 08:55:01 -0700883 entry.maxLines = 10;
884 mOtherEntries.add(entry);
Evan Millar951fa9c2009-10-26 14:57:43 -0700885 } else if (Website.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
886 // Build note entries
887 entry.uri = null;
888 entry.maxLines = 10;
889 try {
890 WebAddress webAddress = new WebAddress(entry.data);
891 entry.intent = new Intent(Intent.ACTION_VIEW,
892 Uri.parse(webAddress.toString()));
893 } catch (ParseException e) {
894 Log.e(TAG, "Couldn't parse website: " + entry.data);
895 }
896 mOtherEntries.add(entry);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700897 } else {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700898 // Handle showing custom rows
Evan Millarff04a272009-09-26 15:23:37 -0700899 entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700900
901 // Use social summary when requested by external source
902 final DataStatus status = mStatuses.get(entry.id);
903 final boolean hasSocial = kind.actionBodySocial && status != null;
904 if (hasSocial) {
905 entry.applyStatus(status, true);
906 }
907
908 if (hasSocial || hasData) {
909 mOtherEntries.add(entry);
910 }
Evan Millar11d628c2009-09-02 08:55:01 -0700911 }
Evan Millar2e1b8af2009-09-24 09:39:21 -0700912 }
Evan Millar66388be2009-05-28 15:41:07 -0700913 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800914 }
915 }
916
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700917 static String buildActionString(DataKind kind, ContentValues values, boolean lowerCase,
918 Context context) {
Evan Millar11d628c2009-09-02 08:55:01 -0700919 if (kind.actionHeader == null) {
920 return null;
Jeff Hamilton8350e5b2009-03-24 21:01:34 -0700921 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700922 CharSequence actionHeader = kind.actionHeader.inflateUsing(context, values);
Evan Millar11d628c2009-09-02 08:55:01 -0700923 if (actionHeader == null) {
924 return null;
925 }
926 return lowerCase ? actionHeader.toString().toLowerCase() : actionHeader.toString();
927 }
Jeff Hamilton8350e5b2009-03-24 21:01:34 -0700928
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700929 static String buildDataString(DataKind kind, ContentValues values, Context context) {
Evan Millar11d628c2009-09-02 08:55:01 -0700930 if (kind.actionBody == null) {
931 return null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800932 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700933 CharSequence actionBody = kind.actionBody.inflateUsing(context, values);
Evan Millar11d628c2009-09-02 08:55:01 -0700934 return actionBody == null ? null : actionBody.toString();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800935 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700936
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800937 /**
938 * A basic structure with the data for a contact entry in the list.
939 */
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700940 static class ViewEntry extends ContactEntryAdapter.Entry implements Collapsible<ViewEntry> {
941 public Context context = null;
Jeff Sharkeyab066932009-09-21 09:55:30 -0700942 public String resPackageName = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800943 public int actionIcon = -1;
Evan Millar15e514d2009-08-04 10:14:57 -0700944 public boolean isPrimary = false;
Evan Millar15e514d2009-08-04 10:14:57 -0700945 public int secondaryActionIcon = -1;
946 public Intent intent;
947 public Intent secondaryIntent = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800948 public int maxLabelLines = 1;
Evan Millar54a5c9f2009-06-23 17:41:09 -0700949 public ArrayList<Long> ids = new ArrayList<Long>();
950 public int collapseCount = 0;
951
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700952 public int presence = -1;
953 public int presenceIcon = -1;
954
955 public CharSequence footerLine = null;
956
957 private ViewEntry() {
958 }
959
960 /**
961 * Build new {@link ViewEntry} and populate from the given values.
962 */
963 public static ViewEntry fromValues(Context context, String mimeType, DataKind kind,
964 long rawContactId, long dataId, ContentValues values) {
965 final ViewEntry entry = new ViewEntry();
966 entry.context = context;
967 entry.contactId = rawContactId;
968 entry.id = dataId;
969 entry.uri = ContentUris.withAppendedId(Data.CONTENT_URI, entry.id);
970 entry.mimetype = mimeType;
971 entry.label = buildActionString(kind, values, false, context);
972 entry.data = buildDataString(kind, values, context);
973
974 if (kind.typeColumn != null && values.containsKey(kind.typeColumn)) {
975 entry.type = values.getAsInteger(kind.typeColumn);
976 }
977 if (kind.iconRes > 0) {
978 entry.resPackageName = kind.resPackageName;
979 entry.actionIcon = kind.iconRes;
980 }
981
982 return entry;
983 }
984
985 /**
986 * Apply given {@link DataStatus} values over this {@link ViewEntry}
987 *
988 * @param fillData When true, the given status replaces {@link #data}
989 * and {@link #footerLine}. Otherwise only {@link #presence}
990 * is updated.
991 */
992 public ViewEntry applyStatus(DataStatus status, boolean fillData) {
993 presence = status.getPresence();
994 presenceIcon = (presence == -1) ? -1 :
995 StatusUpdates.getPresenceIconResourceId(this.presence);
996
997 if (fillData && status.isValid()) {
998 this.data = status.getStatus().toString();
999 this.footerLine = status.getTimestampLabel(context);
1000 }
1001
1002 return this;
1003 }
1004
Evan Millar54a5c9f2009-06-23 17:41:09 -07001005 public boolean collapseWith(ViewEntry entry) {
1006 // assert equal collapse keys
Evan Millaradb0f8c2009-09-28 17:20:50 -07001007 if (!shouldCollapseWith(entry)) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001008 return false;
1009 }
1010
1011 // Choose the label associated with the highest type precedence.
1012 if (TypePrecedence.getTypePrecedence(mimetype, type)
1013 > TypePrecedence.getTypePrecedence(entry.mimetype, entry.type)) {
1014 type = entry.type;
1015 label = entry.label;
1016 }
1017
1018 // Choose the max of the maxLines and maxLabelLines values.
1019 maxLines = Math.max(maxLines, entry.maxLines);
1020 maxLabelLines = Math.max(maxLabelLines, entry.maxLabelLines);
1021
1022 // Choose the presence with the highest precedence.
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001023 if (StatusUpdates.getPresencePrecedence(presence)
1024 < StatusUpdates.getPresencePrecedence(entry.presence)) {
1025 presence = entry.presence;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001026 }
1027
1028 // If any of the collapsed entries are primary make the whole thing primary.
Evan Millar15e514d2009-08-04 10:14:57 -07001029 isPrimary = entry.isPrimary ? true : isPrimary;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001030
1031 // uri, and contactdId, shouldn't make a difference. Just keep the original.
1032
1033 // Keep track of all the ids that have been collapsed with this one.
1034 ids.add(entry.id);
1035 collapseCount++;
1036 return true;
1037 }
1038
Evan Millaradb0f8c2009-09-28 17:20:50 -07001039 public boolean shouldCollapseWith(ViewEntry entry) {
1040 if (entry == null) {
1041 return false;
1042 }
1043
Makoto Onukic710b0e2009-10-13 15:43:24 -07001044 if (!ContactsUtils.areDataEqual(context, mimetype, data, entry.mimetype, entry.data)) {
1045 return false;
Evan Millaradb0f8c2009-09-28 17:20:50 -07001046 }
1047
Makoto Onukic710b0e2009-10-13 15:43:24 -07001048 if (!TextUtils.equals(mimetype, entry.mimetype)
1049 || !ContactsUtils.areIntentActionEqual(intent, entry.intent)
1050 || !ContactsUtils.areIntentActionEqual(secondaryIntent, entry.secondaryIntent)
Evan Millaradb0f8c2009-09-28 17:20:50 -07001051 || actionIcon != entry.actionIcon) {
1052 return false;
1053 }
1054
1055 return true;
1056 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001057 }
1058
Evan Millar15e514d2009-08-04 10:14:57 -07001059 /** Cache of the children views of a row */
1060 static class ViewCache {
1061 public TextView label;
1062 public TextView data;
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001063 public TextView footer;
Evan Millar15e514d2009-08-04 10:14:57 -07001064 public ImageView actionIcon;
1065 public ImageView presenceIcon;
1066 public ImageView primaryIcon;
1067 public ImageView secondaryActionButton;
1068 public View secondaryActionDivider;
Evan Millar5c22c3b2009-05-29 11:37:54 -07001069
Evan Millar15e514d2009-08-04 10:14:57 -07001070 // Need to keep track of this too
1071 ViewEntry entry;
1072 }
1073
1074 private final class ViewAdapter extends ContactEntryAdapter<ViewEntry>
1075 implements View.OnClickListener {
1076
Evan Millar5c22c3b2009-05-29 11:37:54 -07001077
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001078 ViewAdapter(Context context, ArrayList<ArrayList<ViewEntry>> sections) {
1079 super(context, sections, SHOW_SEPARATORS);
1080 }
1081
Evan Millar15e514d2009-08-04 10:14:57 -07001082 public void onClick(View v) {
1083 Intent intent = (Intent) v.getTag();
1084 startActivity(intent);
1085 }
1086
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001087 @Override
1088 public View getView(int position, View convertView, ViewGroup parent) {
Evan Millar5c22c3b2009-05-29 11:37:54 -07001089 ViewEntry entry = getEntry(mSections, position, false);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001090 View v;
1091
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001092 ViewCache views;
1093
1094 // Check to see if we can reuse convertView
1095 if (convertView != null) {
1096 v = convertView;
1097 views = (ViewCache) v.getTag();
1098 } else {
1099 // Create a new view if needed
1100 v = mInflater.inflate(R.layout.list_item_text_icons, parent, false);
1101
1102 // Cache the children
1103 views = new ViewCache();
1104 views.label = (TextView) v.findViewById(android.R.id.text1);
1105 views.data = (TextView) v.findViewById(android.R.id.text2);
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001106 views.footer = (TextView) v.findViewById(R.id.footer);
Evan Millar15e514d2009-08-04 10:14:57 -07001107 views.actionIcon = (ImageView) v.findViewById(R.id.action_icon);
1108 views.primaryIcon = (ImageView) v.findViewById(R.id.primary_icon);
1109 views.presenceIcon = (ImageView) v.findViewById(R.id.presence_icon);
1110 views.secondaryActionButton = (ImageView) v.findViewById(
1111 R.id.secondary_action_button);
1112 views.secondaryActionButton.setOnClickListener(this);
Evan Millar15e514d2009-08-04 10:14:57 -07001113 views.secondaryActionDivider = v.findViewById(R.id.divider);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001114 v.setTag(views);
1115 }
1116
1117 // Update the entry in the view cache
1118 views.entry = entry;
1119
1120 // Bind the data to the view
1121 bindView(v, entry);
1122 return v;
1123 }
1124
1125 @Override
1126 protected View newView(int position, ViewGroup parent) {
1127 // getView() handles this
1128 throw new UnsupportedOperationException();
1129 }
1130
1131 @Override
1132 protected void bindView(View view, ViewEntry entry) {
1133 final Resources resources = mContext.getResources();
1134 ViewCache views = (ViewCache) view.getTag();
1135
1136 // Set the label
1137 TextView label = views.label;
1138 setMaxLines(label, entry.maxLabelLines);
1139 label.setText(entry.label);
1140
1141 // Set the data
1142 TextView data = views.data;
1143 if (data != null) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001144 if (entry.mimetype.equals(Phone.CONTENT_ITEM_TYPE)
Jeff Sharkey49d17b32009-09-07 02:14:21 -07001145 || entry.mimetype.equals(Constants.MIME_SMS_ADDRESS)) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001146 data.setText(PhoneNumberUtils.formatNumber(entry.data));
1147 } else {
1148 data.setText(entry.data);
1149 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001150 setMaxLines(data, entry.maxLines);
1151 }
1152
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001153 // Set the footer
1154 if (!TextUtils.isEmpty(entry.footerLine)) {
1155 views.footer.setText(entry.footerLine);
1156 views.footer.setVisibility(View.VISIBLE);
1157 } else {
1158 views.footer.setVisibility(View.GONE);
1159 }
1160
Evan Millar15e514d2009-08-04 10:14:57 -07001161 // Set the primary icon
1162 views.primaryIcon.setVisibility(entry.isPrimary ? View.VISIBLE : View.GONE);
1163
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001164 // Set the action icon
1165 ImageView action = views.actionIcon;
1166 if (entry.actionIcon != -1) {
Jeff Sharkeyab066932009-09-21 09:55:30 -07001167 Drawable actionIcon;
1168 if (entry.resPackageName != null) {
1169 // Load external resources through PackageManager
1170 actionIcon = mContext.getPackageManager().getDrawable(entry.resPackageName,
1171 entry.actionIcon, null);
1172 } else {
1173 actionIcon = resources.getDrawable(entry.actionIcon);
1174 }
1175 action.setImageDrawable(actionIcon);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001176 action.setVisibility(View.VISIBLE);
1177 } else {
1178 // Things should still line up as if there was an icon, so make it invisible
1179 action.setVisibility(View.INVISIBLE);
1180 }
1181
1182 // Set the presence icon
1183 Drawable presenceIcon = null;
Evan Millar15e514d2009-08-04 10:14:57 -07001184 if (entry.presenceIcon != -1) {
1185 presenceIcon = resources.getDrawable(entry.presenceIcon);
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001186 } else if (entry.presence != -1) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001187 presenceIcon = resources.getDrawable(
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001188 StatusUpdates.getPresenceIconResourceId(entry.presence));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001189 }
Evan Millar15e514d2009-08-04 10:14:57 -07001190 ImageView presenceIconView = views.presenceIcon;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001191 if (presenceIcon != null) {
Evan Millar15e514d2009-08-04 10:14:57 -07001192 presenceIconView.setImageDrawable(presenceIcon);
1193 presenceIconView.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001194 } else {
Evan Millar15e514d2009-08-04 10:14:57 -07001195 presenceIconView.setVisibility(View.GONE);
1196 }
1197
1198 // Set the secondary action button
1199 ImageView secondaryActionView = views.secondaryActionButton;
1200 Drawable secondaryActionIcon = null;
1201 if (entry.secondaryActionIcon != -1) {
1202 secondaryActionIcon = resources.getDrawable(entry.secondaryActionIcon);
1203 }
1204 if (entry.secondaryIntent != null && secondaryActionIcon != null) {
1205 secondaryActionView.setImageDrawable(secondaryActionIcon);
1206 secondaryActionView.setTag(entry.secondaryIntent);
1207 secondaryActionView.setVisibility(View.VISIBLE);
1208 views.secondaryActionDivider.setVisibility(View.VISIBLE);
1209 } else {
1210 secondaryActionView.setVisibility(View.GONE);
1211 views.secondaryActionDivider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001212 }
1213 }
1214
1215 private void setMaxLines(TextView textView, int maxLines) {
1216 if (maxLines == 1) {
1217 textView.setSingleLine(true);
1218 textView.setEllipsize(TextUtils.TruncateAt.END);
1219 } else {
1220 textView.setSingleLine(false);
1221 textView.setMaxLines(maxLines);
1222 textView.setEllipsize(null);
1223 }
1224 }
1225 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001226
1227 private interface StatusQuery {
1228 final String[] PROJECTION = new String[] {
1229 Data._ID,
1230 Data.STATUS,
1231 Data.STATUS_RES_PACKAGE,
1232 Data.STATUS_ICON,
1233 Data.STATUS_LABEL,
1234 Data.STATUS_TIMESTAMP,
1235 Data.PRESENCE,
1236 };
1237
1238 final int _ID = 0;
1239 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001240}