BrowserYesNoPreference.java revision 0c90888c75eed12f6e2e14a9044faf50bd4af8ed
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
17package com.android.browser;
18
19import com.android.internal.preference.YesNoPreference;
20
21import android.content.Context;
22import android.util.AttributeSet;
23
24class BrowserYesNoPreference extends YesNoPreference {
25
26    // This is the constructor called by the inflater
27    public BrowserYesNoPreference(Context context, AttributeSet attrs) {
28        super(context, attrs);
29    }
30
31    @Override
32    protected void onDialogClosed(boolean positiveResult) {
33        super.onDialogClosed(positiveResult);
34
35        if (positiveResult) {
36            setEnabled(false);
37
38            Context context = getContext();
39            if (BrowserSettings.PREF_CLEAR_CACHE.equals(getKey())) {
40                BrowserSettings.getInstance().clearCache(context);
41            } else if (BrowserSettings.PREF_CLEAR_COOKIES.equals(getKey())) {
42                BrowserSettings.getInstance().clearCookies(context);
43            } else if (BrowserSettings.PREF_CLEAR_HISTORY.equals(getKey())) {
44                BrowserSettings.getInstance().clearHistory(context);
45            } else if (BrowserSettings.PREF_CLEAR_FORM_DATA.equals(getKey())) {
46                BrowserSettings.getInstance().clearFormData(context);
47            } else if (BrowserSettings.PREF_CLEAR_PASSWORDS.equals(getKey())) {
48                BrowserSettings.getInstance().clearPasswords(context);
49            } else if (BrowserSettings.PREF_EXTRAS_RESET_DEFAULTS.equals(
50                    getKey())) {
51                BrowserSettings.getInstance().resetDefaultPreferences(context);
52                setEnabled(true);
53            }
54        }
55    }
56}
57