blob: 353a472fa2c8929f2ee0cc9d008987ea57ce00b3 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
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
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
The Android Open Source Project0c908882009-03-03 19:32:16 -080018
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000019import android.app.ActionBar;
John Reck7b182d72011-07-08 10:30:53 -070020import android.content.Intent;
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000021import android.os.Bundle;
The Android Open Source Project0c908882009-03-03 19:32:16 -080022import android.preference.PreferenceActivity;
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000023import android.view.MenuItem;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010024
Bijan Amirzada41242f22014-03-21 12:12:18 -070025import com.android.browser.R;
26import com.android.browser.preferences.BandwidthPreferencesFragment;
27import com.android.browser.preferences.DebugPreferencesFragment;
John Reck7b182d72011-07-08 10:30:53 -070028
Vivek Sekhar0989b452014-08-01 12:30:35 -070029import java.util.Arrays;
30import java.util.HashSet;
Jeff Hamilton462b8e82010-09-23 14:33:43 -050031import java.util.List;
Vivek Sekhar0989b452014-08-01 12:30:35 -070032import java.util.Set;
The Android Open Source Project0c908882009-03-03 19:32:16 -080033
Jeff Hamilton462b8e82010-09-23 14:33:43 -050034public class BrowserPreferencesPage extends PreferenceActivity {
The Android Open Source Project0c908882009-03-03 19:32:16 -080035
Jeff Hamilton462b8e82010-09-23 14:33:43 -050036 public static final String CURRENT_PAGE = "currentPage";
John Reck7b182d72011-07-08 10:30:53 -070037 private List<Header> mHeaders;
Nicolas Roard78a98e42009-05-11 13:34:17 +010038
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000039 @Override
40 public void onCreate(Bundle icicle) {
41 super.onCreate(icicle);
42
43 ActionBar actionBar = getActionBar();
44 if (actionBar != null) {
45 actionBar.setDisplayOptions(
46 ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
47 }
48 }
49
Jeff Hamilton462b8e82010-09-23 14:33:43 -050050 /**
51 * Populate the activity with the top-level headers.
Nicolas Roarde46990e2009-06-19 16:27:49 +010052 */
53 @Override
Jeff Hamilton462b8e82010-09-23 14:33:43 -050054 public void onBuildHeaders(List<Header> target) {
55 loadHeadersFromResource(R.xml.preference_headers, target);
56
John Reckf48314f2011-04-27 17:52:17 -070057 if (BrowserSettings.getInstance().isDebugEnabled()) {
Jeff Hamilton462b8e82010-09-23 14:33:43 -050058 Header debug = new Header();
59 debug.title = getText(R.string.pref_development_title);
60 debug.fragment = DebugPreferencesFragment.class.getName();
61 target.add(debug);
62 }
John Reck7b182d72011-07-08 10:30:53 -070063 mHeaders = target;
64 }
65
66 @Override
67 public Header onGetInitialHeader() {
68 String action = getIntent().getAction();
69 if (Intent.ACTION_MANAGE_NETWORK_USAGE.equals(action)) {
70 String fragName = BandwidthPreferencesFragment.class.getName();
71 for (Header h : mHeaders) {
72 if (fragName.equals(h.fragment)) {
73 return h;
74 }
75 }
76 }
77 return super.onGetInitialHeader();
The Android Open Source Project0c908882009-03-03 19:32:16 -080078 }
79
80 @Override
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000081 public boolean onOptionsItemSelected(MenuItem item) {
82 switch (item.getItemId()) {
83 case android.R.id.home:
Dianne Hackbornbf1d10a2011-01-17 12:29:51 -080084 if (getFragmentManager().getBackStackEntryCount() > 0) {
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000085 getFragmentManager().popBackStack();
86 } else {
87 finish();
88 }
89 return true;
90 }
91
92 return false;
93 }
John Reck42dfb9f2011-08-15 13:57:37 -070094
95 @Override
96 public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
97 int titleRes, int shortTitleRes) {
98 Intent intent = super.onBuildStartFragmentIntent(fragmentName, args,
99 titleRes, shortTitleRes);
100 String url = getIntent().getStringExtra(CURRENT_PAGE);
101 intent.putExtra(CURRENT_PAGE, url);
102 return intent;
103 }
104
Vivek Sekhar0989b452014-08-01 12:30:35 -0700105 private static final Set<String> sKnownFragments = new HashSet<String>(Arrays.asList(
106 "com.android.browser.preferences.GeneralPreferencesFragment",
107 "com.android.browser.preferences.PrivacySecurityPreferencesFragment",
108 "com.android.browser.preferences.AccessibilityPreferencesFragment",
109 "com.android.browser.preferences.AdvancedPreferencesFragment",
110 "com.android.browser.preferences.BandwidthPreferencesFragment",
111 "com.android.browser.preferences.LabPreferencesFragment",
Tarun Nainaniea28dde2014-08-27 17:25:09 -0700112 "com.android.browser.preferences.AboutPreferencesFragment",
Tarun Nainani8eb00912014-07-17 12:28:32 -0700113 "com.android.browser.AutoFillSettingsFragment",
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800114 "com.android.browser.preferences.DebugPreferencesFragment",
Tarun Nainani8eb00912014-07-17 12:28:32 -0700115 "com.android.browser.preferences.WebsiteSettingsFragment"));
Vivek Sekhar0989b452014-08-01 12:30:35 -0700116
117 @Override
118 protected boolean isValidFragment(String fragmentName) {
119 return sKnownFragments.contains(fragmentName);
120 }
121
122
The Android Open Source Project0c908882009-03-03 19:32:16 -0800123}