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 17 package com.android.loaderapp; 18 19 import com.android.loaderapp.fragments.ContactFragment; 20 import com.android.loaderapp.fragments.ContactsListFragment; 21 22 import android.app.ActionBar; 23 import android.app.Activity; 24 import android.app.FragmentTransaction; 25 import android.content.Intent; 26 import android.content.res.Resources; 27 import android.net.Uri; 28 import android.os.Bundle; 29 import android.provider.ContactsContract; 30 import android.view.Menu; 31 import android.view.MenuItem; 32 33 public class HomeXLarge extends Activity implements ContactsListFragment.Controller, 34 ActionBar.Callback { 35 private static final int ACTION_ID_SEARCH = 0; 36 private static final int ACTION_ID_ADD = 1; 37 38 ContactsListFragment mList; 39 ContactFragment mDetails; 40 41 @Override 42 public void onCreate(Bundle savedState) { 43 super.onCreate(savedState); 44 45 setContentView(R.layout.home_xlarge); 46 47 mList = new ContactsListFragment(); 48 mList.setController(this); 49 mDetails = new ContactFragment(null, new ContactFragment.DefaultController(this)); 50 FragmentTransaction transaction = openFragmentTransaction(); 51 transaction.add(R.id.contacts_list, mList); 52 transaction.add(R.id.contact_details, mDetails); 53 transaction.commit(); 54 55 getActionBar().setCallback(this); 56 57 Intent intent = getIntent(); 58 if (Intent.ACTION_VIEW.equals(intent.getAction())) { 59 mDetails.loadContact(intent.getData()); 60 } 61 } 62 63 public void onAction(int id) { 64 switch (id) { 65 case ACTION_ID_SEARCH: 66 startSearch(null, false, null, true); 67 break; 68 69 case ACTION_ID_ADD: 70 startActivity(new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI)); 71 break; 72 } 73 } 74 75 public void onContactSelected(Uri contactUri) { 76 // The user clicked on an item in the left side pane, start loading the data for it 77 mDetails.loadContact(contactUri); 78 } 79 80 /** Implements ActionBar.Callback */ 81 public boolean onCreateActionMenu(Menu menu) { 82 Resources resources = getResources(); 83 menu.add(0, ACTION_ID_SEARCH, 0, R.string.menu_search) 84 .setIcon(resources.getDrawable(android.R.drawable.ic_menu_search)); 85 menu.add(0, ACTION_ID_ADD, 1, R.string.menu_newContact) 86 .setIcon(resources.getDrawable(android.R.drawable.ic_menu_add)); 87 88 return true; 89 } 90 91 /** Implements ActionBar.Callback */ 92 public boolean onUpdateActionMenu(Menu menu) { 93 return false; 94 } 95 96 /** Implements ActionBar.Callback */ 97 public boolean onActionItemClicked(MenuItem item) { 98 switch (item.getItemId()) { 99 case ACTION_ID_SEARCH: { 100 startSearch(null, false, null, true); 101 return true; 102 } 103 104 case ACTION_ID_ADD: { 105 startActivity(new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI)); 106 return true; 107 } 108 } 109 return false; 110 } 111 112 /** Implements ActionBar.Callback */ 113 public boolean onNavigationItemSelected(int itemPosition, long itemId) { 114 return false; 115 } 116 117 /** Implements ActionBar.Callback */ 118 public boolean onCreateContextMode(int modeId, Menu menu) { 119 return false; 120 } 121 122 /** Implements ActionBar.Callback */ 123 public boolean onPrepareContextMode(int modeId, Menu menu) { 124 return false; 125 } 126 127 /** Implements ActionBar.Callback */ 128 public boolean onContextItemClicked(int modeId, MenuItem item) { 129 return false; 130 } 131 } 132