blob: 966d968fee513c24c1324f75a145260256acc84a [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
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 Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
The Android Open Source Project0c908882009-03-03 19:32:16 -080018
Pankaj Gargb3b57462014-11-18 17:28:30 -080019import android.app.Activity;
The Android Open Source Project0c908882009-03-03 19:32:16 -080020import android.content.Context;
Pankaj Gargb3b57462014-11-18 17:28:30 -080021import android.content.Intent;
22import android.content.SharedPreferences;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080023import android.preference.DialogPreference;
Pankaj Gargb3b57462014-11-18 17:28:30 -080024import android.preference.PreferenceManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080025import android.util.AttributeSet;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080026import android.util.Log;
Pankaj Gargb3b57462014-11-18 17:28:30 -080027import android.view.View;
The Android Open Source Project0c908882009-03-03 19:32:16 -080028
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080029class BrowserYesNoPreference extends DialogPreference {
Pankaj Gargb3b57462014-11-18 17:28:30 -080030 private SharedPreferences mPrefs;
31 private Context mContext;
The Android Open Source Project0c908882009-03-03 19:32:16 -080032
33 // This is the constructor called by the inflater
34 public BrowserYesNoPreference(Context context, AttributeSet attrs) {
35 super(context, attrs);
Pankaj Gargb3b57462014-11-18 17:28:30 -080036 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 Project0c908882009-03-03 19:32:16 -080086 }
87
88 @Override
89 protected void onDialogClosed(boolean positiveResult) {
90 super.onDialogClosed(positiveResult);
91
Vivek Sekharb7499802014-04-08 07:48:38 -070092 if (callChangeListener(positiveResult)) {
Vivek Sekhar107f74f2014-05-09 15:51:48 -070093 if (!positiveResult)
94 return;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -070095 setEnabled(false);
John Reck35e9dd62011-04-25 09:01:54 -070096 BrowserSettings settings = BrowserSettings.getInstance();
Pankaj Gargb3b57462014-11-18 17:28:30 -080097 if (PreferenceKeys.PREF_CLEAR_SELECTED_DATA.equals(getKey())) {
98 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_CACHE, false)) {
99 settings.clearCache();
100 settings.clearDatabases();
101 }
102 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_COOKIES, false)) {
103 settings.clearCookies();
104 }
105 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY, false)) {
106 settings.clearHistory();
107 }
108 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_FORM_DATA, false)) {
109 settings.clearFormData();
110 }
111 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_PASSWORDS, false)) {
112 settings.clearPasswords();
113 }
114 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_GEOLOCATION_ACCESS,
115 false)) {
116 settings.clearLocationAccess();
117 }
118
119 setEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700120 } else if (PreferenceKeys.PREF_RESET_DEFAULT_PREFERENCES.equals(
The Android Open Source Project0c908882009-03-03 19:32:16 -0800121 getKey())) {
John Reck35e9dd62011-04-25 09:01:54 -0700122 settings.resetDefaultPreferences();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800123 setEnabled(true);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800124 }
125 }
126 }
127}