1/* 2 * Copyright (C) 2008 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.browser; 18 19import android.app.ActionBar; 20import android.content.Intent; 21import android.os.Bundle; 22import android.preference.PreferenceActivity; 23import android.view.MenuItem; 24 25import com.android.browser.preferences.AccessibilityPreferencesFragment; 26import com.android.browser.preferences.AdvancedPreferencesFragment; 27import com.android.browser.preferences.BandwidthPreferencesFragment; 28import com.android.browser.preferences.DebugPreferencesFragment; 29import com.android.browser.preferences.GeneralPreferencesFragment; 30import com.android.browser.preferences.LabPreferencesFragment; 31import com.android.browser.preferences.PrivacySecurityPreferencesFragment; 32import com.android.browser.preferences.WebsiteSettingsFragment; 33 34import java.util.List; 35 36public class BrowserPreferencesPage extends PreferenceActivity { 37 38 public static final String CURRENT_PAGE = "currentPage"; 39 private List<Header> mHeaders; 40 41 @Override 42 public void onCreate(Bundle icicle) { 43 super.onCreate(icicle); 44 45 ActionBar actionBar = getActionBar(); 46 if (actionBar != null) { 47 actionBar.setDisplayOptions( 48 ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP); 49 } 50 } 51 52 /** 53 * Populate the activity with the top-level headers. 54 */ 55 @Override 56 public void onBuildHeaders(List<Header> target) { 57 loadHeadersFromResource(R.xml.preference_headers, target); 58 59 if (BrowserSettings.getInstance().isDebugEnabled()) { 60 Header debug = new Header(); 61 debug.title = getText(R.string.pref_development_title); 62 debug.fragment = DebugPreferencesFragment.class.getName(); 63 target.add(debug); 64 } 65 mHeaders = target; 66 } 67 68 @Override 69 public Header onGetInitialHeader() { 70 String action = getIntent().getAction(); 71 if (Intent.ACTION_MANAGE_NETWORK_USAGE.equals(action)) { 72 String fragName = BandwidthPreferencesFragment.class.getName(); 73 for (Header h : mHeaders) { 74 if (fragName.equals(h.fragment)) { 75 return h; 76 } 77 } 78 } 79 return super.onGetInitialHeader(); 80 } 81 82 @Override 83 public boolean onOptionsItemSelected(MenuItem item) { 84 switch (item.getItemId()) { 85 case android.R.id.home: 86 if (getFragmentManager().getBackStackEntryCount() > 0) { 87 getFragmentManager().popBackStack(); 88 } else { 89 finish(); 90 } 91 return true; 92 } 93 94 return false; 95 } 96 97 @Override 98 public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args, 99 int titleRes, int shortTitleRes) { 100 Intent intent = super.onBuildStartFragmentIntent(fragmentName, args, 101 titleRes, shortTitleRes); 102 String url = getIntent().getStringExtra(CURRENT_PAGE); 103 intent.putExtra(CURRENT_PAGE, url); 104 return intent; 105 } 106 107 @Override 108 protected boolean isValidFragment(String fragmentName) { 109 return AccessibilityPreferencesFragment.class.getName().equals(fragmentName) || 110 AdvancedPreferencesFragment.class.getName().equals(fragmentName) || 111 BandwidthPreferencesFragment.class.getName().equals(fragmentName) || 112 DebugPreferencesFragment.class.getName().equals(fragmentName) || 113 GeneralPreferencesFragment.class.getName().equals(fragmentName) || 114 LabPreferencesFragment.class.getName().equals(fragmentName) || 115 PrivacySecurityPreferencesFragment.class.getName().equals(fragmentName) || 116 WebsiteSettingsFragment.class.getName().equals(fragmentName); 117 118 } 119} 120