blob: 909cf518057a181458e57ea13121e003ade1ae16 [file] [log] [blame]
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.contacts;
18
Evan Millar54a5c9f2009-06-23 17:41:09 -070019import com.android.contacts.Collapser.Collapsible;
Evan Millar11d628c2009-09-02 08:55:01 -070020import com.android.contacts.model.ContactsSource;
21import com.android.contacts.model.Sources;
22import com.android.contacts.model.ContactsSource.DataKind;
Evan Millardf181202009-09-30 15:15:51 -070023import com.android.contacts.ui.EditContactActivity;
Jeff Sharkey49d17b32009-09-07 02:14:21 -070024import com.android.contacts.util.Constants;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070025import com.android.contacts.util.DataStatus;
Evan Millar11d628c2009-09-02 08:55:01 -070026import com.android.contacts.util.NotifyingAsyncQueryHandler;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080027import com.android.internal.telephony.ITelephony;
Evan Millar11d628c2009-09-02 08:55:01 -070028import com.android.internal.widget.ContactHeaderWidget;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070029import com.google.android.collect.Lists;
30import com.google.android.collect.Maps;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080031
Evan Millar11d628c2009-09-02 08:55:01 -070032import android.app.Activity;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080033import android.app.AlertDialog;
34import android.app.Dialog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080035import android.content.ActivityNotFoundException;
36import android.content.ContentResolver;
37import android.content.ContentUris;
38import android.content.ContentValues;
39import android.content.Context;
40import android.content.DialogInterface;
Evan Millar5f4af702009-08-11 11:12:00 -070041import android.content.Entity;
Evan Millar11d628c2009-09-02 08:55:01 -070042import android.content.EntityIterator;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080043import android.content.Intent;
Evan Millar11d628c2009-09-02 08:55:01 -070044import android.content.Entity.NamedContentValues;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080045import android.content.res.Resources;
46import android.database.ContentObserver;
47import android.database.Cursor;
48import android.graphics.drawable.Drawable;
Evan Millar951fa9c2009-10-26 14:57:43 -070049import android.net.ParseException;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080050import android.net.Uri;
Evan Millar951fa9c2009-10-26 14:57:43 -070051import android.net.WebAddress;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080052import android.os.Bundle;
53import android.os.Handler;
54import android.os.RemoteException;
55import android.os.ServiceManager;
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -070056import android.provider.ContactsContract;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070057import android.provider.ContactsContract.AggregationExceptions;
58import android.provider.ContactsContract.CommonDataKinds;
Evan Millar11d628c2009-09-02 08:55:01 -070059import android.provider.ContactsContract.Contacts;
Evan Millar66388be2009-05-28 15:41:07 -070060import android.provider.ContactsContract.Data;
Dmitri Plotnikov39466592009-07-27 11:23:51 -070061import android.provider.ContactsContract.RawContacts;
Dmitri Plotnikov160e9da2009-09-30 23:48:12 -070062import android.provider.ContactsContract.StatusUpdates;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070063import android.provider.ContactsContract.CommonDataKinds.Email;
64import android.provider.ContactsContract.CommonDataKinds.Im;
65import android.provider.ContactsContract.CommonDataKinds.Nickname;
66import android.provider.ContactsContract.CommonDataKinds.Note;
67import android.provider.ContactsContract.CommonDataKinds.Organization;
Evan Millar54a5c9f2009-06-23 17:41:09 -070068import android.provider.ContactsContract.CommonDataKinds.Phone;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070069import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
Evan Millar951fa9c2009-10-26 14:57:43 -070070import android.provider.ContactsContract.CommonDataKinds.Website;
Evan Millar54a5c9f2009-06-23 17:41:09 -070071import android.telephony.PhoneNumberUtils;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080072import android.text.TextUtils;
73import android.util.Log;
74import android.view.ContextMenu;
75import android.view.KeyEvent;
Evan Millar11d628c2009-09-02 08:55:01 -070076import android.view.LayoutInflater;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080077import android.view.Menu;
Jeff Sharkey49d17b32009-09-07 02:14:21 -070078import android.view.MenuInflater;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080079import android.view.MenuItem;
80import android.view.View;
81import android.view.ViewGroup;
Evan Millar11d628c2009-09-02 08:55:01 -070082import android.view.Window;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080083import android.view.ContextMenu.ContextMenuInfo;
84import android.widget.AdapterView;
Evan Millar7911ff52009-07-21 15:55:18 -070085import android.widget.FrameLayout;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080086import android.widget.ImageView;
87import android.widget.ListView;
Evan Millarcdeea942009-10-07 11:47:35 -070088import android.widget.ScrollView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080089import android.widget.TextView;
90import android.widget.Toast;
91
92import java.util.ArrayList;
Jeff Sharkey624ddc32009-10-01 21:32:19 -070093import java.util.HashMap;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080094
95/**
96 * Displays the details of a specific contact.
97 */
Evan Millar11d628c2009-09-02 08:55:01 -070098public class ViewContactActivity extends Activity
Evan Millar7911ff52009-07-21 15:55:18 -070099 implements View.OnCreateContextMenuListener, DialogInterface.OnClickListener,
Evan Millardf181202009-09-30 15:15:51 -0700100 AdapterView.OnItemClickListener, NotifyingAsyncQueryHandler.AsyncQueryListener {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800101 private static final String TAG = "ViewContact";
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800102
103 private static final boolean SHOW_SEPARATORS = false;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800104
105 private static final int DIALOG_CONFIRM_DELETE = 1;
Megha Joshid5afd8a2009-09-22 09:38:41 -0700106 private static final int DIALOG_CONFIRM_READONLY_DELETE = 2;
107 private static final int DIALOG_CONFIRM_MULTIPLE_DELETE = 3;
Megha Joshic508bd82009-10-01 17:31:49 -0700108 private static final int DIALOG_CONFIRM_READONLY_HIDE = 4;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800109
Evan Millar8a79cee2009-08-19 17:20:49 -0700110 private static final int REQUEST_JOIN_CONTACT = 1;
Evan Millar9cd81242009-09-26 16:02:31 -0700111 private static final int REQUEST_EDIT_CONTACT = 2;
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700112
Evan Millar8a79cee2009-08-19 17:20:49 -0700113 public static final int MENU_ITEM_MAKE_DEFAULT = 3;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800114
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700115 protected Uri mLookupUri;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800116 private ContentResolver mResolver;
117 private ViewAdapter mAdapter;
118 private int mNumPhoneNumbers = 0;
119
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700120 /**
Dmitri Plotnikove1cd6792009-07-27 20:28:17 -0700121 * A list of distinct contact IDs included in the current contact.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700122 */
Evan Millar7911ff52009-07-21 15:55:18 -0700123 private ArrayList<Long> mRawContactIds = new ArrayList<Long>();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700124
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800125 /* package */ ArrayList<ViewEntry> mPhoneEntries = new ArrayList<ViewEntry>();
126 /* package */ ArrayList<ViewEntry> mSmsEntries = new ArrayList<ViewEntry>();
127 /* package */ ArrayList<ViewEntry> mEmailEntries = new ArrayList<ViewEntry>();
128 /* package */ ArrayList<ViewEntry> mPostalEntries = new ArrayList<ViewEntry>();
129 /* package */ ArrayList<ViewEntry> mImEntries = new ArrayList<ViewEntry>();
130 /* package */ ArrayList<ViewEntry> mOrganizationEntries = new ArrayList<ViewEntry>();
The Android Open Source Projectcac191e2009-03-18 22:20:27 -0700131 /* package */ ArrayList<ViewEntry> mGroupEntries = new ArrayList<ViewEntry>();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800132 /* package */ ArrayList<ViewEntry> mOtherEntries = new ArrayList<ViewEntry>();
133 /* package */ ArrayList<ArrayList<ViewEntry>> mSections = new ArrayList<ArrayList<ViewEntry>>();
134
135 private Cursor mCursor;
Evan Millar5c22c3b2009-05-29 11:37:54 -0700136
Evan Millar11d628c2009-09-02 08:55:01 -0700137 protected ContactHeaderWidget mContactHeaderWidget;
138 private NotifyingAsyncQueryHandler mHandler;
139
140 protected LayoutInflater mInflater;
141
Megha Joshid5afd8a2009-09-22 09:38:41 -0700142 protected int mReadOnlySourcesCnt;
143 protected int mWritableSourcesCnt;
Jeff Sharkeye0408762009-11-03 12:57:16 -0800144 protected boolean mAllRestricted;
145
Megha Joshid5afd8a2009-09-22 09:38:41 -0700146 protected ArrayList<Long> mWritableRawContactIds = new ArrayList<Long>();
Evan Millar11d628c2009-09-02 08:55:01 -0700147
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700148 private static final int TOKEN_ENTITIES = 0;
149 private static final int TOKEN_STATUSES = 1;
150
151 private boolean mHasEntities = false;
152 private boolean mHasStatuses = false;
153
154 private ArrayList<Entity> mEntities = Lists.newArrayList();
155 private HashMap<Long, DataStatus> mStatuses = Maps.newHashMap();
Evan Millar11d628c2009-09-02 08:55:01 -0700156
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800157 private ContentObserver mObserver = new ContentObserver(new Handler()) {
158 @Override
159 public boolean deliverSelfNotifications() {
160 return true;
161 }
162
163 @Override
164 public void onChange(boolean selfChange) {
Evan Millar11d628c2009-09-02 08:55:01 -0700165 if (mCursor != null && !mCursor.isClosed()) {
166 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800167 }
168 }
169 };
170
171 public void onClick(DialogInterface dialog, int which) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700172 closeCursor();
Megha Joshic508bd82009-10-01 17:31:49 -0700173 getContentResolver().delete(mLookupUri, null, null);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800174 finish();
175 }
176
Evan Millar7911ff52009-07-21 15:55:18 -0700177 private ListView mListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800178 private boolean mShowSmsLinksForAllPhones;
179
180 @Override
181 protected void onCreate(Bundle icicle) {
182 super.onCreate(icicle);
183
Evan Millar11d628c2009-09-02 08:55:01 -0700184 final Intent intent = getIntent();
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -0700185 Uri data = intent.getData();
186 String authority = data.getAuthority();
187 if (ContactsContract.AUTHORITY.equals(authority)) {
188 mLookupUri = data;
189 } else if (android.provider.Contacts.AUTHORITY.equals(authority)) {
190 final long rawContactId = ContentUris.parseId(data);
191 mLookupUri = RawContacts.getContactLookupUri(getContentResolver(),
192 ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700193
Dmitri Plotnikov4e3a0432009-09-15 13:54:40 -0700194 }
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700195 mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Evan Millar11d628c2009-09-02 08:55:01 -0700196
197 requestWindowFeature(Window.FEATURE_NO_TITLE);
198 setContentView(R.layout.contact_card_layout);
199
200 mContactHeaderWidget = (ContactHeaderWidget) findViewById(R.id.contact_header_widget);
201 mContactHeaderWidget.showStar(true);
Evan Millar11d628c2009-09-02 08:55:01 -0700202 mContactHeaderWidget.setExcludeMimes(new String[] {
203 Contacts.CONTENT_ITEM_TYPE
204 });
205
Evan Millar11d628c2009-09-02 08:55:01 -0700206 mHandler = new NotifyingAsyncQueryHandler(this, this);
207
Evan Millarcdeea942009-10-07 11:47:35 -0700208 mListView = (ListView) findViewById(R.id.contact_data);
Evan Millar7911ff52009-07-21 15:55:18 -0700209 mListView.setOnCreateContextMenuListener(this);
210 mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
211 mListView.setOnItemClickListener(this);
Evan Millarcdeea942009-10-07 11:47:35 -0700212 mListView.setEmptyView((ScrollView) findViewById(android.R.id.empty));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800213
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800214 mResolver = getContentResolver();
215
216 // Build the list of sections. The order they're added to mSections dictates the
217 // order they are displayed in the list.
218 mSections.add(mPhoneEntries);
219 mSections.add(mSmsEntries);
220 mSections.add(mEmailEntries);
221 mSections.add(mImEntries);
222 mSections.add(mPostalEntries);
223 mSections.add(mOrganizationEntries);
The Android Open Source Projectcac191e2009-03-18 22:20:27 -0700224 mSections.add(mGroupEntries);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800225 mSections.add(mOtherEntries);
226
227 //TODO Read this value from a preference
228 mShowSmsLinksForAllPhones = true;
Evan Millar11d628c2009-09-02 08:55:01 -0700229 }
230
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800231 @Override
232 protected void onResume() {
233 super.onResume();
Evan Millar11d628c2009-09-02 08:55:01 -0700234 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800235 }
236
237 @Override
238 protected void onPause() {
239 super.onPause();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700240 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800241 }
242
243 @Override
244 protected void onDestroy() {
245 super.onDestroy();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700246 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800247 }
248
249 @Override
250 protected Dialog onCreateDialog(int id) {
251 switch (id) {
252 case DIALOG_CONFIRM_DELETE:
253 return new AlertDialog.Builder(this)
254 .setTitle(R.string.deleteConfirmation_title)
255 .setIcon(android.R.drawable.ic_dialog_alert)
256 .setMessage(R.string.deleteConfirmation)
257 .setNegativeButton(android.R.string.cancel, null)
258 .setPositiveButton(android.R.string.ok, this)
259 .setCancelable(false)
260 .create();
Megha Joshid5afd8a2009-09-22 09:38:41 -0700261 case DIALOG_CONFIRM_READONLY_DELETE:
262 return new AlertDialog.Builder(this)
263 .setTitle(R.string.deleteConfirmation_title)
264 .setIcon(android.R.drawable.ic_dialog_alert)
265 .setMessage(R.string.readOnlyContactDeleteConfirmation)
266 .setNegativeButton(android.R.string.cancel, null)
267 .setPositiveButton(android.R.string.ok, this)
268 .setCancelable(false)
269 .create();
270 case DIALOG_CONFIRM_MULTIPLE_DELETE:
271 return new AlertDialog.Builder(this)
272 .setTitle(R.string.deleteConfirmation_title)
273 .setIcon(android.R.drawable.ic_dialog_alert)
274 .setMessage(R.string.multipleContactDeleteConfirmation)
275 .setNegativeButton(android.R.string.cancel, null)
276 .setPositiveButton(android.R.string.ok, this)
277 .setCancelable(false)
278 .create();
Evan Millarcdeea942009-10-07 11:47:35 -0700279 case DIALOG_CONFIRM_READONLY_HIDE: {
Megha Joshic508bd82009-10-01 17:31:49 -0700280 return new AlertDialog.Builder(this)
281 .setTitle(R.string.deleteConfirmation_title)
282 .setIcon(android.R.drawable.ic_dialog_alert)
283 .setMessage(R.string.readOnlyContactWarning)
284 .setPositiveButton(android.R.string.ok, this)
Evan Millarcdeea942009-10-07 11:47:35 -0700285 .create();
Megha Joshic508bd82009-10-01 17:31:49 -0700286 }
287
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800288 }
289 return null;
290 }
291
Evan Millar11d628c2009-09-02 08:55:01 -0700292 // QUERY CODE //
293 /** {@inheritDoc} */
294 public void onQueryEntitiesComplete(int token, Object cookie, EntityIterator iterator) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700295 try {
296 // Read incoming entities and consider binding
297 readEntities(iterator);
298 considerBindData();
Evan Millar11d628c2009-09-02 08:55:01 -0700299 } finally {
300 if (iterator != null) {
301 iterator.close();
302 }
303 }
304 }
305
306 /** {@inheritDoc} */
307 public void onQueryComplete(int token, Object cookie, Cursor cursor) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700308 try {
309 // Read available social rows and consider binding
310 readStatuses(cursor);
311 considerBindData();
312 } finally {
313 if (cursor != null) {
314 cursor.close();
315 }
316 }
Evan Millar11d628c2009-09-02 08:55:01 -0700317 }
318
Evan Millar6a61a1a2009-09-29 14:00:43 -0700319 private long getRefreshedContactId() {
320 Uri freshContactUri = Contacts.lookupContact(getContentResolver(), mLookupUri);
321 if (freshContactUri != null) {
322 return ContentUris.parseId(freshContactUri);
323 }
324 return -1;
325 }
326
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700327 /**
328 * Read from the given {@link EntityIterator} to build internal set of
329 * {@link #mEntities} for data display.
330 */
331 private synchronized void readEntities(EntityIterator iterator) {
332 mEntities.clear();
Evan Millar11d628c2009-09-02 08:55:01 -0700333 try {
334 while (iterator.hasNext()) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700335 mEntities.add(iterator.next());
Evan Millar11d628c2009-09-02 08:55:01 -0700336 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700337 mHasEntities = true;
Evan Millar11d628c2009-09-02 08:55:01 -0700338 } catch (RemoteException e) {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700339 Log.w(TAG, "Problem reading contact data: " + e.toString());
Evan Millar11d628c2009-09-02 08:55:01 -0700340 }
Evan Millar11d628c2009-09-02 08:55:01 -0700341 }
342
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700343 /**
344 * Read from the given {@link Cursor} and build a set of {@link DataStatus}
345 * objects to match any valid statuses found.
346 */
347 private synchronized void readStatuses(Cursor cursor) {
348 mStatuses.clear();
349
350 // Walk found statuses, creating internal row for each
351 while (cursor.moveToNext()) {
352 final DataStatus status = new DataStatus(cursor);
353 final long dataId = cursor.getLong(StatusQuery._ID);
354 mStatuses.put(dataId, status);
355 }
356
357 mHasStatuses = true;
358 }
359
360 private synchronized void startEntityQuery() {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700361 closeCursor();
362
Evan Millar6a61a1a2009-09-29 14:00:43 -0700363 Uri uri = null;
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700364 if (mLookupUri != null) {
365 mLookupUri = Contacts.getLookupUri(getContentResolver(), mLookupUri);
366 if (mLookupUri != null) {
Evan Millar6a61a1a2009-09-29 14:00:43 -0700367 uri = Contacts.lookupContact(getContentResolver(), mLookupUri);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700368 }
369 }
370
Evan Millar6a61a1a2009-09-29 14:00:43 -0700371 if (uri == null) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700372
373 // TODO either figure out a way to prevent a flash of black background or
374 // use some other UI than a toast
375 Toast.makeText(this, R.string.invalidContactMessage, Toast.LENGTH_SHORT).show();
376 Log.e(TAG, "invalid contact uri: " + mLookupUri);
377 finish();
378 return;
379 }
380
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700381 final Uri dataUri = Uri.withAppendedPath(uri, Contacts.Data.CONTENT_DIRECTORY);
382
383 // Keep stub cursor open on side to watch for change events
384 mCursor = mResolver.query(dataUri,
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700385 new String[] {Contacts.DISPLAY_NAME}, null, null, null);
386 mCursor.registerContentObserver(mObserver);
387
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700388 final long contactId = ContentUris.parseId(uri);
389
390 // Clear flags and start queries to data and status
391 mHasEntities = false;
392 mHasStatuses = false;
393
394 mHandler.startQueryEntities(TOKEN_ENTITIES, null, RawContacts.CONTENT_URI,
395 RawContacts.CONTACT_ID + "=" + contactId, null, null);
396 mHandler.startQuery(TOKEN_STATUSES, null, dataUri, StatusQuery.PROJECTION,
397 StatusUpdates.PRESENCE + " IS NOT NULL OR " + StatusUpdates.STATUS
398 + " IS NOT NULL", null, null);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700399
Evan Millar9b1a1242009-09-16 10:26:10 -0700400 mContactHeaderWidget.bindFromContactLookupUri(mLookupUri);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700401 }
402
403 private void closeCursor() {
404 if (mCursor != null) {
405 mCursor.unregisterContentObserver(mObserver);
406 mCursor.close();
407 mCursor = null;
408 }
Evan Millar11d628c2009-09-02 08:55:01 -0700409 }
410
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700411 /**
412 * Consider binding views after any of several background queries has
413 * completed. We check internal flags and only bind when all data has
414 * arrived.
415 */
416 private void considerBindData() {
417 if (mHasEntities && mHasStatuses) {
418 bindData();
419 }
420 }
421
Evan Millar11d628c2009-09-02 08:55:01 -0700422 private void bindData() {
423
424 // Build up the contact entries
425 buildEntries();
426
427 // Collapse similar data items in select sections.
428 Collapser.collapseList(mPhoneEntries);
429 Collapser.collapseList(mSmsEntries);
430 Collapser.collapseList(mEmailEntries);
431 Collapser.collapseList(mPostalEntries);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700432 Collapser.collapseList(mImEntries);
Evan Millar11d628c2009-09-02 08:55:01 -0700433
434 if (mAdapter == null) {
435 mAdapter = new ViewAdapter(this, mSections);
436 mListView.setAdapter(mAdapter);
437 } else {
438 mAdapter.setSections(mSections, SHOW_SEPARATORS);
439 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800440 }
441
442 @Override
443 public boolean onCreateOptionsMenu(Menu menu) {
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700444 super.onCreateOptionsMenu(menu);
445
446 final MenuInflater inflater = getMenuInflater();
447 inflater.inflate(R.menu.view, menu);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800448 return true;
449 }
450
451 @Override
452 public boolean onPrepareOptionsMenu(Menu menu) {
453 super.onPrepareOptionsMenu(menu);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700454
Evan Millar51514db2009-09-22 11:42:35 -0700455 // Only allow edit when we have at least one raw_contact id
456 final boolean hasRawContact = (mRawContactIds.size() > 0);
Evan Millar2e1b8af2009-09-24 09:39:21 -0700457 menu.findItem(R.id.menu_edit).setEnabled(hasRawContact);
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700458
Jeff Sharkeye0408762009-11-03 12:57:16 -0800459 // Only allow share when unrestricted contacts available
460 menu.findItem(R.id.menu_share).setEnabled(!mAllRestricted);
461
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800462 return true;
463 }
464
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800465 @Override
466 public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
467 AdapterView.AdapterContextMenuInfo info;
468 try {
469 info = (AdapterView.AdapterContextMenuInfo) menuInfo;
470 } catch (ClassCastException e) {
471 Log.e(TAG, "bad menuInfo", e);
472 return;
473 }
474
475 // This can be null sometimes, don't crash...
476 if (info == null) {
477 Log.e(TAG, "bad menuInfo");
478 return;
479 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700480
Evan Millar45e0ed32009-06-01 16:44:38 -0700481 ViewEntry entry = ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
Neel Parekha8fb68a2009-09-25 18:05:18 -0700482 menu.setHeaderTitle(R.string.contactOptionsTitle);
Evan Millar45e0ed32009-06-01 16:44:38 -0700483 if (entry.mimetype.equals(CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
484 menu.add(0, 0, 0, R.string.menu_call).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700485 menu.add(0, 0, 0, R.string.menu_sendSMS).setIntent(entry.secondaryIntent);
486 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700487 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultNumber);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800488 }
Evan Millar45e0ed32009-06-01 16:44:38 -0700489 } else if (entry.mimetype.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
490 menu.add(0, 0, 0, R.string.menu_sendEmail).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700491 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700492 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultEmail);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800493 }
Jeff Sharkeyc6ad3ab2009-07-21 19:30:15 -0700494 } else if (entry.mimetype.equals(CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700495 menu.add(0, 0, 0, R.string.menu_viewAddress).setIntent(entry.intent);
496 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800497 }
498
499 @Override
500 public boolean onOptionsItemSelected(MenuItem item) {
501 switch (item.getItemId()) {
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700502 case R.id.menu_edit: {
Evan Millardf181202009-09-30 15:15:51 -0700503 Long rawContactIdToEdit = null;
504 if (mRawContactIds.size() > 0) {
505 rawContactIdToEdit = mRawContactIds.get(0);
506 } else {
507 // There is no rawContact to edit.
508 break;
Evan Millardb5d88c2009-08-28 09:31:57 -0700509 }
Evan Millar2e1b8af2009-09-24 09:39:21 -0700510 Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI,
511 rawContactIdToEdit);
Evan Millar9cd81242009-09-26 16:02:31 -0700512 startActivityForResult(new Intent(Intent.ACTION_EDIT, rawContactUri),
513 REQUEST_EDIT_CONTACT);
Evan Millar8a79cee2009-08-19 17:20:49 -0700514 break;
515 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700516 case R.id.menu_delete: {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800517 // Get confirmation
Evan Millarcdeea942009-10-07 11:47:35 -0700518 if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) {
Megha Joshid5afd8a2009-09-22 09:38:41 -0700519 showDialog(DIALOG_CONFIRM_READONLY_DELETE);
Evan Millarcdeea942009-10-07 11:47:35 -0700520 } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
Megha Joshic508bd82009-10-01 17:31:49 -0700521 showDialog(DIALOG_CONFIRM_READONLY_HIDE);
Evan Millarcdeea942009-10-07 11:47:35 -0700522 } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
523 showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE);
524 } else {
525 showDialog(DIALOG_CONFIRM_DELETE);
526 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800527 return true;
528 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700529 case R.id.menu_join: {
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700530 showJoinAggregateActivity();
531 return true;
532 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700533 case R.id.menu_options: {
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700534 showOptionsActivity();
535 return true;
536 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700537 case R.id.menu_share: {
Jeff Sharkeye0408762009-11-03 12:57:16 -0800538 if (mAllRestricted) return false;
539
Jeff Sharkey93049312009-09-27 17:28:13 -0700540 // TODO: Keep around actual LOOKUP_KEY, or formalize method of extracting
541 final String lookupKey = mLookupUri.getPathSegments().get(2);
542 final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
543
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700544 final Intent intent = new Intent(Intent.ACTION_SEND);
Jeff Sharkey93049312009-09-27 17:28:13 -0700545 intent.setType(Contacts.CONTENT_VCARD_TYPE);
546 intent.putExtra(Intent.EXTRA_STREAM, shareUri);
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700547
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700548 // Launch chooser to share contact via
549 final CharSequence chooseTitle = getText(R.string.share_via);
550 final Intent chooseIntent = Intent.createChooser(intent, chooseTitle);
Evan Millar5c22c3b2009-05-29 11:37:54 -0700551
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700552 try {
553 startActivity(chooseIntent);
554 } catch (ActivityNotFoundException ex) {
555 Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800556 }
Jeff Sharkey49d17b32009-09-07 02:14:21 -0700557 return true;
558 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800559 }
560 return super.onOptionsItemSelected(item);
561 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700562
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800563 @Override
564 public boolean onContextItemSelected(MenuItem item) {
565 switch (item.getItemId()) {
566 case MENU_ITEM_MAKE_DEFAULT: {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700567 if (makeItemDefault(item)) {
568 return true;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800569 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700570 break;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800571 }
572 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700573
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800574 return super.onContextItemSelected(item);
575 }
576
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700577 private boolean makeItemDefault(MenuItem item) {
578 ViewEntry entry = getViewEntryForMenuItem(item);
579 if (entry == null) {
580 return false;
581 }
582
583 // Update the primary values in the data record.
Evan Millar14fecb62009-09-09 09:23:12 -0700584 ContentValues values = new ContentValues(1);
Evan Millar54a5c9f2009-06-23 17:41:09 -0700585 values.put(Data.IS_SUPER_PRIMARY, 1);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700586 getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, entry.id),
587 values, null, null);
Evan Millar11d628c2009-09-02 08:55:01 -0700588 startEntityQuery();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700589 return true;
590 }
591
592 /**
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700593 * Shows a list of aggregates that can be joined into the currently viewed aggregate.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700594 */
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700595 public void showJoinAggregateActivity() {
Evan Millar6a61a1a2009-09-29 14:00:43 -0700596 long freshId = getRefreshedContactId();
597 if (freshId > 0) {
598 String displayName = null;
599 if (mCursor.moveToFirst()) {
600 displayName = mCursor.getString(0);
601 }
602 Intent intent = new Intent(ContactsListActivity.JOIN_AGGREGATE);
603 intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_ID, freshId);
604 if (displayName != null) {
605 intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_NAME, displayName);
606 }
607 startActivityForResult(intent, REQUEST_JOIN_CONTACT);
Dmitri Plotnikova5cfca32009-09-29 18:13:08 -0700608 }
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700609 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700610
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700611 @Override
612 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
Evan Millar2e1b8af2009-09-24 09:39:21 -0700613 if (requestCode == REQUEST_JOIN_CONTACT) {
614 if (resultCode == RESULT_OK && intent != null) {
615 final long contactId = ContentUris.parseId(intent.getData());
616 joinAggregate(contactId);
Evan Millar8a79cee2009-08-19 17:20:49 -0700617 }
Evan Millar9cd81242009-09-26 16:02:31 -0700618 } else if (requestCode == REQUEST_EDIT_CONTACT) {
Evan Millardf181202009-09-30 15:15:51 -0700619 if (resultCode == EditContactActivity.RESULT_CLOSE_VIEW_ACTIVITY) {
620 finish();
Jeff Hamilton5297c6a2009-10-01 02:22:33 -0700621 } else if (resultCode == Activity.RESULT_OK) {
Dmitri Plotnikov160e9da2009-09-30 23:48:12 -0700622 mLookupUri = intent.getData();
623 if (mLookupUri == null) {
624 finish();
625 }
Evan Millardf181202009-09-30 15:15:51 -0700626 }
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700627 }
628 }
629
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700630 private void splitContact(long rawContactId) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700631 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_SEPARATE);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700632
633 // The split operation may have removed the original aggregate contact, so we need
634 // to requery everything
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700635 Toast.makeText(this, R.string.contactsSplitMessage, Toast.LENGTH_LONG).show();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700636 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700637 }
638
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700639 private void joinAggregate(final long contactId) {
Dmitri Plotnikov39466592009-07-27 11:23:51 -0700640 Cursor c = mResolver.query(RawContacts.CONTENT_URI, new String[] {RawContacts._ID},
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700641 RawContacts.CONTACT_ID + "=" + contactId, null, null);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700642
643 try {
644 while(c.moveToNext()) {
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700645 long rawContactId = c.getLong(0);
646 setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_TOGETHER);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700647 }
648 } finally {
649 c.close();
650 }
651
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700652 Toast.makeText(this, R.string.contactsJoinedMessage, Toast.LENGTH_LONG).show();
653 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700654 }
655
656 /**
657 * Given a contact ID sets an aggregation exception to either join the contact with the
658 * current aggregate or split off.
659 */
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700660 protected void setAggregationException(long rawContactId, int exceptionType) {
Dmitri Plotnikovd09f75c2009-06-16 11:59:22 -0700661 ContentValues values = new ContentValues(3);
Dmitri Plotnikovf40ccdf2009-09-04 17:37:15 -0700662 for (long aRawContactId : mRawContactIds) {
663 if (aRawContactId != rawContactId) {
664 values.put(AggregationExceptions.RAW_CONTACT_ID1, aRawContactId);
665 values.put(AggregationExceptions.RAW_CONTACT_ID2, rawContactId);
666 values.put(AggregationExceptions.TYPE, exceptionType);
667 mResolver.update(AggregationExceptions.CONTENT_URI, values, null, null);
668 }
669 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700670 }
671
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700672 private void showOptionsActivity() {
673 final Intent intent = new Intent(this, ContactOptionsActivity.class);
Evan Millar6a61a1a2009-09-29 14:00:43 -0700674 intent.setData(mLookupUri);
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700675 startActivity(intent);
676 }
677
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700678 private ViewEntry getViewEntryForMenuItem(MenuItem item) {
679 AdapterView.AdapterContextMenuInfo info;
680 try {
681 info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
682 } catch (ClassCastException e) {
683 Log.e(TAG, "bad menuInfo", e);
684 return null;
685 }
686
687 return ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS);
688 }
689
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800690 @Override
691 public boolean onKeyDown(int keyCode, KeyEvent event) {
692 switch (keyCode) {
693 case KeyEvent.KEYCODE_CALL: {
694 try {
695 ITelephony phone = ITelephony.Stub.asInterface(
696 ServiceManager.checkService("phone"));
697 if (phone != null && !phone.isIdle()) {
698 // Skip out and let the key be handled at a higher level
699 break;
700 }
701 } catch (RemoteException re) {
702 // Fall through and try to call the contact
703 }
704
Evan Millar7911ff52009-07-21 15:55:18 -0700705 int index = mListView.getSelectedItemPosition();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800706 if (index != -1) {
707 ViewEntry entry = ViewAdapter.getEntry(mSections, index, SHOW_SEPARATORS);
Evan Millar66388be2009-05-28 15:41:07 -0700708 if (entry.intent.getAction() == Intent.ACTION_CALL_PRIVILEGED) {
709 startActivity(entry.intent);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800710 }
711 } else if (mNumPhoneNumbers != 0) {
712 // There isn't anything selected, call the default number
Evan Millar6a61a1a2009-09-29 14:00:43 -0700713 long freshContactId = getRefreshedContactId();
714 if (freshContactId > 0) {
715 Uri hardContacUri = ContentUris.withAppendedId(
716 Contacts.CONTENT_URI, freshContactId);
717 Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, hardContacUri);
718 startActivity(intent);
719 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800720 }
721 return true;
722 }
723
724 case KeyEvent.KEYCODE_DEL: {
Evan Millarcdeea942009-10-07 11:47:35 -0700725 if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) {
Megha Joshid5afd8a2009-09-22 09:38:41 -0700726 showDialog(DIALOG_CONFIRM_READONLY_DELETE);
Evan Millarcdeea942009-10-07 11:47:35 -0700727 } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
Megha Joshic508bd82009-10-01 17:31:49 -0700728 showDialog(DIALOG_CONFIRM_READONLY_HIDE);
Evan Millarcdeea942009-10-07 11:47:35 -0700729 } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
730 showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE);
731 } else {
732 showDialog(DIALOG_CONFIRM_DELETE);
733 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800734 return true;
735 }
736 }
737
738 return super.onKeyDown(keyCode, event);
739 }
740
Evan Millar7911ff52009-07-21 15:55:18 -0700741 public void onItemClick(AdapterView parent, View v, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800742 ViewEntry entry = ViewAdapter.getEntry(mSections, position, SHOW_SEPARATORS);
743 if (entry != null) {
744 Intent intent = entry.intent;
Evan Millardf181202009-09-30 15:15:51 -0700745 if (intent != null) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800746 try {
747 startActivity(intent);
748 } catch (ActivityNotFoundException e) {
749 Log.e(TAG, "No activity found for intent: " + intent);
750 signalError();
751 }
752 } else {
753 signalError();
754 }
755 } else {
756 signalError();
757 }
758 }
759
760 /**
761 * Signal an error to the user via a beep, or some other method.
762 */
763 private void signalError() {
764 //TODO: implement this when we have the sonification APIs
765 }
766
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800767 /**
768 * Build up the entries to display on the screen.
Evan Millar5c22c3b2009-05-29 11:37:54 -0700769 *
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800770 * @param personCursor the URI for the contact being displayed
771 */
Evan Millar11d628c2009-09-02 08:55:01 -0700772 private final void buildEntries() {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800773 // Clear out the old entries
774 final int numSections = mSections.size();
775 for (int i = 0; i < numSections; i++) {
776 mSections.get(i).clear();
777 }
778
Evan Millar7911ff52009-07-21 15:55:18 -0700779 mRawContactIds.clear();
Jeff Sharkeye0408762009-11-03 12:57:16 -0800780
Megha Joshid5afd8a2009-09-22 09:38:41 -0700781 mReadOnlySourcesCnt = 0;
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700782 mWritableSourcesCnt = 0;
Jeff Sharkeye0408762009-11-03 12:57:16 -0800783 mAllRestricted = true;
784
Megha Joshid5afd8a2009-09-22 09:38:41 -0700785 mWritableRawContactIds.clear();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700786
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700787 final Context context = this;
788 final Sources sources = Sources.getInstance(context);
Evan Millar11d628c2009-09-02 08:55:01 -0700789
Evan Millar66388be2009-05-28 15:41:07 -0700790 // Build up method entries
Evan Millar6a61a1a2009-09-29 14:00:43 -0700791 if (mLookupUri != null) {
Evan Millar11d628c2009-09-02 08:55:01 -0700792 for (Entity entity: mEntities) {
793 final ContentValues entValues = entity.getEntityValues();
794 final String accountType = entValues.getAsString(RawContacts.ACCOUNT_TYPE);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700795 final long rawContactId = entValues.getAsLong(RawContacts._ID);
Evan Millar7911ff52009-07-21 15:55:18 -0700796
Jeff Sharkeye0408762009-11-03 12:57:16 -0800797 // Mark when this contact has any unrestricted components
798 final boolean isRestricted = entValues.getAsInteger(RawContacts.IS_RESTRICTED) != 0;
799 if (!isRestricted) mAllRestricted = false;
800
Dmitri Plotnikov2a8cef02009-09-23 19:01:15 -0700801 if (!mRawContactIds.contains(rawContactId)) {
802 mRawContactIds.add(rawContactId);
803 }
Megha Joshic508bd82009-10-01 17:31:49 -0700804 ContactsSource contactsSource = sources.getInflatedSource(accountType,
805 ContactsSource.LEVEL_SUMMARY);
806 if (contactsSource != null && contactsSource.readOnly) {
807 mReadOnlySourcesCnt += 1;
808 } else {
809 mWritableSourcesCnt += 1;
Evan Millarcdeea942009-10-07 11:47:35 -0700810 mWritableRawContactIds.add(rawContactId);
811 }
Megha Joshic508bd82009-10-01 17:31:49 -0700812
Dmitri Plotnikov2a8cef02009-09-23 19:01:15 -0700813
Evan Millar11d628c2009-09-02 08:55:01 -0700814 for (NamedContentValues subValue : entity.getSubValues()) {
Jeff Sharkeyab066932009-09-21 09:55:30 -0700815 final ContentValues entryValues = subValue.values;
816 entryValues.put(Data.RAW_CONTACT_ID, rawContactId);
817
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700818 final long dataId = entryValues.getAsLong(Data._ID);
819 final String mimeType = entryValues.getAsString(Data.MIMETYPE);
820 if (mimeType == null) continue;
Evan Millar66388be2009-05-28 15:41:07 -0700821
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700822 final DataKind kind = sources.getKindOrFallback(accountType, mimeType, this,
Evan Millar11d628c2009-09-02 08:55:01 -0700823 ContactsSource.LEVEL_MIMETYPES);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700824 if (kind == null) continue;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800825
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700826 final ViewEntry entry = ViewEntry.fromValues(context, mimeType, kind,
827 rawContactId, dataId, entryValues);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800828
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700829 final boolean hasData = !TextUtils.isEmpty(entry.data);
Evan Millarff04a272009-09-26 15:23:37 -0700830 final boolean isSuperPrimary = entryValues.getAsInteger(
831 Data.IS_SUPER_PRIMARY) != 0;
Evan Millar11d628c2009-09-02 08:55:01 -0700832
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700833 if (Phone.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700834 // Build phone entries
835 mNumPhoneNumbers++;
Evan Millar11d628c2009-09-02 08:55:01 -0700836
Evan Millarff04a272009-09-26 15:23:37 -0700837 entry.intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700838 Uri.fromParts(Constants.SCHEME_TEL, entry.data, null));
Evan Millarff04a272009-09-26 15:23:37 -0700839 entry.secondaryIntent = new Intent(Intent.ACTION_SENDTO,
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700840 Uri.fromParts(Constants.SCHEME_SMSTO, entry.data, null));
Evan Millar49714ee2009-09-02 16:42:47 -0700841
Evan Millarff04a272009-09-26 15:23:37 -0700842 entry.isPrimary = isSuperPrimary;
843 mPhoneEntries.add(entry);
844
845 if (entry.type == CommonDataKinds.Phone.TYPE_MOBILE
846 || mShowSmsLinksForAllPhones) {
847 // Add an SMS entry
848 if (kind.iconAltRes > 0) {
849 entry.secondaryActionIcon = kind.iconAltRes;
Evan Millar49714ee2009-09-02 16:42:47 -0700850 }
Evan Millarff04a272009-09-26 15:23:37 -0700851 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700852 } else if (Email.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700853 // Build email entries
854 entry.intent = new Intent(Intent.ACTION_SENDTO,
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700855 Uri.fromParts(Constants.SCHEME_MAILTO, entry.data, null));
Evan Millarff04a272009-09-26 15:23:37 -0700856 entry.isPrimary = isSuperPrimary;
857 mEmailEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700858
859 // When Email rows have status, create additional Im row
860 final DataStatus status = mStatuses.get(entry.id);
861 if (status != null) {
862 final String imMime = Im.CONTENT_ITEM_TYPE;
863 final DataKind imKind = sources.getKindOrFallback(accountType,
864 imMime, this, ContactsSource.LEVEL_MIMETYPES);
865 final ViewEntry imEntry = ViewEntry.fromValues(context,
866 imMime, imKind, rawContactId, dataId, entryValues);
867 imEntry.intent = ContactsUtils.buildImIntent(entryValues);
868 imEntry.applyStatus(status, false);
869 mImEntries.add(imEntry);
870 }
871 } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700872 // Build postal entries
873 entry.maxLines = 4;
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700874 entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri);
Evan Millarff04a272009-09-26 15:23:37 -0700875 mPostalEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700876 } else if (Im.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
877 // Build IM entries
878 entry.intent = ContactsUtils.buildImIntent(entryValues);
Evan Millarff04a272009-09-26 15:23:37 -0700879 if (TextUtils.isEmpty(entry.label)) {
880 entry.label = getString(R.string.chat).toLowerCase();
881 }
Evan Millar11d628c2009-09-02 08:55:01 -0700882
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700883 // Apply presence and status details when available
884 final DataStatus status = mStatuses.get(entry.id);
885 if (status != null) {
886 entry.applyStatus(status, false);
Evan Millarff04a272009-09-26 15:23:37 -0700887 }
Evan Millarff04a272009-09-26 15:23:37 -0700888 mImEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700889 } else if ((Organization.CONTENT_ITEM_TYPE.equals(mimeType)
890 || Nickname.CONTENT_ITEM_TYPE.equals(mimeType)) && hasData) {
Evan Millarff04a272009-09-26 15:23:37 -0700891 // Build organization and note entries
892 entry.uri = null;
Evan Millar11d628c2009-09-02 08:55:01 -0700893 mOrganizationEntries.add(entry);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700894 } else if (Note.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
Evan Millar11d628c2009-09-02 08:55:01 -0700895 // Build note entries
Evan Millar11d628c2009-09-02 08:55:01 -0700896 entry.uri = null;
Evan Millar11d628c2009-09-02 08:55:01 -0700897 entry.maxLines = 10;
898 mOtherEntries.add(entry);
Evan Millar951fa9c2009-10-26 14:57:43 -0700899 } else if (Website.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) {
900 // Build note entries
901 entry.uri = null;
902 entry.maxLines = 10;
903 try {
904 WebAddress webAddress = new WebAddress(entry.data);
905 entry.intent = new Intent(Intent.ACTION_VIEW,
906 Uri.parse(webAddress.toString()));
907 } catch (ParseException e) {
908 Log.e(TAG, "Couldn't parse website: " + entry.data);
909 }
910 mOtherEntries.add(entry);
Jeff Sharkeyab066932009-09-21 09:55:30 -0700911 } else {
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700912 // Handle showing custom rows
Evan Millarff04a272009-09-26 15:23:37 -0700913 entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri);
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700914
915 // Use social summary when requested by external source
916 final DataStatus status = mStatuses.get(entry.id);
917 final boolean hasSocial = kind.actionBodySocial && status != null;
918 if (hasSocial) {
919 entry.applyStatus(status, true);
920 }
921
922 if (hasSocial || hasData) {
923 mOtherEntries.add(entry);
924 }
Evan Millar11d628c2009-09-02 08:55:01 -0700925 }
Evan Millar2e1b8af2009-09-24 09:39:21 -0700926 }
Evan Millar66388be2009-05-28 15:41:07 -0700927 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800928 }
929 }
930
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700931 static String buildActionString(DataKind kind, ContentValues values, boolean lowerCase,
932 Context context) {
Evan Millar11d628c2009-09-02 08:55:01 -0700933 if (kind.actionHeader == null) {
934 return null;
Jeff Hamilton8350e5b2009-03-24 21:01:34 -0700935 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700936 CharSequence actionHeader = kind.actionHeader.inflateUsing(context, values);
Evan Millar11d628c2009-09-02 08:55:01 -0700937 if (actionHeader == null) {
938 return null;
939 }
940 return lowerCase ? actionHeader.toString().toLowerCase() : actionHeader.toString();
941 }
Jeff Hamilton8350e5b2009-03-24 21:01:34 -0700942
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700943 static String buildDataString(DataKind kind, ContentValues values, Context context) {
Evan Millar11d628c2009-09-02 08:55:01 -0700944 if (kind.actionBody == null) {
945 return null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800946 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700947 CharSequence actionBody = kind.actionBody.inflateUsing(context, values);
Evan Millar11d628c2009-09-02 08:55:01 -0700948 return actionBody == null ? null : actionBody.toString();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800949 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700950
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800951 /**
952 * A basic structure with the data for a contact entry in the list.
953 */
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700954 static class ViewEntry extends ContactEntryAdapter.Entry implements Collapsible<ViewEntry> {
955 public Context context = null;
Jeff Sharkeyab066932009-09-21 09:55:30 -0700956 public String resPackageName = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800957 public int actionIcon = -1;
Evan Millar15e514d2009-08-04 10:14:57 -0700958 public boolean isPrimary = false;
Evan Millar15e514d2009-08-04 10:14:57 -0700959 public int secondaryActionIcon = -1;
960 public Intent intent;
961 public Intent secondaryIntent = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800962 public int maxLabelLines = 1;
Evan Millar54a5c9f2009-06-23 17:41:09 -0700963 public ArrayList<Long> ids = new ArrayList<Long>();
964 public int collapseCount = 0;
965
Jeff Sharkey624ddc32009-10-01 21:32:19 -0700966 public int presence = -1;
967 public int presenceIcon = -1;
968
969 public CharSequence footerLine = null;
970
971 private ViewEntry() {
972 }
973
974 /**
975 * Build new {@link ViewEntry} and populate from the given values.
976 */
977 public static ViewEntry fromValues(Context context, String mimeType, DataKind kind,
978 long rawContactId, long dataId, ContentValues values) {
979 final ViewEntry entry = new ViewEntry();
980 entry.context = context;
981 entry.contactId = rawContactId;
982 entry.id = dataId;
983 entry.uri = ContentUris.withAppendedId(Data.CONTENT_URI, entry.id);
984 entry.mimetype = mimeType;
985 entry.label = buildActionString(kind, values, false, context);
986 entry.data = buildDataString(kind, values, context);
987
988 if (kind.typeColumn != null && values.containsKey(kind.typeColumn)) {
989 entry.type = values.getAsInteger(kind.typeColumn);
990 }
991 if (kind.iconRes > 0) {
992 entry.resPackageName = kind.resPackageName;
993 entry.actionIcon = kind.iconRes;
994 }
995
996 return entry;
997 }
998
999 /**
1000 * Apply given {@link DataStatus} values over this {@link ViewEntry}
1001 *
1002 * @param fillData When true, the given status replaces {@link #data}
1003 * and {@link #footerLine}. Otherwise only {@link #presence}
1004 * is updated.
1005 */
1006 public ViewEntry applyStatus(DataStatus status, boolean fillData) {
1007 presence = status.getPresence();
1008 presenceIcon = (presence == -1) ? -1 :
1009 StatusUpdates.getPresenceIconResourceId(this.presence);
1010
1011 if (fillData && status.isValid()) {
1012 this.data = status.getStatus().toString();
1013 this.footerLine = status.getTimestampLabel(context);
1014 }
1015
1016 return this;
1017 }
1018
Evan Millar54a5c9f2009-06-23 17:41:09 -07001019 public boolean collapseWith(ViewEntry entry) {
1020 // assert equal collapse keys
Evan Millaradb0f8c2009-09-28 17:20:50 -07001021 if (!shouldCollapseWith(entry)) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001022 return false;
1023 }
1024
1025 // Choose the label associated with the highest type precedence.
1026 if (TypePrecedence.getTypePrecedence(mimetype, type)
1027 > TypePrecedence.getTypePrecedence(entry.mimetype, entry.type)) {
1028 type = entry.type;
1029 label = entry.label;
1030 }
1031
1032 // Choose the max of the maxLines and maxLabelLines values.
1033 maxLines = Math.max(maxLines, entry.maxLines);
1034 maxLabelLines = Math.max(maxLabelLines, entry.maxLabelLines);
1035
1036 // Choose the presence with the highest precedence.
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001037 if (StatusUpdates.getPresencePrecedence(presence)
1038 < StatusUpdates.getPresencePrecedence(entry.presence)) {
1039 presence = entry.presence;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001040 }
1041
1042 // If any of the collapsed entries are primary make the whole thing primary.
Evan Millar15e514d2009-08-04 10:14:57 -07001043 isPrimary = entry.isPrimary ? true : isPrimary;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001044
1045 // uri, and contactdId, shouldn't make a difference. Just keep the original.
1046
1047 // Keep track of all the ids that have been collapsed with this one.
1048 ids.add(entry.id);
1049 collapseCount++;
1050 return true;
1051 }
1052
Evan Millaradb0f8c2009-09-28 17:20:50 -07001053 public boolean shouldCollapseWith(ViewEntry entry) {
1054 if (entry == null) {
1055 return false;
1056 }
1057
Makoto Onukic710b0e2009-10-13 15:43:24 -07001058 if (!ContactsUtils.areDataEqual(context, mimetype, data, entry.mimetype, entry.data)) {
1059 return false;
Evan Millaradb0f8c2009-09-28 17:20:50 -07001060 }
1061
Makoto Onukic710b0e2009-10-13 15:43:24 -07001062 if (!TextUtils.equals(mimetype, entry.mimetype)
1063 || !ContactsUtils.areIntentActionEqual(intent, entry.intent)
1064 || !ContactsUtils.areIntentActionEqual(secondaryIntent, entry.secondaryIntent)
Evan Millaradb0f8c2009-09-28 17:20:50 -07001065 || actionIcon != entry.actionIcon) {
1066 return false;
1067 }
1068
1069 return true;
1070 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001071 }
1072
Evan Millar15e514d2009-08-04 10:14:57 -07001073 /** Cache of the children views of a row */
1074 static class ViewCache {
1075 public TextView label;
1076 public TextView data;
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001077 public TextView footer;
Evan Millar15e514d2009-08-04 10:14:57 -07001078 public ImageView actionIcon;
1079 public ImageView presenceIcon;
1080 public ImageView primaryIcon;
1081 public ImageView secondaryActionButton;
1082 public View secondaryActionDivider;
Evan Millar5c22c3b2009-05-29 11:37:54 -07001083
Evan Millar15e514d2009-08-04 10:14:57 -07001084 // Need to keep track of this too
1085 ViewEntry entry;
1086 }
1087
1088 private final class ViewAdapter extends ContactEntryAdapter<ViewEntry>
1089 implements View.OnClickListener {
1090
Evan Millar5c22c3b2009-05-29 11:37:54 -07001091
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001092 ViewAdapter(Context context, ArrayList<ArrayList<ViewEntry>> sections) {
1093 super(context, sections, SHOW_SEPARATORS);
1094 }
1095
Evan Millar15e514d2009-08-04 10:14:57 -07001096 public void onClick(View v) {
1097 Intent intent = (Intent) v.getTag();
1098 startActivity(intent);
1099 }
1100
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001101 @Override
1102 public View getView(int position, View convertView, ViewGroup parent) {
Evan Millar5c22c3b2009-05-29 11:37:54 -07001103 ViewEntry entry = getEntry(mSections, position, false);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001104 View v;
1105
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001106 ViewCache views;
1107
1108 // Check to see if we can reuse convertView
1109 if (convertView != null) {
1110 v = convertView;
1111 views = (ViewCache) v.getTag();
1112 } else {
1113 // Create a new view if needed
1114 v = mInflater.inflate(R.layout.list_item_text_icons, parent, false);
1115
1116 // Cache the children
1117 views = new ViewCache();
1118 views.label = (TextView) v.findViewById(android.R.id.text1);
1119 views.data = (TextView) v.findViewById(android.R.id.text2);
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001120 views.footer = (TextView) v.findViewById(R.id.footer);
Evan Millar15e514d2009-08-04 10:14:57 -07001121 views.actionIcon = (ImageView) v.findViewById(R.id.action_icon);
1122 views.primaryIcon = (ImageView) v.findViewById(R.id.primary_icon);
1123 views.presenceIcon = (ImageView) v.findViewById(R.id.presence_icon);
1124 views.secondaryActionButton = (ImageView) v.findViewById(
1125 R.id.secondary_action_button);
1126 views.secondaryActionButton.setOnClickListener(this);
Evan Millar15e514d2009-08-04 10:14:57 -07001127 views.secondaryActionDivider = v.findViewById(R.id.divider);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001128 v.setTag(views);
1129 }
1130
1131 // Update the entry in the view cache
1132 views.entry = entry;
1133
1134 // Bind the data to the view
1135 bindView(v, entry);
1136 return v;
1137 }
1138
1139 @Override
1140 protected View newView(int position, ViewGroup parent) {
1141 // getView() handles this
1142 throw new UnsupportedOperationException();
1143 }
1144
1145 @Override
1146 protected void bindView(View view, ViewEntry entry) {
1147 final Resources resources = mContext.getResources();
1148 ViewCache views = (ViewCache) view.getTag();
1149
1150 // Set the label
1151 TextView label = views.label;
1152 setMaxLines(label, entry.maxLabelLines);
1153 label.setText(entry.label);
1154
1155 // Set the data
1156 TextView data = views.data;
1157 if (data != null) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001158 if (entry.mimetype.equals(Phone.CONTENT_ITEM_TYPE)
Jeff Sharkey49d17b32009-09-07 02:14:21 -07001159 || entry.mimetype.equals(Constants.MIME_SMS_ADDRESS)) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001160 data.setText(PhoneNumberUtils.formatNumber(entry.data));
1161 } else {
1162 data.setText(entry.data);
1163 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001164 setMaxLines(data, entry.maxLines);
1165 }
1166
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001167 // Set the footer
1168 if (!TextUtils.isEmpty(entry.footerLine)) {
1169 views.footer.setText(entry.footerLine);
1170 views.footer.setVisibility(View.VISIBLE);
1171 } else {
1172 views.footer.setVisibility(View.GONE);
1173 }
1174
Evan Millar15e514d2009-08-04 10:14:57 -07001175 // Set the primary icon
1176 views.primaryIcon.setVisibility(entry.isPrimary ? View.VISIBLE : View.GONE);
1177
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001178 // Set the action icon
1179 ImageView action = views.actionIcon;
1180 if (entry.actionIcon != -1) {
Jeff Sharkeyab066932009-09-21 09:55:30 -07001181 Drawable actionIcon;
1182 if (entry.resPackageName != null) {
1183 // Load external resources through PackageManager
1184 actionIcon = mContext.getPackageManager().getDrawable(entry.resPackageName,
1185 entry.actionIcon, null);
1186 } else {
1187 actionIcon = resources.getDrawable(entry.actionIcon);
1188 }
1189 action.setImageDrawable(actionIcon);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001190 action.setVisibility(View.VISIBLE);
1191 } else {
1192 // Things should still line up as if there was an icon, so make it invisible
1193 action.setVisibility(View.INVISIBLE);
1194 }
1195
1196 // Set the presence icon
1197 Drawable presenceIcon = null;
Evan Millar15e514d2009-08-04 10:14:57 -07001198 if (entry.presenceIcon != -1) {
1199 presenceIcon = resources.getDrawable(entry.presenceIcon);
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001200 } else if (entry.presence != -1) {
Evan Millar54a5c9f2009-06-23 17:41:09 -07001201 presenceIcon = resources.getDrawable(
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001202 StatusUpdates.getPresenceIconResourceId(entry.presence));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001203 }
Evan Millar15e514d2009-08-04 10:14:57 -07001204 ImageView presenceIconView = views.presenceIcon;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001205 if (presenceIcon != null) {
Evan Millar15e514d2009-08-04 10:14:57 -07001206 presenceIconView.setImageDrawable(presenceIcon);
1207 presenceIconView.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001208 } else {
Evan Millar15e514d2009-08-04 10:14:57 -07001209 presenceIconView.setVisibility(View.GONE);
1210 }
1211
1212 // Set the secondary action button
1213 ImageView secondaryActionView = views.secondaryActionButton;
1214 Drawable secondaryActionIcon = null;
1215 if (entry.secondaryActionIcon != -1) {
1216 secondaryActionIcon = resources.getDrawable(entry.secondaryActionIcon);
1217 }
1218 if (entry.secondaryIntent != null && secondaryActionIcon != null) {
1219 secondaryActionView.setImageDrawable(secondaryActionIcon);
1220 secondaryActionView.setTag(entry.secondaryIntent);
1221 secondaryActionView.setVisibility(View.VISIBLE);
1222 views.secondaryActionDivider.setVisibility(View.VISIBLE);
1223 } else {
1224 secondaryActionView.setVisibility(View.GONE);
1225 views.secondaryActionDivider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001226 }
1227 }
1228
1229 private void setMaxLines(TextView textView, int maxLines) {
1230 if (maxLines == 1) {
1231 textView.setSingleLine(true);
1232 textView.setEllipsize(TextUtils.TruncateAt.END);
1233 } else {
1234 textView.setSingleLine(false);
1235 textView.setMaxLines(maxLines);
1236 textView.setEllipsize(null);
1237 }
1238 }
1239 }
Jeff Sharkey624ddc32009-10-01 21:32:19 -07001240
1241 private interface StatusQuery {
1242 final String[] PROJECTION = new String[] {
1243 Data._ID,
1244 Data.STATUS,
1245 Data.STATUS_RES_PACKAGE,
1246 Data.STATUS_ICON,
1247 Data.STATUS_LABEL,
1248 Data.STATUS_TIMESTAMP,
1249 Data.PRESENCE,
1250 };
1251
1252 final int _ID = 0;
1253 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001254}