blob: 7a3a3b924c3cd7c3d9d70055150457971340f963 [file] [log] [blame]
Daniel Lehmann4cd94412010-04-08 16:44:36 -07001/*
Daniel Lehmannef3f8f02010-07-26 18:55:25 -07002 * Copyright (C) 2010 The Android Open Source Project
Daniel Lehmann4cd94412010-04-08 16:44:36 -07003 *
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.activities;
18
Dmitri Plotnikov18ffaa22010-12-03 14:28:00 -080019import com.android.contacts.ContactSaveService;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070020import com.android.contacts.ContactsSearchManager;
21import com.android.contacts.R;
Dmitri Plotnikov18ffaa22010-12-03 14:28:00 -080022import com.android.contacts.detail.ContactDetailFragment;
Daniel Lehmann69e7fec2010-07-20 14:14:56 -070023import com.android.contacts.interactions.ContactDeletionInteraction;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070024
Dmitri Plotnikovcaf0bc72010-09-03 15:16:21 -070025import android.accounts.Account;
Daniel Lehmann18f104f2010-05-07 15:41:11 -070026import android.app.Activity;
Daniel Lehmann60be1a12010-08-05 18:37:21 -070027import android.content.ActivityNotFoundException;
Dmitri Plotnikovcaf0bc72010-09-03 15:16:21 -070028import android.content.ContentValues;
Daniel Lehmann18f104f2010-05-07 15:41:11 -070029import android.content.Intent;
Daniel Lehmannc2687c32010-04-19 18:20:44 -070030import android.net.Uri;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070031import android.os.Bundle;
32import android.util.Log;
33import android.view.KeyEvent;
Dmitri Plotnikovcaf0bc72010-09-03 15:16:21 -070034import android.widget.Toast;
35
36import java.util.ArrayList;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070037
Daniel Lehmann18f104f2010-05-07 15:41:11 -070038public class ContactDetailActivity extends Activity {
Daniel Lehmann4cd94412010-04-08 16:44:36 -070039 private static final String TAG = "ContactDetailActivity";
40
Daniel Lehmann25a02822010-05-11 15:52:43 -070041 private ContactDetailFragment mFragment;
42
Daniel Lehmann4cd94412010-04-08 16:44:36 -070043 @Override
44 public void onCreate(Bundle savedState) {
45 super.onCreate(savedState);
46
Daniel Lehmann25a02822010-05-11 15:52:43 -070047 setContentView(R.layout.contact_detail_activity);
Daniel Lehmann4cd94412010-04-08 16:44:36 -070048
Daniel Lehmann3514fd32010-08-19 14:45:26 -070049 mFragment = (ContactDetailFragment) getFragmentManager().findFragmentById(
50 R.id.contact_detail_fragment);
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070051 mFragment.setListener(mFragmentListener);
Daniel Lehmann25a02822010-05-11 15:52:43 -070052 mFragment.loadUri(getIntent().getData());
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070053
54 Log.i(TAG, getIntent().getData().toString());
Daniel Lehmann4cd94412010-04-08 16:44:36 -070055 }
56
Daniel Lehmann4cd94412010-04-08 16:44:36 -070057 @Override
Daniel Lehmann4cd94412010-04-08 16:44:36 -070058 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 Lehmann16249642010-09-10 19:56:51 -070069 if (mFragment.handleKeyDown(keyCode)) return true;
Daniel Lehmann4cd94412010-04-08 16:44:36 -070070
71 return super.onKeyDown(keyCode, event);
72 }
Daniel Lehmann18f104f2010-05-07 15:41:11 -070073
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070074 private final ContactDetailFragment.Listener mFragmentListener =
75 new ContactDetailFragment.Listener() {
Daniel Lehmann69e7fec2010-07-20 14:14:56 -070076 @Override
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070077 public void onContactNotFound() {
Daniel Lehmann18f104f2010-05-07 15:41:11 -070078 finish();
79 }
80
Daniel Lehmann69e7fec2010-07-20 14:14:56 -070081 @Override
Daniel Lehmann825cb622010-08-27 11:44:29 -070082 public void onEditRequested(Uri contactLookupUri) {
83 startActivity(new Intent(Intent.ACTION_EDIT, contactLookupUri));
Daniel Lehmann18f104f2010-05-07 15:41:11 -070084 }
85
Daniel Lehmann69e7fec2010-07-20 14:14:56 -070086 @Override
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070087 public void onItemClicked(Intent intent) {
Daniel Lehmann60be1a12010-08-05 18:37:21 -070088 try {
89 startActivity(intent);
90 } catch (ActivityNotFoundException e) {
91 Log.e(TAG, "No activity found for intent: " + intent);
92 }
Daniel Lehmann18f104f2010-05-07 15:41:11 -070093 }
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070094
Daniel Lehmann69e7fec2010-07-20 14:14:56 -070095 @Override
Dmitri Plotnikov66bca8f2010-11-24 16:59:24 -080096 public void onDeleteRequested(Uri contactUri) {
97 ContactDeletionInteraction.start(ContactDetailActivity.this, contactUri);
Daniel Lehmanncdef2b62010-06-06 18:25:49 -070098 }
Dmitri Plotnikovcaf0bc72010-09-03 15:16:21 -070099
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 Plotnikov9d730dd2010-11-24 13:22:23 -0800106 ContactDetailActivity.this, values, account,
107 ContactDetailActivity.class, Intent.ACTION_VIEW);
Dmitri Plotnikovcaf0bc72010-09-03 15:16:21 -0700108 startService(serviceIntent);
109
110 }
Daniel Lehmanncdef2b62010-06-06 18:25:49 -0700111 };
Daniel Lehmann4cd94412010-04-08 16:44:36 -0700112}