1 /* 2 * Copyright (C) 2009 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 17 package com.android.contacts.preference; 18 19 import com.android.contacts.R; 20 import com.android.contacts.activities.PeopleActivity; 21 22 import android.app.ActionBar; 23 import android.content.Context; 24 import android.content.Intent; 25 import android.os.Bundle; 26 import android.preference.PreferenceActivity; 27 import android.view.MenuItem; 28 29 import java.util.List; 30 31 /** 32 * Contacts settings. 33 */ 34 public final class ContactsPreferenceActivity extends PreferenceActivity { 35 36 @Override 37 protected void onCreate(Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 40 // This Activity will always fall back to the "top" Contacts screen when touched on the 41 // app up icon, regardless of launch context. 42 ActionBar actionBar = getActionBar(); 43 if (actionBar != null) { 44 actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP); 45 } 46 } 47 48 /** 49 * Populate the activity with the top-level headers. 50 */ 51 @Override 52 public void onBuildHeaders(List<Header> target) { 53 loadHeadersFromResource(R.xml.preference_headers, target); 54 } 55 56 /** 57 * Returns true if there are no preferences to display and therefore the 58 * corresponding menu item can be removed. 59 */ 60 public static boolean isEmpty(Context context) { 61 return !context.getResources().getBoolean(R.bool.config_sort_order_user_changeable) 62 && !context.getResources().getBoolean(R.bool.config_display_order_user_changeable); 63 } 64 65 @Override 66 public boolean onOptionsItemSelected(MenuItem item) { 67 switch (item.getItemId()) { 68 case android.R.id.home: { 69 Intent intent = new Intent(this, PeopleActivity.class); 70 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 71 startActivity(intent); 72 finish(); 73 return true; 74 } 75 } 76 return false; 77 } 78 } 79