Cleanup of settings menu

- Removed obsolete items
- Rearranged similar items together
- Reduced the depth of menu

Change-Id: I693dbb2b3c8cb244329be965f49ab288b73efa1a
diff --git a/src/com/android/browser/BrowserPreferencesPage.java b/src/com/android/browser/BrowserPreferencesPage.java
index 353a472..3765452 100644
--- a/src/com/android/browser/BrowserPreferencesPage.java
+++ b/src/com/android/browser/BrowserPreferencesPage.java
@@ -16,108 +16,20 @@
 
 package com.android.browser;
 
-import android.app.ActionBar;
-import android.content.Intent;
+import android.app.Activity;
 import android.os.Bundle;
-import android.preference.PreferenceActivity;
-import android.view.MenuItem;
 
-import com.android.browser.R;
-import com.android.browser.preferences.BandwidthPreferencesFragment;
-import com.android.browser.preferences.DebugPreferencesFragment;
+import com.android.browser.preferences.GeneralPreferencesFragment;
 
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class BrowserPreferencesPage extends PreferenceActivity {
+public class BrowserPreferencesPage extends Activity {
 
     public static final String CURRENT_PAGE = "currentPage";
-    private List<Header> mHeaders;
 
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
-        ActionBar actionBar = getActionBar();
-        if (actionBar != null) {
-            actionBar.setDisplayOptions(
-                    ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
-        }
+        getFragmentManager().beginTransaction().replace(android.R.id.content,
+                new GeneralPreferencesFragment()).commit();
     }
-
-    /**
-     * Populate the activity with the top-level headers.
-     */
-    @Override
-    public void onBuildHeaders(List<Header> target) {
-        loadHeadersFromResource(R.xml.preference_headers, target);
-
-        if (BrowserSettings.getInstance().isDebugEnabled()) {
-            Header debug = new Header();
-            debug.title = getText(R.string.pref_development_title);
-            debug.fragment = DebugPreferencesFragment.class.getName();
-            target.add(debug);
-        }
-        mHeaders = target;
-    }
-
-    @Override
-    public Header onGetInitialHeader() {
-        String action = getIntent().getAction();
-        if (Intent.ACTION_MANAGE_NETWORK_USAGE.equals(action)) {
-            String fragName = BandwidthPreferencesFragment.class.getName();
-            for (Header h : mHeaders) {
-                if (fragName.equals(h.fragment)) {
-                    return h;
-                }
-            }
-        }
-        return super.onGetInitialHeader();
-    }
-
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        switch (item.getItemId()) {
-            case android.R.id.home:
-                if (getFragmentManager().getBackStackEntryCount() > 0) {
-                    getFragmentManager().popBackStack();
-                } else {
-                    finish();
-                }
-                return true;
-        }
-
-        return false;
-    }
-
-    @Override
-    public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
-            int titleRes, int shortTitleRes) {
-        Intent intent = super.onBuildStartFragmentIntent(fragmentName, args,
-                titleRes, shortTitleRes);
-        String url = getIntent().getStringExtra(CURRENT_PAGE);
-        intent.putExtra(CURRENT_PAGE, url);
-        return intent;
-    }
-
-    private static final Set<String> sKnownFragments = new HashSet<String>(Arrays.asList(
-        "com.android.browser.preferences.GeneralPreferencesFragment",
-        "com.android.browser.preferences.PrivacySecurityPreferencesFragment",
-        "com.android.browser.preferences.AccessibilityPreferencesFragment",
-        "com.android.browser.preferences.AdvancedPreferencesFragment",
-        "com.android.browser.preferences.BandwidthPreferencesFragment",
-        "com.android.browser.preferences.LabPreferencesFragment",
-        "com.android.browser.preferences.AboutPreferencesFragment",
-        "com.android.browser.AutoFillSettingsFragment",
-        "com.android.browser.preferences.DebugPreferencesFragment",
-        "com.android.browser.preferences.WebsiteSettingsFragment"));
-
-    @Override
-    protected boolean isValidFragment(String fragmentName) {
-        return sKnownFragments.contains(fragmentName);
-    }
-
-
 }
