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 17 package com.android.browser; 18 19 import android.app.ActionBar; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.preference.PreferenceActivity; 23 import android.view.MenuItem; 24 25 import com.android.browser.preferences.BandwidthPreferencesFragment; 26 import com.android.browser.preferences.DebugPreferencesFragment; 27 28 import java.util.List; 29 30 public class BrowserPreferencesPage extends PreferenceActivity { 31 32 public static final String CURRENT_PAGE = "currentPage"; 33 private List<Header> mHeaders; 34 35 @Override onCreate(Bundle icicle)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 46 /** 47 * Populate the activity with the top-level headers. 48 */ 49 @Override onBuildHeaders(List<Header> target)50 public void onBuildHeaders(List<Header> target) { 51 loadHeadersFromResource(R.xml.preference_headers, target); 52 53 if (BrowserSettings.getInstance().isDebugEnabled()) { 54 Header debug = new Header(); 55 debug.title = getText(R.string.pref_development_title); 56 debug.fragment = DebugPreferencesFragment.class.getName(); 57 target.add(debug); 58 } 59 mHeaders = target; 60 } 61 62 @Override onGetInitialHeader()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(); 74 } 75 76 @Override onOptionsItemSelected(MenuItem item)77 public boolean onOptionsItemSelected(MenuItem item) { 78 switch (item.getItemId()) { 79 case android.R.id.home: 80 if (getFragmentManager().getBackStackEntryCount() > 0) { 81 getFragmentManager().popBackStack(); 82 } else { 83 finish(); 84 } 85 return true; 86 } 87 88 return false; 89 } 90 91 @Override onBuildStartFragmentIntent(String fragmentName, Bundle args, int titleRes, int shortTitleRes)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 101 } 102