ContactDetailActivity.java revision 3514fd3fbc7aabdddc647cd6f745437ba4f780a6
1/* 2 * Copyright (C) 2010 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.activities; 18 19import com.android.contacts.ContactsSearchManager; 20import com.android.contacts.R; 21import com.android.contacts.interactions.ContactDeletionInteraction; 22import com.android.contacts.views.detail.ContactDetailFragment; 23 24import android.app.Activity; 25import android.app.Dialog; 26import android.content.ActivityNotFoundException; 27import android.content.Intent; 28import android.net.Uri; 29import android.os.Bundle; 30import android.util.Log; 31import android.view.KeyEvent; 32import android.view.MenuItem; 33 34public class ContactDetailActivity extends Activity { 35 private static final String TAG = "ContactDetailActivity"; 36 37 private ContactDetailFragment mFragment; 38 private ContactDeletionInteraction mContactDeletionInteraction; 39 40 @Override 41 public void onCreate(Bundle savedState) { 42 super.onCreate(savedState); 43 44 setContentView(R.layout.contact_detail_activity); 45 46 mFragment = (ContactDetailFragment) getFragmentManager().findFragmentById( 47 R.id.contact_detail_fragment); 48 mFragment.setListener(mFragmentListener); 49 mFragment.loadUri(getIntent().getData()); 50 51 Log.i(TAG, getIntent().getData().toString()); 52 } 53 54 @Override 55 protected Dialog onCreateDialog(int id, Bundle args) { 56 final Dialog deletionDialog = getContactDeletionInteraction().onCreateDialog(id, args); 57 if (deletionDialog != null) return deletionDialog; 58 59 // Nobody knows about the Dialog 60 Log.w(TAG, "Unknown dialog requested, id: " + id + ", args: " + args); 61 return null; 62 } 63 64 @Override 65 protected void onPrepareDialog(int id, Dialog dialog, Bundle args) { 66 if (getContactDeletionInteraction().onPrepareDialog(id, dialog, args)) { 67 return; 68 } 69 } 70 71 @Override 72 public boolean onContextItemSelected(MenuItem item) { 73 // TODO: This is too hardwired. 74 if (mFragment.onContextItemSelected(item)) return true; 75 76 return super.onContextItemSelected(item); 77 } 78 79 @Override 80 public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, 81 boolean globalSearch) { 82 if (globalSearch) { 83 super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); 84 } else { 85 ContactsSearchManager.startSearch(this, initialQuery); 86 } 87 } 88 89 @Override 90 public boolean onKeyDown(int keyCode, KeyEvent event) { 91 // TODO: This is too hardwired. 92 if (mFragment.onKeyDown(keyCode, event)) return true; 93 94 return super.onKeyDown(keyCode, event); 95 } 96 97 private ContactDeletionInteraction getContactDeletionInteraction() { 98 if (mContactDeletionInteraction == null) { 99 mContactDeletionInteraction = new ContactDeletionInteraction(); 100 mContactDeletionInteraction.attachToActivity(this); 101 } 102 return mContactDeletionInteraction; 103 } 104 105 private final ContactDetailFragment.Listener mFragmentListener = 106 new ContactDetailFragment.Listener() { 107 @Override 108 public void onContactNotFound() { 109 finish(); 110 } 111 112 @Override 113 public void onEditRequested(Uri lookupUri) { 114 startActivity(new Intent(Intent.ACTION_EDIT, lookupUri)); 115 } 116 117 @Override 118 public void onItemClicked(Intent intent) { 119 try { 120 startActivity(intent); 121 } catch (ActivityNotFoundException e) { 122 Log.e(TAG, "No activity found for intent: " + intent); 123 } 124 } 125 126 @Override 127 public void onDeleteRequested(Uri lookupUri) { 128 getContactDeletionInteraction().deleteContact(lookupUri); 129 } 130 }; 131} 132