Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 1 | /* |
Daniel Lehmann | ef3f8f0 | 2010-07-26 18:55:25 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 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.activities; |
| 18 | |
Dmitri Plotnikov | 18ffaa2 | 2010-12-03 14:28:00 -0800 | [diff] [blame^] | 19 | import com.android.contacts.ContactSaveService; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 20 | import com.android.contacts.ContactsSearchManager; |
| 21 | import com.android.contacts.R; |
Dmitri Plotnikov | 18ffaa2 | 2010-12-03 14:28:00 -0800 | [diff] [blame^] | 22 | import com.android.contacts.detail.ContactDetailFragment; |
Daniel Lehmann | 69e7fec | 2010-07-20 14:14:56 -0700 | [diff] [blame] | 23 | import com.android.contacts.interactions.ContactDeletionInteraction; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 24 | |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 25 | import android.accounts.Account; |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 26 | import android.app.Activity; |
Daniel Lehmann | 60be1a1 | 2010-08-05 18:37:21 -0700 | [diff] [blame] | 27 | import android.content.ActivityNotFoundException; |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 28 | import android.content.ContentValues; |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 29 | import android.content.Intent; |
Daniel Lehmann | c2687c3 | 2010-04-19 18:20:44 -0700 | [diff] [blame] | 30 | import android.net.Uri; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 31 | import android.os.Bundle; |
| 32 | import android.util.Log; |
| 33 | import android.view.KeyEvent; |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 34 | import android.widget.Toast; |
| 35 | |
| 36 | import java.util.ArrayList; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 37 | |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 38 | public class ContactDetailActivity extends Activity { |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 39 | private static final String TAG = "ContactDetailActivity"; |
| 40 | |
Daniel Lehmann | 25a0282 | 2010-05-11 15:52:43 -0700 | [diff] [blame] | 41 | private ContactDetailFragment mFragment; |
| 42 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 43 | @Override |
| 44 | public void onCreate(Bundle savedState) { |
| 45 | super.onCreate(savedState); |
| 46 | |
Daniel Lehmann | 25a0282 | 2010-05-11 15:52:43 -0700 | [diff] [blame] | 47 | setContentView(R.layout.contact_detail_activity); |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 48 | |
Daniel Lehmann | 3514fd3 | 2010-08-19 14:45:26 -0700 | [diff] [blame] | 49 | mFragment = (ContactDetailFragment) getFragmentManager().findFragmentById( |
| 50 | R.id.contact_detail_fragment); |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 51 | mFragment.setListener(mFragmentListener); |
Daniel Lehmann | 25a0282 | 2010-05-11 15:52:43 -0700 | [diff] [blame] | 52 | mFragment.loadUri(getIntent().getData()); |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 53 | |
| 54 | Log.i(TAG, getIntent().getData().toString()); |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 57 | @Override |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 58 | public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, |
| 59 | boolean globalSearch) { |
| 60 | if (globalSearch) { |
| 61 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 62 | } else { |
| 63 | ContactsSearchManager.startSearch(this, initialQuery); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Daniel Lehmann | 1624964 | 2010-09-10 19:56:51 -0700 | [diff] [blame] | 69 | if (mFragment.handleKeyDown(keyCode)) return true; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 70 | |
| 71 | return super.onKeyDown(keyCode, event); |
| 72 | } |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 73 | |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 74 | private final ContactDetailFragment.Listener mFragmentListener = |
| 75 | new ContactDetailFragment.Listener() { |
Daniel Lehmann | 69e7fec | 2010-07-20 14:14:56 -0700 | [diff] [blame] | 76 | @Override |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 77 | public void onContactNotFound() { |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 78 | finish(); |
| 79 | } |
| 80 | |
Daniel Lehmann | 69e7fec | 2010-07-20 14:14:56 -0700 | [diff] [blame] | 81 | @Override |
Daniel Lehmann | 825cb62 | 2010-08-27 11:44:29 -0700 | [diff] [blame] | 82 | public void onEditRequested(Uri contactLookupUri) { |
| 83 | startActivity(new Intent(Intent.ACTION_EDIT, contactLookupUri)); |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Daniel Lehmann | 69e7fec | 2010-07-20 14:14:56 -0700 | [diff] [blame] | 86 | @Override |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 87 | public void onItemClicked(Intent intent) { |
Daniel Lehmann | 60be1a1 | 2010-08-05 18:37:21 -0700 | [diff] [blame] | 88 | try { |
| 89 | startActivity(intent); |
| 90 | } catch (ActivityNotFoundException e) { |
| 91 | Log.e(TAG, "No activity found for intent: " + intent); |
| 92 | } |
Daniel Lehmann | 18f104f | 2010-05-07 15:41:11 -0700 | [diff] [blame] | 93 | } |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 94 | |
Daniel Lehmann | 69e7fec | 2010-07-20 14:14:56 -0700 | [diff] [blame] | 95 | @Override |
Dmitri Plotnikov | 66bca8f | 2010-11-24 16:59:24 -0800 | [diff] [blame] | 96 | public void onDeleteRequested(Uri contactUri) { |
| 97 | ContactDeletionInteraction.start(ContactDetailActivity.this, contactUri); |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 98 | } |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 99 | |
| 100 | @Override |
| 101 | public void onCreateRawContactRequested( |
| 102 | ArrayList<ContentValues> values, Account account) { |
| 103 | Toast.makeText(ContactDetailActivity.this, R.string.toast_making_personal_copy, |
| 104 | Toast.LENGTH_LONG).show(); |
| 105 | Intent serviceIntent = ContactSaveService.createNewRawContactIntent( |
Dmitri Plotnikov | 9d730dd | 2010-11-24 13:22:23 -0800 | [diff] [blame] | 106 | ContactDetailActivity.this, values, account, |
| 107 | ContactDetailActivity.class, Intent.ACTION_VIEW); |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 108 | startService(serviceIntent); |
| 109 | |
| 110 | } |
Daniel Lehmann | cdef2b6 | 2010-06-06 18:25:49 -0700 | [diff] [blame] | 111 | }; |
Daniel Lehmann | 4cd9441 | 2010-04-08 16:44:36 -0700 | [diff] [blame] | 112 | } |