ContactDetailActivity.java revision c3a00085193e474c69ff0f455dd5d6086ff72e69
1/* 2 * Copyright (C) 2010 Google Inc. 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.mvcframework.DialogManager; 22import com.android.contacts.mvcframework.LoaderActivity; 23import com.android.contacts.views.detail.ContactDetailView; 24import com.android.contacts.views.detail.ContactLoader; 25 26import android.app.Dialog; 27import android.os.Bundle; 28import android.util.Log; 29import android.view.KeyEvent; 30import android.view.Menu; 31import android.view.MenuItem; 32 33public class ContactDetailActivity extends LoaderActivity<ContactLoader.Result> implements 34 DialogManager.DialogShowingViewActivity { 35 private static final int LOADER_DETAILS = 1; 36 private ContactDetailView mDetails; 37 private DialogManager mDialogManager; 38 39 private static final String TAG = "ContactDetailActivity"; 40 41 private static final int DIALOG_VIEW_DIALOGS_ID1 = 1; 42 private static final int DIALOG_VIEW_DIALOGS_ID2 = 2; 43 44 @Override 45 public void onCreate(Bundle savedState) { 46 super.onCreate(savedState); 47 48 setContentView(R.layout.contact_detail); 49 50 mDialogManager = new DialogManager(this, DIALOG_VIEW_DIALOGS_ID1, DIALOG_VIEW_DIALOGS_ID2); 51 52 mDetails = (ContactDetailView) findViewById(R.id.contact_details); 53 mDetails.setCallbacks(new ContactDetailView.DefaultCallbacks(this)); 54 } 55 56 @Override 57 public void onInitializeLoaders() { 58 startLoading(LOADER_DETAILS, null); 59 } 60 61 @Override 62 protected ContactLoader onCreateLoader(int id, Bundle args) { 63 switch (id) { 64 case LOADER_DETAILS: { 65 return new ContactLoader(this, getIntent().getData()); 66 } 67 } 68 return null; 69 } 70 71 72 @Override 73 public void onLoadComplete(int id, ContactLoader.Result data) { 74 switch (id) { 75 case LOADER_DETAILS: 76 if (data == ContactLoader.Result.NOT_FOUND) { 77 // Item has been deleted 78 Log.i(TAG, "No contact found. Closing activity"); 79 finish(); 80 return; 81 } 82 mDetails.setData(data); 83 break; 84 } 85 } 86 87 @Override 88 public boolean onCreateOptionsMenu(Menu menu) { 89 // TODO: This is too hardwired. 90 if (mDetails.onCreateOptionsMenu(menu, getMenuInflater())) return true; 91 92 return super.onCreateOptionsMenu(menu); 93 } 94 95 @Override 96 public boolean onPrepareOptionsMenu(Menu menu) { 97 // TODO: This is too hardwired. 98 if (mDetails.onPrepareOptionsMenu(menu)) return true; 99 100 return super.onPrepareOptionsMenu(menu); 101 } 102 103 @Override 104 public boolean onOptionsItemSelected(MenuItem item) { 105 // TODO: This is too hardwired. 106 if (mDetails.onOptionsItemSelected(item)) return true; 107 108 return super.onOptionsItemSelected(item); 109 } 110 111 public DialogManager getDialogManager() { 112 return mDialogManager; 113 } 114 115 @Override 116 protected Dialog onCreateDialog(int id, Bundle args) { 117 return mDialogManager.onCreateDialog(id, args); 118 } 119 120 @Override 121 public boolean onContextItemSelected(MenuItem item) { 122 // TODO: This is too hardwired. 123 if (mDetails.onContextItemSelected(item)) return true; 124 125 return super.onContextItemSelected(item); 126 } 127 128 @Override 129 public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, 130 boolean globalSearch) { 131 if (globalSearch) { 132 super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); 133 } else { 134 ContactsSearchManager.startSearch(this, initialQuery); 135 } 136 } 137 138 @Override 139 public boolean onKeyDown(int keyCode, KeyEvent event) { 140 // TODO: This is too hardwired. 141 if (mDetails.onKeyDown(keyCode, event)) return true; 142 143 return super.onKeyDown(keyCode, event); 144 } 145} 146