blob: ca3c08a4f010e9f6d7623c5eeda5f216f141d198 [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;
Evan Millarcdeea942009-10-07 11:47:35 -070085import android.widget.ScrollView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080086import android.widget.TextView;
87import android.widget.Toast;
88
89import java.util.ArrayList;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070090import java.util.HashMap;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080091
92/**
93 * Displays the details of a specific contact.
94 */
Evan Millar11d628c2009-09-02 08:55:01 -070095public class ViewContactActivity extends Activity
Evan Millar7911ff52009-07-21 15:55:18 -070096 implements View.OnCreateContextMenuListener, DialogInterface.OnClickListener,
Evan Millardf181202009-09-30 15:15:51 -070097 AdapterView.OnItemClickListener, NotifyingAsyncQueryHandler.AsyncQueryListener {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080098 private static final String TAG = "ViewContact";
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080099
100 private static final boolean SHOW_SEPARATORS = false;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800101
102 private static final int DIALOG_CONFIRM_DELETE = 1;
Megha Joshid5afd8a2009-09-22 09:38:41 -0700103 private static final int DIALOG_CONFIRM_READONLY_DELETE = 2;
104 private static final int DIALOG_CONFIRM_MULTIPLE_DELETE = 3;
Megha Joshic508bd82009-10-01 17:31:49 -0700105 private static final int DIALOG_CONFIRM_READONLY_HIDE = 4;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800106
Evan Millar8a79cee2009-08-19 17:20:49 -0700107 private static final int REQUEST_JOIN_CONTACT = 1;
Evan Millar9cd81242009-09-26 16:02:31 -0700108 private static final int REQUEST_EDIT_CONTACT = 2;
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700109
Evan Millar8a79cee2009-08-19 17:20:49 -0700110 public static final int MENU_ITEM_MAKE_DEFAULT = 3;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800111
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700112 protected Uri mLookupUri;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800113 private ContentResolver mResolver;
114 private ViewAdapter mAdapter;
115 private int mNumPhoneNumbers = 0;
116
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700117 /**
Dmitri Plotnikove1cd6792009-07-27 20:28:17 -0700118 * A list of distinct contact IDs included in the current contact.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700119 */
Evan Millar7911ff52009-07-21 15:55:18 -0700120 private ArrayList<Long> mRawContactIds = new ArrayList<Long>();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700121
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800122 /* package */ ArrayList<ViewEntry> mPhoneEntries = new ArrayList<ViewEntry>();
123 /* package */ ArrayList<ViewEntry> mSmsEntries = new ArrayList<ViewEntry>();
124 /* package */ ArrayList<ViewEntry> mEmailEntries = new ArrayList<ViewEntry>();
125 /* package */ ArrayList<ViewEntry> mPostalEntries = new ArrayList<ViewEntry>();
126 /* package */ ArrayList<ViewEntry> mImEntries = new ArrayList<ViewEntry>();
127 /* package */ ArrayList<ViewEntry> mOrganizationEntries = new ArrayList<ViewEntry>();
The Android Open Source Projectcac191e2009-03-18 22:20:27 -0700128 /* package */ ArrayList<ViewEntry> mGroupEntries = new ArrayList<ViewEntry>();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800129 /* package */ ArrayList<ViewEntry> mOtherEntries = new ArrayList<ViewEntry>();
130 /* package */ ArrayList<ArrayList<ViewEntry>> mSections = new ArrayList<ArrayList<ViewEntry>>();
131
132 private Cursor mCursor;
Evan Millar5c22c3b2009-05-29 11:37:54 -0700133
Evan Millar11d628c2009-09-02 08:55:01 -0700134 protected ContactHeaderWidget mContactHeaderWidget;
135 private NotifyingAsyncQueryHandler mHandler;
136
137 protected LayoutInflater mInflater;
138
Megha Joshid5afd8a2009-09-22 09:38:41 -0700139 protected int mReadOnlySourcesCnt;
140 protected int mWritableSourcesCnt;
Jeff Sharkeye0408762009-11-03 12:57:16 -0800141 protected boolean mAllRestricted;
142
Megha Joshid5afd8a2009-09-22 09:38:41 -0700143 protected ArrayList<Long> mWritableRawContactIds = new ArrayList<Long>();
Evan Millar11d628c2009-09-02 08:55:01 -0700144
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700145 private static final int TOKEN_ENTITIES = 0;
146 private static final int TOKEN_STATUSES = 1;
147
148 private boolean mHasEntities = false;
149 private boolean mHasStatuses = false;
150
151 private ArrayList<Entity> mEntities = Lists.newArrayList();
152 private HashMap<Long, DataStatus> mStatuses = Maps.newHashMap();
Evan Millar11d628c2009-09-02 08:55:01 -0700153
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800154 private ContentObserver mObserver = new ContentObserver(new Handler()) {
155 @Override
156 public boolean deliverSelfNotifications() {
157 return true;
158 }
159
160 @Override
161 public void onChange(boolean selfChange) {
Evan Millar11d628c2009-09-02 08:55:01 -0700162 if (mCursor != null && !mCursor.isClosed()) {
163 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800164 }
165 }
166 };
167
168 public void onClick(DialogInterface dialog, int which) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700169 closeCursor();
Megha Joshic508bd82009-10-01 17:31:49 -0700170 getContentResolver().delete(mLookupUri, null, null);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800171 finish();
172 }
173
Evan Millar7911ff52009-07-21 15:55:18 -0700174 private ListView mListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800175 private boolean mShowSmsLinksForAllPhones;
176
177 @Override
178 protected void onCreate(Bundle icicle) {
179 super.onCreate(icicle);
180
Evan Millar11d628c2009-09-02 08:55:01 -0700181 final Intent intent = getIntent();
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -0700182 Uri data = intent.getData();
183 String authority = data.getAuthority();
184 if (ContactsContract.AUTHORITY.equals(authority)) {
185 mLookupUri = data;
186 } else if (android.provider.Contacts.AUTHORITY.equals(authority)) {
187 final long rawContactId = ContentUris.parseId(data);
188 mLookupUri = RawContacts.getContactLookupUri(getContentResolver(),
189 ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700190
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -0700191 }
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700192 mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Evan Millar11d628c2009-09-02 08:55:01 -0700193
194 requestWindowFeature(Window.FEATURE_NO_TITLE);
195 setContentView(R.layout.contact_card_layout);
196
197 mContactHeaderWidget = (ContactHeaderWidget) findViewById(R.id.contact_header_widget);
198 mContactHeaderWidget.showStar(true);
Evan Millar11d628c2009-09-02 08:55:01 -0700199 mContactHeaderWidget.setExcludeMimes(new String[] {
200 Contacts.CONTENT_ITEM_TYPE
201 });
202
Evan Millar11d628c2009-09-02 08:55:01 -0700203 mHandler = new NotifyingAsyncQueryHandler(this, this);
204
Evan Millarcdeea942009-10-07 11:47:35 -0700205 mListView = (ListView) findViewById(R.id.contact_data);
Evan Millar7911ff52009-07-21 15:55:18 -0700206 mListView.setOnCreateContextMenuListener(this);
207 mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
208 mListView.setOnItemClickListener(this);
Evan Millarcdeea942009-10-07 11:47:35 -0700209 mListView.setEmptyView((ScrollView) findViewById(android.R.id.empty));
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();
Evan Millarcdeea942009-10-07 11:47:35 -0700276 case DIALOG_CONFIRM_READONLY_HIDE: {
Megha Joshic508bd82009-10-01 17:31:49 -0700277 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)
Evan Millarcdeea942009-10-07 11:47:35 -0700282 .create();
Megha Joshic508bd82009-10-01 17:31:49 -0700283 }
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
Jeff Sharkeye0408762009-11-03 12:57:16 -0800456 // Only allow share when unrestricted contacts available
457 menu.findItem(R.id.menu_share).setEnabled(!mAllRestricted);
458
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800459 return true;
460 }
461
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800462 @Override
463 public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
464 AdapterView.AdapterContextMenuInfo info;
465 try {
466 info = (AdapterView.AdapterContextMenuInfo) menuInfo;
467 } catch (ClassCastException e) {
468 Log.e(TAG, "bad menuInfo", e);
469 return;
470 }
471
472 // This can be null sometimes, don't crash...
473 if (info == null) {
474 Log.e(TAG, "bad menuInfo");
475 return;
476 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700477
Evan Millar45e0ed32009-06-01 16:44:38 -0700478 ViewEntry entry = ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
Neel Parekha8fb68a2009-09-25 18:05:18 -0700479 menu.setHeaderTitle(R.string.contactOptionsTitle);
Evan Millar45e0ed32009-06-01 16:44:38 -0700480 if (entry.mimetype.equals(CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
481 menu.add(0, 0, 0, R.string.menu_call).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700482 menu.add(0, 0, 0, R.string.menu_sendSMS).setIntent(entry.secondaryIntent);
483 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700484 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultNumber);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800485 }
Evan Millar45e0ed32009-06-01 16:44:38 -0700486 } else if (entry.mimetype.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
487 menu.add(0, 0, 0, R.string.menu_sendEmail).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700488 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700489 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultEmail);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800490 }
Jeff Sharkeyc6ad3ab2009-07-21 19:30:15 -0700491 } else if (entry.mimetype.equals(CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700492 menu.add(0, 0, 0, R.string.menu_viewAddress).setIntent(entry.intent);
493 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800494 }
495
496 @Override
497 public boolean onOptionsItemSelected(MenuItem item) {
498 switch (item.getItemId()) {
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700499 case R.id.menu_edit: {
Evan Millardf181202009-09-30 15:15:51 -0700500 Long rawContactIdToEdit = null;
501 if (mRawContactIds.size() > 0) {
502 rawContactIdToEdit = mRawContactIds.get(0);
503 } else {
504 // There is no rawContact to edit.
505 break;
Evan Millardb5d88c2009-08-28 09:31:57 -0700506 }
Evan Millar2e1b8af2009-09-24 09:39:21 -0700507 Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI,
508 rawContactIdToEdit);
Evan Millar9cd81242009-09-26 16:02:31 -0700509 startActivityForResult(new Intent(Intent.ACTION_EDIT, rawContactUri),
510 REQUEST_EDIT_CONTACT);
Evan Millar8a79cee2009-08-19 17:20:49 -0700511 break;
512 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700513 case R.id.menu_delete: {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800514 // Get confirmation
Evan Millarcdeea942009-10-07 11:47:35 -0700515 if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) {
Megha Joshid5afd8a2009-09-22 09:38:41 -0700516 showDialog(DIALOG_CONFIRM_READONLY_DELETE);
Evan Millarcdeea942009-10-07 11:47:35 -0700517 } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
Megha Joshic508bd82009-10-01 17:31:49 -0700518 showDialog(DIALOG_CONFIRM_READONLY_HIDE);
Evan Millarcdeea942009-10-07 11:47:35 -0700519 } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
520 showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE);
521 } else {
522 showDialog(DIALOG_CONFIRM_DELETE);
523 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800524 return true;
525 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700526 case R.id.menu_join: {
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700527 showJoinAggregateActivity();
528 return true;
529 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700530 case R.id.menu_options: {
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700531 showOptionsActivity();
532 return true;
533 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700534 case R.id.menu_share: {
Jeff Sharkeye0408762009-11-03 12:57:16 -0800535 if (mAllRestricted) return false;
536
Jeff Sharkey93049312009-09-27 17:28:13 -0700537 // TODO: Keep around actual LOOKUP_KEY, or formalize method of extracting
538 final String lookupKey = mLookupUri.getPathSegments().get(2);
539 final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
540
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700541 final Intent intent = new Intent(Intent.ACTION_SEND);
Jeff Sharkey93049312009-09-27 17:28:13 -0700542 intent.setType(Contacts.CONTENT_VCARD_TYPE);
543 intent.putExtra(Intent.EXTRA_STREAM, shareUri);
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700544
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700545 // Launch chooser to share contact via
546 final CharSequence chooseTitle = getText(R.string.share_via);
547 final Intent chooseIntent = Intent.createChooser(intent, chooseTitle);
Evan Millar5c22c3b2009-05-29 11:37:54 -0700548
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700549 try {
550 startActivity(chooseIntent);
551 } catch (ActivityNotFoundException ex) {
552 Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800553 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700554 return true;
555 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800556 }
557 return super.onOptionsItemSelected(item);
558 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700559
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800560 @Override
561 public boolean onContextItemSelected(MenuItem item) {
562 switch (item.getItemId()) {
563 case MENU_ITEM_MAKE_DEFAULT: {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700564 if (makeItemDefault(item)) {
565 return true;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800566 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700567 break;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800568 }
569 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700570
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800571 return super.onContextItemSelected(item);
572 }
573
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700574 private boolean makeItemDefault(MenuItem item) {
575 ViewEntry entry = getViewEntryForMenuItem(item);
576 if (entry == null) {
577 return false;
578 }
579
580 // Update the primary values in the data record.
Evan Millar14fecb62009-09-09 09:23:12 -0700581 ContentValues values = new ContentValues(1);
Evan Millar54a5c9f2009-06-23 17:41:09 -0700582 values.put(Data.IS_SUPER_PRIMARY, 1);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700583 getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, entry.id),
584 values, null, null);
Evan Millar11d628c2009-09-02 08:55:01 -0700585 startEntityQuery();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700586 return true;
587 }
588
589 /**
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700590 * Shows a list of aggregates that can be joined into the currently viewed aggregate.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700591 */
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700592 public void showJoinAggregateActivity() {
Evan Millar6a61a1a2009-09-29 14:00:43 -0700593 long freshId = getRefreshedContactId();
594 if (freshId > 0) {
595 String displayName = null;
596 if (mCursor.moveToFirst()) {
597 displayName = mCursor.getString(0);
598 }
599 Intent intent = new Intent(ContactsListActivity.JOIN_AGGREGATE);
600 intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_ID, freshId);
601 if (displayName != null) {
602 intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_NAME, displayName);
603 }
604 startActivityForResult(intent, REQUEST_JOIN_CONTACT);
Dmitri Plotnikova5cfca32009-09-29 18:13:08 -0700605 }
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700606 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700607
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700608 @Override
609 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
Evan Millar2e1b8af2009-09-24 09:39:21 -0700610 if (requestCode == REQUEST_JOIN_CONTACT) {
611 if (resultCode == RESULT_OK && intent != null) {
612 final long contactId = ContentUris.parseId(intent.getData());
613 joinAggregate(contactId);
Evan Millar8a79cee2009-08-19 17:20:49 -0700614 }
Evan Millar9cd81242009-09-26 16:02:31 -0700615 } else if (requestCode == REQUEST_EDIT_CONTACT) {
Evan Millardf181202009-09-30 15:15:51 -0700616 if (resultCode == EditContactActivity.RESULT_CLOSE_VIEW_ACTIVITY) {
617 finish();
Jeff Hamilton5297c6a2009-10-01 02:22:33 -0700618 } else if (resultCode == Activity.RESULT_OK) {
Dmitri Plotnikov160e9da2009-09-30 23:48:12 -0700619 mLookupUri = intent.getData();
620 if (mLookupUri == null) {
621 finish();
622 }
Evan Millardf181202009-09-30 15:15:51 -0700623 }
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700624 }
625 }
626
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700627 private void splitContact(long rawContactId) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700628 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_SEPARATE);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700629
630 // The split operation may have removed the original aggregate contact, so we need
631 // to requery everything
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700632 Toast.makeText(this, R.string.contactsSplitMessage, Toast.LENGTH_LONG).show();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700633 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700634 }
635
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700636 private void joinAggregate(final long contactId) {
Dmitri Plotnikov39466592009-07-27 11:23:51 -0700637 Cursor c = mResolver.query(RawContacts.CONTENT_URI, new String[] {RawContacts._ID},
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700638 RawContacts.CONTACT_ID + "=" + contactId, null, null);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700639
640 try {
641 while(c.moveToNext()) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700642 long rawContactId = c.getLong(0);
643 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_TOGETHER);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700644 }
645 } finally {
646 c.close();
647 }
648
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700649 Toast.makeText(this, R.string.contactsJoinedMessage, Toast.LENGTH_LONG).show();
650 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700651 }
652
653 /**
654 * Given a contact ID sets an aggregation exception to either join the contact with the
655 * current aggregate or split off.
656 */
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700657 protected void setAggregationException(long rawContactId, int exceptionType) {
Dmitri Plotnikovd09f75c2009-06-16 11:59:22 -0700658 ContentValues values = new ContentValues(3);
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700659 for (long aRawContactId : mRawContactIds) {
660 if (aRawContactId != rawContactId) {
661 values.put(AggregationExceptions.RAW_CONTACT_ID1, aRawContactId);
662 values.put(AggregationExceptions.RAW_CONTACT_ID2, rawContactId);
663 values.put(AggregationExceptions.TYPE, exceptionType);
664 mResolver.update(AggregationExceptions.CONTENT_URI, values, null, null);
665 }
666 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700667 }
668
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700669 private void showOptionsActivity() {
670 final Intent intent = new Intent(this, ContactOptionsActivity.class);
Evan Millar6a61a1a2009-09-29 14:00:43 -0700671 intent.setData(mLookupUri);
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700672 startActivity(intent);
673 }
674
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700675 private ViewEntry getViewEntryForMenuItem(MenuItem item) {
676 AdapterView.AdapterContextMenuInfo info;
677 try {
678 info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
679 } catch (ClassCastException e) {
680 Log.e(TAG, "bad menuInfo", e);
681 return null;
682 }
683
684 return ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
685 }
686
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800687 @Override
688 public boolean onKeyDown(int keyCode, KeyEvent event) {
689 switch (keyCode) {
690 case KeyEvent.KEYCODE_CALL: {
691 try {
692 ITelephony phone = ITelephony.Stub.asInterface(
693 ServiceManager.checkService("phone"));
694 if (phone != null && !phone.isIdle()) {
695 // Skip out and let the key be handled at a higher level
696 break;
697 }
698 } catch (RemoteException re) {
699 // Fall through and try to call the contact
700 }
701
Evan Millar7911ff52009-07-21 15:55:18 -0700702 int index = mListView.getSelectedItemPosition();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800703 if (index != -1) {
704 ViewEntry entry = ViewAdapter.getEntry(mSections, index, SHOW_SEPARATORS);
Evan Millar66388be2009-05-28 15:41:07 -0700705 if (entry.intent.getAction() == Intent.ACTION_CALL_PRIVILEGED) {
706 startActivity(entry.intent);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800707 }
708 } else if (mNumPhoneNumbers != 0) {
709 // There isn't anything selected, call the default number
Evan Millar6a61a1a2009-09-29 14:00:43 -0700710 long freshContactId = getRefreshedContactId();
711 if (freshContactId > 0) {
712 Uri hardContacUri = ContentUris.withAppendedId(
713 Contacts.CONTENT_URI, freshContactId);
714 Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, hardContacUri);
715 startActivity(intent);
716 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800717 }
718 return true;
719 }
720
721 case KeyEvent.KEYCODE_DEL: {
Evan Millarcdeea942009-10-07 11:47:35 -0700722 if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) {
Megha Joshid5afd8a2009-09-22 09:38:41 -0700723 showDialog(DIALOG_CONFIRM_READONLY_DELETE);
Evan Millarcdeea942009-10-07 11:47:35 -0700724 } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
Megha Joshic508bd82009-10-01 17:31:49 -0700725 showDialog(DIALOG_CONFIRM_READONLY_HIDE);
Evan Millarcdeea942009-10-07 11:47:35 -0700726 } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
727 showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE);
728 } else {
729 showDialog(DIALOG_CONFIRM_DELETE);
730 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800731 return true;
732 }
733 }
734
735 return super.onKeyDown(keyCode, event);
736 }
737
Evan Millar7911ff52009-07-21 15:55:18 -0700738 public void onItemClick(AdapterView parent, View v, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800739 ViewEntry entry = ViewAdapter.getEntry(mSections, position, SHOW_SEPARATORS);
740 if (entry != null) {
741 Intent intent = entry.intent;
Evan Millardf181202009-09-30 15:15:51 -0700742 if (intent != null) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800743 try {
744 startActivity(intent);
745 } catch (ActivityNotFoundException e) {
746 Log.e(TAG, "No activity found for intent: " + intent);
747 signalError();
748 }
749 } else {
750 signalError();
751 }
752 } else {
753 signalError();
754 }
755 }
756
757 /**
758 * Signal an error to the user via a beep, or some other method.
759 */
760 private void signalError() {
761 //TODO: implement this when we have the sonification APIs
762 }
763
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800764 /**
765 * Build up the entries to display on the screen.
Evan Millar5c22c3b2009-05-29 11:37:54 -0700766 *
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800767 * @param personCursor the URI for the contact being displayed
768 */
Evan Millar11d628c2009-09-02 08:55:01 -0700769 private final void buildEntries() {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800770 // Clear out the old entries
771 final int numSections = mSections.size();
772 for (int i = 0; i < numSections; i++) {
773 mSections.get(i).clear();
774 }
775
Evan Millar7911ff52009-07-21 15:55:18 -0700776 mRawContactIds.clear();
Jeff Sharkeye0408762009-11-03 12:57:16 -0800777
Megha Joshid5afd8a2009-09-22 09:38:41 -0700778 mReadOnlySourcesCnt = 0;
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700779 mWritableSourcesCnt = 0;
Jeff Sharkeye0408762009-11-03 12:57:16 -0800780 mAllRestricted = true;
781
Megha Joshid5afd8a2009-09-22 09:38:41 -0700782 mWritableRawContactIds.clear();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700783
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700784 final Context context = this;
785 final Sources sources = Sources.getInstance(context);
Evan Millar11d628c2009-09-02 08:55:01 -0700786
Evan Millar66388be2009-05-28 15:41:07 -0700787 // Build up method entries
Evan Millar6a61a1a2009-09-29 14:00:43 -0700788 if (mLookupUri != null) {
Evan Millar11d628c2009-09-02 08:55:01 -0700789 for (Entity entity: mEntities) {
790 final ContentValues entValues = entity.getEntityValues();
791 final String accountType = entValues.getAsString(RawContacts.ACCOUNT_TYPE);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700792 final long rawContactId = entValues.getAsLong(RawContacts._ID);
Evan Millar7911ff52009-07-21 15:55:18 -0700793
Jeff Sharkeye0408762009-11-03 12:57:16 -0800794 // Mark when this contact has any unrestricted components
795 final boolean isRestricted = entValues.getAsInteger(RawContacts.IS_RESTRICTED) != 0;
796 if (!isRestricted) mAllRestricted = false;
797
Dmitri Plotnikov2a8cef02009-09-23 19:01:15 -0700798 if (!mRawContactIds.contains(rawContactId)) {
799 mRawContactIds.add(rawContactId);
800 }
Megha Joshic508bd82009-10-01 17:31:49 -0700801 ContactsSource contactsSource = sources.getInflatedSource(accountType,
802 ContactsSource.LEVEL_SUMMARY);
803 if (contactsSource != null && contactsSource.readOnly) {
804 mReadOnlySourcesCnt += 1;
805 } else {
806 mWritableSourcesCnt += 1;
Evan Millarcdeea942009-10-07 11:47:35 -0700807 mWritableRawContactIds.add(rawContactId);
808 }
Megha Joshic508bd82009-10-01 17:31:49 -0700809
Dmitri Plotnikov2a8cef02009-09-23 19:01:15 -0700810
Evan Millar11d628c2009-09-02 08:55:01 -0700811 for (NamedContentValues subValue : entity.getSubValues()) {
Jeff Sharkeyab066932009-09-21 09:55:30 -0700812 final ContentValues entryValues = subValue.values;
813 entryValues.put(Data.RAW_CONTACT_ID, rawContactId);
814
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700815 final long dataId = entryValues.getAsLong(Data._ID);
816 final String mimeType = entryValues.getAsString(Data.MIMETYPE);
817 if (mimeType == null) continue;
Evan Millar66388be2009-05-28 15:41:07 -0700818
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700819 final DataKind kind = sources.getKindOrFallback(accountType, mimeType, this,
Evan Millar11d628c2009-09-02 08:55:01 -0700820 ContactsSource.LEVEL_MIMETYPES);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700821 if (kind == null) continue;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800822
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700823 final ViewEntry entry = ViewEntry.fromValues(context, mimeType, kind,
824 rawContactId, dataId, entryValues);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800825
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700826 final boolean hasData = !TextUtils.isEmpty(entry.data);
Evan Millarff04a272009-09-26 15:23:37 -0700827 final boolean isSuperPrimary = entryValues.getAsInteger(
828 Data.IS_SUPER_PRIMARY) != 0;
Evan Millar11d628c2009-09-02 08:55:01 -0700829
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700830 if (Phone.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700831 // Build phone entries
832 mNumPhoneNumbers++;
Evan Millar11d628c2009-09-02 08:55:01 -0700833
Evan Millarff04a272009-09-26 15:23:37 -0700834 entry.intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700835 Uri.fromParts(Constants.SCHEME_TEL, entry.data, null));
Evan Millarff04a272009-09-26 15:23:37 -0700836 entry.secondaryIntent = new Intent(Intent.ACTION_SENDTO,
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700837 Uri.fromParts(Constants.SCHEME_SMSTO, entry.data, null));
Evan Millar49714ee2009-09-02 16:42:47 -0700838
Evan Millarff04a272009-09-26 15:23:37 -0700839 entry.isPrimary = isSuperPrimary;
840 mPhoneEntries.add(entry);
841
842 if (entry.type == CommonDataKinds.Phone.TYPE_MOBILE
843 || mShowSmsLinksForAllPhones) {
844 // Add an SMS entry
845 if (kind.iconAltRes > 0) {
846 entry.secondaryActionIcon = kind.iconAltRes;
Evan Millar49714ee2009-09-02 16:42:47 -0700847 }
Evan Millarff04a272009-09-26 15:23:37 -0700848 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700849 } else if (Email.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700850 // Build email entries
851 entry.intent = new Intent(Intent.ACTION_SENDTO,
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700852 Uri.fromParts(Constants.SCHEME_MAILTO, entry.data, null));
Evan Millarff04a272009-09-26 15:23:37 -0700853 entry.isPrimary = isSuperPrimary;
854 mEmailEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700855
856 // When Email rows have status, create additional Im row
857 final DataStatus status = mStatuses.get(entry.id);
858 if (status != null) {
859 final String imMime = Im.CONTENT_ITEM_TYPE;
860 final DataKind imKind = sources.getKindOrFallback(accountType,
861 imMime, this, ContactsSource.LEVEL_MIMETYPES);
862 final ViewEntry imEntry = ViewEntry.fromValues(context,
863 imMime, imKind, rawContactId, dataId, entryValues);
864 imEntry.intent = ContactsUtils.buildImIntent(entryValues);
865 imEntry.applyStatus(status, false);
866 mImEntries.add(imEntry);
867 }
868 } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700869 // Build postal entries
870 entry.maxLines = 4;
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700871 entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri);
Evan Millarff04a272009-09-26 15:23:37 -0700872 mPostalEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700873 } else if (Im.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
874 // Build IM entries
875 entry.intent = ContactsUtils.buildImIntent(entryValues);
Evan Millarff04a272009-09-26 15:23:37 -0700876 if (TextUtils.isEmpty(entry.label)) {
877 entry.label = getString(R.string.chat).toLowerCase();
878 }
Evan Millar11d628c2009-09-02 08:55:01 -0700879
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700880 // Apply presence and status details when available
881 final DataStatus status = mStatuses.get(entry.id);
882 if (status != null) {
883 entry.applyStatus(status, false);
Evan Millarff04a272009-09-26 15:23:37 -0700884 }
Evan Millarff04a272009-09-26 15:23:37 -0700885 mImEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700886 } else if ((Organization.CONTENT_ITEM_TYPE.equals(mimeType)
887 || Nickname.CONTENT_ITEM_TYPE.equals(mimeType)) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700888 // Build organization and note entries
889 entry.uri = null;
Evan Millar11d628c2009-09-02 08:55:01 -0700890 mOrganizationEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700891 } else if (Note.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millar11d628c2009-09-02 08:55:01 -0700892 // Build note entries
Evan Millar11d628c2009-09-02 08:55:01 -0700893 entry.uri = null;
Evan Millar11d628c2009-09-02 08:55:01 -0700894 entry.maxLines = 10;
895 mOtherEntries.add(entry);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700896 } else {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700897 // Handle showing custom rows
Evan Millarff04a272009-09-26 15:23:37 -0700898 entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700899
900 // Use social summary when requested by external source
901 final DataStatus status = mStatuses.get(entry.id);
902 final boolean hasSocial = kind.actionBodySocial && status != null;
903 if (hasSocial) {
904 entry.applyStatus(status, true);
905 }
906
907 if (hasSocial || hasData) {
908 mOtherEntries.add(entry);
909 }
Evan Millar11d628c2009-09-02 08:55:01 -0700910 }
Evan Millar2e1b8af2009-09-24 09:39:21 -0700911 }
Evan Millar66388be2009-05-28 15:41:07 -0700912 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800913 }
914 }
915
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700916 static String buildActionString(DataKind kind, ContentValues values, boolean lowerCase,
917 Context context) {
Evan Millar11d628c2009-09-02 08:55:01 -0700918 if (kind.actionHeader == null) {
919 return null;
Jeff Hamilton8350e5b2009-03-24 21:01:34 -0700920 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700921 CharSequence actionHeader = kind.actionHeader.inflateUsing(context, values);
Evan Millar11d628c2009-09-02 08:55:01 -0700922 if (actionHeader == null) {
923 return null;
924 }
925 return lowerCase ? actionHeader.toString().toLowerCase() : actionHeader.toString();
926 }
Jeff Hamilton8350e5b2009-03-24 21:01:34 -0700927
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700928 static String buildDataString(DataKind kind, ContentValues values, Context context) {
Evan Millar11d628c2009-09-02 08:55:01 -0700929 if (kind.actionBody == null) {
930 return null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800931 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700932 CharSequence actionBody = kind.actionBody.inflateUsing(context, values);
Evan Millar11d628c2009-09-02 08:55:01 -0700933 return actionBody == null ? null : actionBody.toString();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800934 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700935
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800936 /**
937 * A basic structure with the data for a contact entry in the list.
938 */
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700939 static class ViewEntry extends ContactEntryAdapter.Entry implements Collapsible<ViewEntry> {
940 public Context context = null;
Jeff Sharkeyab066932009-09-21 09:55:30 -0700941 public String resPackageName = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800942 public int actionIcon = -1;
Evan Millar15e514d2009-08-04 10:14:57 -0700943 public boolean isPrimary = false;
Evan Millar15e514d2009-08-04 10:14:57 -0700944 public int secondaryActionIcon = -1;
945 public Intent intent;
946 public Intent secondaryIntent = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800947 public int maxLabelLines = 1;
Evan Millar54a5c9f2009-06-23 17:41:09 -0700948 public ArrayList<Long> ids = new ArrayList<Long>();
949 public int collapseCount = 0;
950
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700951 public int presence = -1;
952 public int presenceIcon = -1;
953
954 public CharSequence footerLine = null;
955
956 private ViewEntry() {
957 }
958
959 /**
960 * Build new {@link ViewEntry} and populate from the given values.
961 */
962 public static ViewEntry fromValues(Context context, String mimeType, DataKind kind,
963 long rawContactId, long dataId, ContentValues values) {
964 final ViewEntry entry = new ViewEntry();
965 entry.context = context;
966 entry.contactId = rawContactId;
967 entry.id = dataId;
968 entry.uri = ContentUris.withAppendedId(Data.CONTENT_URI, entry.id);
969 entry.mimetype = mimeType;
970 entry.label = buildActionString(kind, values, false, context);
971 entry.data = buildDataString(kind, values, context);
972
973 if (kind.typeColumn != null && values.containsKey(kind.typeColumn)) {
974 entry.type = values.getAsInteger(kind.typeColumn);
975 }
976 if (kind.iconRes > 0) {
977 entry.resPackageName = kind.resPackageName;
978 entry.actionIcon = kind.iconRes;
979 }
980
981 return entry;
982 }
983
984 /**
985 * Apply given {@link DataStatus} values over this {@link ViewEntry}
986 *
987 * @param fillData When true, the given status replaces {@link #data}
988 * and {@link #footerLine}. Otherwise only {@link #presence}
989 * is updated.
990 */
991 public ViewEntry applyStatus(DataStatus status, boolean fillData) {
992 presence = status.getPresence();
993 presenceIcon = (presence == -1) ? -1 :
994 StatusUpdates.getPresenceIconResourceId(this.presence);
995
996 if (fillData && status.isValid()) {
997 this.data = status.getStatus().toString();
998 this.footerLine = status.getTimestampLabel(context);
999 }
1000
1001 return this;
1002 }
1003
Evan Millar54a5c9f2009-06-23 17:41:09 -07001004 public boolean collapseWith(ViewEntry entry) {
1005 // assert equal collapse keys
Evan Millaradb0f8c2009-09-28 17:20:50 -07001006 if (!shouldCollapseWith(entry)) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001007 return false;
1008 }
1009
1010 // Choose the label associated with the highest type precedence.
1011 if (TypePrecedence.getTypePrecedence(mimetype, type)
1012 > TypePrecedence.getTypePrecedence(entry.mimetype, entry.type)) {
1013 type = entry.type;
1014 label = entry.label;
1015 }
1016
1017 // Choose the max of the maxLines and maxLabelLines values.
1018 maxLines = Math.max(maxLines, entry.maxLines);
1019 maxLabelLines = Math.max(maxLabelLines, entry.maxLabelLines);
1020
1021 // Choose the presence with the highest precedence.
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001022 if (StatusUpdates.getPresencePrecedence(presence)
1023 < StatusUpdates.getPresencePrecedence(entry.presence)) {
1024 presence = entry.presence;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001025 }
1026
1027 // If any of the collapsed entries are primary make the whole thing primary.
Evan Millar15e514d2009-08-04 10:14:57 -07001028 isPrimary = entry.isPrimary ? true : isPrimary;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001029
1030 // uri, and contactdId, shouldn't make a difference. Just keep the original.
1031
1032 // Keep track of all the ids that have been collapsed with this one.
1033 ids.add(entry.id);
1034 collapseCount++;
1035 return true;
1036 }
1037
Evan Millaradb0f8c2009-09-28 17:20:50 -07001038 public boolean shouldCollapseWith(ViewEntry entry) {
1039 if (entry == null) {
1040 return false;
1041 }
1042
1043 if (Phone.CONTENT_ITEM_TYPE.equals(mimetype)
1044 && Phone.CONTENT_ITEM_TYPE.equals(entry.mimetype)) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001045 if (!PhoneNumberUtils.compare(this.context, data, entry.data)) {
Evan Millaradb0f8c2009-09-28 17:20:50 -07001046 return false;
1047 }
1048 } else {
1049 if (!equals(data, entry.data)) {
1050 return false;
1051 }
1052 }
1053
1054 if (!equals(mimetype, entry.mimetype)
1055 || !intentCollapsible(intent, entry.intent)
1056 || !intentCollapsible(secondaryIntent, entry.secondaryIntent)
1057 || actionIcon != entry.actionIcon) {
1058 return false;
1059 }
1060
1061 return true;
1062 }
1063
1064 private boolean equals(Object a, Object b) {
1065 return a==b || (a != null && a.equals(b));
1066 }
1067
1068 private boolean intentCollapsible(Intent a, Intent b) {
1069 if (a == b) {
1070 return true;
1071 } else if ((a != null && b != null) && equals(a.getAction(), b.getAction())) {
1072 return true;
1073 }
1074 return false;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001075 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001076 }
1077
Evan Millar15e514d2009-08-04 10:14:57 -07001078 /** Cache of the children views of a row */
1079 static class ViewCache {
1080 public TextView label;
1081 public TextView data;
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001082 public TextView footer;
Evan Millar15e514d2009-08-04 10:14:57 -07001083 public ImageView actionIcon;
1084 public ImageView presenceIcon;
1085 public ImageView primaryIcon;
1086 public ImageView secondaryActionButton;
1087 public View secondaryActionDivider;
Evan Millar5c22c3b2009-05-29 11:37:54 -07001088
Evan Millar15e514d2009-08-04 10:14:57 -07001089 // Need to keep track of this too
1090 ViewEntry entry;
1091 }
1092
1093 private final class ViewAdapter extends ContactEntryAdapter<ViewEntry>
1094 implements View.OnClickListener {
1095
Evan Millar5c22c3b2009-05-29 11:37:54 -07001096
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001097 ViewAdapter(Context context, ArrayList<ArrayList<ViewEntry>> sections) {
1098 super(context, sections, SHOW_SEPARATORS);
1099 }
1100
Evan Millar15e514d2009-08-04 10:14:57 -07001101 public void onClick(View v) {
1102 Intent intent = (Intent) v.getTag();
1103 startActivity(intent);
1104 }
1105
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001106 @Override
1107 public View getView(int position, View convertView, ViewGroup parent) {
Evan Millar5c22c3b2009-05-29 11:37:54 -07001108 ViewEntry entry = getEntry(mSections, position, false);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001109 View v;
1110
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001111 ViewCache views;
1112
1113 // Check to see if we can reuse convertView
1114 if (convertView != null) {
1115 v = convertView;
1116 views = (ViewCache) v.getTag();
1117 } else {
1118 // Create a new view if needed
1119 v = mInflater.inflate(R.layout.list_item_text_icons, parent, false);
1120
1121 // Cache the children
1122 views = new ViewCache();
1123 views.label = (TextView) v.findViewById(android.R.id.text1);
1124 views.data = (TextView) v.findViewById(android.R.id.text2);
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001125 views.footer = (TextView) v.findViewById(R.id.footer);
Evan Millar15e514d2009-08-04 10:14:57 -07001126 views.actionIcon = (ImageView) v.findViewById(R.id.action_icon);
1127 views.primaryIcon = (ImageView) v.findViewById(R.id.primary_icon);
1128 views.presenceIcon = (ImageView) v.findViewById(R.id.presence_icon);
1129 views.secondaryActionButton = (ImageView) v.findViewById(
1130 R.id.secondary_action_button);
1131 views.secondaryActionButton.setOnClickListener(this);
Evan Millar15e514d2009-08-04 10:14:57 -07001132 views.secondaryActionDivider = v.findViewById(R.id.divider);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001133 v.setTag(views);
1134 }
1135
1136 // Update the entry in the view cache
1137 views.entry = entry;
1138
1139 // Bind the data to the view
1140 bindView(v, entry);
1141 return v;
1142 }
1143
1144 @Override
1145 protected View newView(int position, ViewGroup parent) {
1146 // getView() handles this
1147 throw new UnsupportedOperationException();
1148 }
1149
1150 @Override
1151 protected void bindView(View view, ViewEntry entry) {
1152 final Resources resources = mContext.getResources();
1153 ViewCache views = (ViewCache) view.getTag();
1154
1155 // Set the label
1156 TextView label = views.label;
1157 setMaxLines(label, entry.maxLabelLines);
1158 label.setText(entry.label);
1159
1160 // Set the data
1161 TextView data = views.data;
1162 if (data != null) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001163 if (entry.mimetype.equals(Phone.CONTENT_ITEM_TYPE)
Jeff Sharkey49d17b32009-09-07 02:14:21 -07001164 || entry.mimetype.equals(Constants.MIME_SMS_ADDRESS)) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001165 data.setText(PhoneNumberUtils.formatNumber(entry.data));
1166 } else {
1167 data.setText(entry.data);
1168 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001169 setMaxLines(data, entry.maxLines);
1170 }
1171
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001172 // Set the footer
1173 if (!TextUtils.isEmpty(entry.footerLine)) {
1174 views.footer.setText(entry.footerLine);
1175 views.footer.setVisibility(View.VISIBLE);
1176 } else {
1177 views.footer.setVisibility(View.GONE);
1178 }
1179
Evan Millar15e514d2009-08-04 10:14:57 -07001180 // Set the primary icon
1181 views.primaryIcon.setVisibility(entry.isPrimary ? View.VISIBLE : View.GONE);
1182
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001183 // Set the action icon
1184 ImageView action = views.actionIcon;
1185 if (entry.actionIcon != -1) {
Jeff Sharkeyab066932009-09-21 09:55:30 -07001186 Drawable actionIcon;
1187 if (entry.resPackageName != null) {
1188 // Load external resources through PackageManager
1189 actionIcon = mContext.getPackageManager().getDrawable(entry.resPackageName,
1190 entry.actionIcon, null);
1191 } else {
1192 actionIcon = resources.getDrawable(entry.actionIcon);
1193 }
1194 action.setImageDrawable(actionIcon);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001195 action.setVisibility(View.VISIBLE);
1196 } else {
1197 // Things should still line up as if there was an icon, so make it invisible
1198 action.setVisibility(View.INVISIBLE);
1199 }
1200
1201 // Set the presence icon
1202 Drawable presenceIcon = null;
Evan Millar15e514d2009-08-04 10:14:57 -07001203 if (entry.presenceIcon != -1) {
1204 presenceIcon = resources.getDrawable(entry.presenceIcon);
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001205 } else if (entry.presence != -1) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001206 presenceIcon = resources.getDrawable(
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001207 StatusUpdates.getPresenceIconResourceId(entry.presence));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001208 }
Evan Millar15e514d2009-08-04 10:14:57 -07001209 ImageView presenceIconView = views.presenceIcon;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001210 if (presenceIcon != null) {
Evan Millar15e514d2009-08-04 10:14:57 -07001211 presenceIconView.setImageDrawable(presenceIcon);
1212 presenceIconView.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001213 } else {
Evan Millar15e514d2009-08-04 10:14:57 -07001214 presenceIconView.setVisibility(View.GONE);
1215 }
1216
1217 // Set the secondary action button
1218 ImageView secondaryActionView = views.secondaryActionButton;
1219 Drawable secondaryActionIcon = null;
1220 if (entry.secondaryActionIcon != -1) {
1221 secondaryActionIcon = resources.getDrawable(entry.secondaryActionIcon);
1222 }
1223 if (entry.secondaryIntent != null && secondaryActionIcon != null) {
1224 secondaryActionView.setImageDrawable(secondaryActionIcon);
1225 secondaryActionView.setTag(entry.secondaryIntent);
1226 secondaryActionView.setVisibility(View.VISIBLE);
1227 views.secondaryActionDivider.setVisibility(View.VISIBLE);
1228 } else {
1229 secondaryActionView.setVisibility(View.GONE);
1230 views.secondaryActionDivider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001231 }
1232 }
1233
1234 private void setMaxLines(TextView textView, int maxLines) {
1235 if (maxLines == 1) {
1236 textView.setSingleLine(true);
1237 textView.setEllipsize(TextUtils.TruncateAt.END);
1238 } else {
1239 textView.setSingleLine(false);
1240 textView.setMaxLines(maxLines);
1241 textView.setEllipsize(null);
1242 }
1243 }
1244 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001245
1246 private interface StatusQuery {
1247 final String[] PROJECTION = new String[] {
1248 Data._ID,
1249 Data.STATUS,
1250 Data.STATUS_RES_PACKAGE,
1251 Data.STATUS_ICON,
1252 Data.STATUS_LABEL,
1253 Data.STATUS_TIMESTAMP,
1254 Data.PRESENCE,
1255 };
1256
1257 final int _ID = 0;
1258 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001259}