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