The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.contacts; |
| 18 | |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 19 | import com.android.contacts.Collapser.Collapsible; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 20 | import com.android.contacts.model.ContactsSource; |
| 21 | import com.android.contacts.model.Sources; |
| 22 | import com.android.contacts.model.ContactsSource.DataKind; |
Evan Millar | df18120 | 2009-09-30 15:15:51 -0700 | [diff] [blame] | 23 | import com.android.contacts.ui.EditContactActivity; |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 24 | import com.android.contacts.util.Constants; |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 25 | import com.android.contacts.util.DataStatus; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 26 | import com.android.contacts.util.NotifyingAsyncQueryHandler; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 27 | import com.android.internal.telephony.ITelephony; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 28 | import com.android.internal.widget.ContactHeaderWidget; |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 29 | import com.google.android.collect.Lists; |
| 30 | import com.google.android.collect.Maps; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 31 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 32 | import android.app.Activity; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 33 | import android.app.AlertDialog; |
| 34 | import android.app.Dialog; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 35 | import android.content.ActivityNotFoundException; |
| 36 | import android.content.ContentResolver; |
| 37 | import android.content.ContentUris; |
| 38 | import android.content.ContentValues; |
| 39 | import android.content.Context; |
| 40 | import android.content.DialogInterface; |
Evan Millar | 5f4af70 | 2009-08-11 11:12:00 -0700 | [diff] [blame] | 41 | import android.content.Entity; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 42 | import android.content.EntityIterator; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 43 | import android.content.Intent; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 44 | import android.content.Entity.NamedContentValues; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 45 | import android.content.res.Resources; |
| 46 | import android.database.ContentObserver; |
| 47 | import android.database.Cursor; |
| 48 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 49 | import android.net.Uri; |
| 50 | import android.os.Bundle; |
| 51 | import android.os.Handler; |
| 52 | import android.os.RemoteException; |
| 53 | import android.os.ServiceManager; |
Dmitri Plotnikov | 4e3a043 | 2009-09-15 13:54:40 -0700 | [diff] [blame] | 54 | import android.provider.ContactsContract; |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 55 | import android.provider.ContactsContract.AggregationExceptions; |
| 56 | import android.provider.ContactsContract.CommonDataKinds; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 57 | import android.provider.ContactsContract.Contacts; |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 58 | import android.provider.ContactsContract.Data; |
Dmitri Plotnikov | 3946659 | 2009-07-27 11:23:51 -0700 | [diff] [blame] | 59 | import android.provider.ContactsContract.RawContacts; |
Dmitri Plotnikov | 160e9da | 2009-09-30 23:48:12 -0700 | [diff] [blame] | 60 | import android.provider.ContactsContract.StatusUpdates; |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 61 | import android.provider.ContactsContract.CommonDataKinds.Email; |
| 62 | import android.provider.ContactsContract.CommonDataKinds.Im; |
| 63 | import android.provider.ContactsContract.CommonDataKinds.Nickname; |
| 64 | import android.provider.ContactsContract.CommonDataKinds.Note; |
| 65 | import android.provider.ContactsContract.CommonDataKinds.Organization; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 66 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 67 | import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 68 | import android.telephony.PhoneNumberUtils; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 69 | import android.text.TextUtils; |
| 70 | import android.util.Log; |
| 71 | import android.view.ContextMenu; |
| 72 | import android.view.KeyEvent; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 73 | import android.view.LayoutInflater; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 74 | import android.view.Menu; |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 75 | import android.view.MenuInflater; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 76 | import android.view.MenuItem; |
| 77 | import android.view.View; |
| 78 | import android.view.ViewGroup; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 79 | import android.view.Window; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 80 | import android.view.ContextMenu.ContextMenuInfo; |
| 81 | import android.widget.AdapterView; |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 82 | import android.widget.FrameLayout; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 83 | import android.widget.ImageView; |
| 84 | import android.widget.ListView; |
| 85 | import android.widget.TextView; |
| 86 | import android.widget.Toast; |
| 87 | |
| 88 | import java.util.ArrayList; |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 89 | import java.util.HashMap; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * Displays the details of a specific contact. |
| 93 | */ |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 94 | public class ViewContactActivity extends Activity |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 95 | implements View.OnCreateContextMenuListener, DialogInterface.OnClickListener, |
Evan Millar | df18120 | 2009-09-30 15:15:51 -0700 | [diff] [blame] | 96 | AdapterView.OnItemClickListener, NotifyingAsyncQueryHandler.AsyncQueryListener { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 97 | private static final String TAG = "ViewContact"; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 98 | |
| 99 | private static final boolean SHOW_SEPARATORS = false; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 100 | |
| 101 | private static final int DIALOG_CONFIRM_DELETE = 1; |
Megha Joshi | d5afd8a | 2009-09-22 09:38:41 -0700 | [diff] [blame] | 102 | private static final int DIALOG_CONFIRM_READONLY_DELETE = 2; |
| 103 | private static final int DIALOG_CONFIRM_MULTIPLE_DELETE = 3; |
Megha Joshi | c508bd8 | 2009-10-01 17:31:49 -0700 | [diff] [blame] | 104 | private static final int DIALOG_CONFIRM_READONLY_HIDE = 4; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 105 | |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 106 | private static final int REQUEST_JOIN_CONTACT = 1; |
Evan Millar | 9cd8124 | 2009-09-26 16:02:31 -0700 | [diff] [blame] | 107 | private static final int REQUEST_EDIT_CONTACT = 2; |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 108 | |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 109 | public static final int MENU_ITEM_MAKE_DEFAULT = 3; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 110 | |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 111 | protected Uri mLookupUri; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 112 | private ContentResolver mResolver; |
| 113 | private ViewAdapter mAdapter; |
| 114 | private int mNumPhoneNumbers = 0; |
| 115 | |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 116 | /** |
Dmitri Plotnikov | e1cd679 | 2009-07-27 20:28:17 -0700 | [diff] [blame] | 117 | * A list of distinct contact IDs included in the current contact. |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 118 | */ |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 119 | private ArrayList<Long> mRawContactIds = new ArrayList<Long>(); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 120 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 121 | /* package */ ArrayList<ViewEntry> mPhoneEntries = new ArrayList<ViewEntry>(); |
| 122 | /* package */ ArrayList<ViewEntry> mSmsEntries = new ArrayList<ViewEntry>(); |
| 123 | /* package */ ArrayList<ViewEntry> mEmailEntries = new ArrayList<ViewEntry>(); |
| 124 | /* package */ ArrayList<ViewEntry> mPostalEntries = new ArrayList<ViewEntry>(); |
| 125 | /* package */ ArrayList<ViewEntry> mImEntries = new ArrayList<ViewEntry>(); |
| 126 | /* package */ ArrayList<ViewEntry> mOrganizationEntries = new ArrayList<ViewEntry>(); |
The Android Open Source Project | cac191e | 2009-03-18 22:20:27 -0700 | [diff] [blame] | 127 | /* package */ ArrayList<ViewEntry> mGroupEntries = new ArrayList<ViewEntry>(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 128 | /* package */ ArrayList<ViewEntry> mOtherEntries = new ArrayList<ViewEntry>(); |
| 129 | /* package */ ArrayList<ArrayList<ViewEntry>> mSections = new ArrayList<ArrayList<ViewEntry>>(); |
| 130 | |
| 131 | private Cursor mCursor; |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 132 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 133 | protected ContactHeaderWidget mContactHeaderWidget; |
| 134 | private NotifyingAsyncQueryHandler mHandler; |
| 135 | |
| 136 | protected LayoutInflater mInflater; |
| 137 | |
Megha Joshi | d5afd8a | 2009-09-22 09:38:41 -0700 | [diff] [blame] | 138 | protected int mReadOnlySourcesCnt; |
| 139 | protected int mWritableSourcesCnt; |
| 140 | protected ArrayList<Long> mWritableRawContactIds = new ArrayList<Long>(); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 141 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 142 | private static final int TOKEN_ENTITIES = 0; |
| 143 | private static final int TOKEN_STATUSES = 1; |
| 144 | |
| 145 | private boolean mHasEntities = false; |
| 146 | private boolean mHasStatuses = false; |
| 147 | |
| 148 | private ArrayList<Entity> mEntities = Lists.newArrayList(); |
| 149 | private HashMap<Long, DataStatus> mStatuses = Maps.newHashMap(); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 150 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 151 | private ContentObserver mObserver = new ContentObserver(new Handler()) { |
| 152 | @Override |
| 153 | public boolean deliverSelfNotifications() { |
| 154 | return true; |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public void onChange(boolean selfChange) { |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 159 | if (mCursor != null && !mCursor.isClosed()) { |
| 160 | startEntityQuery(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | }; |
| 164 | |
| 165 | public void onClick(DialogInterface dialog, int which) { |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 166 | closeCursor(); |
Megha Joshi | c508bd8 | 2009-10-01 17:31:49 -0700 | [diff] [blame] | 167 | getContentResolver().delete(mLookupUri, null, null); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 168 | finish(); |
| 169 | } |
| 170 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 171 | private FrameLayout mTabContentLayout; |
| 172 | private ListView mListView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 173 | private boolean mShowSmsLinksForAllPhones; |
| 174 | |
| 175 | @Override |
| 176 | protected void onCreate(Bundle icicle) { |
| 177 | super.onCreate(icicle); |
| 178 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 179 | final Intent intent = getIntent(); |
Dmitri Plotnikov | 4e3a043 | 2009-09-15 13:54:40 -0700 | [diff] [blame] | 180 | Uri data = intent.getData(); |
| 181 | String authority = data.getAuthority(); |
| 182 | if (ContactsContract.AUTHORITY.equals(authority)) { |
| 183 | mLookupUri = data; |
| 184 | } else if (android.provider.Contacts.AUTHORITY.equals(authority)) { |
| 185 | final long rawContactId = ContentUris.parseId(data); |
| 186 | mLookupUri = RawContacts.getContactLookupUri(getContentResolver(), |
| 187 | ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); |
Dmitri Plotnikov | 83129f0 | 2009-09-02 19:04:41 -0700 | [diff] [blame] | 188 | |
Dmitri Plotnikov | 4e3a043 | 2009-09-15 13:54:40 -0700 | [diff] [blame] | 189 | } |
Dmitri Plotnikov | 83129f0 | 2009-09-02 19:04:41 -0700 | [diff] [blame] | 190 | mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 191 | |
| 192 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
| 193 | setContentView(R.layout.contact_card_layout); |
| 194 | |
| 195 | mContactHeaderWidget = (ContactHeaderWidget) findViewById(R.id.contact_header_widget); |
| 196 | mContactHeaderWidget.showStar(true); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 197 | mContactHeaderWidget.setExcludeMimes(new String[] { |
| 198 | Contacts.CONTENT_ITEM_TYPE |
| 199 | }); |
| 200 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 201 | mHandler = new NotifyingAsyncQueryHandler(this, this); |
| 202 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 203 | mListView = new ListView(this); |
| 204 | mListView.setOnCreateContextMenuListener(this); |
| 205 | mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY); |
| 206 | mListView.setOnItemClickListener(this); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 207 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 208 | mTabContentLayout = (FrameLayout) findViewById(android.R.id.tabcontent); |
| 209 | mTabContentLayout.addView(mListView); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 210 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 211 | 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 Project | cac191e | 2009-03-18 22:20:27 -0700 | [diff] [blame] | 221 | mSections.add(mGroupEntries); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 222 | mSections.add(mOtherEntries); |
| 223 | |
| 224 | //TODO Read this value from a preference |
| 225 | mShowSmsLinksForAllPhones = true; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 226 | } |
| 227 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 228 | @Override |
| 229 | protected void onResume() { |
| 230 | super.onResume(); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 231 | startEntityQuery(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | @Override |
| 235 | protected void onPause() { |
| 236 | super.onPause(); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 237 | closeCursor(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
| 241 | protected void onDestroy() { |
| 242 | super.onDestroy(); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 243 | closeCursor(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 244 | } |
| 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 Joshi | d5afd8a | 2009-09-22 09:38:41 -0700 | [diff] [blame] | 258 | case DIALOG_CONFIRM_READONLY_DELETE: |
| 259 | return new AlertDialog.Builder(this) |
| 260 | .setTitle(R.string.deleteConfirmation_title) |
| 261 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 262 | .setMessage(R.string.readOnlyContactDeleteConfirmation) |
| 263 | .setNegativeButton(android.R.string.cancel, null) |
| 264 | .setPositiveButton(android.R.string.ok, this) |
| 265 | .setCancelable(false) |
| 266 | .create(); |
| 267 | case DIALOG_CONFIRM_MULTIPLE_DELETE: |
| 268 | return new AlertDialog.Builder(this) |
| 269 | .setTitle(R.string.deleteConfirmation_title) |
| 270 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 271 | .setMessage(R.string.multipleContactDeleteConfirmation) |
| 272 | .setNegativeButton(android.R.string.cancel, null) |
| 273 | .setPositiveButton(android.R.string.ok, this) |
| 274 | .setCancelable(false) |
| 275 | .create(); |
Megha Joshi | c508bd8 | 2009-10-01 17:31:49 -0700 | [diff] [blame] | 276 | case DIALOG_CONFIRM_READONLY_HIDE: { |
| 277 | return new AlertDialog.Builder(this) |
| 278 | .setTitle(R.string.deleteConfirmation_title) |
| 279 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 280 | .setMessage(R.string.readOnlyContactWarning) |
| 281 | .setPositiveButton(android.R.string.ok, this) |
| 282 | .create(); |
| 283 | } |
| 284 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 285 | } |
| 286 | return null; |
| 287 | } |
| 288 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 289 | // QUERY CODE // |
| 290 | /** {@inheritDoc} */ |
| 291 | public void onQueryEntitiesComplete(int token, Object cookie, EntityIterator iterator) { |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 292 | try { |
| 293 | // Read incoming entities and consider binding |
| 294 | readEntities(iterator); |
| 295 | considerBindData(); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 296 | } 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 Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 305 | 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 Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Evan Millar | 6a61a1a | 2009-09-29 14:00:43 -0700 | [diff] [blame] | 316 | 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 Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 324 | /** |
| 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 Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 330 | try { |
| 331 | while (iterator.hasNext()) { |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 332 | mEntities.add(iterator.next()); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 333 | } |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 334 | mHasEntities = true; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 335 | } catch (RemoteException e) { |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 336 | Log.w(TAG, "Problem reading contact data: " + e.toString()); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 337 | } |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 340 | /** |
| 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 Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 358 | closeCursor(); |
| 359 | |
Evan Millar | 6a61a1a | 2009-09-29 14:00:43 -0700 | [diff] [blame] | 360 | Uri uri = null; |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 361 | if (mLookupUri != null) { |
| 362 | mLookupUri = Contacts.getLookupUri(getContentResolver(), mLookupUri); |
| 363 | if (mLookupUri != null) { |
Evan Millar | 6a61a1a | 2009-09-29 14:00:43 -0700 | [diff] [blame] | 364 | uri = Contacts.lookupContact(getContentResolver(), mLookupUri); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
Evan Millar | 6a61a1a | 2009-09-29 14:00:43 -0700 | [diff] [blame] | 368 | if (uri == null) { |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 369 | |
| 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 Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 378 | 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 Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 382 | new String[] {Contacts.DISPLAY_NAME}, null, null, null); |
| 383 | mCursor.registerContentObserver(mObserver); |
| 384 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 385 | 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 Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 396 | |
Evan Millar | 9b1a124 | 2009-09-16 10:26:10 -0700 | [diff] [blame] | 397 | mContactHeaderWidget.bindFromContactLookupUri(mLookupUri); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | private void closeCursor() { |
| 401 | if (mCursor != null) { |
| 402 | mCursor.unregisterContentObserver(mObserver); |
| 403 | mCursor.close(); |
| 404 | mCursor = null; |
| 405 | } |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 408 | /** |
| 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 Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 419 | 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 Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 429 | Collapser.collapseList(mImEntries); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 430 | |
| 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 Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | @Override |
| 440 | public boolean onCreateOptionsMenu(Menu menu) { |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 441 | super.onCreateOptionsMenu(menu); |
| 442 | |
| 443 | final MenuInflater inflater = getMenuInflater(); |
| 444 | inflater.inflate(R.menu.view, menu); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 445 | return true; |
| 446 | } |
| 447 | |
| 448 | @Override |
| 449 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 450 | super.onPrepareOptionsMenu(menu); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 451 | |
Evan Millar | 51514db | 2009-09-22 11:42:35 -0700 | [diff] [blame] | 452 | // Only allow edit when we have at least one raw_contact id |
| 453 | final boolean hasRawContact = (mRawContactIds.size() > 0); |
Evan Millar | 2e1b8af | 2009-09-24 09:39:21 -0700 | [diff] [blame] | 454 | menu.findItem(R.id.menu_edit).setEnabled(hasRawContact); |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 455 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 456 | return true; |
| 457 | } |
| 458 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 459 | @Override |
| 460 | public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { |
| 461 | AdapterView.AdapterContextMenuInfo info; |
| 462 | try { |
| 463 | info = (AdapterView.AdapterContextMenuInfo) menuInfo; |
| 464 | } catch (ClassCastException e) { |
| 465 | Log.e(TAG, "bad menuInfo", e); |
| 466 | return; |
| 467 | } |
| 468 | |
| 469 | // This can be null sometimes, don't crash... |
| 470 | if (info == null) { |
| 471 | Log.e(TAG, "bad menuInfo"); |
| 472 | return; |
| 473 | } |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 474 | |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 475 | ViewEntry entry = ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS); |
Neel Parekh | a8fb68a | 2009-09-25 18:05:18 -0700 | [diff] [blame] | 476 | menu.setHeaderTitle(R.string.contactOptionsTitle); |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 477 | if (entry.mimetype.equals(CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) { |
| 478 | menu.add(0, 0, 0, R.string.menu_call).setIntent(entry.intent); |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 479 | menu.add(0, 0, 0, R.string.menu_sendSMS).setIntent(entry.secondaryIntent); |
| 480 | if (!entry.isPrimary) { |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 481 | menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultNumber); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 482 | } |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 483 | } else if (entry.mimetype.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)) { |
| 484 | menu.add(0, 0, 0, R.string.menu_sendEmail).setIntent(entry.intent); |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 485 | if (!entry.isPrimary) { |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 486 | menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultEmail); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 487 | } |
Jeff Sharkey | c6ad3ab | 2009-07-21 19:30:15 -0700 | [diff] [blame] | 488 | } else if (entry.mimetype.equals(CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)) { |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 489 | menu.add(0, 0, 0, R.string.menu_viewAddress).setIntent(entry.intent); |
| 490 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | @Override |
| 494 | public boolean onOptionsItemSelected(MenuItem item) { |
| 495 | switch (item.getItemId()) { |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 496 | case R.id.menu_edit: { |
Evan Millar | df18120 | 2009-09-30 15:15:51 -0700 | [diff] [blame] | 497 | Long rawContactIdToEdit = null; |
| 498 | if (mRawContactIds.size() > 0) { |
| 499 | rawContactIdToEdit = mRawContactIds.get(0); |
| 500 | } else { |
| 501 | // There is no rawContact to edit. |
| 502 | break; |
Evan Millar | db5d88c | 2009-08-28 09:31:57 -0700 | [diff] [blame] | 503 | } |
Evan Millar | 2e1b8af | 2009-09-24 09:39:21 -0700 | [diff] [blame] | 504 | Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, |
| 505 | rawContactIdToEdit); |
Evan Millar | 9cd8124 | 2009-09-26 16:02:31 -0700 | [diff] [blame] | 506 | startActivityForResult(new Intent(Intent.ACTION_EDIT, rawContactUri), |
| 507 | REQUEST_EDIT_CONTACT); |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 508 | break; |
| 509 | } |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 510 | case R.id.menu_delete: { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 511 | // Get confirmation |
Megha Joshi | d5afd8a | 2009-09-22 09:38:41 -0700 | [diff] [blame] | 512 | if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) { |
| 513 | showDialog(DIALOG_CONFIRM_READONLY_DELETE); |
Megha Joshi | c508bd8 | 2009-10-01 17:31:49 -0700 | [diff] [blame] | 514 | } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) { |
| 515 | showDialog(DIALOG_CONFIRM_READONLY_HIDE); |
| 516 | } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) { |
Megha Joshi | d5afd8a | 2009-09-22 09:38:41 -0700 | [diff] [blame] | 517 | showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE); |
| 518 | } else { |
| 519 | showDialog(DIALOG_CONFIRM_DELETE); |
| 520 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 521 | return true; |
| 522 | } |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 523 | case R.id.menu_join: { |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 524 | showJoinAggregateActivity(); |
| 525 | return true; |
| 526 | } |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 527 | case R.id.menu_options: { |
Dmitri Plotnikov | ef03872 | 2009-06-24 18:51:47 -0700 | [diff] [blame] | 528 | showOptionsActivity(); |
| 529 | return true; |
| 530 | } |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 531 | case R.id.menu_share: { |
Jeff Sharkey | 9304931 | 2009-09-27 17:28:13 -0700 | [diff] [blame] | 532 | // TODO: Keep around actual LOOKUP_KEY, or formalize method of extracting |
| 533 | final String lookupKey = mLookupUri.getPathSegments().get(2); |
| 534 | final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); |
| 535 | |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 536 | final Intent intent = new Intent(Intent.ACTION_SEND); |
Jeff Sharkey | 9304931 | 2009-09-27 17:28:13 -0700 | [diff] [blame] | 537 | intent.setType(Contacts.CONTENT_VCARD_TYPE); |
| 538 | intent.putExtra(Intent.EXTRA_STREAM, shareUri); |
Dmitri Plotnikov | ef03872 | 2009-06-24 18:51:47 -0700 | [diff] [blame] | 539 | |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 540 | // Launch chooser to share contact via |
| 541 | final CharSequence chooseTitle = getText(R.string.share_via); |
| 542 | final Intent chooseIntent = Intent.createChooser(intent, chooseTitle); |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 543 | |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 544 | try { |
| 545 | startActivity(chooseIntent); |
| 546 | } catch (ActivityNotFoundException ex) { |
| 547 | Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 548 | } |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 549 | return true; |
| 550 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 551 | } |
| 552 | return super.onOptionsItemSelected(item); |
| 553 | } |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 554 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 555 | @Override |
| 556 | public boolean onContextItemSelected(MenuItem item) { |
| 557 | switch (item.getItemId()) { |
| 558 | case MENU_ITEM_MAKE_DEFAULT: { |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 559 | if (makeItemDefault(item)) { |
| 560 | return true; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 561 | } |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 562 | break; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 563 | } |
| 564 | } |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 565 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 566 | return super.onContextItemSelected(item); |
| 567 | } |
| 568 | |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 569 | private boolean makeItemDefault(MenuItem item) { |
| 570 | ViewEntry entry = getViewEntryForMenuItem(item); |
| 571 | if (entry == null) { |
| 572 | return false; |
| 573 | } |
| 574 | |
| 575 | // Update the primary values in the data record. |
Evan Millar | 14fecb6 | 2009-09-09 09:23:12 -0700 | [diff] [blame] | 576 | ContentValues values = new ContentValues(1); |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 577 | values.put(Data.IS_SUPER_PRIMARY, 1); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 578 | getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, entry.id), |
| 579 | values, null, null); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 580 | startEntityQuery(); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 581 | return true; |
| 582 | } |
| 583 | |
| 584 | /** |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 585 | * Shows a list of aggregates that can be joined into the currently viewed aggregate. |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 586 | */ |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 587 | public void showJoinAggregateActivity() { |
Evan Millar | 6a61a1a | 2009-09-29 14:00:43 -0700 | [diff] [blame] | 588 | long freshId = getRefreshedContactId(); |
| 589 | if (freshId > 0) { |
| 590 | String displayName = null; |
| 591 | if (mCursor.moveToFirst()) { |
| 592 | displayName = mCursor.getString(0); |
| 593 | } |
| 594 | Intent intent = new Intent(ContactsListActivity.JOIN_AGGREGATE); |
| 595 | intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_ID, freshId); |
| 596 | if (displayName != null) { |
| 597 | intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_NAME, displayName); |
| 598 | } |
| 599 | startActivityForResult(intent, REQUEST_JOIN_CONTACT); |
Dmitri Plotnikov | a5cfca3 | 2009-09-29 18:13:08 -0700 | [diff] [blame] | 600 | } |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 601 | } |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 602 | |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 603 | @Override |
| 604 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { |
Evan Millar | 2e1b8af | 2009-09-24 09:39:21 -0700 | [diff] [blame] | 605 | if (requestCode == REQUEST_JOIN_CONTACT) { |
| 606 | if (resultCode == RESULT_OK && intent != null) { |
| 607 | final long contactId = ContentUris.parseId(intent.getData()); |
| 608 | joinAggregate(contactId); |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 609 | } |
Evan Millar | 9cd8124 | 2009-09-26 16:02:31 -0700 | [diff] [blame] | 610 | } else if (requestCode == REQUEST_EDIT_CONTACT) { |
Evan Millar | df18120 | 2009-09-30 15:15:51 -0700 | [diff] [blame] | 611 | if (resultCode == EditContactActivity.RESULT_CLOSE_VIEW_ACTIVITY) { |
| 612 | finish(); |
Jeff Hamilton | 5297c6a | 2009-10-01 02:22:33 -0700 | [diff] [blame] | 613 | } else if (resultCode == Activity.RESULT_OK) { |
Dmitri Plotnikov | 160e9da | 2009-09-30 23:48:12 -0700 | [diff] [blame] | 614 | mLookupUri = intent.getData(); |
| 615 | if (mLookupUri == null) { |
| 616 | finish(); |
| 617 | } |
Evan Millar | df18120 | 2009-09-30 15:15:51 -0700 | [diff] [blame] | 618 | } |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 622 | private void splitContact(long rawContactId) { |
Dmitri Plotnikov | f40ccdf | 2009-09-04 17:37:15 -0700 | [diff] [blame] | 623 | setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_SEPARATE); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 624 | |
| 625 | // The split operation may have removed the original aggregate contact, so we need |
| 626 | // to requery everything |
Dmitri Plotnikov | 040dc15 | 2009-09-03 15:17:56 -0700 | [diff] [blame] | 627 | Toast.makeText(this, R.string.contactsSplitMessage, Toast.LENGTH_LONG).show(); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 628 | startEntityQuery(); |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Dmitri Plotnikov | f40ccdf | 2009-09-04 17:37:15 -0700 | [diff] [blame] | 631 | private void joinAggregate(final long contactId) { |
Dmitri Plotnikov | 3946659 | 2009-07-27 11:23:51 -0700 | [diff] [blame] | 632 | Cursor c = mResolver.query(RawContacts.CONTENT_URI, new String[] {RawContacts._ID}, |
Dmitri Plotnikov | f40ccdf | 2009-09-04 17:37:15 -0700 | [diff] [blame] | 633 | RawContacts.CONTACT_ID + "=" + contactId, null, null); |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 634 | |
| 635 | try { |
| 636 | while(c.moveToNext()) { |
Dmitri Plotnikov | f40ccdf | 2009-09-04 17:37:15 -0700 | [diff] [blame] | 637 | long rawContactId = c.getLong(0); |
| 638 | setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_TOGETHER); |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 639 | } |
| 640 | } finally { |
| 641 | c.close(); |
| 642 | } |
| 643 | |
Dmitri Plotnikov | 040dc15 | 2009-09-03 15:17:56 -0700 | [diff] [blame] | 644 | Toast.makeText(this, R.string.contactsJoinedMessage, Toast.LENGTH_LONG).show(); |
| 645 | startEntityQuery(); |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | /** |
| 649 | * Given a contact ID sets an aggregation exception to either join the contact with the |
| 650 | * current aggregate or split off. |
| 651 | */ |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 652 | protected void setAggregationException(long rawContactId, int exceptionType) { |
Dmitri Plotnikov | d09f75c | 2009-06-16 11:59:22 -0700 | [diff] [blame] | 653 | ContentValues values = new ContentValues(3); |
Dmitri Plotnikov | f40ccdf | 2009-09-04 17:37:15 -0700 | [diff] [blame] | 654 | for (long aRawContactId : mRawContactIds) { |
| 655 | if (aRawContactId != rawContactId) { |
| 656 | values.put(AggregationExceptions.RAW_CONTACT_ID1, aRawContactId); |
| 657 | values.put(AggregationExceptions.RAW_CONTACT_ID2, rawContactId); |
| 658 | values.put(AggregationExceptions.TYPE, exceptionType); |
| 659 | mResolver.update(AggregationExceptions.CONTENT_URI, values, null, null); |
| 660 | } |
| 661 | } |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Dmitri Plotnikov | ef03872 | 2009-06-24 18:51:47 -0700 | [diff] [blame] | 664 | private void showOptionsActivity() { |
| 665 | final Intent intent = new Intent(this, ContactOptionsActivity.class); |
Evan Millar | 6a61a1a | 2009-09-29 14:00:43 -0700 | [diff] [blame] | 666 | intent.setData(mLookupUri); |
Dmitri Plotnikov | ef03872 | 2009-06-24 18:51:47 -0700 | [diff] [blame] | 667 | startActivity(intent); |
| 668 | } |
| 669 | |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 670 | private ViewEntry getViewEntryForMenuItem(MenuItem item) { |
| 671 | AdapterView.AdapterContextMenuInfo info; |
| 672 | try { |
| 673 | info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); |
| 674 | } catch (ClassCastException e) { |
| 675 | Log.e(TAG, "bad menuInfo", e); |
| 676 | return null; |
| 677 | } |
| 678 | |
| 679 | return ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS); |
| 680 | } |
| 681 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 682 | @Override |
| 683 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 684 | switch (keyCode) { |
| 685 | case KeyEvent.KEYCODE_CALL: { |
| 686 | try { |
| 687 | ITelephony phone = ITelephony.Stub.asInterface( |
| 688 | ServiceManager.checkService("phone")); |
| 689 | if (phone != null && !phone.isIdle()) { |
| 690 | // Skip out and let the key be handled at a higher level |
| 691 | break; |
| 692 | } |
| 693 | } catch (RemoteException re) { |
| 694 | // Fall through and try to call the contact |
| 695 | } |
| 696 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 697 | int index = mListView.getSelectedItemPosition(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 698 | if (index != -1) { |
| 699 | ViewEntry entry = ViewAdapter.getEntry(mSections, index, SHOW_SEPARATORS); |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 700 | if (entry.intent.getAction() == Intent.ACTION_CALL_PRIVILEGED) { |
| 701 | startActivity(entry.intent); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 702 | } |
| 703 | } else if (mNumPhoneNumbers != 0) { |
| 704 | // There isn't anything selected, call the default number |
Evan Millar | 6a61a1a | 2009-09-29 14:00:43 -0700 | [diff] [blame] | 705 | long freshContactId = getRefreshedContactId(); |
| 706 | if (freshContactId > 0) { |
| 707 | Uri hardContacUri = ContentUris.withAppendedId( |
| 708 | Contacts.CONTENT_URI, freshContactId); |
| 709 | Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, hardContacUri); |
| 710 | startActivity(intent); |
| 711 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 712 | } |
| 713 | return true; |
| 714 | } |
| 715 | |
| 716 | case KeyEvent.KEYCODE_DEL: { |
Megha Joshi | d5afd8a | 2009-09-22 09:38:41 -0700 | [diff] [blame] | 717 | if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) { |
| 718 | showDialog(DIALOG_CONFIRM_READONLY_DELETE); |
Megha Joshi | c508bd8 | 2009-10-01 17:31:49 -0700 | [diff] [blame] | 719 | } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) { |
| 720 | showDialog(DIALOG_CONFIRM_READONLY_HIDE); |
| 721 | } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) { |
Megha Joshi | d5afd8a | 2009-09-22 09:38:41 -0700 | [diff] [blame] | 722 | showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE); |
| 723 | } else { |
| 724 | showDialog(DIALOG_CONFIRM_DELETE); |
| 725 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 726 | return true; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | return super.onKeyDown(keyCode, event); |
| 731 | } |
| 732 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 733 | public void onItemClick(AdapterView parent, View v, int position, long id) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 734 | ViewEntry entry = ViewAdapter.getEntry(mSections, position, SHOW_SEPARATORS); |
| 735 | if (entry != null) { |
| 736 | Intent intent = entry.intent; |
Evan Millar | df18120 | 2009-09-30 15:15:51 -0700 | [diff] [blame] | 737 | if (intent != null) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 738 | try { |
| 739 | startActivity(intent); |
| 740 | } catch (ActivityNotFoundException e) { |
| 741 | Log.e(TAG, "No activity found for intent: " + intent); |
| 742 | signalError(); |
| 743 | } |
| 744 | } else { |
| 745 | signalError(); |
| 746 | } |
| 747 | } else { |
| 748 | signalError(); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | /** |
| 753 | * Signal an error to the user via a beep, or some other method. |
| 754 | */ |
| 755 | private void signalError() { |
| 756 | //TODO: implement this when we have the sonification APIs |
| 757 | } |
| 758 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 759 | /** |
| 760 | * Build up the entries to display on the screen. |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 761 | * |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 762 | * @param personCursor the URI for the contact being displayed |
| 763 | */ |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 764 | private final void buildEntries() { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 765 | // Clear out the old entries |
| 766 | final int numSections = mSections.size(); |
| 767 | for (int i = 0; i < numSections; i++) { |
| 768 | mSections.get(i).clear(); |
| 769 | } |
| 770 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 771 | mRawContactIds.clear(); |
Megha Joshi | d5afd8a | 2009-09-22 09:38:41 -0700 | [diff] [blame] | 772 | mReadOnlySourcesCnt = 0; |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 773 | mWritableSourcesCnt = 0; |
Megha Joshi | d5afd8a | 2009-09-22 09:38:41 -0700 | [diff] [blame] | 774 | mWritableRawContactIds.clear(); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 775 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 776 | final Context context = this; |
| 777 | final Sources sources = Sources.getInstance(context); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 778 | |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 779 | // Build up method entries |
Evan Millar | 6a61a1a | 2009-09-29 14:00:43 -0700 | [diff] [blame] | 780 | if (mLookupUri != null) { |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 781 | for (Entity entity: mEntities) { |
| 782 | final ContentValues entValues = entity.getEntityValues(); |
| 783 | final String accountType = entValues.getAsString(RawContacts.ACCOUNT_TYPE); |
Jeff Sharkey | ab06693 | 2009-09-21 09:55:30 -0700 | [diff] [blame] | 784 | final long rawContactId = entValues.getAsLong(RawContacts._ID); |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 785 | |
Dmitri Plotnikov | 2a8cef0 | 2009-09-23 19:01:15 -0700 | [diff] [blame] | 786 | if (!mRawContactIds.contains(rawContactId)) { |
| 787 | mRawContactIds.add(rawContactId); |
| 788 | } |
Megha Joshi | c508bd8 | 2009-10-01 17:31:49 -0700 | [diff] [blame] | 789 | ContactsSource contactsSource = sources.getInflatedSource(accountType, |
| 790 | ContactsSource.LEVEL_SUMMARY); |
| 791 | if (contactsSource != null && contactsSource.readOnly) { |
| 792 | mReadOnlySourcesCnt += 1; |
| 793 | } else { |
| 794 | mWritableSourcesCnt += 1; |
| 795 | mWritableRawContactIds.add(rawContactId); |
| 796 | } |
| 797 | |
Dmitri Plotnikov | 2a8cef0 | 2009-09-23 19:01:15 -0700 | [diff] [blame] | 798 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 799 | for (NamedContentValues subValue : entity.getSubValues()) { |
Jeff Sharkey | ab06693 | 2009-09-21 09:55:30 -0700 | [diff] [blame] | 800 | final ContentValues entryValues = subValue.values; |
| 801 | entryValues.put(Data.RAW_CONTACT_ID, rawContactId); |
| 802 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 803 | final long dataId = entryValues.getAsLong(Data._ID); |
| 804 | final String mimeType = entryValues.getAsString(Data.MIMETYPE); |
| 805 | if (mimeType == null) continue; |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 806 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 807 | final DataKind kind = sources.getKindOrFallback(accountType, mimeType, this, |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 808 | ContactsSource.LEVEL_MIMETYPES); |
Jeff Sharkey | ab06693 | 2009-09-21 09:55:30 -0700 | [diff] [blame] | 809 | if (kind == null) continue; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 810 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 811 | final ViewEntry entry = ViewEntry.fromValues(context, mimeType, kind, |
| 812 | rawContactId, dataId, entryValues); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 813 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 814 | final boolean hasData = !TextUtils.isEmpty(entry.data); |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 815 | final boolean isSuperPrimary = entryValues.getAsInteger( |
| 816 | Data.IS_SUPER_PRIMARY) != 0; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 817 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 818 | if (Phone.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) { |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 819 | // Build phone entries |
| 820 | mNumPhoneNumbers++; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 821 | |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 822 | entry.intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 823 | Uri.fromParts(Constants.SCHEME_TEL, entry.data, null)); |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 824 | entry.secondaryIntent = new Intent(Intent.ACTION_SENDTO, |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 825 | Uri.fromParts(Constants.SCHEME_SMSTO, entry.data, null)); |
Evan Millar | 49714ee | 2009-09-02 16:42:47 -0700 | [diff] [blame] | 826 | |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 827 | entry.isPrimary = isSuperPrimary; |
| 828 | mPhoneEntries.add(entry); |
| 829 | |
| 830 | if (entry.type == CommonDataKinds.Phone.TYPE_MOBILE |
| 831 | || mShowSmsLinksForAllPhones) { |
| 832 | // Add an SMS entry |
| 833 | if (kind.iconAltRes > 0) { |
| 834 | entry.secondaryActionIcon = kind.iconAltRes; |
Evan Millar | 49714ee | 2009-09-02 16:42:47 -0700 | [diff] [blame] | 835 | } |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 836 | } |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 837 | } else if (Email.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) { |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 838 | // Build email entries |
| 839 | entry.intent = new Intent(Intent.ACTION_SENDTO, |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 840 | Uri.fromParts(Constants.SCHEME_MAILTO, entry.data, null)); |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 841 | entry.isPrimary = isSuperPrimary; |
| 842 | mEmailEntries.add(entry); |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 843 | |
| 844 | // When Email rows have status, create additional Im row |
| 845 | final DataStatus status = mStatuses.get(entry.id); |
| 846 | if (status != null) { |
| 847 | final String imMime = Im.CONTENT_ITEM_TYPE; |
| 848 | final DataKind imKind = sources.getKindOrFallback(accountType, |
| 849 | imMime, this, ContactsSource.LEVEL_MIMETYPES); |
| 850 | final ViewEntry imEntry = ViewEntry.fromValues(context, |
| 851 | imMime, imKind, rawContactId, dataId, entryValues); |
| 852 | imEntry.intent = ContactsUtils.buildImIntent(entryValues); |
| 853 | imEntry.applyStatus(status, false); |
| 854 | mImEntries.add(imEntry); |
| 855 | } |
| 856 | } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) { |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 857 | // Build postal entries |
| 858 | entry.maxLines = 4; |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 859 | entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri); |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 860 | mPostalEntries.add(entry); |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 861 | } else if (Im.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) { |
| 862 | // Build IM entries |
| 863 | entry.intent = ContactsUtils.buildImIntent(entryValues); |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 864 | if (TextUtils.isEmpty(entry.label)) { |
| 865 | entry.label = getString(R.string.chat).toLowerCase(); |
| 866 | } |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 867 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 868 | // Apply presence and status details when available |
| 869 | final DataStatus status = mStatuses.get(entry.id); |
| 870 | if (status != null) { |
| 871 | entry.applyStatus(status, false); |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 872 | } |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 873 | mImEntries.add(entry); |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 874 | } else if ((Organization.CONTENT_ITEM_TYPE.equals(mimeType) |
| 875 | || Nickname.CONTENT_ITEM_TYPE.equals(mimeType)) && hasData) { |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 876 | // Build organization and note entries |
| 877 | entry.uri = null; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 878 | mOrganizationEntries.add(entry); |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 879 | } else if (Note.CONTENT_ITEM_TYPE.equals(mimeType) && hasData) { |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 880 | // Build note entries |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 881 | entry.uri = null; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 882 | entry.maxLines = 10; |
| 883 | mOtherEntries.add(entry); |
Jeff Sharkey | ab06693 | 2009-09-21 09:55:30 -0700 | [diff] [blame] | 884 | } else { |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 885 | // Handle showing custom rows |
Evan Millar | ff04a27 | 2009-09-26 15:23:37 -0700 | [diff] [blame] | 886 | entry.intent = new Intent(Intent.ACTION_VIEW, entry.uri); |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 887 | |
| 888 | // Use social summary when requested by external source |
| 889 | final DataStatus status = mStatuses.get(entry.id); |
| 890 | final boolean hasSocial = kind.actionBodySocial && status != null; |
| 891 | if (hasSocial) { |
| 892 | entry.applyStatus(status, true); |
| 893 | } |
| 894 | |
| 895 | if (hasSocial || hasData) { |
| 896 | mOtherEntries.add(entry); |
| 897 | } |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 898 | } |
Evan Millar | 2e1b8af | 2009-09-24 09:39:21 -0700 | [diff] [blame] | 899 | } |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 900 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 904 | static String buildActionString(DataKind kind, ContentValues values, boolean lowerCase, |
| 905 | Context context) { |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 906 | if (kind.actionHeader == null) { |
| 907 | return null; |
Jeff Hamilton | 8350e5b | 2009-03-24 21:01:34 -0700 | [diff] [blame] | 908 | } |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 909 | CharSequence actionHeader = kind.actionHeader.inflateUsing(context, values); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 910 | if (actionHeader == null) { |
| 911 | return null; |
| 912 | } |
| 913 | return lowerCase ? actionHeader.toString().toLowerCase() : actionHeader.toString(); |
| 914 | } |
Jeff Hamilton | 8350e5b | 2009-03-24 21:01:34 -0700 | [diff] [blame] | 915 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 916 | static String buildDataString(DataKind kind, ContentValues values, Context context) { |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 917 | if (kind.actionBody == null) { |
| 918 | return null; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 919 | } |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 920 | CharSequence actionBody = kind.actionBody.inflateUsing(context, values); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 921 | return actionBody == null ? null : actionBody.toString(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 922 | } |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 923 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 924 | /** |
| 925 | * A basic structure with the data for a contact entry in the list. |
| 926 | */ |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 927 | static class ViewEntry extends ContactEntryAdapter.Entry implements Collapsible<ViewEntry> { |
| 928 | public Context context = null; |
Jeff Sharkey | ab06693 | 2009-09-21 09:55:30 -0700 | [diff] [blame] | 929 | public String resPackageName = null; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 930 | public int actionIcon = -1; |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 931 | public boolean isPrimary = false; |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 932 | public int secondaryActionIcon = -1; |
| 933 | public Intent intent; |
| 934 | public Intent secondaryIntent = null; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 935 | public int maxLabelLines = 1; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 936 | public ArrayList<Long> ids = new ArrayList<Long>(); |
| 937 | public int collapseCount = 0; |
| 938 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 939 | public int presence = -1; |
| 940 | public int presenceIcon = -1; |
| 941 | |
| 942 | public CharSequence footerLine = null; |
| 943 | |
| 944 | private ViewEntry() { |
| 945 | } |
| 946 | |
| 947 | /** |
| 948 | * Build new {@link ViewEntry} and populate from the given values. |
| 949 | */ |
| 950 | public static ViewEntry fromValues(Context context, String mimeType, DataKind kind, |
| 951 | long rawContactId, long dataId, ContentValues values) { |
| 952 | final ViewEntry entry = new ViewEntry(); |
| 953 | entry.context = context; |
| 954 | entry.contactId = rawContactId; |
| 955 | entry.id = dataId; |
| 956 | entry.uri = ContentUris.withAppendedId(Data.CONTENT_URI, entry.id); |
| 957 | entry.mimetype = mimeType; |
| 958 | entry.label = buildActionString(kind, values, false, context); |
| 959 | entry.data = buildDataString(kind, values, context); |
| 960 | |
| 961 | if (kind.typeColumn != null && values.containsKey(kind.typeColumn)) { |
| 962 | entry.type = values.getAsInteger(kind.typeColumn); |
| 963 | } |
| 964 | if (kind.iconRes > 0) { |
| 965 | entry.resPackageName = kind.resPackageName; |
| 966 | entry.actionIcon = kind.iconRes; |
| 967 | } |
| 968 | |
| 969 | return entry; |
| 970 | } |
| 971 | |
| 972 | /** |
| 973 | * Apply given {@link DataStatus} values over this {@link ViewEntry} |
| 974 | * |
| 975 | * @param fillData When true, the given status replaces {@link #data} |
| 976 | * and {@link #footerLine}. Otherwise only {@link #presence} |
| 977 | * is updated. |
| 978 | */ |
| 979 | public ViewEntry applyStatus(DataStatus status, boolean fillData) { |
| 980 | presence = status.getPresence(); |
| 981 | presenceIcon = (presence == -1) ? -1 : |
| 982 | StatusUpdates.getPresenceIconResourceId(this.presence); |
| 983 | |
| 984 | if (fillData && status.isValid()) { |
| 985 | this.data = status.getStatus().toString(); |
| 986 | this.footerLine = status.getTimestampLabel(context); |
| 987 | } |
| 988 | |
| 989 | return this; |
| 990 | } |
| 991 | |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 992 | public boolean collapseWith(ViewEntry entry) { |
| 993 | // assert equal collapse keys |
Evan Millar | adb0f8c | 2009-09-28 17:20:50 -0700 | [diff] [blame] | 994 | if (!shouldCollapseWith(entry)) { |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 995 | return false; |
| 996 | } |
| 997 | |
| 998 | // Choose the label associated with the highest type precedence. |
| 999 | if (TypePrecedence.getTypePrecedence(mimetype, type) |
| 1000 | > TypePrecedence.getTypePrecedence(entry.mimetype, entry.type)) { |
| 1001 | type = entry.type; |
| 1002 | label = entry.label; |
| 1003 | } |
| 1004 | |
| 1005 | // Choose the max of the maxLines and maxLabelLines values. |
| 1006 | maxLines = Math.max(maxLines, entry.maxLines); |
| 1007 | maxLabelLines = Math.max(maxLabelLines, entry.maxLabelLines); |
| 1008 | |
| 1009 | // Choose the presence with the highest precedence. |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 1010 | if (StatusUpdates.getPresencePrecedence(presence) |
| 1011 | < StatusUpdates.getPresencePrecedence(entry.presence)) { |
| 1012 | presence = entry.presence; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | // If any of the collapsed entries are primary make the whole thing primary. |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1016 | isPrimary = entry.isPrimary ? true : isPrimary; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1017 | |
| 1018 | // uri, and contactdId, shouldn't make a difference. Just keep the original. |
| 1019 | |
| 1020 | // Keep track of all the ids that have been collapsed with this one. |
| 1021 | ids.add(entry.id); |
| 1022 | collapseCount++; |
| 1023 | return true; |
| 1024 | } |
| 1025 | |
Evan Millar | adb0f8c | 2009-09-28 17:20:50 -0700 | [diff] [blame] | 1026 | public boolean shouldCollapseWith(ViewEntry entry) { |
| 1027 | if (entry == null) { |
| 1028 | return false; |
| 1029 | } |
| 1030 | |
| 1031 | if (Phone.CONTENT_ITEM_TYPE.equals(mimetype) |
| 1032 | && Phone.CONTENT_ITEM_TYPE.equals(entry.mimetype)) { |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 1033 | if (!PhoneNumberUtils.compare(this.context, data, entry.data)) { |
Evan Millar | adb0f8c | 2009-09-28 17:20:50 -0700 | [diff] [blame] | 1034 | return false; |
| 1035 | } |
| 1036 | } else { |
| 1037 | if (!equals(data, entry.data)) { |
| 1038 | return false; |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | if (!equals(mimetype, entry.mimetype) |
| 1043 | || !intentCollapsible(intent, entry.intent) |
| 1044 | || !intentCollapsible(secondaryIntent, entry.secondaryIntent) |
| 1045 | || actionIcon != entry.actionIcon) { |
| 1046 | return false; |
| 1047 | } |
| 1048 | |
| 1049 | return true; |
| 1050 | } |
| 1051 | |
| 1052 | private boolean equals(Object a, Object b) { |
| 1053 | return a==b || (a != null && a.equals(b)); |
| 1054 | } |
| 1055 | |
| 1056 | private boolean intentCollapsible(Intent a, Intent b) { |
| 1057 | if (a == b) { |
| 1058 | return true; |
| 1059 | } else if ((a != null && b != null) && equals(a.getAction(), b.getAction())) { |
| 1060 | return true; |
| 1061 | } |
| 1062 | return false; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1063 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1064 | } |
| 1065 | |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1066 | /** Cache of the children views of a row */ |
| 1067 | static class ViewCache { |
| 1068 | public TextView label; |
| 1069 | public TextView data; |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 1070 | public TextView footer; |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1071 | public ImageView actionIcon; |
| 1072 | public ImageView presenceIcon; |
| 1073 | public ImageView primaryIcon; |
| 1074 | public ImageView secondaryActionButton; |
| 1075 | public View secondaryActionDivider; |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 1076 | |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1077 | // Need to keep track of this too |
| 1078 | ViewEntry entry; |
| 1079 | } |
| 1080 | |
| 1081 | private final class ViewAdapter extends ContactEntryAdapter<ViewEntry> |
| 1082 | implements View.OnClickListener { |
| 1083 | |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 1084 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1085 | ViewAdapter(Context context, ArrayList<ArrayList<ViewEntry>> sections) { |
| 1086 | super(context, sections, SHOW_SEPARATORS); |
| 1087 | } |
| 1088 | |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1089 | public void onClick(View v) { |
| 1090 | Intent intent = (Intent) v.getTag(); |
| 1091 | startActivity(intent); |
| 1092 | } |
| 1093 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1094 | @Override |
| 1095 | public View getView(int position, View convertView, ViewGroup parent) { |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 1096 | ViewEntry entry = getEntry(mSections, position, false); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1097 | View v; |
| 1098 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1099 | ViewCache views; |
| 1100 | |
| 1101 | // Check to see if we can reuse convertView |
| 1102 | if (convertView != null) { |
| 1103 | v = convertView; |
| 1104 | views = (ViewCache) v.getTag(); |
| 1105 | } else { |
| 1106 | // Create a new view if needed |
| 1107 | v = mInflater.inflate(R.layout.list_item_text_icons, parent, false); |
| 1108 | |
| 1109 | // Cache the children |
| 1110 | views = new ViewCache(); |
| 1111 | views.label = (TextView) v.findViewById(android.R.id.text1); |
| 1112 | views.data = (TextView) v.findViewById(android.R.id.text2); |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 1113 | views.footer = (TextView) v.findViewById(R.id.footer); |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1114 | views.actionIcon = (ImageView) v.findViewById(R.id.action_icon); |
| 1115 | views.primaryIcon = (ImageView) v.findViewById(R.id.primary_icon); |
| 1116 | views.presenceIcon = (ImageView) v.findViewById(R.id.presence_icon); |
| 1117 | views.secondaryActionButton = (ImageView) v.findViewById( |
| 1118 | R.id.secondary_action_button); |
| 1119 | views.secondaryActionButton.setOnClickListener(this); |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1120 | views.secondaryActionDivider = v.findViewById(R.id.divider); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1121 | v.setTag(views); |
| 1122 | } |
| 1123 | |
| 1124 | // Update the entry in the view cache |
| 1125 | views.entry = entry; |
| 1126 | |
| 1127 | // Bind the data to the view |
| 1128 | bindView(v, entry); |
| 1129 | return v; |
| 1130 | } |
| 1131 | |
| 1132 | @Override |
| 1133 | protected View newView(int position, ViewGroup parent) { |
| 1134 | // getView() handles this |
| 1135 | throw new UnsupportedOperationException(); |
| 1136 | } |
| 1137 | |
| 1138 | @Override |
| 1139 | protected void bindView(View view, ViewEntry entry) { |
| 1140 | final Resources resources = mContext.getResources(); |
| 1141 | ViewCache views = (ViewCache) view.getTag(); |
| 1142 | |
| 1143 | // Set the label |
| 1144 | TextView label = views.label; |
| 1145 | setMaxLines(label, entry.maxLabelLines); |
| 1146 | label.setText(entry.label); |
| 1147 | |
| 1148 | // Set the data |
| 1149 | TextView data = views.data; |
| 1150 | if (data != null) { |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1151 | if (entry.mimetype.equals(Phone.CONTENT_ITEM_TYPE) |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 1152 | || entry.mimetype.equals(Constants.MIME_SMS_ADDRESS)) { |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1153 | data.setText(PhoneNumberUtils.formatNumber(entry.data)); |
| 1154 | } else { |
| 1155 | data.setText(entry.data); |
| 1156 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1157 | setMaxLines(data, entry.maxLines); |
| 1158 | } |
| 1159 | |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 1160 | // Set the footer |
| 1161 | if (!TextUtils.isEmpty(entry.footerLine)) { |
| 1162 | views.footer.setText(entry.footerLine); |
| 1163 | views.footer.setVisibility(View.VISIBLE); |
| 1164 | } else { |
| 1165 | views.footer.setVisibility(View.GONE); |
| 1166 | } |
| 1167 | |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1168 | // Set the primary icon |
| 1169 | views.primaryIcon.setVisibility(entry.isPrimary ? View.VISIBLE : View.GONE); |
| 1170 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1171 | // Set the action icon |
| 1172 | ImageView action = views.actionIcon; |
| 1173 | if (entry.actionIcon != -1) { |
Jeff Sharkey | ab06693 | 2009-09-21 09:55:30 -0700 | [diff] [blame] | 1174 | Drawable actionIcon; |
| 1175 | if (entry.resPackageName != null) { |
| 1176 | // Load external resources through PackageManager |
| 1177 | actionIcon = mContext.getPackageManager().getDrawable(entry.resPackageName, |
| 1178 | entry.actionIcon, null); |
| 1179 | } else { |
| 1180 | actionIcon = resources.getDrawable(entry.actionIcon); |
| 1181 | } |
| 1182 | action.setImageDrawable(actionIcon); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1183 | action.setVisibility(View.VISIBLE); |
| 1184 | } else { |
| 1185 | // Things should still line up as if there was an icon, so make it invisible |
| 1186 | action.setVisibility(View.INVISIBLE); |
| 1187 | } |
| 1188 | |
| 1189 | // Set the presence icon |
| 1190 | Drawable presenceIcon = null; |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1191 | if (entry.presenceIcon != -1) { |
| 1192 | presenceIcon = resources.getDrawable(entry.presenceIcon); |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 1193 | } else if (entry.presence != -1) { |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1194 | presenceIcon = resources.getDrawable( |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 1195 | StatusUpdates.getPresenceIconResourceId(entry.presence)); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1196 | } |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1197 | ImageView presenceIconView = views.presenceIcon; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1198 | if (presenceIcon != null) { |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1199 | presenceIconView.setImageDrawable(presenceIcon); |
| 1200 | presenceIconView.setVisibility(View.VISIBLE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1201 | } else { |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1202 | presenceIconView.setVisibility(View.GONE); |
| 1203 | } |
| 1204 | |
| 1205 | // Set the secondary action button |
| 1206 | ImageView secondaryActionView = views.secondaryActionButton; |
| 1207 | Drawable secondaryActionIcon = null; |
| 1208 | if (entry.secondaryActionIcon != -1) { |
| 1209 | secondaryActionIcon = resources.getDrawable(entry.secondaryActionIcon); |
| 1210 | } |
| 1211 | if (entry.secondaryIntent != null && secondaryActionIcon != null) { |
| 1212 | secondaryActionView.setImageDrawable(secondaryActionIcon); |
| 1213 | secondaryActionView.setTag(entry.secondaryIntent); |
| 1214 | secondaryActionView.setVisibility(View.VISIBLE); |
| 1215 | views.secondaryActionDivider.setVisibility(View.VISIBLE); |
| 1216 | } else { |
| 1217 | secondaryActionView.setVisibility(View.GONE); |
| 1218 | views.secondaryActionDivider.setVisibility(View.GONE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | private void setMaxLines(TextView textView, int maxLines) { |
| 1223 | if (maxLines == 1) { |
| 1224 | textView.setSingleLine(true); |
| 1225 | textView.setEllipsize(TextUtils.TruncateAt.END); |
| 1226 | } else { |
| 1227 | textView.setSingleLine(false); |
| 1228 | textView.setMaxLines(maxLines); |
| 1229 | textView.setEllipsize(null); |
| 1230 | } |
| 1231 | } |
| 1232 | } |
Jeff Sharkey | 624ddc3 | 2009-10-01 21:32:19 -0700 | [diff] [blame] | 1233 | |
| 1234 | private interface StatusQuery { |
| 1235 | final String[] PROJECTION = new String[] { |
| 1236 | Data._ID, |
| 1237 | Data.STATUS, |
| 1238 | Data.STATUS_RES_PACKAGE, |
| 1239 | Data.STATUS_ICON, |
| 1240 | Data.STATUS_LABEL, |
| 1241 | Data.STATUS_TIMESTAMP, |
| 1242 | Data.PRESENCE, |
| 1243 | }; |
| 1244 | |
| 1245 | final int _ID = 0; |
| 1246 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1247 | } |