The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 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 com.android.internal.preference.YesNoPreference; |
| 20 | |
| 21 | import android.content.Context; |
| 22 | import android.util.AttributeSet; |
| 23 | |
| 24 | class BrowserYesNoPreference extends YesNoPreference { |
| 25 | |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 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 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 31 | // This is the constructor called by the inflater |
| 32 | public BrowserYesNoPreference(Context context, AttributeSet attrs) { |
| 33 | super(context, attrs); |
| 34 | } |
| 35 | |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 36 | public BrowserYesNoPreference(Context context, OriginSettings origin) { |
| 37 | super(context); |
| 38 | mOrigin = origin; |
| 39 | } |
| 40 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 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); |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 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 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 65 | } else if (BrowserSettings.PREF_EXTRAS_RESET_DEFAULTS.equals( |
| 66 | getKey())) { |
| 67 | BrowserSettings.getInstance().resetDefaultPreferences(context); |
| 68 | setEnabled(true); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |