blob: 3d5ac859c7c9ee81d7230371287460294d88fa1a [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;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080049import android.net.Uri;
50import android.os.Bundle;
51import android.os.Handler;
52import android.os.RemoteException;
53import android.os.ServiceManager;
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -070054import android.provider.ContactsContract;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070055import android.provider.ContactsContract.AggregationExceptions;
56import android.provider.ContactsContract.CommonDataKinds;
Evan Millar11d628c2009-09-02 08:55:01 -070057import android.provider.ContactsContract.Contacts;
Evan Millar66388be2009-05-28 15:41:07 -070058import android.provider.ContactsContract.Data;
Dmitri Plotnikov39466592009-07-27 11:23:51 -070059import android.provider.ContactsContract.RawContacts;
Dmitri Plotnikov160e9da2009-09-30 23:48:12 -070060import android.provider.ContactsContract.StatusUpdates;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070061import android.provider.ContactsContract.CommonDataKinds.Email;
62import android.provider.ContactsContract.CommonDataKinds.Im;
63import android.provider.ContactsContract.CommonDataKinds.Nickname;
64import android.provider.ContactsContract.CommonDataKinds.Note;
65import android.provider.ContactsContract.CommonDataKinds.Organization;
Evan Millar54a5c9f2009-06-23 17:41:09 -070066import android.provider.ContactsContract.CommonDataKinds.Phone;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070067import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
Evan Millar54a5c9f2009-06-23 17:41:09 -070068import android.telephony.PhoneNumberUtils;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080069import android.text.TextUtils;
70import android.util.Log;
71import android.view.ContextMenu;
72import android.view.KeyEvent;
Evan Millar11d628c2009-09-02 08:55:01 -070073import android.view.LayoutInflater;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080074import android.view.Menu;
Jeff Sharkey49d17b32009-09-07 02:14:21 -070075import android.view.MenuInflater;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080076import android.view.MenuItem;
77import android.view.View;
78import android.view.ViewGroup;
Evan Millar11d628c2009-09-02 08:55:01 -070079import android.view.Window;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080080import android.view.ContextMenu.ContextMenuInfo;
81import android.widget.AdapterView;
Evan Millar7911ff52009-07-21 15:55:18 -070082import android.widget.FrameLayout;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080083import android.widget.ImageView;
84import android.widget.ListView;
85import android.widget.TextView;
86import android.widget.Toast;
87
88import java.util.ArrayList;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070089import java.util.HashMap;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080090
91/**
92 * Displays the details of a specific contact.
93 */
Evan Millar11d628c2009-09-02 08:55:01 -070094public class ViewContactActivity extends Activity
Evan Millar7911ff52009-07-21 15:55:18 -070095 implements View.OnCreateContextMenuListener, DialogInterface.OnClickListener,
Evan Millardf181202009-09-30 15:15:51 -070096 AdapterView.OnItemClickListener, NotifyingAsyncQueryHandler.AsyncQueryListener {
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
99 private static final boolean SHOW_SEPARATORS = false;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800100
101 private static final int DIALOG_CONFIRM_DELETE = 1;
Megha Joshid5afd8a2009-09-22 09:38:41 -0700102 private static final int DIALOG_CONFIRM_READONLY_DELETE = 2;
103 private static final int DIALOG_CONFIRM_MULTIPLE_DELETE = 3;
Megha Joshic508bd82009-10-01 17:31:49 -0700104 private static final int DIALOG_CONFIRM_READONLY_HIDE = 4;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800105
Evan Millar8a79cee2009-08-19 17:20:49 -0700106 private static final int REQUEST_JOIN_CONTACT = 1;
Evan Millar9cd81242009-09-26 16:02:31 -0700107 private static final int REQUEST_EDIT_CONTACT = 2;
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700108
Evan Millar8a79cee2009-08-19 17:20:49 -0700109 public static final int MENU_ITEM_MAKE_DEFAULT = 3;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800110
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700111 protected Uri mLookupUri;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800112 private ContentResolver mResolver;
113 private ViewAdapter mAdapter;
114 private int mNumPhoneNumbers = 0;
115
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700116 /**
Dmitri Plotnikove1cd6792009-07-27 20:28:17 -0700117 * A list of distinct contact IDs included in the current contact.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700118 */
Evan Millar7911ff52009-07-21 15:55:18 -0700119 private ArrayList<Long> mRawContactIds = new ArrayList<Long>();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700120
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800121 /* package */ ArrayList<ViewEntry> mPhoneEntries = new ArrayList<ViewEntry>();
122 /* package */ ArrayList<ViewEntry> mSmsEntries = new ArrayList<ViewEntry>();
123 /* package */ ArrayList<ViewEntry> mEmailEntries = new ArrayList<ViewEntry>();
124 /* package */ ArrayList<ViewEntry> mPostalEntries = new ArrayList<ViewEntry>();
125 /* package */ ArrayList<ViewEntry> mImEntries = new ArrayList<ViewEntry>();
126 /* package */ ArrayList<ViewEntry> mOrganizationEntries = new ArrayList<ViewEntry>();
The Android Open Source Projectcac191e2009-03-18 22:20:27 -0700127 /* package */ ArrayList<ViewEntry> mGroupEntries = new ArrayList<ViewEntry>();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800128 /* package */ ArrayList<ViewEntry> mOtherEntries = new ArrayList<ViewEntry>();
129 /* package */ ArrayList<ArrayList<ViewEntry>> mSections = new ArrayList<ArrayList<ViewEntry>>();
130
131 private Cursor mCursor;
Evan Millar5c22c3b2009-05-29 11:37:54 -0700132
Evan Millar11d628c2009-09-02 08:55:01 -0700133 protected ContactHeaderWidget mContactHeaderWidget;
134 private NotifyingAsyncQueryHandler mHandler;
135
136 protected LayoutInflater mInflater;
137
Megha Joshid5afd8a2009-09-22 09:38:41 -0700138 protected int mReadOnlySourcesCnt;
139 protected int mWritableSourcesCnt;
140 protected ArrayList<Long> mWritableRawContactIds = new ArrayList<Long>();
Evan Millar11d628c2009-09-02 08:55:01 -0700141
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700142 private static final int TOKEN_ENTITIES = 0;
143 private static final int TOKEN_STATUSES = 1;
144
145 private boolean mHasEntities = false;
146 private boolean mHasStatuses = false;
147
148 private ArrayList<Entity> mEntities = Lists.newArrayList();
149 private HashMap<Long, DataStatus> mStatuses = Maps.newHashMap();
Evan Millar11d628c2009-09-02 08:55:01 -0700150
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800151 private ContentObserver mObserver = new ContentObserver(new Handler()) {
152 @Override
153 public boolean deliverSelfNotifications() {
154 return true;
155 }
156
157 @Override
158 public void onChange(boolean selfChange) {
Evan Millar11d628c2009-09-02 08:55:01 -0700159 if (mCursor != null && !mCursor.isClosed()) {
160 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800161 }
162 }
163 };
164
165 public void onClick(DialogInterface dialog, int which) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700166 closeCursor();
Megha Joshic508bd82009-10-01 17:31:49 -0700167 getContentResolver().delete(mLookupUri, null, null);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800168 finish();
169 }
170
Evan Millar7911ff52009-07-21 15:55:18 -0700171 private FrameLayout mTabContentLayout;
172 private ListView mListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800173 private boolean mShowSmsLinksForAllPhones;
174
175 @Override
176 protected void onCreate(Bundle icicle) {
177 super.onCreate(icicle);
178
Evan Millar11d628c2009-09-02 08:55:01 -0700179 final Intent intent = getIntent();
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -0700180 Uri data = intent.getData();
181 String authority = data.getAuthority();
182 if (ContactsContract.AUTHORITY.equals(authority)) {
183 mLookupUri = data;
184 } else if (android.provider.Contacts.AUTHORITY.equals(authority)) {
185 final long rawContactId = ContentUris.parseId(data);
186 mLookupUri = RawContacts.getContactLookupUri(getContentResolver(),
187 ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700188
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -0700189 }
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700190 mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Evan Millar11d628c2009-09-02 08:55:01 -0700191
192 requestWindowFeature(Window.FEATURE_NO_TITLE);
193 setContentView(R.layout.contact_card_layout);
194
195 mContactHeaderWidget = (ContactHeaderWidget) findViewById(R.id.contact_header_widget);
196 mContactHeaderWidget.showStar(true);
Evan Millar11d628c2009-09-02 08:55:01 -0700197 mContactHeaderWidget.setExcludeMimes(new String[] {
198 Contacts.CONTENT_ITEM_TYPE
199 });
200
Evan Millar11d628c2009-09-02 08:55:01 -0700201 mHandler = new NotifyingAsyncQueryHandler(this, this);
202
Evan Millar7911ff52009-07-21 15:55:18 -0700203 mListView = new ListView(this);
204 mListView.setOnCreateContextMenuListener(this);
205 mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
206 mListView.setOnItemClickListener(this);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800207
Evan Millar7911ff52009-07-21 15:55:18 -0700208 mTabContentLayout = (FrameLayout) findViewById(android.R.id.tabcontent);
209 mTabContentLayout.addView(mListView);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800210
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800211 mResolver = getContentResolver();
212
213 // Build the list of sections. The order they're added to mSections dictates the
214 // order they are displayed in the list.
215 mSections.add(mPhoneEntries);
216 mSections.add(mSmsEntries);
217 mSections.add(mEmailEntries);
218 mSections.add(mImEntries);
219 mSections.add(mPostalEntries);
220 mSections.add(mOrganizationEntries);
The Android Open Source Projectcac191e2009-03-18 22:20:27 -0700221 mSections.add(mGroupEntries);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800222 mSections.add(mOtherEntries);
223
224 //TODO Read this value from a preference
225 mShowSmsLinksForAllPhones = true;
Evan Millar11d628c2009-09-02 08:55:01 -0700226 }
227
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800228 @Override
229 protected void onResume() {
230 super.onResume();
Evan Millar11d628c2009-09-02 08:55:01 -0700231 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800232 }
233
234 @Override
235 protected void onPause() {
236 super.onPause();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700237 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800238 }
239
240 @Override
241 protected void onDestroy() {
242 super.onDestroy();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700243 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800244 }
245
246 @Override
247 protected Dialog onCreateDialog(int id) {
248 switch (id) {
249 case DIALOG_CONFIRM_DELETE:
250 return new AlertDialog.Builder(this)
251 .setTitle(R.string.deleteConfirmation_title)
252 .setIcon(android.R.drawable.ic_dialog_alert)
253 .setMessage(R.string.deleteConfirmation)
254 .setNegativeButton(android.R.string.cancel, null)
255 .setPositiveButton(android.R.string.ok, this)
256 .setCancelable(false)
257 .create();
Megha Joshid5afd8a2009-09-22 09:38:41 -0700258 case DIALOG_CONFIRM_READONLY_DELETE:
259 return new AlertDialog.Builder(this)
260 .setTitle(R.string.deleteConfirmation_title)
261 .setIcon(android.R.drawable.ic_dialog_alert)
262 .setMessage(R.string.readOnlyContactDeleteConfirmation)
263 .setNegativeButton(android.R.string.cancel, null)
264 .setPositiveButton(android.R.string.ok, this)
265 .setCancelable(false)
266 .create();
267 case DIALOG_CONFIRM_MULTIPLE_DELETE:
268 return new AlertDialog.Builder(this)
269 .setTitle(R.string.deleteConfirmation_title)
270 .setIcon(android.R.drawable.ic_dialog_alert)
271 .setMessage(R.string.multipleContactDeleteConfirmation)
272 .setNegativeButton(android.R.string.cancel, null)
273 .setPositiveButton(android.R.string.ok, this)
274 .setCancelable(false)
275 .create();
Megha Joshic508bd82009-10-01 17:31:49 -0700276 case DIALOG_CONFIRM_READONLY_HIDE: {
277 return new AlertDialog.Builder(this)
278 .setTitle(R.string.deleteConfirmation_title)
279 .setIcon(android.R.drawable.ic_dialog_alert)
280 .setMessage(R.string.readOnlyContactWarning)
281 .setPositiveButton(android.R.string.ok, this)
282 .create();
283 }
284
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800285 }
286 return null;
287 }
288
Evan Millar11d628c2009-09-02 08:55:01 -0700289 // QUERY CODE //
290 /** {@inheritDoc} */
291 public void onQueryEntitiesComplete(int token, Object cookie, EntityIterator iterator) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700292 try {
293 // Read incoming entities and consider binding
294 readEntities(iterator);
295 considerBindData();
Evan Millar11d628c2009-09-02 08:55:01 -0700296 } finally {
297 if (iterator != null) {
298 iterator.close();
299 }
300 }
301 }
302
303 /** {@inheritDoc} */
304 public void onQueryComplete(int token, Object cookie, Cursor cursor) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700305 try {
306 // Read available social rows and consider binding
307 readStatuses(cursor);
308 considerBindData();
309 } finally {
310 if (cursor != null) {
311 cursor.close();
312 }
313 }
Evan Millar11d628c2009-09-02 08:55:01 -0700314 }
315
Evan Millar6a61a1a2009-09-29 14:00:43 -0700316 private long getRefreshedContactId() {
317 Uri freshContactUri = Contacts.lookupContact(getContentResolver(), mLookupUri);
318 if (freshContactUri != null) {
319 return ContentUris.parseId(freshContactUri);
320 }
321 return -1;
322 }
323
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700324 /**
325 * Read from the given {@link EntityIterator} to build internal set of
326 * {@link #mEntities} for data display.
327 */
328 private synchronized void readEntities(EntityIterator iterator) {
329 mEntities.clear();
Evan Millar11d628c2009-09-02 08:55:01 -0700330 try {
331 while (iterator.hasNext()) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700332 mEntities.add(iterator.next());
Evan Millar11d628c2009-09-02 08:55:01 -0700333 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700334 mHasEntities = true;
Evan Millar11d628c2009-09-02 08:55:01 -0700335 } catch (RemoteException e) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700336 Log.w(TAG, "Problem reading contact data: " + e.toString());
Evan Millar11d628c2009-09-02 08:55:01 -0700337 }
Evan Millar11d628c2009-09-02 08:55:01 -0700338 }
339
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700340 /**
341 * Read from the given {@link Cursor} and build a set of {@link DataStatus}
342 * objects to match any valid statuses found.
343 */
344 private synchronized void readStatuses(Cursor cursor) {
345 mStatuses.clear();
346
347 // Walk found statuses, creating internal row for each
348 while (cursor.moveToNext()) {
349 final DataStatus status = new DataStatus(cursor);
350 final long dataId = cursor.getLong(StatusQuery._ID);
351 mStatuses.put(dataId, status);
352 }
353
354 mHasStatuses = true;
355 }
356
357 private synchronized void startEntityQuery() {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700358 closeCursor();
359
Evan Millar6a61a1a2009-09-29 14:00:43 -0700360 Uri uri = null;
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700361 if (mLookupUri != null) {
362 mLookupUri = Contacts.getLookupUri(getContentResolver(), mLookupUri);
363 if (mLookupUri != null) {
Evan Millar6a61a1a2009-09-29 14:00:43 -0700364 uri = Contacts.lookupContact(getContentResolver(), mLookupUri);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700365 }
366 }
367
Evan Millar6a61a1a2009-09-29 14:00:43 -0700368 if (uri == null) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700369
370 // TODO either figure out a way to prevent a flash of black background or
371 // use some other UI than a toast
372 Toast.makeText(this, R.string.invalidContactMessage, Toast.LENGTH_SHORT).show();
373 Log.e(TAG, "invalid contact uri: " + mLookupUri);
374 finish();
375 return;
376 }
377
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700378 final Uri dataUri = Uri.withAppendedPath(uri, Contacts.Data.CONTENT_DIRECTORY);
379
380 // Keep stub cursor open on side to watch for change events
381 mCursor = mResolver.query(dataUri,
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700382 new String[] {Contacts.DISPLAY_NAME}, null, null, null);
383 mCursor.registerContentObserver(mObserver);
384
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700385 final long contactId = ContentUris.parseId(uri);
386
387 // Clear flags and start queries to data and status
388 mHasEntities = false;
389 mHasStatuses = false;
390
391 mHandler.startQueryEntities(TOKEN_ENTITIES, null, RawContacts.CONTENT_URI,
392 RawContacts.CONTACT_ID + "=" + contactId, null, null);
393 mHandler.startQuery(TOKEN_STATUSES, null, dataUri, StatusQuery.PROJECTION,
394 StatusUpdates.PRESENCE + " IS NOT NULL OR " + StatusUpdates.STATUS
395 + " IS NOT NULL", null, null);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700396
Evan Millar9b1a1242009-09-16 10:26:10 -0700397 mContactHeaderWidget.bindFromContactLookupUri(mLookupUri);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700398 }
399
400 private void closeCursor() {
401 if (mCursor != null) {
402 mCursor.unregisterContentObserver(mObserver);
403 mCursor.close();
404 mCursor = null;
405 }
Evan Millar11d628c2009-09-02 08:55:01 -0700406 }
407
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700408 /**
409 * Consider binding views after any of several background queries has
410 * completed. We check internal flags and only bind when all data has
411 * arrived.
412 */
413 private void considerBindData() {
414 if (mHasEntities && mHasStatuses) {
415 bindData();
416 }
417 }
418
Evan Millar11d628c2009-09-02 08:55:01 -0700419 private void bindData() {
420
421 // Build up the contact entries
422 buildEntries();
423
424 // Collapse similar data items in select sections.
425 Collapser.collapseList(mPhoneEntries);
426 Collapser.collapseList(mSmsEntries);
427 Collapser.collapseList(mEmailEntries);
428 Collapser.collapseList(mPostalEntries);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700429 Collapser.collapseList(mImEntries);
Evan Millar11d628c2009-09-02 08:55:01 -0700430
431 if (mAdapter == null) {
432 mAdapter = new ViewAdapter(this, mSections);
433 mListView.setAdapter(mAdapter);
434 } else {
435 mAdapter.setSections(mSections, SHOW_SEPARATORS);
436 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800437 }
438
439 @Override
440 public boolean onCreateOptionsMenu(Menu menu) {
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700441 super.onCreateOptionsMenu(menu);
442
443 final MenuInflater inflater = getMenuInflater();
444 inflater.inflate(R.menu.view, menu);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800445 return true;
446 }
447
448 @Override
449 public boolean onPrepareOptionsMenu(Menu menu) {
450 super.onPrepareOptionsMenu(menu);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700451
Evan Millar51514db2009-09-22 11:42:35 -0700452 // Only allow edit when we have at least one raw_contact id
453 final boolean hasRawContact = (mRawContactIds.size() > 0);
Evan Millar2e1b8af2009-09-24 09:39:21 -0700454 menu.findItem(R.id.menu_edit).setEnabled(hasRawContact);
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700455
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800456 return true;
457 }
458
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800459 @Override
460 public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
461 AdapterView.AdapterContextMenuInfo info;
462 try {
463 info = (AdapterView.AdapterContextMenuInfo) menuInfo;
464 } catch (ClassCastException e) {
465 Log.e(TAG, "bad menuInfo", e);
466 return;
467 }
468
469 // This can be null sometimes, don't crash...
470 if (info == null) {
471 Log.e(TAG, "bad menuInfo");
472 return;
473 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700474
Evan Millar45e0ed32009-06-01 16:44:38 -0700475 ViewEntry entry = ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
Neel Parekha8fb68a2009-09-25 18:05:18 -0700476 menu.setHeaderTitle(R.string.contactOptionsTitle);
Evan Millar45e0ed32009-06-01 16:44:38 -0700477 if (entry.mimetype.equals(CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
478 menu.add(0, 0, 0, R.string.menu_call).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700479 menu.add(0, 0, 0, R.string.menu_sendSMS).setIntent(entry.secondaryIntent);
480 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700481 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultNumber);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800482 }
Evan Millar45e0ed32009-06-01 16:44:38 -0700483 } else if (entry.mimetype.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
484 menu.add(0, 0, 0, R.string.menu_sendEmail).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700485 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700486 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultEmail);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800487 }
Jeff Sharkeyc6ad3ab2009-07-21 19:30:15 -0700488 } else if (entry.mimetype.equals(CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700489 menu.add(0, 0, 0, R.string.menu_viewAddress).setIntent(entry.intent);
490 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800491 }
492
493 @Override
494 public boolean onOptionsItemSelected(MenuItem item) {
495 switch (item.getItemId()) {
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700496 case R.id.menu_edit: {
Evan Millardf181202009-09-30 15:15:51 -0700497 Long rawContactIdToEdit = null;
498 if (mRawContactIds.size() > 0) {
499 rawContactIdToEdit = mRawContactIds.get(0);
500 } else {
501 // There is no rawContact to edit.
502 break;
Evan Millardb5d88c2009-08-28 09:31:57 -0700503 }
Evan Millar2e1b8af2009-09-24 09:39:21 -0700504 Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI,
505 rawContactIdToEdit);
Evan Millar9cd81242009-09-26 16:02:31 -0700506 startActivityForResult(new Intent(Intent.ACTION_EDIT, rawContactUri),
507 REQUEST_EDIT_CONTACT);
Evan Millar8a79cee2009-08-19 17:20:49 -0700508 break;
509 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700510 case R.id.menu_delete: {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800511 // Get confirmation
Megha Joshid5afd8a2009-09-22 09:38:41 -0700512 if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) {
513 showDialog(DIALOG_CONFIRM_READONLY_DELETE);
Megha Joshic508bd82009-10-01 17:31:49 -0700514 } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
515 showDialog(DIALOG_CONFIRM_READONLY_HIDE);
516 } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
Megha Joshid5afd8a2009-09-22 09:38:41 -0700517 showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE);
518 } else {
519 showDialog(DIALOG_CONFIRM_DELETE);
520 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800521 return true;
522 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700523 case R.id.menu_join: {
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700524 showJoinAggregateActivity();
525 return true;
526 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700527 case R.id.menu_options: {
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700528 showOptionsActivity();
529 return true;
530 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700531 case R.id.menu_share: {
Jeff Sharkey93049312009-09-27 17:28:13 -0700532 // TODO: Keep around actual LOOKUP_KEY, or formalize method of extracting
533 final String lookupKey = mLookupUri.getPathSegments().get(2);
534 final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
535
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700536 final Intent intent = new Intent(Intent.ACTION_SEND);
Jeff Sharkey93049312009-09-27 17:28:13 -0700537 intent.setType(Contacts.CONTENT_VCARD_TYPE);
538 intent.putExtra(Intent.EXTRA_STREAM, shareUri);
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700539
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700540 // Launch chooser to share contact via
541 final CharSequence chooseTitle = getText(R.string.share_via);
542 final Intent chooseIntent = Intent.createChooser(intent, chooseTitle);
Evan Millar5c22c3b2009-05-29 11:37:54 -0700543
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700544 try {
545 startActivity(chooseIntent);
546 } catch (ActivityNotFoundException ex) {
547 Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800548 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700549 return true;
550 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800551 }
552 return super.onOptionsItemSelected(item);
553 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700554
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800555 @Override
556 public boolean onContextItemSelected(MenuItem item) {
557 switch (item.getItemId()) {
558 case MENU_ITEM_MAKE_DEFAULT: {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700559 if (makeItemDefault(item)) {
560 return true;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800561 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700562 break;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800563 }
564 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700565
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800566 return super.onContextItemSelected(item);
567 }
568
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700569 private boolean makeItemDefault(MenuItem item) {
570 ViewEntry entry = getViewEntryForMenuItem(item);
571 if (entry == null) {
572 return false;
573 }
574
575 // Update the primary values in the data record.
Evan Millar14fecb62009-09-09 09:23:12 -0700576 ContentValues values = new ContentValues(1);
Evan Millar54a5c9f2009-06-23 17:41:09 -0700577 values.put(Data.IS_SUPER_PRIMARY, 1);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700578 getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, entry.id),
579 values, null, null);
Evan Millar11d628c2009-09-02 08:55:01 -0700580 startEntityQuery();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700581 return true;
582 }
583
584 /**
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700585 * Shows a list of aggregates that can be joined into the currently viewed aggregate.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700586 */
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700587 public void showJoinAggregateActivity() {
Evan Millar6a61a1a2009-09-29 14:00:43 -0700588 long freshId = getRefreshedContactId();
589 if (freshId > 0) {
590 String displayName = null;
591 if (mCursor.moveToFirst()) {
592 displayName = mCursor.getString(0);
593 }
594 Intent intent = new Intent(ContactsListActivity.JOIN_AGGREGATE);
595 intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_ID, freshId);
596 if (displayName != null) {
597 intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_NAME, displayName);
598 }
599 startActivityForResult(intent, REQUEST_JOIN_CONTACT);
Dmitri Plotnikova5cfca32009-09-29 18:13:08 -0700600 }
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700601 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700602
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700603 @Override
604 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
Evan Millar2e1b8af2009-09-24 09:39:21 -0700605 if (requestCode == REQUEST_JOIN_CONTACT) {
606 if (resultCode == RESULT_OK && intent != null) {
607 final long contactId = ContentUris.parseId(intent.getData());
608 joinAggregate(contactId);
Evan Millar8a79cee2009-08-19 17:20:49 -0700609 }
Evan Millar9cd81242009-09-26 16:02:31 -0700610 } else if (requestCode == REQUEST_EDIT_CONTACT) {
Evan Millardf181202009-09-30 15:15:51 -0700611 if (resultCode == EditContactActivity.RESULT_CLOSE_VIEW_ACTIVITY) {
612 finish();
Jeff Hamilton5297c6a2009-10-01 02:22:33 -0700613 } else if (resultCode == Activity.RESULT_OK) {
Dmitri Plotnikov160e9da2009-09-30 23:48:12 -0700614 mLookupUri = intent.getData();
615 if (mLookupUri == null) {
616 finish();
617 }
Evan Millardf181202009-09-30 15:15:51 -0700618 }
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700619 }
620 }
621
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700622 private void splitContact(long rawContactId) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700623 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_SEPARATE);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700624
625 // The split operation may have removed the original aggregate contact, so we need
626 // to requery everything
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700627 Toast.makeText(this, R.string.contactsSplitMessage, Toast.LENGTH_LONG).show();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700628 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700629 }
630
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700631 private void joinAggregate(final long contactId) {
Dmitri Plotnikov39466592009-07-27 11:23:51 -0700632 Cursor c = mResolver.query(RawContacts.CONTENT_URI, new String[] {RawContacts._ID},
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700633 RawContacts.CONTACT_ID + "=" + contactId, null, null);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700634
635 try {
636 while(c.moveToNext()) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700637 long rawContactId = c.getLong(0);
638 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_TOGETHER);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700639 }
640 } finally {
641 c.close();
642 }
643
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700644 Toast.makeText(this, R.string.contactsJoinedMessage, Toast.LENGTH_LONG).show();
645 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700646 }
647
648 /**
649 * Given a contact ID sets an aggregation exception to either join the contact with the
650 * current aggregate or split off.
651 */
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700652 protected void setAggregationException(long rawContactId, int exceptionType) {
Dmitri Plotnikovd09f75c2009-06-16 11:59:22 -0700653 ContentValues values = new ContentValues(3);
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700654 for (long aRawContactId : mRawContactIds) {
655 if (aRawContactId != rawContactId) {
656 values.put(AggregationExceptions.RAW_CONTACT_ID1, aRawContactId);
657 values.put(AggregationExceptions.RAW_CONTACT_ID2, rawContactId);
658 values.put(AggregationExceptions.TYPE, exceptionType);
659 mResolver.update(AggregationExceptions.CONTENT_URI, values, null, null);
660 }
661 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700662 }
663
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700664 private void showOptionsActivity() {
665 final Intent intent = new Intent(this, ContactOptionsActivity.class);
Evan Millar6a61a1a2009-09-29 14:00:43 -0700666 intent.setData(mLookupUri);
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700667 startActivity(intent);
668 }
669
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700670 private ViewEntry getViewEntryForMenuItem(MenuItem item) {
671 AdapterView.AdapterContextMenuInfo info;
672 try {
673 info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
674 } catch (ClassCastException e) {
675 Log.e(TAG, "bad menuInfo", e);
676 return null;
677 }
678
679 return ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
680 }
681
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800682 @Override
683 public boolean onKeyDown(int keyCode, KeyEvent event) {
684 switch (keyCode) {
685 case KeyEvent.KEYCODE_CALL: {
686 try {
687 ITelephony phone = ITelephony.Stub.asInterface(
688 ServiceManager.checkService("phone"));
689 if (phone != null && !phone.isIdle()) {
690 // Skip out and let the key be handled at a higher level
691 break;
692 }
693 } catch (RemoteException re) {
694 // Fall through and try to call the contact
695 }
696
Evan Millar7911ff52009-07-21 15:55:18 -0700697 int index = mListView.getSelectedItemPosition();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800698 if (index != -1) {
699 ViewEntry entry = ViewAdapter.getEntry(mSections, index, SHOW_SEPARATORS);
Evan Millar66388be2009-05-28 15:41:07 -0700700 if (entry.intent.getAction() == Intent.ACTION_CALL_PRIVILEGED) {
701 startActivity(entry.intent);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800702 }
703 } else if (mNumPhoneNumbers != 0) {
704 // There isn't anything selected, call the default number
Evan Millar6a61a1a2009-09-29 14:00:43 -0700705 long freshContactId = getRefreshedContactId();
706 if (freshContactId > 0) {
707 Uri hardContacUri = ContentUris.withAppendedId(
708 Contacts.CONTENT_URI, freshContactId);
709 Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, hardContacUri);
710 startActivity(intent);
711 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800712 }
713 return true;
714 }
715
716 case KeyEvent.KEYCODE_DEL: {
Megha Joshid5afd8a2009-09-22 09:38:41 -0700717 if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) {
718 showDialog(DIALOG_CONFIRM_READONLY_DELETE);
Megha Joshic508bd82009-10-01 17:31:49 -0700719 } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
720 showDialog(DIALOG_CONFIRM_READONLY_HIDE);
721 } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
Megha Joshid5afd8a2009-09-22 09:38:41 -0700722 showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE);
723 } else {
724 showDialog(DIALOG_CONFIRM_DELETE);
725 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800726 return true;
727 }
728 }
729
730 return super.onKeyDown(keyCode, event);
731 }
732
Evan Millar7911ff52009-07-21 15:55:18 -0700733 public void onItemClick(AdapterView parent, View v, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800734 ViewEntry entry = ViewAdapter.getEntry(mSections, position, SHOW_SEPARATORS);
735 if (entry != null) {
736 Intent intent = entry.intent;
Evan Millardf181202009-09-30 15:15:51 -0700737 if (intent != null) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800738 try {
739 startActivity(intent);
740 } catch (ActivityNotFoundException e) {
741 Log.e(TAG, "No activity found for intent: " + intent);
742 signalError();
743 }
744 } else {
745 signalError();
746 }
747 } else {
748 signalError();
749 }
750 }
751
752 /**
753 * Signal an error to the user via a beep, or some other method.
754 */
755 private void signalError() {
756 //TODO: implement this when we have the sonification APIs
757 }
758
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800759 /**
760 * Build up the entries to display on the screen.
Evan Millar5c22c3b2009-05-29 11:37:54 -0700761 *
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800762 * @param personCursor the URI for the contact being displayed
763 */
Evan Millar11d628c2009-09-02 08:55:01 -0700764 private final void buildEntries() {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800765 // Clear out the old entries
766 final int numSections = mSections.size();
767 for (int i = 0; i < numSections; i++) {
768 mSections.get(i).clear();
769 }
770
Evan Millar7911ff52009-07-21 15:55:18 -0700771 mRawContactIds.clear();
Megha Joshid5afd8a2009-09-22 09:38:41 -0700772 mReadOnlySourcesCnt = 0;
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700773 mWritableSourcesCnt = 0;
Megha Joshid5afd8a2009-09-22 09:38:41 -0700774 mWritableRawContactIds.clear();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700775
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700776 final Context context = this;
777 final Sources sources = Sources.getInstance(context);
Evan Millar11d628c2009-09-02 08:55:01 -0700778
Evan Millar66388be2009-05-28 15:41:07 -0700779 // Build up method entries
Evan Millar6a61a1a2009-09-29 14:00:43 -0700780 if (mLookupUri != null) {
Evan Millar11d628c2009-09-02 08:55:01 -0700781 for (Entity entity: mEntities) {
782 final ContentValues entValues = entity.getEntityValues();
783 final String accountType = entValues.getAsString(RawContacts.ACCOUNT_TYPE);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700784 final long rawContactId = entValues.getAsLong(RawContacts._ID);
Evan Millar7911ff52009-07-21 15:55:18 -0700785
Dmitri Plotnikov2a8cef02009-09-23 19:01:15 -0700786 if (!mRawContactIds.contains(rawContactId)) {
787 mRawContactIds.add(rawContactId);
788 }
Megha Joshic508bd82009-10-01 17:31:49 -0700789 ContactsSource contactsSource = sources.getInflatedSource(accountType,
790 ContactsSource.LEVEL_SUMMARY);
791 if (contactsSource != null && contactsSource.readOnly) {
792 mReadOnlySourcesCnt += 1;
793 } else {
794 mWritableSourcesCnt += 1;
795 mWritableRawContactIds.add(rawContactId);
796 }
797
Dmitri Plotnikov2a8cef02009-09-23 19:01:15 -0700798
Evan Millar11d628c2009-09-02 08:55:01 -0700799 for (NamedContentValues subValue : entity.getSubValues()) {
Jeff Sharkeyab066932009-09-21 09:55:30 -0700800 final ContentValues entryValues = subValue.values;
801 entryValues.put(Data.RAW_CONTACT_ID, rawContactId);
802
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700803 final long dataId = entryValues.getAsLong(Data._ID);
804 final String mimeType = entryValues.getAsString(Data.MIMETYPE);
805 if (mimeType == null) continue;
Evan Millar66388be2009-05-28 15:41:07 -0700806
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700807 final DataKind kind = sources.getKindOrFallback(accountType, mimeType, this,
Evan Millar11d628c2009-09-02 08:55:01 -0700808 ContactsSource.LEVEL_MIMETYPES);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700809 if (kind == null) continue;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800810
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700811 final ViewEntry entry = ViewEntry.fromValues(context, mimeType, kind,
812 rawContactId, dataId, entryValues);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800813
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700814 final boolean hasData = !TextUtils.isEmpty(entry.data);
Evan Millarff04a272009-09-26 15:23:37 -0700815 final boolean isSuperPrimary = entryValues.getAsInteger(
816 Data.IS_SUPER_PRIMARY) != 0;
Evan Millar11d628c2009-09-02 08:55:01 -0700817
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700818 if (Phone.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700819 // Build phone entries
820 mNumPhoneNumbers++;
Evan Millar11d628c2009-09-02 08:55:01 -0700821
Evan Millarff04a272009-09-26 15:23:37 -0700822 entry.intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700823 Uri.fromParts(Constants.SCHEME_TEL, entry.data, null));
Evan Millarff04a272009-09-26 15:23:37 -0700824 entry.secondaryIntent = new Intent(Intent.ACTION_SENDTO,
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700825 Uri.fromParts(Constants.SCHEME_SMSTO, entry.data, null));
Evan Millarff04a272009-09-26 15:23:37 -0700826 entry.data = PhoneNumberUtils.stripSeparators(entry.data);
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);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700885 } else {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700886 // Handle showing custom rows
Evan Millarff04a272009-09-26 15:23:37 -0700887 entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700888
889 // Use social summary when requested by external source
890 final DataStatus status = mStatuses.get(entry.id);
891 final boolean hasSocial = kind.actionBodySocial && status != null;
892 if (hasSocial) {
893 entry.applyStatus(status, true);
894 }
895
896 if (hasSocial || hasData) {
897 mOtherEntries.add(entry);
898 }
Evan Millar11d628c2009-09-02 08:55:01 -0700899 }
Evan Millar2e1b8af2009-09-24 09:39:21 -0700900 }
Evan Millar66388be2009-05-28 15:41:07 -0700901 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800902 }
903 }
904
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700905 static String buildActionString(DataKind kind, ContentValues values, boolean lowerCase,
906 Context context) {
Evan Millar11d628c2009-09-02 08:55:01 -0700907 if (kind.actionHeader == null) {
908 return null;
Jeff Hamilton8350e5b2009-03-24 21:01:34 -0700909 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700910 CharSequence actionHeader = kind.actionHeader.inflateUsing(context, values);
Evan Millar11d628c2009-09-02 08:55:01 -0700911 if (actionHeader == null) {
912 return null;
913 }
914 return lowerCase ? actionHeader.toString().toLowerCase() : actionHeader.toString();
915 }
Jeff Hamilton8350e5b2009-03-24 21:01:34 -0700916
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700917 static String buildDataString(DataKind kind, ContentValues values, Context context) {
Evan Millar11d628c2009-09-02 08:55:01 -0700918 if (kind.actionBody == null) {
919 return null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800920 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700921 CharSequence actionBody = kind.actionBody.inflateUsing(context, values);
Evan Millar11d628c2009-09-02 08:55:01 -0700922 return actionBody == null ? null : actionBody.toString();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800923 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700924
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800925 /**
926 * A basic structure with the data for a contact entry in the list.
927 */
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700928 static class ViewEntry extends ContactEntryAdapter.Entry implements Collapsible<ViewEntry> {
929 public Context context = null;
Jeff Sharkeyab066932009-09-21 09:55:30 -0700930 public String resPackageName = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800931 public int actionIcon = -1;
Evan Millar15e514d2009-08-04 10:14:57 -0700932 public boolean isPrimary = false;
Evan Millar15e514d2009-08-04 10:14:57 -0700933 public int secondaryActionIcon = -1;
934 public Intent intent;
935 public Intent secondaryIntent = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800936 public int maxLabelLines = 1;
Evan Millar54a5c9f2009-06-23 17:41:09 -0700937 public ArrayList<Long> ids = new ArrayList<Long>();
938 public int collapseCount = 0;
939
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700940 public int presence = -1;
941 public int presenceIcon = -1;
942
943 public CharSequence footerLine = null;
944
945 private ViewEntry() {
946 }
947
948 /**
949 * Build new {@link ViewEntry} and populate from the given values.
950 */
951 public static ViewEntry fromValues(Context context, String mimeType, DataKind kind,
952 long rawContactId, long dataId, ContentValues values) {
953 final ViewEntry entry = new ViewEntry();
954 entry.context = context;
955 entry.contactId = rawContactId;
956 entry.id = dataId;
957 entry.uri = ContentUris.withAppendedId(Data.CONTENT_URI, entry.id);
958 entry.mimetype = mimeType;
959 entry.label = buildActionString(kind, values, false, context);
960 entry.data = buildDataString(kind, values, context);
961
962 if (kind.typeColumn != null && values.containsKey(kind.typeColumn)) {
963 entry.type = values.getAsInteger(kind.typeColumn);
964 }
965 if (kind.iconRes > 0) {
966 entry.resPackageName = kind.resPackageName;
967 entry.actionIcon = kind.iconRes;
968 }
969
970 return entry;
971 }
972
973 /**
974 * Apply given {@link DataStatus} values over this {@link ViewEntry}
975 *
976 * @param fillData When true, the given status replaces {@link #data}
977 * and {@link #footerLine}. Otherwise only {@link #presence}
978 * is updated.
979 */
980 public ViewEntry applyStatus(DataStatus status, boolean fillData) {
981 presence = status.getPresence();
982 presenceIcon = (presence == -1) ? -1 :
983 StatusUpdates.getPresenceIconResourceId(this.presence);
984
985 if (fillData && status.isValid()) {
986 this.data = status.getStatus().toString();
987 this.footerLine = status.getTimestampLabel(context);
988 }
989
990 return this;
991 }
992
Evan Millar54a5c9f2009-06-23 17:41:09 -0700993 public boolean collapseWith(ViewEntry entry) {
994 // assert equal collapse keys
Evan Millaradb0f8c2009-09-28 17:20:50 -0700995 if (!shouldCollapseWith(entry)) {
Evan Millar54a5c9f2009-06-23 17:41:09 -0700996 return false;
997 }
998
999 // Choose the label associated with the highest type precedence.
1000 if (TypePrecedence.getTypePrecedence(mimetype, type)
1001 > TypePrecedence.getTypePrecedence(entry.mimetype, entry.type)) {
1002 type = entry.type;
1003 label = entry.label;
1004 }
1005
1006 // Choose the max of the maxLines and maxLabelLines values.
1007 maxLines = Math.max(maxLines, entry.maxLines);
1008 maxLabelLines = Math.max(maxLabelLines, entry.maxLabelLines);
1009
1010 // Choose the presence with the highest precedence.
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001011 if (StatusUpdates.getPresencePrecedence(presence)
1012 < StatusUpdates.getPresencePrecedence(entry.presence)) {
1013 presence = entry.presence;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001014 }
1015
1016 // If any of the collapsed entries are primary make the whole thing primary.
Evan Millar15e514d2009-08-04 10:14:57 -07001017 isPrimary = entry.isPrimary ? true : isPrimary;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001018
1019 // uri, and contactdId, shouldn't make a difference. Just keep the original.
1020
1021 // Keep track of all the ids that have been collapsed with this one.
1022 ids.add(entry.id);
1023 collapseCount++;
1024 return true;
1025 }
1026
Evan Millaradb0f8c2009-09-28 17:20:50 -07001027 public boolean shouldCollapseWith(ViewEntry entry) {
1028 if (entry == null) {
1029 return false;
1030 }
1031
1032 if (Phone.CONTENT_ITEM_TYPE.equals(mimetype)
1033 && Phone.CONTENT_ITEM_TYPE.equals(entry.mimetype)) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001034 if (!PhoneNumberUtils.compare(this.context, data, entry.data)) {
Evan Millaradb0f8c2009-09-28 17:20:50 -07001035 return false;
1036 }
1037 } else {
1038 if (!equals(data, entry.data)) {
1039 return false;
1040 }
1041 }
1042
1043 if (!equals(mimetype, entry.mimetype)
1044 || !intentCollapsible(intent, entry.intent)
1045 || !intentCollapsible(secondaryIntent, entry.secondaryIntent)
1046 || actionIcon != entry.actionIcon) {
1047 return false;
1048 }
1049
1050 return true;
1051 }
1052
1053 private boolean equals(Object a, Object b) {
1054 return a==b || (a != null && a.equals(b));
1055 }
1056
1057 private boolean intentCollapsible(Intent a, Intent b) {
1058 if (a == b) {
1059 return true;
1060 } else if ((a != null && b != null) && equals(a.getAction(), b.getAction())) {
1061 return true;
1062 }
1063 return false;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001064 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001065 }
1066
Evan Millar15e514d2009-08-04 10:14:57 -07001067 /** Cache of the children views of a row */
1068 static class ViewCache {
1069 public TextView label;
1070 public TextView data;
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001071 public TextView footer;
Evan Millar15e514d2009-08-04 10:14:57 -07001072 public ImageView actionIcon;
1073 public ImageView presenceIcon;
1074 public ImageView primaryIcon;
1075 public ImageView secondaryActionButton;
1076 public View secondaryActionDivider;
Evan Millar5c22c3b2009-05-29 11:37:54 -07001077
Evan Millar15e514d2009-08-04 10:14:57 -07001078 // Need to keep track of this too
1079 ViewEntry entry;
1080 }
1081
1082 private final class ViewAdapter extends ContactEntryAdapter<ViewEntry>
1083 implements View.OnClickListener {
1084
Evan Millar5c22c3b2009-05-29 11:37:54 -07001085
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001086 ViewAdapter(Context context, ArrayList<ArrayList<ViewEntry>> sections) {
1087 super(context, sections, SHOW_SEPARATORS);
1088 }
1089
Evan Millar15e514d2009-08-04 10:14:57 -07001090 public void onClick(View v) {
1091 Intent intent = (Intent) v.getTag();
1092 startActivity(intent);
1093 }
1094
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001095 @Override
1096 public View getView(int position, View convertView, ViewGroup parent) {
Evan Millar5c22c3b2009-05-29 11:37:54 -07001097 ViewEntry entry = getEntry(mSections, position, false);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001098 View v;
1099
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001100 ViewCache views;
1101
1102 // Check to see if we can reuse convertView
1103 if (convertView != null) {
1104 v = convertView;
1105 views = (ViewCache) v.getTag();
1106 } else {
1107 // Create a new view if needed
1108 v = mInflater.inflate(R.layout.list_item_text_icons, parent, false);
1109
1110 // Cache the children
1111 views = new ViewCache();
1112 views.label = (TextView) v.findViewById(android.R.id.text1);
1113 views.data = (TextView) v.findViewById(android.R.id.text2);
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001114 views.footer = (TextView) v.findViewById(R.id.footer);
Evan Millar15e514d2009-08-04 10:14:57 -07001115 views.actionIcon = (ImageView) v.findViewById(R.id.action_icon);
1116 views.primaryIcon = (ImageView) v.findViewById(R.id.primary_icon);
1117 views.presenceIcon = (ImageView) v.findViewById(R.id.presence_icon);
1118 views.secondaryActionButton = (ImageView) v.findViewById(
1119 R.id.secondary_action_button);
1120 views.secondaryActionButton.setOnClickListener(this);
Evan Millar15e514d2009-08-04 10:14:57 -07001121 views.secondaryActionDivider = v.findViewById(R.id.divider);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001122 v.setTag(views);
1123 }
1124
1125 // Update the entry in the view cache
1126 views.entry = entry;
1127
1128 // Bind the data to the view
1129 bindView(v, entry);
1130 return v;
1131 }
1132
1133 @Override
1134 protected View newView(int position, ViewGroup parent) {
1135 // getView() handles this
1136 throw new UnsupportedOperationException();
1137 }
1138
1139 @Override
1140 protected void bindView(View view, ViewEntry entry) {
1141 final Resources resources = mContext.getResources();
1142 ViewCache views = (ViewCache) view.getTag();
1143
1144 // Set the label
1145 TextView label = views.label;
1146 setMaxLines(label, entry.maxLabelLines);
1147 label.setText(entry.label);
1148
1149 // Set the data
1150 TextView data = views.data;
1151 if (data != null) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001152 if (entry.mimetype.equals(Phone.CONTENT_ITEM_TYPE)
Jeff Sharkey49d17b32009-09-07 02:14:21 -07001153 || entry.mimetype.equals(Constants.MIME_SMS_ADDRESS)) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001154 data.setText(PhoneNumberUtils.formatNumber(entry.data));
1155 } else {
1156 data.setText(entry.data);
1157 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001158 setMaxLines(data, entry.maxLines);
1159 }
1160
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001161 // Set the footer
1162 if (!TextUtils.isEmpty(entry.footerLine)) {
1163 views.footer.setText(entry.footerLine);
1164 views.footer.setVisibility(View.VISIBLE);
1165 } else {
1166 views.footer.setVisibility(View.GONE);
1167 }
1168
Evan Millar15e514d2009-08-04 10:14:57 -07001169 // Set the primary icon
1170 views.primaryIcon.setVisibility(entry.isPrimary ? View.VISIBLE : View.GONE);
1171
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001172 // Set the action icon
1173 ImageView action = views.actionIcon;
1174 if (entry.actionIcon != -1) {
Jeff Sharkeyab066932009-09-21 09:55:30 -07001175 Drawable actionIcon;
1176 if (entry.resPackageName != null) {
1177 // Load external resources through PackageManager
1178 actionIcon = mContext.getPackageManager().getDrawable(entry.resPackageName,
1179 entry.actionIcon, null);
1180 } else {
1181 actionIcon = resources.getDrawable(entry.actionIcon);
1182 }
1183 action.setImageDrawable(actionIcon);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001184 action.setVisibility(View.VISIBLE);
1185 } else {
1186 // Things should still line up as if there was an icon, so make it invisible
1187 action.setVisibility(View.INVISIBLE);
1188 }
1189
1190 // Set the presence icon
1191 Drawable presenceIcon = null;
Evan Millar15e514d2009-08-04 10:14:57 -07001192 if (entry.presenceIcon != -1) {
1193 presenceIcon = resources.getDrawable(entry.presenceIcon);
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001194 } else if (entry.presence != -1) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001195 presenceIcon = resources.getDrawable(
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001196 StatusUpdates.getPresenceIconResourceId(entry.presence));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001197 }
Evan Millar15e514d2009-08-04 10:14:57 -07001198 ImageView presenceIconView = views.presenceIcon;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001199 if (presenceIcon != null) {
Evan Millar15e514d2009-08-04 10:14:57 -07001200 presenceIconView.setImageDrawable(presenceIcon);
1201 presenceIconView.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001202 } else {
Evan Millar15e514d2009-08-04 10:14:57 -07001203 presenceIconView.setVisibility(View.GONE);
1204 }
1205
1206 // Set the secondary action button
1207 ImageView secondaryActionView = views.secondaryActionButton;
1208 Drawable secondaryActionIcon = null;
1209 if (entry.secondaryActionIcon != -1) {
1210 secondaryActionIcon = resources.getDrawable(entry.secondaryActionIcon);
1211 }
1212 if (entry.secondaryIntent != null && secondaryActionIcon != null) {
1213 secondaryActionView.setImageDrawable(secondaryActionIcon);
1214 secondaryActionView.setTag(entry.secondaryIntent);
1215 secondaryActionView.setVisibility(View.VISIBLE);
1216 views.secondaryActionDivider.setVisibility(View.VISIBLE);
1217 } else {
1218 secondaryActionView.setVisibility(View.GONE);
1219 views.secondaryActionDivider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001220 }
1221 }
1222
1223 private void setMaxLines(TextView textView, int maxLines) {
1224 if (maxLines == 1) {
1225 textView.setSingleLine(true);
1226 textView.setEllipsize(TextUtils.TruncateAt.END);
1227 } else {
1228 textView.setSingleLine(false);
1229 textView.setMaxLines(maxLines);
1230 textView.setEllipsize(null);
1231 }
1232 }
1233 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001234
1235 private interface StatusQuery {
1236 final String[] PROJECTION = new String[] {
1237 Data._ID,
1238 Data.STATUS,
1239 Data.STATUS_RES_PACKAGE,
1240 Data.STATUS_ICON,
1241 Data.STATUS_LABEL,
1242 Data.STATUS_TIMESTAMP,
1243 Data.PRESENCE,
1244 };
1245
1246 final int _ID = 0;
1247 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001248}