11461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb/*
21461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb * Copyright (C) 2011 The Android Open Source Project
31461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb *
41461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb * Licensed under the Apache License, Version 2.0 (the "License");
51461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb * you may not use this file except in compliance with the License.
61461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb * You may obtain a copy of the License at
71461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb *
81461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb *      http://www.apache.org/licenses/LICENSE-2.0
91461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb *
101461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb * Unless required by applicable law or agreed to in writing, software
111461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb * distributed under the License is distributed on an "AS IS" BASIS,
121461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb * See the License for the specific language governing permissions and
141461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb * limitations under the License
151461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb */
161461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb
171461244018a225006a8d4c203f9dfe294ffe94faMichael Kolbpackage com.android.browser.preferences;
181461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb
1996497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Leaseimport android.content.SharedPreferences;
201461244018a225006a8d4c203f9dfe294ffe94faMichael Kolbimport android.os.Bundle;
21825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwoodimport android.preference.ListPreference;
221461244018a225006a8d4c203f9dfe294ffe94faMichael Kolbimport android.preference.PreferenceFragment;
2396497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Leaseimport android.preference.PreferenceScreen;
241461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb
25825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwoodimport com.android.browser.BrowserSettings;
261461244018a225006a8d4c203f9dfe294ffe94faMichael Kolbimport com.android.browser.PreferenceKeys;
271461244018a225006a8d4c203f9dfe294ffe94faMichael Kolbimport com.android.browser.R;
281461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb
291461244018a225006a8d4c203f9dfe294ffe94faMichael Kolbpublic class BandwidthPreferencesFragment extends PreferenceFragment {
301461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb
311461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb    static final String TAG = "BandwidthPreferencesFragment";
321461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb
331461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb    @Override
341461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb    public void onCreate(Bundle savedInstanceState) {
351461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb        super.onCreate(savedInstanceState);
361461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb        // Load the XML preferences file
371461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb        addPreferencesFromResource(R.xml.bandwidth_preferences);
381461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb    }
391461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb
40825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwood    @Override
41825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwood    public void onResume() {
42825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwood        super.onResume();
4396497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease        PreferenceScreen prefScreen = getPreferenceScreen();
4496497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease        SharedPreferences sharedPrefs = prefScreen.getSharedPreferences();
4596497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease        if (!sharedPrefs.contains(PreferenceKeys.PREF_DATA_PRELOAD)) {
46825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwood            // set default value for preload setting
4796497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease            ListPreference preload = (ListPreference) prefScreen.findPreference(
48825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwood                    PreferenceKeys.PREF_DATA_PRELOAD);
49825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwood            if (preload != null) {
50825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwood                preload.setValue(BrowserSettings.getInstance().getDefaultPreloadSetting());
51825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwood            }
52825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwood        }
5396497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease        if (!sharedPrefs.contains(PreferenceKeys.PREF_LINK_PREFETCH)) {
5496497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease            // set default value for link prefetch setting
5596497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease            ListPreference prefetch = (ListPreference) prefScreen.findPreference(
5696497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease                    PreferenceKeys.PREF_LINK_PREFETCH);
5796497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease            if (prefetch != null) {
5896497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease                prefetch.setValue(BrowserSettings.getInstance().getDefaultLinkPrefetchSetting());
5996497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease            }
6096497838babbaeb143b0fbc7d0de9c695e56e9f7Victoria Lease        }
61825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwood    }
62825fba7eb4dae7911f84d8a48a662c4cd6a4db1fMathew Inwood
631461244018a225006a8d4c203f9dfe294ffe94faMichael Kolb}
64