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 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 17 | package com.android.browser; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 18 | |
Pankaj Garg | b3b5746 | 2014-11-18 17:28:30 -0800 | [diff] [blame] | 19 | import android.app.Activity; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Pankaj Garg | b3b5746 | 2014-11-18 17:28:30 -0800 | [diff] [blame] | 21 | import android.content.Intent; |
| 22 | import android.content.SharedPreferences; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 23 | import android.preference.DialogPreference; |
Pankaj Garg | b3b5746 | 2014-11-18 17:28:30 -0800 | [diff] [blame] | 24 | import android.preference.PreferenceManager; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 25 | import android.util.AttributeSet; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 26 | import android.util.Log; |
Pankaj Garg | b3b5746 | 2014-11-18 17:28:30 -0800 | [diff] [blame] | 27 | import android.view.View; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 28 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 29 | class BrowserYesNoPreference extends DialogPreference { |
Pankaj Garg | b3b5746 | 2014-11-18 17:28:30 -0800 | [diff] [blame] | 30 | private SharedPreferences mPrefs; |
| 31 | private Context mContext; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 32 | |
| 33 | // This is the constructor called by the inflater |
| 34 | public BrowserYesNoPreference(Context context, AttributeSet attrs) { |
| 35 | super(context, attrs); |
Pankaj Garg | b3b5746 | 2014-11-18 17:28:30 -0800 | [diff] [blame] | 36 | mPrefs = PreferenceManager.getDefaultSharedPreferences(context); |
| 37 | mContext = context; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | protected View onCreateDialogView() { |
| 42 | if (PreferenceKeys.PREF_CLEAR_SELECTED_DATA.equals(getKey())) { |
| 43 | String dialogMessage = mContext.getString(R.string.pref_privacy_clear_selected_dlg); |
| 44 | boolean itemSelected = false; |
| 45 | |
| 46 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_CACHE, false)) { |
| 47 | dialogMessage = dialogMessage.concat("\n\t" + |
| 48 | mContext.getString(R.string.pref_privacy_clear_cache)); |
| 49 | itemSelected = true; |
| 50 | } |
| 51 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_COOKIES, false)) { |
| 52 | dialogMessage = dialogMessage.concat("\n\t" + |
| 53 | mContext.getString(R.string.pref_privacy_clear_cookies)); |
| 54 | itemSelected = true; |
| 55 | } |
| 56 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY, false)) { |
| 57 | dialogMessage = dialogMessage.concat("\n\t" + |
| 58 | mContext.getString(R.string.pref_privacy_clear_history)); |
| 59 | itemSelected = true; |
| 60 | } |
| 61 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_FORM_DATA, false)) { |
| 62 | dialogMessage = dialogMessage.concat("\n\t" + |
| 63 | mContext.getString(R.string.pref_privacy_clear_form_data)); |
| 64 | itemSelected = true; |
| 65 | } |
| 66 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_PASSWORDS, false)) { |
| 67 | dialogMessage = dialogMessage.concat("\n\t" + |
| 68 | mContext.getString(R.string.pref_privacy_clear_passwords)); |
| 69 | itemSelected = true; |
| 70 | } |
| 71 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_GEOLOCATION_ACCESS, |
| 72 | false)) { |
| 73 | dialogMessage = dialogMessage.concat("\n\t" + |
| 74 | mContext.getString(R.string.pref_privacy_clear_geolocation_access)); |
| 75 | itemSelected = true; |
| 76 | } |
| 77 | |
| 78 | if (!itemSelected) { |
| 79 | setDialogMessage(R.string.pref_select_items); |
| 80 | } else { |
| 81 | setDialogMessage(dialogMessage); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return super.onCreateDialogView(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | @Override |
| 89 | protected void onDialogClosed(boolean positiveResult) { |
| 90 | super.onDialogClosed(positiveResult); |
| 91 | |
Pankaj Garg | e230502 | 2015-03-20 14:11:01 -0700 | [diff] [blame] | 92 | if (!positiveResult) |
| 93 | return; |
| 94 | |
Vivek Sekhar | b749980 | 2014-04-08 07:48:38 -0700 | [diff] [blame] | 95 | if (callChangeListener(positiveResult)) { |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 96 | setEnabled(false); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 97 | BrowserSettings settings = BrowserSettings.getInstance(); |
Pankaj Garg | b3b5746 | 2014-11-18 17:28:30 -0800 | [diff] [blame] | 98 | if (PreferenceKeys.PREF_CLEAR_SELECTED_DATA.equals(getKey())) { |
| 99 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_CACHE, false)) { |
| 100 | settings.clearCache(); |
| 101 | settings.clearDatabases(); |
| 102 | } |
| 103 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_COOKIES, false)) { |
| 104 | settings.clearCookies(); |
| 105 | } |
| 106 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY, false)) { |
| 107 | settings.clearHistory(); |
| 108 | } |
| 109 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_FORM_DATA, false)) { |
| 110 | settings.clearFormData(); |
| 111 | } |
| 112 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_PASSWORDS, false)) { |
| 113 | settings.clearPasswords(); |
| 114 | } |
| 115 | if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_GEOLOCATION_ACCESS, |
| 116 | false)) { |
| 117 | settings.clearLocationAccess(); |
| 118 | } |
| 119 | |
| 120 | setEnabled(true); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 121 | } else if (PreferenceKeys.PREF_RESET_DEFAULT_PREFERENCES.equals( |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 122 | getKey())) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 123 | settings.resetDefaultPreferences(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 124 | setEnabled(true); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |