The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 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 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame^] | 17 | package com.android.browser; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 18 | |
Ben Murdoch | 7ed9bd7 | 2010-12-13 14:30:33 +0000 | [diff] [blame] | 19 | import android.app.ActionBar; |
John Reck | 7b182d7 | 2011-07-08 10:30:53 -0700 | [diff] [blame] | 20 | import android.content.Intent; |
Ben Murdoch | 7ed9bd7 | 2010-12-13 14:30:33 +0000 | [diff] [blame] | 21 | import android.os.Bundle; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 22 | import android.preference.PreferenceActivity; |
Ben Murdoch | 7ed9bd7 | 2010-12-13 14:30:33 +0000 | [diff] [blame] | 23 | import android.view.MenuItem; |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 24 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame^] | 25 | import com.android.browser.R; |
| 26 | import com.android.browser.preferences.BandwidthPreferencesFragment; |
| 27 | import com.android.browser.preferences.DebugPreferencesFragment; |
John Reck | 7b182d7 | 2011-07-08 10:30:53 -0700 | [diff] [blame] | 28 | |
Jeff Hamilton | 462b8e8 | 2010-09-23 14:33:43 -0500 | [diff] [blame] | 29 | import java.util.List; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 30 | |
Jeff Hamilton | 462b8e8 | 2010-09-23 14:33:43 -0500 | [diff] [blame] | 31 | public class BrowserPreferencesPage extends PreferenceActivity { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 32 | |
Jeff Hamilton | 462b8e8 | 2010-09-23 14:33:43 -0500 | [diff] [blame] | 33 | public static final String CURRENT_PAGE = "currentPage"; |
John Reck | 7b182d7 | 2011-07-08 10:30:53 -0700 | [diff] [blame] | 34 | private List<Header> mHeaders; |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 35 | |
Ben Murdoch | 7ed9bd7 | 2010-12-13 14:30:33 +0000 | [diff] [blame] | 36 | @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 Hamilton | 462b8e8 | 2010-09-23 14:33:43 -0500 | [diff] [blame] | 47 | /** |
| 48 | * Populate the activity with the top-level headers. |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 49 | */ |
| 50 | @Override |
Jeff Hamilton | 462b8e8 | 2010-09-23 14:33:43 -0500 | [diff] [blame] | 51 | public void onBuildHeaders(List<Header> target) { |
| 52 | loadHeadersFromResource(R.xml.preference_headers, target); |
| 53 | |
John Reck | f48314f | 2011-04-27 17:52:17 -0700 | [diff] [blame] | 54 | if (BrowserSettings.getInstance().isDebugEnabled()) { |
Jeff Hamilton | 462b8e8 | 2010-09-23 14:33:43 -0500 | [diff] [blame] | 55 | 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 Reck | 7b182d7 | 2011-07-08 10:30:53 -0700 | [diff] [blame] | 60 | 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 Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
Ben Murdoch | 7ed9bd7 | 2010-12-13 14:30:33 +0000 | [diff] [blame] | 78 | public boolean onOptionsItemSelected(MenuItem item) { |
| 79 | switch (item.getItemId()) { |
| 80 | case android.R.id.home: |
Dianne Hackborn | bf1d10a | 2011-01-17 12:29:51 -0800 | [diff] [blame] | 81 | if (getFragmentManager().getBackStackEntryCount() > 0) { |
Ben Murdoch | 7ed9bd7 | 2010-12-13 14:30:33 +0000 | [diff] [blame] | 82 | getFragmentManager().popBackStack(); |
| 83 | } else { |
| 84 | finish(); |
| 85 | } |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | return false; |
| 90 | } |
John Reck | 42dfb9f | 2011-08-15 13:57:37 -0700 | [diff] [blame] | 91 | |
| 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 Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 102 | } |