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