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