HomeGroupsXLarge.java revision 4e5a9e4ee5c1ecab0a7a8eebee883f3f189f5cb4
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.loaderapp; 18 19import com.android.loaderapp.fragments.ContactsListFragment; 20import com.android.loaderapp.fragments.GroupsListFragment; 21import com.android.ui.phat.PhatTitleBar; 22import com.android.ui.phat.PhatTitleBar.OnActionListener; 23 24import android.app.Activity; 25import android.app.FragmentTransaction; 26import android.content.Intent; 27import android.content.res.Resources; 28import android.net.Uri; 29import android.os.Bundle; 30import android.provider.ContactsContract; 31 32public class HomeGroupsXLarge extends Activity implements OnActionListener, 33 ContactsListFragment.Controller, GroupsListFragment.Controller { 34 private static final int ACTION_ID_SEARCH = 0; 35 private static final int ACTION_ID_ADD = 1; 36 37 ContactsListFragment mContactsList; 38 GroupsListFragment mGroupsList; 39 40 @Override 41 public void onCreate(Bundle savedState) { 42 super.onCreate(savedState); 43 44 setContentView(R.layout.groups_home); 45 46 mGroupsList = new GroupsListFragment(); 47 mGroupsList.setController(this); 48 49 mContactsList = new ContactsListFragment(ContactsListFragment.MODE_NULL); 50 mContactsList.setController(this); 51 52 FragmentTransaction xact = openFragmentTransaction(); 53 xact.add(mGroupsList, R.id.groups); 54 xact.add(mContactsList, android.R.id.list); 55 xact.commit(); 56 57 final PhatTitleBar titleBar = (PhatTitleBar) findViewById(R.id.title_bar); 58 final Resources resources = getResources(); 59 60 titleBar.addAction(ACTION_ID_SEARCH, 61 resources.getDrawable(android.R.drawable.ic_menu_search), "Search", this); 62 titleBar.addAction(ACTION_ID_ADD, 63 resources.getDrawable(android.R.drawable.ic_menu_add), "Add", this); 64 } 65 66 public void onAction(int id) { 67 switch (id) { 68 case ACTION_ID_SEARCH: { 69 startSearch(null, false, null, true); 70 break; 71 } 72 73 case ACTION_ID_ADD: { 74 startActivity(new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI)); 75 break; 76 } 77 } 78 } 79 80 public void onAllContactsSelected() { 81 mContactsList.setMode(ContactsListFragment.MODE_VISIBLE); 82 } 83 84 public void onFavoritesSelected() { 85 mContactsList.setMode(ContactsListFragment.MODE_STREQUENT); 86 } 87 88 public void onGroupSelected(String title) { 89 mContactsList.setGroupMode(title); 90 } 91 92 public void onContactSelected(Uri contactUri) { 93 if (contactUri != null) { 94 Intent intent = new Intent(this, DetailsNormal.class); 95 intent.setData(contactUri); 96 startActivity(intent); 97 } 98 } 99} 100