diff --git a/src/com/android/browser/BrowserYesNoPreference.java b/src/com/android/browser/BrowserYesNoPreference.java
index e8d6af9..966d968 100644
--- a/src/com/android/browser/BrowserYesNoPreference.java
+++ b/src/com/android/browser/BrowserYesNoPreference.java
@@ -16,16 +16,73 @@
 
 package com.android.browser;
 
+import android.app.Activity;
 import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
 import android.preference.DialogPreference;
+import android.preference.PreferenceManager;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.view.View;
 
 class BrowserYesNoPreference extends DialogPreference {
+    private SharedPreferences mPrefs;
+    private Context mContext;
 
     // This is the constructor called by the inflater
     public BrowserYesNoPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
+        mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
+        mContext = context;
+    }
+
+    @Override
+    protected View onCreateDialogView() {
+        if (PreferenceKeys.PREF_CLEAR_SELECTED_DATA.equals(getKey())) {
+            String dialogMessage = mContext.getString(R.string.pref_privacy_clear_selected_dlg);
+            boolean itemSelected = false;
+
+            if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_CACHE, false)) {
+                dialogMessage = dialogMessage.concat("\n\t" +
+                        mContext.getString(R.string.pref_privacy_clear_cache));
+                itemSelected = true;
+            }
+            if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_COOKIES, false)) {
+                dialogMessage = dialogMessage.concat("\n\t" +
+                        mContext.getString(R.string.pref_privacy_clear_cookies));
+                itemSelected = true;
+            }
+            if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY, false)) {
+                dialogMessage = dialogMessage.concat("\n\t" +
+                        mContext.getString(R.string.pref_privacy_clear_history));
+                itemSelected = true;
+            }
+            if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_FORM_DATA, false)) {
+                dialogMessage = dialogMessage.concat("\n\t" +
+                        mContext.getString(R.string.pref_privacy_clear_form_data));
+                itemSelected = true;
+            }
+            if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_PASSWORDS, false)) {
+                dialogMessage = dialogMessage.concat("\n\t" +
+                        mContext.getString(R.string.pref_privacy_clear_passwords));
+                itemSelected = true;
+            }
+            if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_GEOLOCATION_ACCESS,
+                    false)) {
+                dialogMessage = dialogMessage.concat("\n\t" +
+                        mContext.getString(R.string.pref_privacy_clear_geolocation_access));
+                itemSelected = true;
+            }
+
+            if (!itemSelected) {
+                setDialogMessage(R.string.pref_select_items);
+            } else {
+                setDialogMessage(dialogMessage);
+            }
+        }
+
+        return super.onCreateDialogView();
     }
 
     @Override
@@ -37,24 +94,33 @@
                 return;
             setEnabled(false);
             BrowserSettings settings = BrowserSettings.getInstance();
-            if (PreferenceKeys.PREF_PRIVACY_CLEAR_CACHE.equals(getKey())) {
-                settings.clearCache();
-                settings.clearDatabases();
-            } else if (PreferenceKeys.PREF_PRIVACY_CLEAR_COOKIES.equals(getKey())) {
-                settings.clearCookies();
-            } else if (PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY.equals(getKey())) {
-                settings.clearHistory();
-            } else if (PreferenceKeys.PREF_PRIVACY_CLEAR_FORM_DATA.equals(getKey())) {
-                settings.clearFormData();
-            } else if (PreferenceKeys.PREF_PRIVACY_CLEAR_PASSWORDS.equals(getKey())) {
-                settings.clearPasswords();
+            if (PreferenceKeys.PREF_CLEAR_SELECTED_DATA.equals(getKey())) {
+                if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_CACHE, false)) {
+                    settings.clearCache();
+                    settings.clearDatabases();
+                }
+                if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_COOKIES, false)) {
+                    settings.clearCookies();
+                }
+                if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY, false)) {
+                    settings.clearHistory();
+                }
+                if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_FORM_DATA, false)) {
+                    settings.clearFormData();
+                }
+                if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_PASSWORDS, false)) {
+                    settings.clearPasswords();
+                }
+                if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_GEOLOCATION_ACCESS,
+                        false)) {
+                    settings.clearLocationAccess();
+                }
+
+                setEnabled(true);
             } else if (PreferenceKeys.PREF_RESET_DEFAULT_PREFERENCES.equals(
                     getKey())) {
                 settings.resetDefaultPreferences();
                 setEnabled(true);
-            } else if (PreferenceKeys.PREF_PRIVACY_CLEAR_GEOLOCATION_ACCESS.equals(
-                    getKey())) {
-                settings.clearLocationAccess();
             }
         }
     }
