BrowserYesNoPreference.java revision 78a98e459323f938e97789a6131beddbebb459ce
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 used for the HTML5 pref UI, where we construct
27    // BrowserYesNoPreference objects on the fly and where we need
28    // to save the corresponding origin.
29    OriginSettings mOrigin = null;
30
31    // This is the constructor called by the inflater
32    public BrowserYesNoPreference(Context context, AttributeSet attrs) {
33        super(context, attrs);
34    }
35
36    public BrowserYesNoPreference(Context context, OriginSettings origin) {
37        super(context);
38        mOrigin = origin;
39    }
40
41    @Override
42    protected void onDialogClosed(boolean positiveResult) {
43        super.onDialogClosed(positiveResult);
44
45        if (positiveResult) {
46            setEnabled(false);
47
48            Context context = getContext();
49            if (BrowserSettings.PREF_CLEAR_CACHE.equals(getKey())) {
50                BrowserSettings.getInstance().clearCache(context);
51            } else if (BrowserSettings.PREF_CLEAR_COOKIES.equals(getKey())) {
52                BrowserSettings.getInstance().clearCookies(context);
53            } else if (BrowserSettings.PREF_CLEAR_HISTORY.equals(getKey())) {
54                BrowserSettings.getInstance().clearHistory(context);
55            } else if (BrowserSettings.PREF_CLEAR_FORM_DATA.equals(getKey())) {
56                BrowserSettings.getInstance().clearFormData(context);
57            } else if (BrowserSettings.PREF_CLEAR_PASSWORDS.equals(getKey())) {
58                BrowserSettings.getInstance().clearPasswords(context);
59            } else if (BrowserSettings.PREF_CLEAR_DATABASES.equals(getKey())) {
60                BrowserSettings.getInstance().clearDatabases(context);
61            } else if (BrowserSettings.PREF_CLEAR_ALL_DATA.equals(getKey())) {
62                if (mOrigin != null) {
63                    mOrigin.delete();
64                }
65            } else if (BrowserSettings.PREF_EXTRAS_RESET_DEFAULTS.equals(
66                    getKey())) {
67                BrowserSettings.getInstance().resetDefaultPreferences(context);
68                setEnabled(true);
69            }
70        }
71    }
72}
73