blob: 6e6da178c8364c678ca605bfd497054a6038d281 [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
17package com.android.browser;
18
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
John Reck7b182d72011-07-08 10:30:53 -070025import com.android.browser.preferences.BandwidthPreferencesFragment;
26import com.android.browser.preferences.DebugPreferencesFragment;
27
Jeff Hamilton462b8e82010-09-23 14:33:43 -050028import java.util.List;
The Android Open Source Project0c908882009-03-03 19:32:16 -080029
Jeff Hamilton462b8e82010-09-23 14:33:43 -050030public class BrowserPreferencesPage extends PreferenceActivity {
The Android Open Source Project0c908882009-03-03 19:32:16 -080031
Jeff Hamilton462b8e82010-09-23 14:33:43 -050032 public static final String CURRENT_PAGE = "currentPage";
John Reck7b182d72011-07-08 10:30:53 -070033 private List<Header> mHeaders;
Nicolas Roard78a98e42009-05-11 13:34:17 +010034
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000035 @Override
36 public void onCreate(Bundle icicle) {
37 super.onCreate(icicle);
38
39 ActionBar actionBar = getActionBar();
40 if (actionBar != null) {
41 actionBar.setDisplayOptions(
42 ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
43 }
44 }
45
Jeff Hamilton462b8e82010-09-23 14:33:43 -050046 /**
47 * Populate the activity with the top-level headers.
Nicolas Roarde46990e2009-06-19 16:27:49 +010048 */
49 @Override
Jeff Hamilton462b8e82010-09-23 14:33:43 -050050 public void onBuildHeaders(List<Header> target) {
51 loadHeadersFromResource(R.xml.preference_headers, target);
52
John Reckf48314f2011-04-27 17:52:17 -070053 if (BrowserSettings.getInstance().isDebugEnabled()) {
Jeff Hamilton462b8e82010-09-23 14:33:43 -050054 Header debug = new Header();
55 debug.title = getText(R.string.pref_development_title);
56 debug.fragment = DebugPreferencesFragment.class.getName();
57 target.add(debug);
58 }
John Reck7b182d72011-07-08 10:30:53 -070059 mHeaders = target;
60 }
61
62 @Override
63 public Header onGetInitialHeader() {
64 String action = getIntent().getAction();
65 if (Intent.ACTION_MANAGE_NETWORK_USAGE.equals(action)) {
66 String fragName = BandwidthPreferencesFragment.class.getName();
67 for (Header h : mHeaders) {
68 if (fragName.equals(h.fragment)) {
69 return h;
70 }
71 }
72 }
73 return super.onGetInitialHeader();
The Android Open Source Project0c908882009-03-03 19:32:16 -080074 }
75
76 @Override
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000077 public boolean onOptionsItemSelected(MenuItem item) {
78 switch (item.getItemId()) {
79 case android.R.id.home:
Dianne Hackbornbf1d10a2011-01-17 12:29:51 -080080 if (getFragmentManager().getBackStackEntryCount() > 0) {
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000081 getFragmentManager().popBackStack();
82 } else {
83 finish();
84 }
85 return true;
86 }
87
88 return false;
89 }
John Reck42dfb9f2011-08-15 13:57:37 -070090
91 @Override
92 public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
93 int titleRes, int shortTitleRes) {
94 Intent intent = super.onBuildStartFragmentIntent(fragmentName, args,
95 titleRes, shortTitleRes);
96 String url = getIntent().getStringExtra(CURRENT_PAGE);
97 intent.putExtra(CURRENT_PAGE, url);
98 return intent;
99 }
100
The Android Open Source Project0c908882009-03-03 19:32:16 -0800101}