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.ScrollingTabWidget.OnTabSelectionChangedListener; |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 21 | import com.android.contacts.SplitAggregateView.OnContactSelectedListener; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 22 | import com.android.contacts.model.ContactsSource; |
| 23 | import com.android.contacts.model.Sources; |
| 24 | import com.android.contacts.model.ContactsSource.DataKind; |
Evan Millar | 49714ee | 2009-09-02 16:42:47 -0700 | [diff] [blame] | 25 | import com.android.contacts.model.HardCodedSources.SimpleInflater; |
Jeff Sharkey | 802b205 | 2009-08-04 14:21:06 -0700 | [diff] [blame] | 26 | import com.android.contacts.ui.FastTrackWindow; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 27 | import com.android.contacts.util.NotifyingAsyncQueryHandler; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 28 | import com.android.internal.telephony.ITelephony; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 29 | import com.android.internal.widget.ContactHeaderWidget; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 30 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 31 | import android.app.Activity; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 32 | import android.app.AlertDialog; |
| 33 | import android.app.Dialog; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 34 | import android.content.ActivityNotFoundException; |
| 35 | import android.content.ContentResolver; |
| 36 | import android.content.ContentUris; |
| 37 | import android.content.ContentValues; |
| 38 | import android.content.Context; |
| 39 | import android.content.DialogInterface; |
Evan Millar | 5f4af70 | 2009-08-11 11:12:00 -0700 | [diff] [blame] | 40 | import android.content.Entity; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 41 | import android.content.EntityIterator; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 42 | import android.content.Intent; |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 43 | import android.content.DialogInterface.OnClickListener; |
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.pm.PackageManager; |
| 46 | import android.content.pm.ResolveInfo; |
| 47 | import android.content.res.Resources; |
| 48 | import android.database.ContentObserver; |
| 49 | import android.database.Cursor; |
Dmitri Plotnikov | 3d53ce2 | 2009-09-02 08:44:32 -0700 | [diff] [blame] | 50 | import android.database.DatabaseUtils; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 51 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 52 | import android.net.Uri; |
| 53 | import android.os.Bundle; |
| 54 | import android.os.Handler; |
| 55 | import android.os.RemoteException; |
| 56 | import android.os.ServiceManager; |
Dmitri Plotnikov | 040dc15 | 2009-09-03 15:17:56 -0700 | [diff] [blame^] | 57 | import android.provider.BaseColumns; |
Dmitri Plotnikov | 3d53ce2 | 2009-09-02 08:44:32 -0700 | [diff] [blame] | 58 | import android.provider.ContactsContract; |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 59 | import android.provider.ContactsContract.AggregationExceptions; |
| 60 | import android.provider.ContactsContract.CommonDataKinds; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 61 | import android.provider.ContactsContract.Contacts; |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 62 | import android.provider.ContactsContract.Data; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 63 | import android.provider.ContactsContract.Presence; |
Dmitri Plotnikov | 3946659 | 2009-07-27 11:23:51 -0700 | [diff] [blame] | 64 | import android.provider.ContactsContract.RawContacts; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 65 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 66 | import android.telephony.PhoneNumberUtils; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 67 | import android.text.TextUtils; |
| 68 | import android.util.Log; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 69 | import android.util.SparseArray; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 70 | import android.view.ContextMenu; |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 71 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 72 | import android.view.KeyEvent; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 73 | import android.view.LayoutInflater; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 74 | import android.view.Menu; |
| 75 | import android.view.MenuItem; |
| 76 | import android.view.View; |
| 77 | import android.view.ViewGroup; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 78 | import android.view.Window; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 79 | import android.view.ContextMenu.ContextMenuInfo; |
| 80 | import android.widget.AdapterView; |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 81 | import android.widget.FrameLayout; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 82 | import android.widget.ImageView; |
| 83 | import android.widget.ListView; |
| 84 | import android.widget.TextView; |
| 85 | import android.widget.Toast; |
| 86 | |
| 87 | import java.util.ArrayList; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Displays the details of a specific contact. |
| 91 | */ |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 92 | public class ViewContactActivity extends Activity |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 93 | implements View.OnCreateContextMenuListener, DialogInterface.OnClickListener, |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 94 | AdapterView.OnItemClickListener, NotifyingAsyncQueryHandler.AsyncQueryListener, |
| 95 | OnTabSelectionChangedListener { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 96 | private static final String TAG = "ViewContact"; |
| 97 | private static final String SHOW_BARCODE_INTENT = "com.google.zxing.client.android.ENCODE"; |
| 98 | |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 99 | public static final String RAW_CONTACT_ID_EXTRA = "rawContactIdExtra"; |
| 100 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 101 | private static final boolean SHOW_SEPARATORS = false; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 102 | |
| 103 | private static final int DIALOG_CONFIRM_DELETE = 1; |
| 104 | |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 105 | private static final int REQUEST_JOIN_CONTACT = 1; |
| 106 | private static final int REQUEST_EDIT_CONTACT = 2; |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 107 | |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 108 | public static final int MENU_ITEM_EDIT = 1; |
| 109 | public static final int MENU_ITEM_DELETE = 2; |
| 110 | public static final int MENU_ITEM_MAKE_DEFAULT = 3; |
| 111 | public static final int MENU_ITEM_SHOW_BARCODE = 4; |
| 112 | public static final int MENU_ITEM_SPLIT_AGGREGATE = 5; |
| 113 | public static final int MENU_ITEM_JOIN_AGGREGATE = 6; |
| 114 | public static final int MENU_ITEM_OPTIONS = 7; |
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; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 117 | private Uri mUri; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 118 | private ContentResolver mResolver; |
| 119 | private ViewAdapter mAdapter; |
| 120 | private int mNumPhoneNumbers = 0; |
| 121 | |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 122 | private static final long ALL_CONTACTS_ID = -100; |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 123 | |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 124 | /** |
Dmitri Plotnikov | e1cd679 | 2009-07-27 20:28:17 -0700 | [diff] [blame] | 125 | * A list of distinct contact IDs included in the current contact. |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 126 | */ |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 127 | private ArrayList<Long> mRawContactIds = new ArrayList<Long>(); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 128 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 129 | /* package */ ArrayList<ViewEntry> mPhoneEntries = new ArrayList<ViewEntry>(); |
| 130 | /* package */ ArrayList<ViewEntry> mSmsEntries = new ArrayList<ViewEntry>(); |
| 131 | /* package */ ArrayList<ViewEntry> mEmailEntries = new ArrayList<ViewEntry>(); |
| 132 | /* package */ ArrayList<ViewEntry> mPostalEntries = new ArrayList<ViewEntry>(); |
| 133 | /* package */ ArrayList<ViewEntry> mImEntries = new ArrayList<ViewEntry>(); |
| 134 | /* package */ ArrayList<ViewEntry> mOrganizationEntries = new ArrayList<ViewEntry>(); |
The Android Open Source Project | cac191e | 2009-03-18 22:20:27 -0700 | [diff] [blame] | 135 | /* package */ ArrayList<ViewEntry> mGroupEntries = new ArrayList<ViewEntry>(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 136 | /* package */ ArrayList<ViewEntry> mOtherEntries = new ArrayList<ViewEntry>(); |
| 137 | /* package */ ArrayList<ArrayList<ViewEntry>> mSections = new ArrayList<ArrayList<ViewEntry>>(); |
| 138 | |
| 139 | private Cursor mCursor; |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 140 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 141 | private SparseArray<Long> mTabRawContactIdMap; |
| 142 | protected ScrollingTabWidget mTabWidget; |
| 143 | protected ContactHeaderWidget mContactHeaderWidget; |
| 144 | private NotifyingAsyncQueryHandler mHandler; |
| 145 | |
| 146 | protected LayoutInflater mInflater; |
| 147 | |
| 148 | //Projection used for the query that determines which tabs to add. |
| 149 | protected static final String[] TAB_PROJECTION = new String[] { |
| 150 | RawContacts._ID, |
| 151 | RawContacts.ACCOUNT_NAME, |
| 152 | RawContacts.ACCOUNT_TYPE |
| 153 | }; |
| 154 | protected static final int TAB_CONTACT_ID_COLUMN_INDEX = 0; |
| 155 | protected static final int TAB_ACCOUNT_NAME_COLUMN_INDEX = 1; |
| 156 | protected static final int TAB_ACCOUNT_TYPE_COLUMN_INDEX = 2; |
| 157 | |
| 158 | protected static final String SELECTED_RAW_CONTACT_ID_KEY = "selectedRawContact"; |
| 159 | protected Long mSelectedRawContactId = null; |
| 160 | |
| 161 | private static final int TOKEN_QUERY = 0; |
| 162 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 163 | private ContentObserver mObserver = new ContentObserver(new Handler()) { |
| 164 | @Override |
| 165 | public boolean deliverSelfNotifications() { |
| 166 | return true; |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void onChange(boolean selfChange) { |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 171 | if (mCursor != null && !mCursor.isClosed()) { |
| 172 | startEntityQuery(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | }; |
| 176 | |
| 177 | public void onClick(DialogInterface dialog, int which) { |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 178 | closeCursor(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 179 | getContentResolver().delete(mUri, null, null); |
| 180 | finish(); |
| 181 | } |
| 182 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 183 | private FrameLayout mTabContentLayout; |
| 184 | private ListView mListView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 185 | private boolean mShowSmsLinksForAllPhones; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 186 | private ArrayList<Entity> mEntities = null; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 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 | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 193 | mLookupUri = intent.getData(); |
Dmitri Plotnikov | 83129f0 | 2009-09-02 19:04:41 -0700 | [diff] [blame] | 194 | |
| 195 | mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 196 | |
| 197 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
| 198 | setContentView(R.layout.contact_card_layout); |
| 199 | |
| 200 | mContactHeaderWidget = (ContactHeaderWidget) findViewById(R.id.contact_header_widget); |
| 201 | mContactHeaderWidget.showStar(true); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 202 | mContactHeaderWidget.setExcludeMimes(new String[] { |
| 203 | Contacts.CONTENT_ITEM_TYPE |
| 204 | }); |
| 205 | |
| 206 | mTabWidget = (ScrollingTabWidget) findViewById(R.id.tab_widget); |
| 207 | mTabWidget.setTabSelectionListener(this); |
| 208 | mTabWidget.setVisibility(View.INVISIBLE); |
| 209 | |
| 210 | mTabRawContactIdMap = new SparseArray<Long>(); |
| 211 | |
| 212 | mHandler = new NotifyingAsyncQueryHandler(this, this); |
| 213 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 214 | mListView = new ListView(this); |
| 215 | mListView.setOnCreateContextMenuListener(this); |
| 216 | mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY); |
| 217 | mListView.setOnItemClickListener(this); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 218 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 219 | mTabContentLayout = (FrameLayout) findViewById(android.R.id.tabcontent); |
| 220 | mTabContentLayout.addView(mListView); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 221 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 222 | mResolver = getContentResolver(); |
| 223 | |
| 224 | // Build the list of sections. The order they're added to mSections dictates the |
| 225 | // order they are displayed in the list. |
| 226 | mSections.add(mPhoneEntries); |
| 227 | mSections.add(mSmsEntries); |
| 228 | mSections.add(mEmailEntries); |
| 229 | mSections.add(mImEntries); |
| 230 | mSections.add(mPostalEntries); |
| 231 | mSections.add(mOrganizationEntries); |
The Android Open Source Project | cac191e | 2009-03-18 22:20:27 -0700 | [diff] [blame] | 232 | mSections.add(mGroupEntries); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 233 | mSections.add(mOtherEntries); |
| 234 | |
| 235 | //TODO Read this value from a preference |
| 236 | mShowSmsLinksForAllPhones = true; |
| 237 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 238 | startEntityQuery(); |
| 239 | } |
| 240 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 241 | @Override |
| 242 | protected void onResume() { |
| 243 | super.onResume(); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 244 | startEntityQuery(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | @Override |
| 248 | protected void onPause() { |
| 249 | super.onPause(); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 250 | closeCursor(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Override |
| 254 | protected void onDestroy() { |
| 255 | super.onDestroy(); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 256 | closeCursor(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | @Override |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 260 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 261 | super.onRestoreInstanceState(savedInstanceState); |
| 262 | mSelectedRawContactId = savedInstanceState.getLong(SELECTED_RAW_CONTACT_ID_KEY); |
| 263 | } |
| 264 | |
| 265 | @Override |
| 266 | protected void onSaveInstanceState(Bundle outState) { |
| 267 | super.onSaveInstanceState(outState); |
| 268 | outState.putLong(SELECTED_RAW_CONTACT_ID_KEY, mSelectedRawContactId); |
| 269 | } |
| 270 | |
| 271 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 272 | protected Dialog onCreateDialog(int id) { |
| 273 | switch (id) { |
| 274 | case DIALOG_CONFIRM_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.deleteConfirmation) |
| 279 | .setNegativeButton(android.R.string.cancel, null) |
| 280 | .setPositiveButton(android.R.string.ok, this) |
| 281 | .setCancelable(false) |
| 282 | .create(); |
| 283 | } |
| 284 | return null; |
| 285 | } |
| 286 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 287 | |
| 288 | // TAB CODE // |
| 289 | /** |
| 290 | * Adds a tab for each {@link RawContact} associated with this contact. |
| 291 | * Override this method if you want to additional tabs and/or different |
| 292 | * tabs for your activity. |
| 293 | * |
| 294 | * @param entities An {@link ArrayList} of {@link Entity}s of all the RawContacts |
| 295 | * associated with the contact being displayed. |
| 296 | */ |
| 297 | protected void bindTabs() { |
| 298 | if (mEntities.size() > 1) { |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 299 | addAllTab(); |
| 300 | } |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 301 | |
| 302 | final Sources sources = Sources.getInstance(this); |
| 303 | |
| 304 | for (Entity entity : mEntities) { |
| 305 | final String accountType = entity.getEntityValues(). |
| 306 | getAsString(RawContacts.ACCOUNT_TYPE); |
| 307 | final Long rawContactId = entity.getEntityValues(). |
| 308 | getAsLong(RawContacts._ID); |
| 309 | |
| 310 | // TODO: ensure inflation on background task so we don't block UI thread here |
| 311 | final ContactsSource source = sources.getInflatedSource(accountType, |
| 312 | ContactsSource.LEVEL_SUMMARY); |
| 313 | addTab(rawContactId, ContactsUtils.createTabIndicatorView(mTabWidget.getTabParent(), source)); |
| 314 | } |
| 315 | |
| 316 | selectInitialTab(); |
| 317 | mTabWidget.setVisibility(View.VISIBLE); |
| 318 | mTabWidget.postInvalidate(); |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Add a tab to be displayed in the {@link ScrollingTabWidget}. |
| 323 | * |
| 324 | * @param contactId The contact id associated with the tab. |
| 325 | * @param view A view to use as the tab indicator. |
| 326 | */ |
| 327 | protected void addTab(long rawContactId, View view) { |
| 328 | mTabRawContactIdMap.put(mTabWidget.getTabCount(), rawContactId); |
| 329 | mTabWidget.addTab(view); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | protected void clearCurrentTabs() { |
| 334 | mTabRawContactIdMap.clear(); |
| 335 | mTabWidget.removeAllTabs(); |
| 336 | } |
| 337 | |
| 338 | protected void selectInitialTab() { |
| 339 | int selectedTabIndex = 0; |
| 340 | |
| 341 | if (mSelectedRawContactId != null) { |
| 342 | selectedTabIndex = getTabIndexForRawContactId(mSelectedRawContactId); |
| 343 | if (selectedTabIndex == -1) { |
| 344 | // If there was no matching tab, just select the first; |
| 345 | selectedTabIndex = 0; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | mTabWidget.setCurrentTab(selectedTabIndex); |
| 350 | onTabSelectionChanged(selectedTabIndex, false); |
| 351 | } |
| 352 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 353 | private void addAllTab() { |
Evan Millar | 56d2caa | 2009-08-20 20:30:12 -0700 | [diff] [blame] | 354 | View allTabIndicator = mInflater.inflate(R.layout.all_tab_indicator, |
| 355 | mTabWidget.getTabParent(), false); |
Evan Millar | 7466091 | 2009-08-19 17:36:33 -0700 | [diff] [blame] | 356 | allTabIndicator.getBackground().setDither(true); |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 357 | addTab(ALL_CONTACTS_ID, allTabIndicator); |
| 358 | } |
| 359 | |
| 360 | public void onTabSelectionChanged(int tabIndex, boolean clicked) { |
| 361 | long rawContactId = getTabRawContactId(tabIndex); |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 362 | mSelectedRawContactId = rawContactId; |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 363 | bindData(); |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 366 | /** |
| 367 | * Return the RawContact id associated with the tab at an index. |
| 368 | * |
| 369 | * @param index The index of the tab in question. |
| 370 | * @return The contactId associated with the tab at the specified index. |
| 371 | */ |
| 372 | protected long getTabRawContactId(int index) { |
| 373 | return mTabRawContactIdMap.get(index); |
| 374 | } |
Evan Millar | 2c1cc83 | 2009-07-13 11:08:06 -0700 | [diff] [blame] | 375 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 376 | /** |
| 377 | * Return the tab index associated with the RawContact id. |
| 378 | * |
| 379 | * @param index The index of the tab in question. |
| 380 | * @return The contactId associated with the tab at the specified index. |
| 381 | */ |
| 382 | protected int getTabIndexForRawContactId(long rawContactId) { |
| 383 | int numTabs = mTabRawContactIdMap.size(); |
| 384 | for (int i=0; i < numTabs; i++) { |
| 385 | if (mTabRawContactIdMap.get(i) == rawContactId) { |
| 386 | return i; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 387 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 388 | } |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 389 | return -1; |
| 390 | } |
| 391 | |
| 392 | |
| 393 | // QUERY CODE // |
| 394 | /** {@inheritDoc} */ |
| 395 | public void onQueryEntitiesComplete(int token, Object cookie, EntityIterator iterator) { |
| 396 | try{ |
| 397 | if (token == TOKEN_QUERY) { |
| 398 | clearCurrentTabs(); |
| 399 | mEntities = readEntities(iterator); |
| 400 | bindTabs(); |
| 401 | bindData(); |
| 402 | } |
| 403 | } finally { |
| 404 | if (iterator != null) { |
| 405 | iterator.close(); |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | /** {@inheritDoc} */ |
| 411 | public void onQueryComplete(int token, Object cookie, Cursor cursor) { |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 412 | // Empty |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | private ArrayList<Entity> readEntities(EntityIterator iterator) { |
| 416 | ArrayList<Entity> entities = new ArrayList<Entity>(); |
| 417 | try { |
| 418 | while (iterator.hasNext()) { |
| 419 | entities.add(iterator.next()); |
| 420 | } |
| 421 | } catch (RemoteException e) { |
| 422 | } |
| 423 | |
| 424 | return entities; |
| 425 | } |
| 426 | |
| 427 | private void startEntityQuery() { |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 428 | closeCursor(); |
| 429 | |
Dmitri Plotnikov | 0306bbd | 2009-09-03 14:37:15 -0700 | [diff] [blame] | 430 | mUri = null; |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 431 | if (mLookupUri != null) { |
| 432 | mLookupUri = Contacts.getLookupUri(getContentResolver(), mLookupUri); |
| 433 | if (mLookupUri != null) { |
| 434 | mUri = Contacts.lookupContact(getContentResolver(), mLookupUri); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | if (mUri == null) { |
| 439 | |
| 440 | // TODO either figure out a way to prevent a flash of black background or |
| 441 | // use some other UI than a toast |
| 442 | Toast.makeText(this, R.string.invalidContactMessage, Toast.LENGTH_SHORT).show(); |
| 443 | Log.e(TAG, "invalid contact uri: " + mLookupUri); |
| 444 | finish(); |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | mCursor = mResolver.query(Uri.withAppendedPath(mUri, Contacts.Data.CONTENT_DIRECTORY), |
| 449 | new String[] {Contacts.DISPLAY_NAME}, null, null, null); |
| 450 | mCursor.registerContentObserver(mObserver); |
| 451 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 452 | long contactId = ContentUris.parseId(mUri); |
| 453 | mHandler.startQueryEntities(TOKEN_QUERY, null, |
| 454 | RawContacts.CONTENT_URI, RawContacts.CONTACT_ID + "=" + contactId, null, null); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 455 | |
| 456 | mContactHeaderWidget.bindFromContactId(ContentUris.parseId(mUri)); |
| 457 | } |
| 458 | |
| 459 | private void closeCursor() { |
| 460 | if (mCursor != null) { |
| 461 | mCursor.unregisterContentObserver(mObserver); |
| 462 | mCursor.close(); |
| 463 | mCursor = null; |
| 464 | } |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | private void bindData() { |
| 468 | |
| 469 | // Build up the contact entries |
| 470 | buildEntries(); |
| 471 | |
| 472 | // Collapse similar data items in select sections. |
| 473 | Collapser.collapseList(mPhoneEntries); |
| 474 | Collapser.collapseList(mSmsEntries); |
| 475 | Collapser.collapseList(mEmailEntries); |
| 476 | Collapser.collapseList(mPostalEntries); |
| 477 | |
| 478 | if (mAdapter == null) { |
| 479 | mAdapter = new ViewAdapter(this, mSections); |
| 480 | mListView.setAdapter(mAdapter); |
| 481 | } else { |
| 482 | mAdapter.setSections(mSections, SHOW_SEPARATORS); |
| 483 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | @Override |
| 487 | public boolean onCreateOptionsMenu(Menu menu) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 488 | menu.add(0, MENU_ITEM_DELETE, 0, R.string.menu_deleteContact) |
| 489 | .setIcon(android.R.drawable.ic_menu_delete); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 490 | menu.add(0, MENU_ITEM_SPLIT_AGGREGATE, 0, R.string.menu_splitAggregate) |
| 491 | .setIcon(android.R.drawable.ic_menu_share); |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 492 | menu.add(0, MENU_ITEM_JOIN_AGGREGATE, 0, R.string.menu_joinAggregate) |
| 493 | .setIcon(android.R.drawable.ic_menu_add); |
Dmitri Plotnikov | ef03872 | 2009-06-24 18:51:47 -0700 | [diff] [blame] | 494 | menu.add(0, MENU_ITEM_OPTIONS, 0, R.string.menu_contactOptions) |
| 495 | .setIcon(R.drawable.ic_menu_mark); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 496 | return true; |
| 497 | } |
| 498 | |
| 499 | @Override |
| 500 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 501 | super.onPrepareOptionsMenu(menu); |
| 502 | // Perform this check each time the menu is about to be shown, because the Barcode Scanner |
| 503 | // could be installed or uninstalled at any time. |
| 504 | if (isBarcodeScannerInstalled()) { |
| 505 | if (menu.findItem(MENU_ITEM_SHOW_BARCODE) == null) { |
| 506 | menu.add(0, MENU_ITEM_SHOW_BARCODE, 0, R.string.menu_showBarcode) |
| 507 | .setIcon(R.drawable.ic_menu_show_barcode); |
| 508 | } |
| 509 | } else { |
| 510 | menu.removeItem(MENU_ITEM_SHOW_BARCODE); |
| 511 | } |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 512 | |
Evan Millar | db5d88c | 2009-08-28 09:31:57 -0700 | [diff] [blame] | 513 | // Only show the edit option if we have a selected tab. |
| 514 | if (mSelectedRawContactId != null) { |
| 515 | if (menu.findItem(MENU_ITEM_EDIT) == null) { |
| 516 | menu.add(0, MENU_ITEM_EDIT, 0, R.string.menu_editContact) |
| 517 | .setIcon(android.R.drawable.ic_menu_edit) |
| 518 | .setAlphabeticShortcut('e'); |
| 519 | } |
| 520 | } else { |
| 521 | menu.removeItem(MENU_ITEM_EDIT); |
| 522 | } |
| 523 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 524 | boolean isAggregate = mRawContactIds.size() > 1; |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 525 | menu.findItem(MENU_ITEM_SPLIT_AGGREGATE).setEnabled(isAggregate); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 526 | return true; |
| 527 | } |
| 528 | |
| 529 | private boolean isBarcodeScannerInstalled() { |
| 530 | final Intent intent = new Intent(SHOW_BARCODE_INTENT); |
| 531 | ResolveInfo ri = getPackageManager().resolveActivity(intent, |
| 532 | PackageManager.MATCH_DEFAULT_ONLY); |
| 533 | return ri != null; |
| 534 | } |
| 535 | |
| 536 | @Override |
| 537 | public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { |
| 538 | AdapterView.AdapterContextMenuInfo info; |
| 539 | try { |
| 540 | info = (AdapterView.AdapterContextMenuInfo) menuInfo; |
| 541 | } catch (ClassCastException e) { |
| 542 | Log.e(TAG, "bad menuInfo", e); |
| 543 | return; |
| 544 | } |
| 545 | |
| 546 | // This can be null sometimes, don't crash... |
| 547 | if (info == null) { |
| 548 | Log.e(TAG, "bad menuInfo"); |
| 549 | return; |
| 550 | } |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 551 | |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 552 | ViewEntry entry = ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS); |
| 553 | if (entry.mimetype.equals(CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) { |
| 554 | menu.add(0, 0, 0, R.string.menu_call).setIntent(entry.intent); |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 555 | menu.add(0, 0, 0, R.string.menu_sendSMS).setIntent(entry.secondaryIntent); |
| 556 | if (!entry.isPrimary) { |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 557 | 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] | 558 | } |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 559 | } else if (entry.mimetype.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)) { |
| 560 | menu.add(0, 0, 0, R.string.menu_sendEmail).setIntent(entry.intent); |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 561 | if (!entry.isPrimary) { |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 562 | 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] | 563 | } |
Jeff Sharkey | c6ad3ab | 2009-07-21 19:30:15 -0700 | [diff] [blame] | 564 | } else if (entry.mimetype.equals(CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)) { |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 565 | menu.add(0, 0, 0, R.string.menu_viewAddress).setIntent(entry.intent); |
| 566 | } |
| 567 | // TODO(emillar): add back with group support. |
| 568 | /* else if (entry.mimetype.equals()) { |
| 569 | menu.add(0, 0, 0, R.string.menu_viewGroup).setIntent(entry.intent); |
| 570 | } */ |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | @Override |
| 574 | public boolean onOptionsItemSelected(MenuItem item) { |
| 575 | switch (item.getItemId()) { |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 576 | case MENU_ITEM_EDIT: { |
Evan Millar | db5d88c | 2009-08-28 09:31:57 -0700 | [diff] [blame] | 577 | Long rawContactIdToEdit = mSelectedRawContactId; |
| 578 | if (rawContactIdToEdit == null) { |
| 579 | // This shouldn't be possible. We only show the edit option if |
| 580 | // this value is non-null. |
| 581 | break; |
| 582 | } |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 583 | if (rawContactIdToEdit == ALL_CONTACTS_ID) { |
| 584 | // If the "all" tab is selected, edit the next tab. |
Evan Millar | db5d88c | 2009-08-28 09:31:57 -0700 | [diff] [blame] | 585 | rawContactIdToEdit = getTabRawContactId(mTabWidget.getCurrentTab() + 1); |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 586 | } |
| 587 | Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, |
| 588 | rawContactIdToEdit); |
| 589 | startActivityForResult(new Intent(Intent.ACTION_EDIT, rawContactUri), |
| 590 | REQUEST_EDIT_CONTACT); |
| 591 | break; |
| 592 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 593 | case MENU_ITEM_DELETE: { |
| 594 | // Get confirmation |
| 595 | showDialog(DIALOG_CONFIRM_DELETE); |
| 596 | return true; |
| 597 | } |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 598 | |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 599 | case MENU_ITEM_SPLIT_AGGREGATE: { |
Dmitri Plotnikov | 040dc15 | 2009-09-03 15:17:56 -0700 | [diff] [blame^] | 600 | if (mRawContactIds.size() == 2) { |
| 601 | splitContact(mRawContactIds.get(1)); |
| 602 | } else { |
| 603 | showSplitAggregateDialog(); |
| 604 | } |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 605 | return true; |
| 606 | } |
| 607 | |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 608 | case MENU_ITEM_JOIN_AGGREGATE: { |
| 609 | showJoinAggregateActivity(); |
| 610 | return true; |
| 611 | } |
| 612 | |
Dmitri Plotnikov | ef03872 | 2009-06-24 18:51:47 -0700 | [diff] [blame] | 613 | case MENU_ITEM_OPTIONS: { |
| 614 | showOptionsActivity(); |
| 615 | return true; |
| 616 | } |
| 617 | |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 618 | // TODO(emillar) Bring this back. |
| 619 | /*case MENU_ITEM_SHOW_BARCODE: |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 620 | if (mCursor.moveToFirst()) { |
| 621 | Intent intent = new Intent(SHOW_BARCODE_INTENT); |
| 622 | intent.putExtra("ENCODE_TYPE", "CONTACT_TYPE"); |
| 623 | Bundle bundle = new Bundle(); |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 624 | String name = mCursor.getString(AGGREGATE_DISPLAY_NAME_COLUMN); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 625 | if (!TextUtils.isEmpty(name)) { |
Jeffrey Sharkey | 715b32a | 2009-03-27 18:56:05 -0700 | [diff] [blame] | 626 | // Correctly handle when section headers are hidden |
| 627 | int sepAdjust = SHOW_SEPARATORS ? 1 : 0; |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 628 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 629 | bundle.putString(Contacts.Intents.Insert.NAME, name); |
| 630 | // The 0th ViewEntry in each ArrayList below is a separator item |
Jeffrey Sharkey | 715b32a | 2009-03-27 18:56:05 -0700 | [diff] [blame] | 631 | int entriesToAdd = Math.min(mPhoneEntries.size() - sepAdjust, PHONE_KEYS.length); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 632 | for (int x = 0; x < entriesToAdd; x++) { |
Jeffrey Sharkey | 715b32a | 2009-03-27 18:56:05 -0700 | [diff] [blame] | 633 | ViewEntry entry = mPhoneEntries.get(x + sepAdjust); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 634 | bundle.putString(PHONE_KEYS[x], entry.data); |
| 635 | } |
Jeffrey Sharkey | 715b32a | 2009-03-27 18:56:05 -0700 | [diff] [blame] | 636 | entriesToAdd = Math.min(mEmailEntries.size() - sepAdjust, EMAIL_KEYS.length); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 637 | for (int x = 0; x < entriesToAdd; x++) { |
Jeffrey Sharkey | 715b32a | 2009-03-27 18:56:05 -0700 | [diff] [blame] | 638 | ViewEntry entry = mEmailEntries.get(x + sepAdjust); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 639 | bundle.putString(EMAIL_KEYS[x], entry.data); |
| 640 | } |
Jeffrey Sharkey | 715b32a | 2009-03-27 18:56:05 -0700 | [diff] [blame] | 641 | if (mPostalEntries.size() >= 1 + sepAdjust) { |
| 642 | ViewEntry entry = mPostalEntries.get(sepAdjust); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 643 | bundle.putString(Contacts.Intents.Insert.POSTAL, entry.data); |
| 644 | } |
| 645 | intent.putExtra("ENCODE_DATA", bundle); |
| 646 | try { |
| 647 | startActivity(intent); |
| 648 | } catch (ActivityNotFoundException e) { |
| 649 | // The check in onPrepareOptionsMenu() should make this impossible, but |
| 650 | // for safety I'm catching the exception rather than crashing. Ideally |
| 651 | // I'd call Menu.removeItem() here too, but I don't see a way to get |
| 652 | // the options menu. |
| 653 | Log.e(TAG, "Show barcode menu item was clicked but Barcode Scanner " + |
| 654 | "was not installed."); |
| 655 | } |
| 656 | return true; |
| 657 | } |
| 658 | } |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 659 | break; */ |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 660 | } |
| 661 | return super.onOptionsItemSelected(item); |
| 662 | } |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 663 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 664 | @Override |
| 665 | public boolean onContextItemSelected(MenuItem item) { |
| 666 | switch (item.getItemId()) { |
| 667 | case MENU_ITEM_MAKE_DEFAULT: { |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 668 | if (makeItemDefault(item)) { |
| 669 | return true; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 670 | } |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 671 | break; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 672 | } |
| 673 | } |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 674 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 675 | return super.onContextItemSelected(item); |
| 676 | } |
| 677 | |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 678 | private boolean makeItemDefault(MenuItem item) { |
| 679 | ViewEntry entry = getViewEntryForMenuItem(item); |
| 680 | if (entry == null) { |
| 681 | return false; |
| 682 | } |
| 683 | |
| 684 | // Update the primary values in the data record. |
| 685 | ContentValues values = new ContentValues(2); |
| 686 | values.put(Data.IS_PRIMARY, 1); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 687 | |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 688 | if (entry.ids.size() > 0) { |
| 689 | for (int i = 0; i < entry.ids.size(); i++) { |
| 690 | getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, |
| 691 | entry.ids.get(i)), |
| 692 | values, null, null); |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | values.put(Data.IS_SUPER_PRIMARY, 1); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 697 | getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, entry.id), |
| 698 | values, null, null); |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 699 | startEntityQuery(); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 700 | return true; |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Shows a dialog that contains a list of all constituent contacts in this aggregate. |
| 705 | * The user picks a contact to be split into its own aggregate or clicks Cancel. |
| 706 | */ |
| 707 | private void showSplitAggregateDialog() { |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 708 | // Wrap this dialog in a specific theme so that list items have correct text color. |
| 709 | final ContextThemeWrapper dialogContext = |
| 710 | new ContextThemeWrapper(this, android.R.style.Theme_Light); |
| 711 | AlertDialog.Builder builder = |
| 712 | new AlertDialog.Builder(dialogContext); |
| 713 | builder.setTitle(getString(R.string.splitAggregate_title)); |
| 714 | |
| 715 | final SplitAggregateView view = new SplitAggregateView(dialogContext, mUri); |
| 716 | builder.setView(view); |
| 717 | |
| 718 | builder.setInverseBackgroundForced(true); |
| 719 | builder.setCancelable(true); |
| 720 | builder.setNegativeButton(android.R.string.cancel, |
| 721 | new OnClickListener() { |
| 722 | public void onClick(DialogInterface dialog, int which) { |
| 723 | dialog.dismiss(); |
| 724 | } |
| 725 | }); |
| 726 | final AlertDialog dialog = builder.create(); |
| 727 | |
| 728 | view.setOnContactSelectedListener(new OnContactSelectedListener() { |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 729 | public void onContactSelected(long rawContactId) { |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 730 | dialog.dismiss(); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 731 | splitContact(rawContactId); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 732 | } |
| 733 | }); |
| 734 | |
| 735 | dialog.show(); |
| 736 | } |
| 737 | |
| 738 | /** |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 739 | * 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] | 740 | */ |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 741 | public void showJoinAggregateActivity() { |
| 742 | Intent intent = new Intent(ContactsListActivity.JOIN_AGGREGATE); |
| 743 | intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_ID, ContentUris.parseId(mUri)); |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 744 | startActivityForResult(intent, REQUEST_JOIN_CONTACT); |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 745 | } |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 746 | |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 747 | @Override |
| 748 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { |
Evan Millar | 8a79cee | 2009-08-19 17:20:49 -0700 | [diff] [blame] | 749 | switch (requestCode) { |
| 750 | case REQUEST_JOIN_CONTACT: { |
| 751 | if (resultCode == RESULT_OK && intent != null) { |
| 752 | final long aggregateId = ContentUris.parseId(intent.getData()); |
| 753 | joinAggregate(aggregateId); |
| 754 | } |
| 755 | break; |
| 756 | } |
| 757 | case REQUEST_EDIT_CONTACT: { |
| 758 | if (resultCode == RESULT_OK && intent != null) { |
| 759 | long newInitialSelectedRawContactId = intent.getLongExtra( |
| 760 | RAW_CONTACT_ID_EXTRA, ALL_CONTACTS_ID); |
| 761 | if (newInitialSelectedRawContactId != mSelectedRawContactId) { |
| 762 | mSelectedRawContactId = newInitialSelectedRawContactId; |
| 763 | selectInitialTab(); |
| 764 | } |
| 765 | } |
| 766 | } |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 770 | private void splitContact(long rawContactId) { |
| 771 | setAggregationException(rawContactId, AggregationExceptions.TYPE_KEEP_OUT); |
| 772 | |
| 773 | // The split operation may have removed the original aggregate contact, so we need |
| 774 | // to requery everything |
Dmitri Plotnikov | 040dc15 | 2009-09-03 15:17:56 -0700 | [diff] [blame^] | 775 | Toast.makeText(this, R.string.contactsSplitMessage, Toast.LENGTH_LONG).show(); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 776 | startEntityQuery(); |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | private void joinAggregate(final long aggregateId) { |
Dmitri Plotnikov | 3946659 | 2009-07-27 11:23:51 -0700 | [diff] [blame] | 780 | Cursor c = mResolver.query(RawContacts.CONTENT_URI, new String[] {RawContacts._ID}, |
Dmitri Plotnikov | e1cd679 | 2009-07-27 20:28:17 -0700 | [diff] [blame] | 781 | RawContacts.CONTACT_ID + "=" + aggregateId, null, null); |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 782 | |
| 783 | try { |
| 784 | while(c.moveToNext()) { |
| 785 | long contactId = c.getLong(0); |
| 786 | setAggregationException(contactId, AggregationExceptions.TYPE_KEEP_IN); |
| 787 | } |
| 788 | } finally { |
| 789 | c.close(); |
| 790 | } |
| 791 | |
Dmitri Plotnikov | 040dc15 | 2009-09-03 15:17:56 -0700 | [diff] [blame^] | 792 | Toast.makeText(this, R.string.contactsJoinedMessage, Toast.LENGTH_LONG).show(); |
| 793 | startEntityQuery(); |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | /** |
| 797 | * Given a contact ID sets an aggregation exception to either join the contact with the |
| 798 | * current aggregate or split off. |
| 799 | */ |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 800 | protected void setAggregationException(long rawContactId, int exceptionType) { |
Dmitri Plotnikov | d09f75c | 2009-06-16 11:59:22 -0700 | [diff] [blame] | 801 | ContentValues values = new ContentValues(3); |
Dmitri Plotnikov | e1cd679 | 2009-07-27 20:28:17 -0700 | [diff] [blame] | 802 | values.put(AggregationExceptions.CONTACT_ID, ContentUris.parseId(mUri)); |
Dmitri Plotnikov | 99eafe7 | 2009-09-03 14:09:45 -0700 | [diff] [blame] | 803 | values.put(AggregationExceptions.RAW_CONTACT_ID, rawContactId); |
Dmitri Plotnikov | 49f705f | 2009-06-17 18:31:56 -0700 | [diff] [blame] | 804 | values.put(AggregationExceptions.TYPE, exceptionType); |
Dmitri Plotnikov | d09f75c | 2009-06-16 11:59:22 -0700 | [diff] [blame] | 805 | mResolver.update(AggregationExceptions.CONTENT_URI, values, null, null); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Dmitri Plotnikov | ef03872 | 2009-06-24 18:51:47 -0700 | [diff] [blame] | 808 | private void showOptionsActivity() { |
| 809 | final Intent intent = new Intent(this, ContactOptionsActivity.class); |
| 810 | intent.setData(mUri); |
| 811 | startActivity(intent); |
| 812 | } |
| 813 | |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 814 | private ViewEntry getViewEntryForMenuItem(MenuItem item) { |
| 815 | AdapterView.AdapterContextMenuInfo info; |
| 816 | try { |
| 817 | info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); |
| 818 | } catch (ClassCastException e) { |
| 819 | Log.e(TAG, "bad menuInfo", e); |
| 820 | return null; |
| 821 | } |
| 822 | |
| 823 | return ContactEntryAdapter.getEntry(mSections, info.position, SHOW_SEPARATORS); |
| 824 | } |
| 825 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 826 | @Override |
| 827 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 828 | switch (keyCode) { |
| 829 | case KeyEvent.KEYCODE_CALL: { |
| 830 | try { |
| 831 | ITelephony phone = ITelephony.Stub.asInterface( |
| 832 | ServiceManager.checkService("phone")); |
| 833 | if (phone != null && !phone.isIdle()) { |
| 834 | // Skip out and let the key be handled at a higher level |
| 835 | break; |
| 836 | } |
| 837 | } catch (RemoteException re) { |
| 838 | // Fall through and try to call the contact |
| 839 | } |
| 840 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 841 | int index = mListView.getSelectedItemPosition(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 842 | if (index != -1) { |
| 843 | ViewEntry entry = ViewAdapter.getEntry(mSections, index, SHOW_SEPARATORS); |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 844 | if (entry.intent.getAction() == Intent.ACTION_CALL_PRIVILEGED) { |
| 845 | startActivity(entry.intent); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 846 | } |
| 847 | } else if (mNumPhoneNumbers != 0) { |
| 848 | // There isn't anything selected, call the default number |
| 849 | Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, mUri); |
| 850 | startActivity(intent); |
| 851 | } |
| 852 | return true; |
| 853 | } |
| 854 | |
| 855 | case KeyEvent.KEYCODE_DEL: { |
| 856 | showDialog(DIALOG_CONFIRM_DELETE); |
| 857 | return true; |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | return super.onKeyDown(keyCode, event); |
| 862 | } |
| 863 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 864 | 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] | 865 | ViewEntry entry = ViewAdapter.getEntry(mSections, position, SHOW_SEPARATORS); |
| 866 | if (entry != null) { |
| 867 | Intent intent = entry.intent; |
| 868 | if (intent != null) { |
| 869 | try { |
| 870 | startActivity(intent); |
| 871 | } catch (ActivityNotFoundException e) { |
| 872 | Log.e(TAG, "No activity found for intent: " + intent); |
| 873 | signalError(); |
| 874 | } |
| 875 | } else { |
| 876 | signalError(); |
| 877 | } |
| 878 | } else { |
| 879 | signalError(); |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | /** |
| 884 | * Signal an error to the user via a beep, or some other method. |
| 885 | */ |
| 886 | private void signalError() { |
| 887 | //TODO: implement this when we have the sonification APIs |
| 888 | } |
| 889 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 890 | private Uri constructImToUrl(String host, String data) { |
Evan Millar | 45e0ed3 | 2009-06-01 16:44:38 -0700 | [diff] [blame] | 891 | // don't encode the url, because the Activity Manager can't find using the encoded url |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 892 | StringBuilder buf = new StringBuilder("imto://"); |
| 893 | buf.append(host); |
| 894 | buf.append('/'); |
| 895 | buf.append(data); |
| 896 | return Uri.parse(buf.toString()); |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * Build up the entries to display on the screen. |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 901 | * |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 902 | * @param personCursor the URI for the contact being displayed |
| 903 | */ |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 904 | private final void buildEntries() { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 905 | // Clear out the old entries |
| 906 | final int numSections = mSections.size(); |
| 907 | for (int i = 0; i < numSections; i++) { |
| 908 | mSections.get(i).clear(); |
| 909 | } |
| 910 | |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 911 | mRawContactIds.clear(); |
Dmitri Plotnikov | b4491ee | 2009-06-15 09:31:02 -0700 | [diff] [blame] | 912 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 913 | Sources sources = Sources.getInstance(this); |
| 914 | |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 915 | // Build up method entries |
| 916 | if (mUri != null) { |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 917 | for (Entity entity: mEntities) { |
| 918 | final ContentValues entValues = entity.getEntityValues(); |
| 919 | final String accountType = entValues.getAsString(RawContacts.ACCOUNT_TYPE); |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 920 | // TODO: entry.contactId should be renamed to entry.rawContactId |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 921 | long contactId = entValues.getAsLong(RawContacts._ID); |
Evan Millar | 7911ff5 | 2009-07-21 15:55:18 -0700 | [diff] [blame] | 922 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 923 | for (NamedContentValues subValue : entity.getSubValues()) { |
| 924 | ViewEntry entry = new ViewEntry(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 925 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 926 | ContentValues entryValues = subValue.values; |
| 927 | final String mimetype = entryValues.getAsString(Data.MIMETYPE); |
| 928 | if (mimetype == null || accountType == null) { |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 929 | continue; |
| 930 | } |
| 931 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 932 | ContactsSource contactsSource = sources.getInflatedSource(accountType, |
| 933 | ContactsSource.LEVEL_MIMETYPES); |
| 934 | if (contactsSource == null) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 935 | continue; |
| 936 | } |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 937 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 938 | DataKind kind = contactsSource.getKindForMimetype(mimetype); |
| 939 | if (kind == null) { |
| 940 | continue; |
| 941 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 942 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 943 | final long id = entryValues.getAsLong(Data._ID); |
| 944 | final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, id); |
| 945 | entry.contactId = contactId; |
| 946 | entry.id = id; |
| 947 | entry.uri = uri; |
| 948 | entry.mimetype = mimetype; |
| 949 | entry.label = buildActionString(kind, entryValues, true); |
| 950 | entry.data = buildDataString(kind, entryValues); |
| 951 | if (kind.typeColumn != null) { |
| 952 | entry.type = entryValues.getAsInteger(kind.typeColumn); |
| 953 | } |
| 954 | if (kind.iconRes > 0) { |
| 955 | entry.actionIcon = kind.iconRes; |
| 956 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 957 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 958 | // Don't crash if the data is bogus |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 959 | if (TextUtils.isEmpty(entry.data)) { |
| 960 | Log.w(TAG, "empty data for contact method " + id); |
Alex Kennberg | 87fc317 | 2009-03-28 06:43:06 -0700 | [diff] [blame] | 961 | continue; |
| 962 | } |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 963 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 964 | if (!mRawContactIds.contains(entry.contactId)) { |
| 965 | mRawContactIds.add(entry.contactId); |
| 966 | } |
| 967 | |
| 968 | // This performs the tab filtering |
| 969 | if (mSelectedRawContactId != null |
| 970 | && mSelectedRawContactId != entry.contactId |
| 971 | && mSelectedRawContactId != ALL_CONTACTS_ID) { |
| 972 | continue; |
| 973 | } |
| 974 | |
| 975 | if (CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(mimetype) |
| 976 | || CommonDataKinds.Email.CONTENT_ITEM_TYPE.equals(mimetype) |
| 977 | || CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE.equals(mimetype) |
| 978 | || CommonDataKinds.Im.CONTENT_ITEM_TYPE.equals(mimetype)) { |
| 979 | final boolean isSuperPrimary = entryValues.getAsInteger( |
| 980 | Data.IS_SUPER_PRIMARY) != 0; |
| 981 | |
| 982 | if (CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(mimetype)) { |
| 983 | // Build phone entries |
| 984 | mNumPhoneNumbers++; |
| 985 | |
| 986 | entry.intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
| 987 | Uri.fromParts("tel", entry.data, null)); |
| 988 | entry.secondaryIntent = new Intent(Intent.ACTION_SENDTO, |
| 989 | Uri.fromParts("sms", entry.data, null)); |
| 990 | entry.data = PhoneNumberUtils.stripSeparators(entry.data); |
Evan Millar | 49714ee | 2009-09-02 16:42:47 -0700 | [diff] [blame] | 991 | |
| 992 | // If data is empty, don't show it. |
| 993 | if (TextUtils.isEmpty(entry.data)) { |
| 994 | Log.w(TAG, "empty data for contact method " + id); |
| 995 | continue; |
| 996 | } |
| 997 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 998 | entry.isPrimary = isSuperPrimary; |
| 999 | mPhoneEntries.add(entry); |
| 1000 | |
| 1001 | if (entry.type == CommonDataKinds.Phone.TYPE_MOBILE |
| 1002 | || mShowSmsLinksForAllPhones) { |
| 1003 | // Add an SMS entry |
| 1004 | if (kind.iconAltRes > 0) { |
| 1005 | entry.secondaryActionIcon = kind.iconAltRes; |
| 1006 | } |
| 1007 | } |
| 1008 | } else if (CommonDataKinds.Email.CONTENT_ITEM_TYPE.equals(mimetype)) { |
| 1009 | // Build email entries |
| 1010 | entry.intent = new Intent(Intent.ACTION_SENDTO, |
| 1011 | Uri.fromParts("mailto", entry.data, null)); |
Evan Millar | 49714ee | 2009-09-02 16:42:47 -0700 | [diff] [blame] | 1012 | // Temporary hack until we get real label resources for exchange. |
| 1013 | if (TextUtils.isEmpty(entry.label)) { |
| 1014 | entry.label = getString(R.string.email).toLowerCase(); |
| 1015 | } |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 1016 | entry.isPrimary = isSuperPrimary; |
| 1017 | mEmailEntries.add(entry); |
| 1018 | } else if (CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE. |
| 1019 | equals(mimetype)) { |
| 1020 | // Build postal entries |
| 1021 | entry.maxLines = 4; |
| 1022 | entry.intent = new Intent(Intent.ACTION_VIEW, uri); |
| 1023 | mPostalEntries.add(entry); |
| 1024 | } else if (CommonDataKinds.Im.CONTENT_ITEM_TYPE.equals(mimetype)) { |
| 1025 | // Build im entries |
| 1026 | Object protocolObj = entryValues.getAsInteger(Data.DATA5); |
| 1027 | String host = null; |
| 1028 | |
Evan Millar | 49714ee | 2009-09-02 16:42:47 -0700 | [diff] [blame] | 1029 | if (TextUtils.isEmpty(entry.label)) { |
| 1030 | entry.label = getString(R.string.im).toLowerCase(); |
| 1031 | } |
| 1032 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 1033 | if (protocolObj instanceof Number) { |
| 1034 | int protocol = ((Number) protocolObj).intValue(); |
| 1035 | host = ContactsUtils.lookupProviderNameFromId( |
| 1036 | protocol).toLowerCase(); |
| 1037 | if (protocol == CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK |
| 1038 | || protocol == CommonDataKinds.Im.PROTOCOL_MSN) { |
| 1039 | entry.maxLabelLines = 2; |
| 1040 | } |
| 1041 | } else if (protocolObj != null) { |
| 1042 | String providerName = (String) protocolObj; |
| 1043 | host = providerName.toLowerCase(); |
| 1044 | } |
| 1045 | |
| 1046 | // Only add the intent if there is a valid host |
| 1047 | if (!TextUtils.isEmpty(host)) { |
| 1048 | entry.intent = new Intent(Intent.ACTION_SENDTO, |
| 1049 | constructImToUrl(host, entry.data)); |
| 1050 | } |
| 1051 | //TODO(emillar) Add in presence info |
| 1052 | /*if (!aggCursor.isNull(METHODS_STATUS_COLUMN)) { |
| 1053 | entry.presenceIcon = Presence.getPresenceIconResourceId( |
| 1054 | aggCursor.getInt(METHODS_STATUS_COLUMN)); |
| 1055 | entry.status = ... |
| 1056 | }*/ |
| 1057 | mImEntries.add(entry); |
| 1058 | } |
| 1059 | } else if (CommonDataKinds.Organization.CONTENT_ITEM_TYPE.equals(mimetype)) { |
| 1060 | // Build organization entries |
| 1061 | mOrganizationEntries.add(entry); |
| 1062 | } else if (CommonDataKinds.Note.CONTENT_ITEM_TYPE.equals(mimetype)) { |
| 1063 | // Build note entries |
| 1064 | entry.id = 0; |
| 1065 | entry.uri = null; |
| 1066 | entry.intent = null; |
| 1067 | entry.maxLines = 10; |
| 1068 | mOtherEntries.add(entry); |
| 1069 | } |
| 1070 | |
| 1071 | |
| 1072 | // TODO(emillar) Add group entries |
| 1073 | // // Build the group entries |
| 1074 | // final Uri groupsUri = Uri.withAppendedPath(mUri, GroupMembership.CONTENT_DIRECTORY); |
| 1075 | // Cursor groupCursor = mResolver.query(groupsUri, ContactsListActivity.GROUPS_PROJECTION, |
| 1076 | // null, null, Groups.DEFAULT_SORT_ORDER); |
| 1077 | // if (groupCursor != null) { |
| 1078 | // try { |
| 1079 | // StringBuilder sb = new StringBuilder(); |
| 1080 | // |
| 1081 | // while (groupCursor.moveToNext()) { |
| 1082 | // String systemId = groupCursor.getString( |
| 1083 | // ContactsListActivity.GROUPS_COLUMN_INDEX_SYSTEM_ID); |
| 1084 | // |
| 1085 | // if (systemId != null || Groups.GROUP_MY_CONTACTS.equals(systemId)) { |
| 1086 | // continue; |
| 1087 | // } |
| 1088 | // |
| 1089 | // String name = groupCursor.getString(ContactsListActivity.GROUPS_COLUMN_INDEX_NAME); |
| 1090 | // if (!TextUtils.isEmpty(name)) { |
| 1091 | // if (sb.length() == 0) { |
| 1092 | // sb.append(name); |
| 1093 | // } else { |
| 1094 | // sb.append(getString(R.string.group_list, name)); |
| 1095 | // } |
| 1096 | // } |
| 1097 | // } |
| 1098 | // |
| 1099 | // if (sb.length() > 0) { |
| 1100 | // ViewEntry entry = new ViewEntry(); |
| 1101 | // entry.kind = ContactEntryAdapter.Entry.KIND_GROUP; |
| 1102 | // entry.label = getString(R.string.label_groups); |
| 1103 | // entry.data = sb.toString(); |
| 1104 | // entry.intent = new Intent(Intent.ACTION_EDIT, mUri); |
| 1105 | // |
| 1106 | // // TODO: Add an icon for the groups item. |
| 1107 | // |
| 1108 | // mGroupEntries.add(entry); |
| 1109 | // } |
| 1110 | // } finally { |
| 1111 | // groupCursor.close(); |
| 1112 | // } |
| 1113 | // } |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 1114 | } |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 1115 | |
Evan Millar | 66388be | 2009-05-28 15:41:07 -0700 | [diff] [blame] | 1116 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 1120 | String buildActionString(DataKind kind, ContentValues values, boolean lowerCase) { |
| 1121 | if (kind.actionHeader == null) { |
| 1122 | return null; |
Jeff Hamilton | 8350e5b | 2009-03-24 21:01:34 -0700 | [diff] [blame] | 1123 | } |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 1124 | CharSequence actionHeader = kind.actionHeader.inflateUsing(this, values); |
| 1125 | if (actionHeader == null) { |
| 1126 | return null; |
| 1127 | } |
| 1128 | return lowerCase ? actionHeader.toString().toLowerCase() : actionHeader.toString(); |
| 1129 | } |
Jeff Hamilton | 8350e5b | 2009-03-24 21:01:34 -0700 | [diff] [blame] | 1130 | |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 1131 | String buildDataString(DataKind kind, ContentValues values) { |
| 1132 | if (kind.actionBody == null) { |
| 1133 | return null; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1134 | } |
Evan Millar | 11d628c | 2009-09-02 08:55:01 -0700 | [diff] [blame] | 1135 | CharSequence actionBody = kind.actionBody.inflateUsing(this, values); |
| 1136 | return actionBody == null ? null : actionBody.toString(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1137 | } |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 1138 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1139 | /** |
| 1140 | * A basic structure with the data for a contact entry in the list. |
| 1141 | */ |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1142 | static class ViewEntry extends ContactEntryAdapter.Entry implements Collapsible<ViewEntry> { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1143 | public int actionIcon = -1; |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1144 | public boolean isPrimary = false; |
| 1145 | public int presenceIcon = -1; |
| 1146 | public int secondaryActionIcon = -1; |
| 1147 | public Intent intent; |
| 1148 | public Intent secondaryIntent = null; |
| 1149 | public int status = -1; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1150 | public int maxLabelLines = 1; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1151 | public ArrayList<Long> ids = new ArrayList<Long>(); |
| 1152 | public int collapseCount = 0; |
| 1153 | |
| 1154 | public boolean collapseWith(ViewEntry entry) { |
| 1155 | // assert equal collapse keys |
| 1156 | if (!getCollapseKey().equals(entry.getCollapseKey())) { |
| 1157 | return false; |
| 1158 | } |
| 1159 | |
| 1160 | // Choose the label associated with the highest type precedence. |
| 1161 | if (TypePrecedence.getTypePrecedence(mimetype, type) |
| 1162 | > TypePrecedence.getTypePrecedence(entry.mimetype, entry.type)) { |
| 1163 | type = entry.type; |
| 1164 | label = entry.label; |
| 1165 | } |
| 1166 | |
| 1167 | // Choose the max of the maxLines and maxLabelLines values. |
| 1168 | maxLines = Math.max(maxLines, entry.maxLines); |
| 1169 | maxLabelLines = Math.max(maxLabelLines, entry.maxLabelLines); |
| 1170 | |
| 1171 | // Choose the presence with the highest precedence. |
| 1172 | if (Presence.getPresencePrecedence(status) |
| 1173 | < Presence.getPresencePrecedence(entry.status)) { |
| 1174 | status = entry.status; |
| 1175 | } |
| 1176 | |
| 1177 | // 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] | 1178 | isPrimary = entry.isPrimary ? true : isPrimary; |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1179 | |
| 1180 | // uri, and contactdId, shouldn't make a difference. Just keep the original. |
| 1181 | |
| 1182 | // Keep track of all the ids that have been collapsed with this one. |
| 1183 | ids.add(entry.id); |
| 1184 | collapseCount++; |
| 1185 | return true; |
| 1186 | } |
| 1187 | |
| 1188 | public String getCollapseKey() { |
| 1189 | StringBuilder hashSb = new StringBuilder(); |
| 1190 | hashSb.append(data); |
| 1191 | hashSb.append(mimetype); |
| 1192 | hashSb.append((intent != null && intent.getAction() != null) |
| 1193 | ? intent.getAction() : ""); |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1194 | hashSb.append((secondaryIntent != null && secondaryIntent.getAction() != null) |
| 1195 | ? secondaryIntent.getAction() : ""); |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1196 | hashSb.append(actionIcon); |
| 1197 | return hashSb.toString(); |
| 1198 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1199 | } |
| 1200 | |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1201 | /** Cache of the children views of a row */ |
| 1202 | static class ViewCache { |
| 1203 | public TextView label; |
| 1204 | public TextView data; |
| 1205 | public ImageView actionIcon; |
| 1206 | public ImageView presenceIcon; |
| 1207 | public ImageView primaryIcon; |
| 1208 | public ImageView secondaryActionButton; |
| 1209 | public View secondaryActionDivider; |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 1210 | |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1211 | // Need to keep track of this too |
| 1212 | ViewEntry entry; |
| 1213 | } |
| 1214 | |
| 1215 | private final class ViewAdapter extends ContactEntryAdapter<ViewEntry> |
| 1216 | implements View.OnClickListener { |
| 1217 | |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 1218 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1219 | ViewAdapter(Context context, ArrayList<ArrayList<ViewEntry>> sections) { |
| 1220 | super(context, sections, SHOW_SEPARATORS); |
| 1221 | } |
| 1222 | |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1223 | public void onClick(View v) { |
| 1224 | Intent intent = (Intent) v.getTag(); |
| 1225 | startActivity(intent); |
| 1226 | } |
| 1227 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1228 | @Override |
| 1229 | public View getView(int position, View convertView, ViewGroup parent) { |
Evan Millar | 5c22c3b | 2009-05-29 11:37:54 -0700 | [diff] [blame] | 1230 | ViewEntry entry = getEntry(mSections, position, false); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1231 | View v; |
| 1232 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1233 | ViewCache views; |
| 1234 | |
| 1235 | // Check to see if we can reuse convertView |
| 1236 | if (convertView != null) { |
| 1237 | v = convertView; |
| 1238 | views = (ViewCache) v.getTag(); |
| 1239 | } else { |
| 1240 | // Create a new view if needed |
| 1241 | v = mInflater.inflate(R.layout.list_item_text_icons, parent, false); |
| 1242 | |
| 1243 | // Cache the children |
| 1244 | views = new ViewCache(); |
| 1245 | views.label = (TextView) v.findViewById(android.R.id.text1); |
| 1246 | views.data = (TextView) v.findViewById(android.R.id.text2); |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1247 | views.actionIcon = (ImageView) v.findViewById(R.id.action_icon); |
| 1248 | views.primaryIcon = (ImageView) v.findViewById(R.id.primary_icon); |
| 1249 | views.presenceIcon = (ImageView) v.findViewById(R.id.presence_icon); |
| 1250 | views.secondaryActionButton = (ImageView) v.findViewById( |
| 1251 | R.id.secondary_action_button); |
| 1252 | views.secondaryActionButton.setOnClickListener(this); |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1253 | views.secondaryActionDivider = v.findViewById(R.id.divider); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1254 | v.setTag(views); |
| 1255 | } |
| 1256 | |
| 1257 | // Update the entry in the view cache |
| 1258 | views.entry = entry; |
| 1259 | |
| 1260 | // Bind the data to the view |
| 1261 | bindView(v, entry); |
| 1262 | return v; |
| 1263 | } |
| 1264 | |
| 1265 | @Override |
| 1266 | protected View newView(int position, ViewGroup parent) { |
| 1267 | // getView() handles this |
| 1268 | throw new UnsupportedOperationException(); |
| 1269 | } |
| 1270 | |
| 1271 | @Override |
| 1272 | protected void bindView(View view, ViewEntry entry) { |
| 1273 | final Resources resources = mContext.getResources(); |
| 1274 | ViewCache views = (ViewCache) view.getTag(); |
| 1275 | |
| 1276 | // Set the label |
| 1277 | TextView label = views.label; |
| 1278 | setMaxLines(label, entry.maxLabelLines); |
| 1279 | label.setText(entry.label); |
| 1280 | |
| 1281 | // Set the data |
| 1282 | TextView data = views.data; |
| 1283 | if (data != null) { |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1284 | if (entry.mimetype.equals(Phone.CONTENT_ITEM_TYPE) |
| 1285 | || entry.mimetype.equals(FastTrackWindow.MIME_SMS_ADDRESS)) { |
| 1286 | data.setText(PhoneNumberUtils.formatNumber(entry.data)); |
| 1287 | } else { |
| 1288 | data.setText(entry.data); |
| 1289 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1290 | setMaxLines(data, entry.maxLines); |
| 1291 | } |
| 1292 | |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1293 | // Set the primary icon |
| 1294 | views.primaryIcon.setVisibility(entry.isPrimary ? View.VISIBLE : View.GONE); |
| 1295 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1296 | // Set the action icon |
| 1297 | ImageView action = views.actionIcon; |
| 1298 | if (entry.actionIcon != -1) { |
| 1299 | action.setImageDrawable(resources.getDrawable(entry.actionIcon)); |
| 1300 | action.setVisibility(View.VISIBLE); |
| 1301 | } else { |
| 1302 | // Things should still line up as if there was an icon, so make it invisible |
| 1303 | action.setVisibility(View.INVISIBLE); |
| 1304 | } |
| 1305 | |
| 1306 | // Set the presence icon |
| 1307 | Drawable presenceIcon = null; |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1308 | if (entry.presenceIcon != -1) { |
| 1309 | presenceIcon = resources.getDrawable(entry.presenceIcon); |
Evan Millar | 54a5c9f | 2009-06-23 17:41:09 -0700 | [diff] [blame] | 1310 | } else if (entry.status != -1) { |
| 1311 | presenceIcon = resources.getDrawable( |
| 1312 | Presence.getPresenceIconResourceId(entry.status)); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1313 | } |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1314 | ImageView presenceIconView = views.presenceIcon; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1315 | if (presenceIcon != null) { |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1316 | presenceIconView.setImageDrawable(presenceIcon); |
| 1317 | presenceIconView.setVisibility(View.VISIBLE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1318 | } else { |
Evan Millar | 15e514d | 2009-08-04 10:14:57 -0700 | [diff] [blame] | 1319 | presenceIconView.setVisibility(View.GONE); |
| 1320 | } |
| 1321 | |
| 1322 | // Set the secondary action button |
| 1323 | ImageView secondaryActionView = views.secondaryActionButton; |
| 1324 | Drawable secondaryActionIcon = null; |
| 1325 | if (entry.secondaryActionIcon != -1) { |
| 1326 | secondaryActionIcon = resources.getDrawable(entry.secondaryActionIcon); |
| 1327 | } |
| 1328 | if (entry.secondaryIntent != null && secondaryActionIcon != null) { |
| 1329 | secondaryActionView.setImageDrawable(secondaryActionIcon); |
| 1330 | secondaryActionView.setTag(entry.secondaryIntent); |
| 1331 | secondaryActionView.setVisibility(View.VISIBLE); |
| 1332 | views.secondaryActionDivider.setVisibility(View.VISIBLE); |
| 1333 | } else { |
| 1334 | secondaryActionView.setVisibility(View.GONE); |
| 1335 | views.secondaryActionDivider.setVisibility(View.GONE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | private void setMaxLines(TextView textView, int maxLines) { |
| 1340 | if (maxLines == 1) { |
| 1341 | textView.setSingleLine(true); |
| 1342 | textView.setEllipsize(TextUtils.TruncateAt.END); |
| 1343 | } else { |
| 1344 | textView.setSingleLine(false); |
| 1345 | textView.setMaxLines(maxLines); |
| 1346 | textView.setEllipsize(null); |
| 1347 | } |
| 1348 | } |
| 1349 | } |
| 1350 | } |