blob: ebc08a40dec2b358541066a7074d99641f345fb7 [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
Jeff Hamilton462b8e82010-09-23 14:33:43 -050029import java.util.List;
The Android Open Source Project0c908882009-03-03 19:32:16 -080030
Jeff Hamilton462b8e82010-09-23 14:33:43 -050031public class BrowserPreferencesPage extends PreferenceActivity {
The Android Open Source Project0c908882009-03-03 19:32:16 -080032
Jeff Hamilton462b8e82010-09-23 14:33:43 -050033 public static final String CURRENT_PAGE = "currentPage";
John Reck7b182d72011-07-08 10:30:53 -070034 private List<Header> mHeaders;
Nicolas Roard78a98e42009-05-11 13:34:17 +010035
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000036 @Override
37 public void onCreate(Bundle icicle) {
38 super.onCreate(icicle);
39
40 ActionBar actionBar = getActionBar();
41 if (actionBar != null) {
42 actionBar.setDisplayOptions(
43 ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
44 }
45 }
46
Jeff Hamilton462b8e82010-09-23 14:33:43 -050047 /**
48 * Populate the activity with the top-level headers.
Nicolas Roarde46990e2009-06-19 16:27:49 +010049 */
50 @Override
Jeff Hamilton462b8e82010-09-23 14:33:43 -050051 public void onBuildHeaders(List<Header> target) {
52 loadHeadersFromResource(R.xml.preference_headers, target);
53
John Reckf48314f2011-04-27 17:52:17 -070054 if (BrowserSettings.getInstance().isDebugEnabled()) {
Jeff Hamilton462b8e82010-09-23 14:33:43 -050055 Header debug = new Header();
56 debug.title = getText(R.string.pref_development_title);
57 debug.fragment = DebugPreferencesFragment.class.getName();
58 target.add(debug);
59 }
John Reck7b182d72011-07-08 10:30:53 -070060 mHeaders = target;
61 }
62
63 @Override
64 public Header onGetInitialHeader() {
65 String action = getIntent().getAction();
66 if (Intent.ACTION_MANAGE_NETWORK_USAGE.equals(action)) {
67 String fragName = BandwidthPreferencesFragment.class.getName();
68 for (Header h : mHeaders) {
69 if (fragName.equals(h.fragment)) {
70 return h;
71 }
72 }
73 }
74 return super.onGetInitialHeader();
The Android Open Source Project0c908882009-03-03 19:32:16 -080075 }
76
77 @Override
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000078 public boolean onOptionsItemSelected(MenuItem item) {
79 switch (item.getItemId()) {
80 case android.R.id.home:
Dianne Hackbornbf1d10a2011-01-17 12:29:51 -080081 if (getFragmentManager().getBackStackEntryCount() > 0) {
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000082 getFragmentManager().popBackStack();
83 } else {
84 finish();
85 }
86 return true;
87 }
88
89 return false;
90 }
John Reck42dfb9f2011-08-15 13:57:37 -070091
92 @Override
93 public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
94 int titleRes, int shortTitleRes) {
95 Intent intent = super.onBuildStartFragmentIntent(fragmentName, args,
96 titleRes, shortTitleRes);
97 String url = getIntent().getStringExtra(CURRENT_PAGE);
98 intent.putExtra(CURRENT_PAGE, url);
99 return intent;
100 }
101
The Android Open Source Project0c908882009-03-03 19:32:16 -0800102}