GroupDetailActivity.java revision d78ee90c0d4d93b82ad440396e87ae4f47f53e93
1/* 2 * Copyright (C) 2011 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.ContactsActivity; 20import com.android.contacts.R; 21import com.android.contacts.group.GroupDetailDisplayUtils; 22import com.android.contacts.group.GroupDetailFragment; 23import com.android.contacts.model.AccountType; 24import com.android.contacts.model.AccountTypeManager; 25 26import android.app.ActionBar; 27import android.content.ContentUris; 28import android.content.Intent; 29import android.net.Uri; 30import android.os.Bundle; 31import android.provider.ContactsContract.Groups; 32import android.text.TextUtils; 33import android.view.Menu; 34import android.view.MenuInflater; 35import android.view.MenuItem; 36import android.view.View; 37import android.view.View.OnClickListener; 38 39public class GroupDetailActivity extends ContactsActivity { 40 41 private static final String TAG = "GroupDetailActivity"; 42 43 private boolean mShowGroupSourceInActionBar; 44 45 private String mAccountTypeString; 46 private String mDataSet; 47 48 private GroupDetailFragment mFragment; 49 50 @Override 51 public void onCreate(Bundle savedState) { 52 super.onCreate(savedState); 53 54 // TODO: Create Intent Resolver to handle the different ways users can get to this list. 55 // TODO: Handle search or key down 56 57 setContentView(R.layout.group_detail_activity); 58 59 mShowGroupSourceInActionBar = getResources().getBoolean( 60 R.bool.config_show_group_action_in_action_bar); 61 62 mFragment = (GroupDetailFragment) getFragmentManager().findFragmentById( 63 R.id.group_detail_fragment); 64 mFragment.setListener(mFragmentListener); 65 mFragment.setShowGroupSourceInActionBar(mShowGroupSourceInActionBar); 66 mFragment.loadGroup(getIntent().getData()); 67 mFragment.closeActivityAfterDelete(true); 68 69 // We want the UP affordance but no app icon. 70 ActionBar actionBar = getActionBar(); 71 if (actionBar != null) { 72 actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE, 73 ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE 74 | ActionBar.DISPLAY_SHOW_HOME); 75 } 76 } 77 78 private final GroupDetailFragment.Listener mFragmentListener = 79 new GroupDetailFragment.Listener() { 80 81 @Override 82 public void onGroupSizeUpdated(String size) { 83 getActionBar().setSubtitle(size); 84 } 85 86 @Override 87 public void onGroupTitleUpdated(String title) { 88 getActionBar().setTitle(title); 89 } 90 91 @Override 92 public void onAccountTypeUpdated(String accountTypeString, String dataSet) { 93 mAccountTypeString = accountTypeString; 94 mDataSet = dataSet; 95 invalidateOptionsMenu(); 96 } 97 98 @Override 99 public void onEditRequested(Uri groupUri) { 100 final Intent intent = new Intent(GroupDetailActivity.this, GroupEditorActivity.class); 101 intent.setData(groupUri); 102 intent.setAction(Intent.ACTION_EDIT); 103 startActivity(intent); 104 } 105 106 @Override 107 public void onContactSelected(Uri contactUri) { 108 startActivity(new Intent(Intent.ACTION_VIEW, contactUri)); 109 } 110 111 }; 112 113 @Override 114 public boolean onCreateOptionsMenu(Menu menu) { 115 super.onCreateOptionsMenu(menu); 116 if (mShowGroupSourceInActionBar) { 117 MenuInflater inflater = getMenuInflater(); 118 inflater.inflate(R.menu.group_source, menu); 119 } 120 return true; 121 } 122 123 @Override 124 public boolean onPrepareOptionsMenu(Menu menu) { 125 if (!mShowGroupSourceInActionBar) { 126 return false; 127 } 128 MenuItem groupSourceMenuItem = menu.findItem(R.id.menu_group_source); 129 if (groupSourceMenuItem == null) { 130 return false; 131 } 132 final AccountTypeManager manager = AccountTypeManager.getInstance(this); 133 final AccountType accountType = 134 manager.getAccountType(mAccountTypeString, mDataSet); 135 if (TextUtils.isEmpty(mAccountTypeString) 136 || TextUtils.isEmpty(accountType.getViewGroupActivity())) { 137 groupSourceMenuItem.setVisible(false); 138 return false; 139 } 140 View groupSourceView = GroupDetailDisplayUtils.getNewGroupSourceView(this); 141 GroupDetailDisplayUtils.bindGroupSourceView(this, groupSourceView, 142 mAccountTypeString, mDataSet); 143 groupSourceView.setOnClickListener(new OnClickListener() { 144 @Override 145 public void onClick(View v) { 146 final Uri uri = ContentUris.withAppendedId(Groups.CONTENT_URI, 147 mFragment.getGroupId()); 148 final Intent intent = new Intent(Intent.ACTION_VIEW, uri); 149 intent.setClassName(accountType.resPackageName, accountType.getViewGroupActivity()); 150 startActivity(intent); 151 } 152 }); 153 groupSourceMenuItem.setActionView(groupSourceView); 154 groupSourceMenuItem.setVisible(true); 155 return true; 156 } 157 158 @Override 159 public boolean onOptionsItemSelected(MenuItem item) { 160 switch (item.getItemId()) { 161 case android.R.id.home: 162 Intent intent = new Intent(this, PeopleActivity.class); 163 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 164 startActivity(intent); 165 finish(); 166 return true; 167 default: 168 break; 169 } 170 return super.onOptionsItemSelected(item); 171 } 172 173 @Override 174 public boolean onSearchRequested() { 175 return true; // Don't respond to the search key. 176 } 177} 178