diff --git a/src/com/android/browser/PreferenceKeys.java b/src/com/android/browser/PreferenceKeys.java
index 7dde8b2..f3e752f 100644
--- a/src/com/android/browser/PreferenceKeys.java
+++ b/src/com/android/browser/PreferenceKeys.java
@@ -87,6 +87,7 @@
     // ----------------------
     // Keys for privacy_security_preferences.xml
     // ----------------------
+    static final String PREF_CLEAR_SELECTED_DATA = "privacy_clear_selected";
     static final String PREF_ACCEPT_COOKIES = "accept_cookies";
     static final String PREF_ENABLE_GEOLOCATION = "enable_geolocation";
     static final String PREF_PRIVACY_CLEAR_CACHE = "privacy_clear_cache";
diff --git a/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java b/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java
index f2f03ed..a51c89e 100644
--- a/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java
+++ b/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java
@@ -27,22 +27,21 @@
 
 import java.text.NumberFormat;
 
-public class AccessibilityPreferencesFragment extends PreferenceFragment
+public class AccessibilityPreferencesFragment
         implements Preference.OnPreferenceChangeListener {
 
     NumberFormat mFormat;
+    PreferenceFragment mFragment;
 
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        addPreferencesFromResource(R.xml.accessibility_preferences);
+    AccessibilityPreferencesFragment(PreferenceFragment fragment) {
+        mFragment = fragment;
         BrowserSettings settings = BrowserSettings.getInstance();
         mFormat = NumberFormat.getPercentInstance();
 
-        Preference e = findPreference(PreferenceKeys.PREF_MIN_FONT_SIZE);
+        Preference e = mFragment.findPreference(PreferenceKeys.PREF_MIN_FONT_SIZE);
         e.setOnPreferenceChangeListener(this);
         updateMinFontSummary(e, settings.getMinimumFontSize());
-        e = findPreference(PreferenceKeys.PREF_TEXT_ZOOM);
+        e = mFragment.findPreference(PreferenceKeys.PREF_TEXT_ZOOM);
         e.setOnPreferenceChangeListener(this);
         updateTextZoomSummary(e, settings.getTextZoom());
         /* SWE: Comment out double tap zoom feature
@@ -60,7 +59,7 @@
     }
 
     void updateMinFontSummary(Preference pref, int minFontSize) {
-        Context c = getActivity();
+        Context c = mFragment.getActivity();
         pref.setSummary(c.getString(R.string.pref_min_font_size_value, minFontSize));
     }
 
@@ -80,7 +79,7 @@
 
     @Override
     public boolean onPreferenceChange(Preference pref, Object objValue) {
-        if (getActivity() == null) {
+        if (mFragment.getActivity() == null) {
             // We aren't attached, so don't accept preferences changes from the
             // invisible UI.
             return false;
diff --git a/src/com/android/browser/preferences/AdvancedPreferencesFragment.java b/src/com/android/browser/preferences/AdvancedPreferencesFragment.java
index e693297..465366b 100644
--- a/src/com/android/browser/preferences/AdvancedPreferencesFragment.java
+++ b/src/com/android/browser/preferences/AdvancedPreferencesFragment.java
@@ -17,13 +17,16 @@
 package com.android.browser.preferences;
 
 import android.app.Activity;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
 import android.content.Intent;
 import android.content.res.Resources;
 import android.content.SharedPreferences.Editor;
 import android.net.Uri;
-import android.os.Bundle;
 import android.preference.ListPreference;
 import android.preference.Preference;
+import android.preference.PreferenceCategory;
 import android.preference.PreferenceFragment;
 import android.preference.PreferenceScreen;
 import android.util.Log;
@@ -41,51 +44,56 @@
 import org.codeaurora.swe.GeolocationPermissions;
 import org.codeaurora.swe.WebStorage;
 
-public class AdvancedPreferencesFragment extends PreferenceFragment
-        implements Preference.OnPreferenceChangeListener {
+public class AdvancedPreferencesFragment
+        implements Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener {
 
     private static final int DOWNLOAD_PATH_RESULT_CODE = 1;
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
 
-        // Load the XML preferences file
-        addPreferencesFromResource(R.xml.advanced_preferences);
+    PreferenceFragment mFragment = null;
 
-        PreferenceScreen websiteSettings = (PreferenceScreen) findPreference(
+    AdvancedPreferencesFragment(PreferenceFragment fragment) {
+        mFragment = fragment;
+
+        PreferenceScreen websiteSettings = (PreferenceScreen) mFragment.findPreference(
                 PreferenceKeys.PREF_WEBSITE_SETTINGS);
         websiteSettings.setFragment(WebsiteSettingsFragment.class.getName());
+        websiteSettings.setOnPreferenceClickListener(this);
 
-        Preference e = findPreference(PreferenceKeys.PREF_DEFAULT_ZOOM);
+        Preference e = mFragment.findPreference(PreferenceKeys.PREF_DEFAULT_ZOOM);
         e.setOnPreferenceChangeListener(this);
         e.setSummary(getVisualDefaultZoomName(
-                getPreferenceScreen().getSharedPreferences()
-                .getString(PreferenceKeys.PREF_DEFAULT_ZOOM, null)) );
+                mFragment.getPreferenceScreen().getSharedPreferences()
+                        .getString(PreferenceKeys.PREF_DEFAULT_ZOOM, null)));
 
-        e = findPreference(PreferenceKeys.PREF_DEFAULT_TEXT_ENCODING);
+        e = mFragment.findPreference(PreferenceKeys.PREF_RESET_DEFAULT_PREFERENCES);
         e.setOnPreferenceChangeListener(this);
 
-        e = findPreference(PreferenceKeys.PREF_RESET_DEFAULT_PREFERENCES);
-        e.setOnPreferenceChangeListener(this);
-
-        e = findPreference(PreferenceKeys.PREF_SEARCH_ENGINE);
+        e = mFragment.findPreference(PreferenceKeys.PREF_SEARCH_ENGINE);
         e.setOnPreferenceChangeListener(this);
         updateListPreferenceSummary((ListPreference) e);
 
-        updateListPreferenceSummary((ListPreference) e);
+        e = mFragment.findPreference(PreferenceKeys.PREF_DEBUG_MENU);
+        if (!BrowserSettings.getInstance().isDebugEnabled()) {
+            PreferenceCategory category = (PreferenceCategory) mFragment.findPreference("advanced");
+            category.removePreference(e);
+        } else {
+            e.setOnPreferenceClickListener(this);
+        }
+
+
+
         onInitdownloadSettingsPreference();
     }
 
     private void onInitdownloadSettingsPreference() {
-        addPreferencesFromResource(R.xml.download_settings_preferences);
         PreferenceScreen downloadPathPreset =
-                (PreferenceScreen) findPreference(PreferenceKeys.PREF_DOWNLOAD_PATH);
+                (PreferenceScreen) mFragment.findPreference(PreferenceKeys.PREF_DOWNLOAD_PATH);
         downloadPathPreset.setOnPreferenceClickListener(onClickDownloadPathSettings());
 
         String downloadPath = downloadPathPreset.getSharedPreferences().
                 getString(PreferenceKeys.PREF_DOWNLOAD_PATH,
                         BrowserSettings.getInstance().getDownloadPath());
-        String downloadPathForUser = DownloadHandler.getDownloadPathForUser(this.getActivity(),
+        String downloadPathForUser = DownloadHandler.getDownloadPathForUser(mFragment.getActivity(),
                 downloadPath);
         downloadPathPreset.setSummary(downloadPathForUser);
     }
@@ -95,22 +103,19 @@
             public boolean onPreferenceClick(Preference preference) {
                 try {
                     Intent i = new Intent("com.android.fileexplorer.action.DIR_SEL");
-                    AdvancedPreferencesFragment.this.startActivityForResult(i,
+                    mFragment.startActivityForResult(i,
                             DOWNLOAD_PATH_RESULT_CODE);
                 } catch (Exception e) {
-                    String err_msg = getResources().getString(R.string.activity_not_found,
+                    String err_msg = mFragment.getResources().getString(R.string.activity_not_found,
                             "com.android.fileexplorer.action.DIR_SEL");
-                    Toast.makeText(getActivity(), err_msg, Toast.LENGTH_LONG).show();
+                    Toast.makeText(mFragment.getActivity(), err_msg, Toast.LENGTH_LONG).show();
                 }
                 return true;
             }
         };
     }
 
-    @Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
-        super.onActivityResult(requestCode, resultCode, data);
-
         if (requestCode == DOWNLOAD_PATH_RESULT_CODE) {
             if (resultCode == Activity.RESULT_OK && data != null) {
                 String downloadPath = data.getStringExtra("result_dir_sel");
@@ -122,12 +127,13 @@
                 }
                 if (downloadPath != null) {
                     PreferenceScreen downloadPathPreset =
-                            (PreferenceScreen) findPreference(PreferenceKeys.PREF_DOWNLOAD_PATH);
+                            (PreferenceScreen) mFragment.findPreference(
+                                    PreferenceKeys.PREF_DOWNLOAD_PATH);
                     Editor editor = downloadPathPreset.getEditor();
                     editor.putString(PreferenceKeys.PREF_DOWNLOAD_PATH, downloadPath);
                     editor.apply();
                     String downloadPathForUser = DownloadHandler.getDownloadPathForUser(
-                            this.getActivity(), downloadPath);
+                            mFragment.getActivity(), downloadPath);
                     downloadPathPreset.setSummary(downloadPathForUser);
                 }
 
@@ -146,10 +152,8 @@
      * origins with active features (WebStorage, Geolocation etc) could have
      * changed after calling the WebsiteSettingsActivity.
      */
-    @Override
     public void onResume() {
-        super.onResume();
-        final PreferenceScreen websiteSettings = (PreferenceScreen) findPreference(
+        final PreferenceScreen websiteSettings = (PreferenceScreen) mFragment.findPreference(
                 PreferenceKeys.PREF_WEBSITE_SETTINGS);
         websiteSettings.setEnabled(false);
         WebStorage.getInstance().getOrigins(new ValueCallback<Map>() {
@@ -172,7 +176,7 @@
 
     @Override
     public boolean onPreferenceChange(Preference pref, Object objValue) {
-        if (getActivity() == null) {
+        if (mFragment.getActivity() == null) {
             // We aren't attached, so don't accept preferences changes from the
             // invisible UI.
             Log.w("PageContentPreferencesFragment", "onPreferenceChange called from detached fragment!");
@@ -182,14 +186,11 @@
         if (pref.getKey().equals(PreferenceKeys.PREF_DEFAULT_ZOOM)) {
             pref.setSummary(getVisualDefaultZoomName((String) objValue));
             return true;
-        } else if (pref.getKey().equals(PreferenceKeys.PREF_DEFAULT_TEXT_ENCODING)) {
-            pref.setSummary((String) objValue);
-            return true;
         } else if (pref.getKey().equals(PreferenceKeys.PREF_RESET_DEFAULT_PREFERENCES)) {
             Boolean value = (Boolean) objValue;
             if (value.booleanValue() == true) {
-                startActivity(new Intent(BrowserActivity.ACTION_RESTART, null,
-                        getActivity(), BrowserActivity.class));
+                mFragment.startActivity(new Intent(BrowserActivity.ACTION_RESTART, null,
+                        mFragment.getActivity(), BrowserActivity.class));
                 return true;
             }
         } else if (pref.getKey().equals(PreferenceKeys.PREF_SEARCH_ENGINE)) {
@@ -202,7 +203,7 @@
     }
 
     private CharSequence getVisualDefaultZoomName(String enumName) {
-        Resources res = getActivity().getResources();
+        Resources res = mFragment.getActivity().getResources();
         CharSequence[] visualNames = res.getTextArray(R.array.pref_default_zoom_choices);
         CharSequence[] enumNames = res.getTextArray(R.array.pref_default_zoom_values);
 
@@ -220,4 +221,29 @@
 
         return "";
     }
+
+    @Override
+    public boolean onPreferenceClick(Preference preference) {
+        FragmentManager fragmentManager = mFragment.getFragmentManager();
+
+        if (preference.getKey().equals(PreferenceKeys.PREF_WEBSITE_SETTINGS)) {
+            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+
+            Fragment newFragment = new WebsiteSettingsFragment();
+            fragmentTransaction.replace(mFragment.getId(), newFragment);
+            fragmentTransaction.addToBackStack(null);
+            fragmentTransaction.commit();
+            return true;
+        } else if (preference.getKey().equals(PreferenceKeys.PREF_DEBUG_MENU)) {
+            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+
+            Fragment newFragment = new DebugPreferencesFragment();
+            fragmentTransaction.replace(mFragment.getId(), newFragment);
+            fragmentTransaction.addToBackStack(null);
+            fragmentTransaction.commit();
+            return true;
+        }
+
+        return false;
+    }
 }
diff --git a/src/com/android/browser/preferences/GeneralPreferencesFragment.java b/src/com/android/browser/preferences/GeneralPreferencesFragment.java
index 2453f46..1a2d5fe 100644
--- a/src/com/android/browser/preferences/GeneralPreferencesFragment.java
+++ b/src/com/android/browser/preferences/GeneralPreferencesFragment.java
@@ -20,8 +20,11 @@
 import android.app.Dialog;
 import android.app.DialogFragment;
 import android.app.Fragment;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
 import android.content.res.Resources;
 import android.os.Bundle;
 import android.preference.ListPreference;
@@ -38,6 +41,7 @@
 import android.widget.TextView;
 import android.widget.TextView.OnEditorActionListener;
 
+import com.android.browser.AutoFillSettingsFragment;
 import com.android.browser.BrowserPreferencesPage;
 import com.android.browser.BrowserSettings;
 import com.android.browser.PreferenceKeys;
@@ -46,7 +50,7 @@
 import com.android.browser.homepages.HomeProvider;
 
 public class GeneralPreferencesFragment extends PreferenceFragment
-        implements Preference.OnPreferenceChangeListener {
+        implements Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener {
 
     static final String TAG = "PersonalPreferencesFragment";
 
@@ -62,6 +66,10 @@
     String[] mChoices, mValues;
     String mCurrentPage;
 
+    AdvancedPreferencesFragment mAdvFrag = null;
+    AccessibilityPreferencesFragment mAccessFrag = null;
+    PrivacySecurityPreferencesFragment mPrivFrag = null;
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -79,6 +87,14 @@
         pref.setPersistent(false);
         pref.setValue(getHomepageValue());
         pref.setOnPreferenceChangeListener(this);
+
+        PreferenceScreen autofill = (PreferenceScreen) findPreference(
+                PreferenceKeys.PREF_AUTOFILL_PROFILE);
+        autofill.setOnPreferenceClickListener(this);
+
+        mAdvFrag = new AdvancedPreferencesFragment(this);
+        mAccessFrag = new AccessibilityPreferencesFragment(this);
+        mPrivFrag = new PrivacySecurityPreferencesFragment(this);
     }
 
     @Override
@@ -168,15 +184,37 @@
     public void onResume() {
         super.onResume();
 
+        mAdvFrag.onResume();
         refreshUi();
     }
 
+    @Override
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        mAdvFrag.onActivityResult(requestCode,resultCode, data);
+    }
+
     void refreshUi() {
         PreferenceScreen autoFillSettings =
                 (PreferenceScreen)findPreference(PreferenceKeys.PREF_AUTOFILL_PROFILE);
         autoFillSettings.setDependency(PreferenceKeys.PREF_AUTOFILL_ENABLED);
     }
 
+    @Override
+    public boolean onPreferenceClick(Preference preference) {
+        if (preference.getKey().equals(PreferenceKeys.PREF_AUTOFILL_PROFILE)) {
+            FragmentManager fragmentManager = getFragmentManager();
+            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+
+            Fragment newFragment = new AutoFillSettingsFragment();
+            fragmentTransaction.replace(getId(), newFragment);
+            fragmentTransaction.addToBackStack(null);
+            fragmentTransaction.commit();
+            return true;
+        }
+        return false;
+    }
+
     /*
       Add this class to manage AlertDialog lifecycle.
     */
diff --git a/src/com/android/browser/preferences/LabPreferencesFragment.java b/src/com/android/browser/preferences/LabPreferencesFragment.java
deleted file mode 100644
index 222b5fa..0000000
--- a/src/com/android/browser/preferences/LabPreferencesFragment.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.browser.preferences;
-
-import android.os.Bundle;
-import android.preference.Preference;
-import android.preference.PreferenceFragment;
-
-import com.android.browser.BrowserSettings;
-import com.android.browser.PreferenceKeys;
-import com.android.browser.R;
-import com.android.browser.search.SearchEngine;
-
-public class LabPreferencesFragment extends PreferenceFragment {
-
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        // Load the XML preferences file
-        addPreferencesFromResource(R.xml.lab_preferences);
-    }
-}
diff --git a/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java b/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java
index 35e6e43..dc32a14 100644
--- a/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java
+++ b/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java
@@ -20,39 +20,38 @@
 import com.android.browser.R;
 
 import android.app.Activity;
+import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.preference.Preference;
 import android.preference.PreferenceFragment;
+import android.preference.PreferenceManager;
 
-public class PrivacySecurityPreferencesFragment extends PreferenceFragment
+public class PrivacySecurityPreferencesFragment
         implements Preference.OnPreferenceChangeListener {
 
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
+    PreferenceFragment mFragment;
 
-        // Load the preferences from an XML resource
-        addPreferencesFromResource(R.xml.privacy_security_preferences);
+    PrivacySecurityPreferencesFragment(PreferenceFragment fragment) {
+        mFragment = fragment;
 
-        Preference e = findPreference(PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY);
+        Preference e = mFragment.findPreference(PreferenceKeys.PREF_CLEAR_SELECTED_DATA);
         e.setOnPreferenceChangeListener(this);
     }
 
     @Override
-    public void onResume() {
-        super.onResume();
-    }
-
-    @Override
     public boolean onPreferenceChange(Preference pref, Object objValue) {
-        if (pref.getKey().equals(PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY)
-                && ((Boolean) objValue).booleanValue() == true) {
-            // Need to tell the browser to remove the parent/child relationship
-            // between tabs
-            getActivity().setResult(Activity.RESULT_OK, (new Intent()).putExtra(Intent.EXTRA_TEXT,
-                    pref.getKey()));
-            return true;
+        if (pref.getKey().equals(PreferenceKeys.PREF_CLEAR_SELECTED_DATA)) {
+            if (pref.getPreferenceManager().getDefaultSharedPreferences(
+                    (Context)mFragment.getActivity()).getBoolean(
+                    PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY, false)) {
+                // Need to tell the browser to remove the parent/child relationship
+                // between tabs
+                mFragment.getActivity().setResult(Activity.RESULT_OK,
+                        (new Intent()).putExtra(Intent.EXTRA_TEXT,
+                                pref.getKey()));
+                return true;
+            }
         }
 
         return false;
diff --git a/src/com/android/browser/preferences/WebsiteSettingsFragment.java b/src/com/android/browser/preferences/WebsiteSettingsFragment.java
index 020492c..49bd98e 100644
--- a/src/com/android/browser/preferences/WebsiteSettingsFragment.java
+++ b/src/com/android/browser/preferences/WebsiteSettingsFragment.java
@@ -16,7 +16,11 @@
 
 package com.android.browser.preferences;
 
+import android.app.Activity;
 import android.app.AlertDialog;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
 import android.app.ListFragment;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -707,12 +711,19 @@
                 }
             } else {
                 Site site = (Site) view.getTag();
-                PreferenceActivity activity = (PreferenceActivity) getActivity();
+                Activity activity = getActivity();
                 if (activity != null) {
                     Bundle args = new Bundle();
                     args.putParcelable(EXTRA_SITE, site);
-                    activity.startPreferencePanel(WebsiteSettingsFragment.class.getName(), args, 0,
-                            site.getPrettyTitle(), null, 0);
+
+                    FragmentManager fragmentManager = activity.getFragmentManager();
+                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+
+                    Fragment newFragment = new WebsiteSettingsFragment();
+                    newFragment.setArguments(args);
+                    fragmentTransaction.replace(getId(), newFragment);
+                    fragmentTransaction.addToBackStack(null);
+                    fragmentTransaction.commit();
                 }
             }
         }
@@ -759,9 +770,9 @@
     }
 
     private void finish() {
-        PreferenceActivity activity = (PreferenceActivity) getActivity();
+        Activity activity = getActivity();
         if (activity != null) {
-            activity.finishPreferencePanel(this, 0, null);
+            getActivity().getFragmentManager().popBackStack();
         }
     }