blob: a668f795b52997f855191bbe2981ba371b2061c5 [file] [log] [blame]
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001/*
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
17package com.android.contacts;
18
Evan Millar54a5c9f2009-06-23 17:41:09 -070019import com.android.contacts.Collapser.Collapsible;
Evan Millar11d628c2009-09-02 08:55:01 -070020import com.android.contacts.ScrollingTabWidget.OnTabSelectionChangedListener;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070021import com.android.contacts.SplitAggregateView.OnContactSelectedListener;
Evan Millar11d628c2009-09-02 08:55:01 -070022import com.android.contacts.model.ContactsSource;
23import com.android.contacts.model.Sources;
24import com.android.contacts.model.ContactsSource.DataKind;
Evan Millar49714ee2009-09-02 16:42:47 -070025import com.android.contacts.model.HardCodedSources.SimpleInflater;
Jeff Sharkey802b2052009-08-04 14:21:06 -070026import com.android.contacts.ui.FastTrackWindow;
Evan Millar11d628c2009-09-02 08:55:01 -070027import com.android.contacts.util.NotifyingAsyncQueryHandler;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080028import com.android.internal.telephony.ITelephony;
Evan Millar11d628c2009-09-02 08:55:01 -070029import com.android.internal.widget.ContactHeaderWidget;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080030
Evan Millar11d628c2009-09-02 08:55:01 -070031import android.app.Activity;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080032import android.app.AlertDialog;
33import android.app.Dialog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080034import android.content.ActivityNotFoundException;
35import android.content.ContentResolver;
36import android.content.ContentUris;
37import android.content.ContentValues;
38import android.content.Context;
39import android.content.DialogInterface;
Evan Millar5f4af702009-08-11 11:12:00 -070040import android.content.Entity;
Evan Millar11d628c2009-09-02 08:55:01 -070041import android.content.EntityIterator;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080042import android.content.Intent;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070043import android.content.DialogInterface.OnClickListener;
Evan Millar11d628c2009-09-02 08:55:01 -070044import android.content.Entity.NamedContentValues;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080045import android.content.pm.PackageManager;
46import android.content.pm.ResolveInfo;
47import android.content.res.Resources;
48import android.database.ContentObserver;
49import android.database.Cursor;
Dmitri Plotnikov3d53ce22009-09-02 08:44:32 -070050import android.database.DatabaseUtils;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080051import android.graphics.drawable.Drawable;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080052import android.net.Uri;
53import android.os.Bundle;
54import android.os.Handler;
55import android.os.RemoteException;
56import android.os.ServiceManager;
Dmitri Plotnikov040dc152009-09-03 15:17:56 -070057import android.provider.BaseColumns;
Dmitri Plotnikov3d53ce22009-09-02 08:44:32 -070058import android.provider.ContactsContract;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070059import android.provider.ContactsContract.AggregationExceptions;
60import android.provider.ContactsContract.CommonDataKinds;
Evan Millar11d628c2009-09-02 08:55:01 -070061import android.provider.ContactsContract.Contacts;
Evan Millar66388be2009-05-28 15:41:07 -070062import android.provider.ContactsContract.Data;
Evan Millar54a5c9f2009-06-23 17:41:09 -070063import android.provider.ContactsContract.Presence;
Dmitri Plotnikov39466592009-07-27 11:23:51 -070064import android.provider.ContactsContract.RawContacts;
Evan Millar54a5c9f2009-06-23 17:41:09 -070065import android.provider.ContactsContract.CommonDataKinds.Phone;
66import android.telephony.PhoneNumberUtils;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080067import android.text.TextUtils;
68import android.util.Log;
Evan Millar11d628c2009-09-02 08:55:01 -070069import android.util.SparseArray;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080070import android.view.ContextMenu;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -070071import android.view.ContextThemeWrapper;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080072import android.view.KeyEvent;
Evan Millar11d628c2009-09-02 08:55:01 -070073import android.view.LayoutInflater;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080074import android.view.Menu;
75import android.view.MenuItem;
76import android.view.View;
77import android.view.ViewGroup;
Evan Millar11d628c2009-09-02 08:55:01 -070078import android.view.Window;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080079import android.view.ContextMenu.ContextMenuInfo;
80import android.widget.AdapterView;
Evan Millar7911ff52009-07-21 15:55:18 -070081import android.widget.FrameLayout;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080082import android.widget.ImageView;
83import android.widget.ListView;
84import android.widget.TextView;
85import android.widget.Toast;
86
87import java.util.ArrayList;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080088
89/**
90 * Displays the details of a specific contact.
91 */
Evan Millar11d628c2009-09-02 08:55:01 -070092public class ViewContactActivity extends Activity
Evan Millar7911ff52009-07-21 15:55:18 -070093 implements View.OnCreateContextMenuListener, DialogInterface.OnClickListener,
Evan Millar11d628c2009-09-02 08:55:01 -070094 AdapterView.OnItemClickListener, NotifyingAsyncQueryHandler.AsyncQueryListener,
95 OnTabSelectionChangedListener {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080096 private static final String TAG = "ViewContact";
97 private static final String SHOW_BARCODE_INTENT = "com.google.zxing.client.android.ENCODE";
98
Evan Millar8a79cee2009-08-19 17:20:49 -070099 public static final String RAW_CONTACT_ID_EXTRA = "rawContactIdExtra";
100
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800101 private static final boolean SHOW_SEPARATORS = false;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800102
103 private static final int DIALOG_CONFIRM_DELETE = 1;
104
Evan Millar8a79cee2009-08-19 17:20:49 -0700105 private static final int REQUEST_JOIN_CONTACT = 1;
106 private static final int REQUEST_EDIT_CONTACT = 2;
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700107
Evan Millar8a79cee2009-08-19 17:20:49 -0700108 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 Project7aa0e4c2009-03-03 19:32:21 -0800115
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700116 protected Uri mLookupUri;
Evan Millar11d628c2009-09-02 08:55:01 -0700117 private Uri mUri;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800118 private ContentResolver mResolver;
119 private ViewAdapter mAdapter;
120 private int mNumPhoneNumbers = 0;
121
Evan Millar8a79cee2009-08-19 17:20:49 -0700122 private static final long ALL_CONTACTS_ID = -100;
Evan Millar7911ff52009-07-21 15:55:18 -0700123
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700124 /**
Dmitri Plotnikove1cd6792009-07-27 20:28:17 -0700125 * A list of distinct contact IDs included in the current contact.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700126 */
Evan Millar7911ff52009-07-21 15:55:18 -0700127 private ArrayList<Long> mRawContactIds = new ArrayList<Long>();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700128
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800129 /* 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 Projectcac191e2009-03-18 22:20:27 -0700135 /* package */ ArrayList<ViewEntry> mGroupEntries = new ArrayList<ViewEntry>();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800136 /* package */ ArrayList<ViewEntry> mOtherEntries = new ArrayList<ViewEntry>();
137 /* package */ ArrayList<ArrayList<ViewEntry>> mSections = new ArrayList<ArrayList<ViewEntry>>();
138
139 private Cursor mCursor;
Evan Millar5c22c3b2009-05-29 11:37:54 -0700140
Evan Millar11d628c2009-09-02 08:55:01 -0700141 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 Project7aa0e4c2009-03-03 19:32:21 -0800163 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 Millar11d628c2009-09-02 08:55:01 -0700171 if (mCursor != null && !mCursor.isClosed()) {
172 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800173 }
174 }
175 };
176
177 public void onClick(DialogInterface dialog, int which) {
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700178 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800179 getContentResolver().delete(mUri, null, null);
180 finish();
181 }
182
Evan Millar7911ff52009-07-21 15:55:18 -0700183 private FrameLayout mTabContentLayout;
184 private ListView mListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800185 private boolean mShowSmsLinksForAllPhones;
Evan Millar11d628c2009-09-02 08:55:01 -0700186 private ArrayList<Entity> mEntities = null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800187
188 @Override
189 protected void onCreate(Bundle icicle) {
190 super.onCreate(icicle);
191
Evan Millar11d628c2009-09-02 08:55:01 -0700192 final Intent intent = getIntent();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700193 mLookupUri = intent.getData();
Dmitri Plotnikov83129f02009-09-02 19:04:41 -0700194
195 mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Evan Millar11d628c2009-09-02 08:55:01 -0700196
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 Millar11d628c2009-09-02 08:55:01 -0700202 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 Millar7911ff52009-07-21 15:55:18 -0700214 mListView = new ListView(this);
215 mListView.setOnCreateContextMenuListener(this);
216 mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
217 mListView.setOnItemClickListener(this);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800218
Evan Millar7911ff52009-07-21 15:55:18 -0700219 mTabContentLayout = (FrameLayout) findViewById(android.R.id.tabcontent);
220 mTabContentLayout.addView(mListView);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800221
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800222 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 Projectcac191e2009-03-18 22:20:27 -0700232 mSections.add(mGroupEntries);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800233 mSections.add(mOtherEntries);
234
235 //TODO Read this value from a preference
236 mShowSmsLinksForAllPhones = true;
237
Evan Millar11d628c2009-09-02 08:55:01 -0700238 startEntityQuery();
239 }
240
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800241 @Override
242 protected void onResume() {
243 super.onResume();
Evan Millar11d628c2009-09-02 08:55:01 -0700244 startEntityQuery();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800245 }
246
247 @Override
248 protected void onPause() {
249 super.onPause();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700250 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800251 }
252
253 @Override
254 protected void onDestroy() {
255 super.onDestroy();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700256 closeCursor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800257 }
258
259 @Override
Evan Millar11d628c2009-09-02 08:55:01 -0700260 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 Project7aa0e4c2009-03-03 19:32:21 -0800272 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 Millar11d628c2009-09-02 08:55:01 -0700287
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 Millar7911ff52009-07-21 15:55:18 -0700299 addAllTab();
300 }
Evan Millar11d628c2009-09-02 08:55:01 -0700301
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 Millar7911ff52009-07-21 15:55:18 -0700353 private void addAllTab() {
Evan Millar56d2caa2009-08-20 20:30:12 -0700354 View allTabIndicator = mInflater.inflate(R.layout.all_tab_indicator,
355 mTabWidget.getTabParent(), false);
Evan Millar74660912009-08-19 17:36:33 -0700356 allTabIndicator.getBackground().setDither(true);
Evan Millar7911ff52009-07-21 15:55:18 -0700357 addTab(ALL_CONTACTS_ID, allTabIndicator);
358 }
359
360 public void onTabSelectionChanged(int tabIndex, boolean clicked) {
361 long rawContactId = getTabRawContactId(tabIndex);
Evan Millar8a79cee2009-08-19 17:20:49 -0700362 mSelectedRawContactId = rawContactId;
Evan Millar11d628c2009-09-02 08:55:01 -0700363 bindData();
Evan Millar7911ff52009-07-21 15:55:18 -0700364 }
365
Evan Millar11d628c2009-09-02 08:55:01 -0700366 /**
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 Millar2c1cc832009-07-13 11:08:06 -0700375
Evan Millar11d628c2009-09-02 08:55:01 -0700376 /**
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 Project7aa0e4c2009-03-03 19:32:21 -0800387 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800388 }
Evan Millar11d628c2009-09-02 08:55:01 -0700389 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 Plotnikov99eafe72009-09-03 14:09:45 -0700412 // Empty
Evan Millar11d628c2009-09-02 08:55:01 -0700413 }
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 Plotnikov99eafe72009-09-03 14:09:45 -0700428 closeCursor();
429
Dmitri Plotnikov0306bbd2009-09-03 14:37:15 -0700430 mUri = null;
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700431 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 Millar11d628c2009-09-02 08:55:01 -0700452 long contactId = ContentUris.parseId(mUri);
453 mHandler.startQueryEntities(TOKEN_QUERY, null,
454 RawContacts.CONTENT_URI, RawContacts.CONTACT_ID + "=" + contactId, null, null);
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700455
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 Millar11d628c2009-09-02 08:55:01 -0700465 }
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 Project7aa0e4c2009-03-03 19:32:21 -0800484 }
485
486 @Override
487 public boolean onCreateOptionsMenu(Menu menu) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800488 menu.add(0, MENU_ITEM_DELETE, 0, R.string.menu_deleteContact)
489 .setIcon(android.R.drawable.ic_menu_delete);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700490 menu.add(0, MENU_ITEM_SPLIT_AGGREGATE, 0, R.string.menu_splitAggregate)
491 .setIcon(android.R.drawable.ic_menu_share);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700492 menu.add(0, MENU_ITEM_JOIN_AGGREGATE, 0, R.string.menu_joinAggregate)
493 .setIcon(android.R.drawable.ic_menu_add);
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700494 menu.add(0, MENU_ITEM_OPTIONS, 0, R.string.menu_contactOptions)
495 .setIcon(R.drawable.ic_menu_mark);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800496 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 Plotnikovb4491ee2009-06-15 09:31:02 -0700512
Evan Millardb5d88c2009-08-28 09:31:57 -0700513 // 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 Millar7911ff52009-07-21 15:55:18 -0700524 boolean isAggregate = mRawContactIds.size() > 1;
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700525 menu.findItem(MENU_ITEM_SPLIT_AGGREGATE).setEnabled(isAggregate);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800526 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 Millar5c22c3b2009-05-29 11:37:54 -0700551
Evan Millar45e0ed32009-06-01 16:44:38 -0700552 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 Millar15e514d2009-08-04 10:14:57 -0700555 menu.add(0, 0, 0, R.string.menu_sendSMS).setIntent(entry.secondaryIntent);
556 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700557 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultNumber);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800558 }
Evan Millar45e0ed32009-06-01 16:44:38 -0700559 } else if (entry.mimetype.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
560 menu.add(0, 0, 0, R.string.menu_sendEmail).setIntent(entry.intent);
Evan Millar15e514d2009-08-04 10:14:57 -0700561 if (!entry.isPrimary) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700562 menu.add(0, MENU_ITEM_MAKE_DEFAULT, 0, R.string.menu_makeDefaultEmail);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800563 }
Jeff Sharkeyc6ad3ab2009-07-21 19:30:15 -0700564 } else if (entry.mimetype.equals(CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700565 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 Project7aa0e4c2009-03-03 19:32:21 -0800571 }
572
573 @Override
574 public boolean onOptionsItemSelected(MenuItem item) {
575 switch (item.getItemId()) {
Evan Millar8a79cee2009-08-19 17:20:49 -0700576 case MENU_ITEM_EDIT: {
Evan Millardb5d88c2009-08-28 09:31:57 -0700577 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 Millar8a79cee2009-08-19 17:20:49 -0700583 if (rawContactIdToEdit == ALL_CONTACTS_ID) {
584 // If the "all" tab is selected, edit the next tab.
Evan Millardb5d88c2009-08-28 09:31:57 -0700585 rawContactIdToEdit = getTabRawContactId(mTabWidget.getCurrentTab() + 1);
Evan Millar8a79cee2009-08-19 17:20:49 -0700586 }
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 Project7aa0e4c2009-03-03 19:32:21 -0800593 case MENU_ITEM_DELETE: {
594 // Get confirmation
595 showDialog(DIALOG_CONFIRM_DELETE);
596 return true;
597 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700598
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700599 case MENU_ITEM_SPLIT_AGGREGATE: {
Dmitri Plotnikov040dc152009-09-03 15:17:56 -0700600 if (mRawContactIds.size() == 2) {
601 splitContact(mRawContactIds.get(1));
602 } else {
603 showSplitAggregateDialog();
604 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700605 return true;
606 }
607
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700608 case MENU_ITEM_JOIN_AGGREGATE: {
609 showJoinAggregateActivity();
610 return true;
611 }
612
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700613 case MENU_ITEM_OPTIONS: {
614 showOptionsActivity();
615 return true;
616 }
617
Evan Millar66388be2009-05-28 15:41:07 -0700618 // TODO(emillar) Bring this back.
619 /*case MENU_ITEM_SHOW_BARCODE:
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800620 if (mCursor.moveToFirst()) {
621 Intent intent = new Intent(SHOW_BARCODE_INTENT);
622 intent.putExtra("ENCODE_TYPE", "CONTACT_TYPE");
623 Bundle bundle = new Bundle();
Evan Millar66388be2009-05-28 15:41:07 -0700624 String name = mCursor.getString(AGGREGATE_DISPLAY_NAME_COLUMN);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800625 if (!TextUtils.isEmpty(name)) {
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700626 // Correctly handle when section headers are hidden
627 int sepAdjust = SHOW_SEPARATORS ? 1 : 0;
Evan Millar5c22c3b2009-05-29 11:37:54 -0700628
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800629 bundle.putString(Contacts.Intents.Insert.NAME, name);
630 // The 0th ViewEntry in each ArrayList below is a separator item
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700631 int entriesToAdd = Math.min(mPhoneEntries.size() - sepAdjust, PHONE_KEYS.length);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800632 for (int x = 0; x < entriesToAdd; x++) {
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700633 ViewEntry entry = mPhoneEntries.get(x + sepAdjust);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800634 bundle.putString(PHONE_KEYS[x], entry.data);
635 }
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700636 entriesToAdd = Math.min(mEmailEntries.size() - sepAdjust, EMAIL_KEYS.length);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800637 for (int x = 0; x < entriesToAdd; x++) {
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700638 ViewEntry entry = mEmailEntries.get(x + sepAdjust);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800639 bundle.putString(EMAIL_KEYS[x], entry.data);
640 }
Jeffrey Sharkey715b32a2009-03-27 18:56:05 -0700641 if (mPostalEntries.size() >= 1 + sepAdjust) {
642 ViewEntry entry = mPostalEntries.get(sepAdjust);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800643 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 Millar66388be2009-05-28 15:41:07 -0700659 break; */
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800660 }
661 return super.onOptionsItemSelected(item);
662 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700663
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800664 @Override
665 public boolean onContextItemSelected(MenuItem item) {
666 switch (item.getItemId()) {
667 case MENU_ITEM_MAKE_DEFAULT: {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700668 if (makeItemDefault(item)) {
669 return true;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800670 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700671 break;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800672 }
673 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700674
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800675 return super.onContextItemSelected(item);
676 }
677
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700678 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 Plotnikovb4491ee2009-06-15 09:31:02 -0700687
Evan Millar54a5c9f2009-06-23 17:41:09 -0700688 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 Plotnikovb4491ee2009-06-15 09:31:02 -0700697 getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, entry.id),
698 values, null, null);
Evan Millar11d628c2009-09-02 08:55:01 -0700699 startEntityQuery();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700700 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 Plotnikovb4491ee2009-06-15 09:31:02 -0700708 // 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 Plotnikov99eafe72009-09-03 14:09:45 -0700729 public void onContactSelected(long rawContactId) {
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700730 dialog.dismiss();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700731 splitContact(rawContactId);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700732 }
733 });
734
735 dialog.show();
736 }
737
738 /**
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700739 * Shows a list of aggregates that can be joined into the currently viewed aggregate.
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700740 */
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700741 public void showJoinAggregateActivity() {
742 Intent intent = new Intent(ContactsListActivity.JOIN_AGGREGATE);
743 intent.putExtra(ContactsListActivity.EXTRA_AGGREGATE_ID, ContentUris.parseId(mUri));
Evan Millar8a79cee2009-08-19 17:20:49 -0700744 startActivityForResult(intent, REQUEST_JOIN_CONTACT);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700745 }
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700746
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700747 @Override
748 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
Evan Millar8a79cee2009-08-19 17:20:49 -0700749 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 Plotnikov49f705f2009-06-17 18:31:56 -0700767 }
768 }
769
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700770 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 Plotnikov040dc152009-09-03 15:17:56 -0700775 Toast.makeText(this, R.string.contactsSplitMessage, Toast.LENGTH_LONG).show();
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700776 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700777 }
778
779 private void joinAggregate(final long aggregateId) {
Dmitri Plotnikov39466592009-07-27 11:23:51 -0700780 Cursor c = mResolver.query(RawContacts.CONTENT_URI, new String[] {RawContacts._ID},
Dmitri Plotnikove1cd6792009-07-27 20:28:17 -0700781 RawContacts.CONTACT_ID + "=" + aggregateId, null, null);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700782
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 Plotnikov040dc152009-09-03 15:17:56 -0700792 Toast.makeText(this, R.string.contactsJoinedMessage, Toast.LENGTH_LONG).show();
793 startEntityQuery();
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700794 }
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 Plotnikov99eafe72009-09-03 14:09:45 -0700800 protected void setAggregationException(long rawContactId, int exceptionType) {
Dmitri Plotnikovd09f75c2009-06-16 11:59:22 -0700801 ContentValues values = new ContentValues(3);
Dmitri Plotnikove1cd6792009-07-27 20:28:17 -0700802 values.put(AggregationExceptions.CONTACT_ID, ContentUris.parseId(mUri));
Dmitri Plotnikov99eafe72009-09-03 14:09:45 -0700803 values.put(AggregationExceptions.RAW_CONTACT_ID, rawContactId);
Dmitri Plotnikov49f705f2009-06-17 18:31:56 -0700804 values.put(AggregationExceptions.TYPE, exceptionType);
Dmitri Plotnikovd09f75c2009-06-16 11:59:22 -0700805 mResolver.update(AggregationExceptions.CONTENT_URI, values, null, null);
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700806 }
807
Dmitri Plotnikovef038722009-06-24 18:51:47 -0700808 private void showOptionsActivity() {
809 final Intent intent = new Intent(this, ContactOptionsActivity.class);
810 intent.setData(mUri);
811 startActivity(intent);
812 }
813
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700814 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 Project7aa0e4c2009-03-03 19:32:21 -0800826 @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 Millar7911ff52009-07-21 15:55:18 -0700841 int index = mListView.getSelectedItemPosition();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800842 if (index != -1) {
843 ViewEntry entry = ViewAdapter.getEntry(mSections, index, SHOW_SEPARATORS);
Evan Millar66388be2009-05-28 15:41:07 -0700844 if (entry.intent.getAction() == Intent.ACTION_CALL_PRIVILEGED) {
845 startActivity(entry.intent);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800846 }
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 Millar7911ff52009-07-21 15:55:18 -0700864 public void onItemClick(AdapterView parent, View v, int position, long id) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800865 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 Project7aa0e4c2009-03-03 19:32:21 -0800890 private Uri constructImToUrl(String host, String data) {
Evan Millar45e0ed32009-06-01 16:44:38 -0700891 // don't encode the url, because the Activity Manager can't find using the encoded url
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800892 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 Millar5c22c3b2009-05-29 11:37:54 -0700901 *
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800902 * @param personCursor the URI for the contact being displayed
903 */
Evan Millar11d628c2009-09-02 08:55:01 -0700904 private final void buildEntries() {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800905 // 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 Millar7911ff52009-07-21 15:55:18 -0700911 mRawContactIds.clear();
Dmitri Plotnikovb4491ee2009-06-15 09:31:02 -0700912
Evan Millar11d628c2009-09-02 08:55:01 -0700913 Sources sources = Sources.getInstance(this);
914
Evan Millar66388be2009-05-28 15:41:07 -0700915 // Build up method entries
916 if (mUri != null) {
Evan Millar11d628c2009-09-02 08:55:01 -0700917 for (Entity entity: mEntities) {
918 final ContentValues entValues = entity.getEntityValues();
919 final String accountType = entValues.getAsString(RawContacts.ACCOUNT_TYPE);
Evan Millar7911ff52009-07-21 15:55:18 -0700920 // TODO: entry.contactId should be renamed to entry.rawContactId
Evan Millar11d628c2009-09-02 08:55:01 -0700921 long contactId = entValues.getAsLong(RawContacts._ID);
Evan Millar7911ff52009-07-21 15:55:18 -0700922
Evan Millar11d628c2009-09-02 08:55:01 -0700923 for (NamedContentValues subValue : entity.getSubValues()) {
924 ViewEntry entry = new ViewEntry();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800925
Evan Millar11d628c2009-09-02 08:55:01 -0700926 ContentValues entryValues = subValue.values;
927 final String mimetype = entryValues.getAsString(Data.MIMETYPE);
928 if (mimetype == null || accountType == null) {
Evan Millar66388be2009-05-28 15:41:07 -0700929 continue;
930 }
931
Evan Millar11d628c2009-09-02 08:55:01 -0700932 ContactsSource contactsSource = sources.getInflatedSource(accountType,
933 ContactsSource.LEVEL_MIMETYPES);
934 if (contactsSource == null) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800935 continue;
936 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700937
Evan Millar11d628c2009-09-02 08:55:01 -0700938 DataKind kind = contactsSource.getKindForMimetype(mimetype);
939 if (kind == null) {
940 continue;
941 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800942
Evan Millar11d628c2009-09-02 08:55:01 -0700943 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 Project7aa0e4c2009-03-03 19:32:21 -0800957
Evan Millar11d628c2009-09-02 08:55:01 -0700958 // Don't crash if the data is bogus
Evan Millar66388be2009-05-28 15:41:07 -0700959 if (TextUtils.isEmpty(entry.data)) {
960 Log.w(TAG, "empty data for contact method " + id);
Alex Kennberg87fc3172009-03-28 06:43:06 -0700961 continue;
962 }
Evan Millar5c22c3b2009-05-29 11:37:54 -0700963
Evan Millar11d628c2009-09-02 08:55:01 -0700964 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 Millar49714ee2009-09-02 16:42:47 -0700991
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 Millar11d628c2009-09-02 08:55:01 -0700998 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 Millar49714ee2009-09-02 16:42:47 -07001012 // 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 Millar11d628c2009-09-02 08:55:01 -07001016 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 Millar49714ee2009-09-02 16:42:47 -07001029 if (TextUtils.isEmpty(entry.label)) {
1030 entry.label = getString(R.string.im).toLowerCase();
1031 }
1032
Evan Millar11d628c2009-09-02 08:55:01 -07001033 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 Millar66388be2009-05-28 15:41:07 -07001114 }
Evan Millar5c22c3b2009-05-29 11:37:54 -07001115
Evan Millar66388be2009-05-28 15:41:07 -07001116 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001117 }
1118 }
1119
Evan Millar11d628c2009-09-02 08:55:01 -07001120 String buildActionString(DataKind kind, ContentValues values, boolean lowerCase) {
1121 if (kind.actionHeader == null) {
1122 return null;
Jeff Hamilton8350e5b2009-03-24 21:01:34 -07001123 }
Evan Millar11d628c2009-09-02 08:55:01 -07001124 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 Hamilton8350e5b2009-03-24 21:01:34 -07001130
Evan Millar11d628c2009-09-02 08:55:01 -07001131 String buildDataString(DataKind kind, ContentValues values) {
1132 if (kind.actionBody == null) {
1133 return null;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001134 }
Evan Millar11d628c2009-09-02 08:55:01 -07001135 CharSequence actionBody = kind.actionBody.inflateUsing(this, values);
1136 return actionBody == null ? null : actionBody.toString();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001137 }
Evan Millar5c22c3b2009-05-29 11:37:54 -07001138
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001139 /**
1140 * A basic structure with the data for a contact entry in the list.
1141 */
Evan Millar54a5c9f2009-06-23 17:41:09 -07001142 static class ViewEntry extends ContactEntryAdapter.Entry implements Collapsible<ViewEntry> {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001143 public int actionIcon = -1;
Evan Millar15e514d2009-08-04 10:14:57 -07001144 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 Project7aa0e4c2009-03-03 19:32:21 -08001150 public int maxLabelLines = 1;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001151 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 Millar15e514d2009-08-04 10:14:57 -07001178 isPrimary = entry.isPrimary ? true : isPrimary;
Evan Millar54a5c9f2009-06-23 17:41:09 -07001179
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 Millar15e514d2009-08-04 10:14:57 -07001194 hashSb.append((secondaryIntent != null && secondaryIntent.getAction() != null)
1195 ? secondaryIntent.getAction() : "");
Evan Millar54a5c9f2009-06-23 17:41:09 -07001196 hashSb.append(actionIcon);
1197 return hashSb.toString();
1198 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001199 }
1200
Evan Millar15e514d2009-08-04 10:14:57 -07001201 /** 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 Millar5c22c3b2009-05-29 11:37:54 -07001210
Evan Millar15e514d2009-08-04 10:14:57 -07001211 // 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 Millar5c22c3b2009-05-29 11:37:54 -07001218
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001219 ViewAdapter(Context context, ArrayList<ArrayList<ViewEntry>> sections) {
1220 super(context, sections, SHOW_SEPARATORS);
1221 }
1222
Evan Millar15e514d2009-08-04 10:14:57 -07001223 public void onClick(View v) {
1224 Intent intent = (Intent) v.getTag();
1225 startActivity(intent);
1226 }
1227
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001228 @Override
1229 public View getView(int position, View convertView, ViewGroup parent) {
Evan Millar5c22c3b2009-05-29 11:37:54 -07001230 ViewEntry entry = getEntry(mSections, position, false);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001231 View v;
1232
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001233 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 Millar15e514d2009-08-04 10:14:57 -07001247 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 Millar15e514d2009-08-04 10:14:57 -07001253 views.secondaryActionDivider = v.findViewById(R.id.divider);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001254 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 Millar54a5c9f2009-06-23 17:41:09 -07001284 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 Project7aa0e4c2009-03-03 19:32:21 -08001290 setMaxLines(data, entry.maxLines);
1291 }
1292
Evan Millar15e514d2009-08-04 10:14:57 -07001293 // Set the primary icon
1294 views.primaryIcon.setVisibility(entry.isPrimary ? View.VISIBLE : View.GONE);
1295
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001296 // 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 Millar15e514d2009-08-04 10:14:57 -07001308 if (entry.presenceIcon != -1) {
1309 presenceIcon = resources.getDrawable(entry.presenceIcon);
Evan Millar54a5c9f2009-06-23 17:41:09 -07001310 } else if (entry.status != -1) {
1311 presenceIcon = resources.getDrawable(
1312 Presence.getPresenceIconResourceId(entry.status));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001313 }
Evan Millar15e514d2009-08-04 10:14:57 -07001314 ImageView presenceIconView = views.presenceIcon;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001315 if (presenceIcon != null) {
Evan Millar15e514d2009-08-04 10:14:57 -07001316 presenceIconView.setImageDrawable(presenceIcon);
1317 presenceIconView.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001318 } else {
Evan Millar15e514d2009-08-04 10:14:57 -07001319 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 Project7aa0e4c2009-03-03 19:32:21 -08001336 }
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}