blob: f47ff3d8dcba6b78dff2ffb90ca5c6c71f7044e6 [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;
Pankaj Garg32e1b942015-06-03 18:13:24 -070028import android.view.ViewGroup;
29import android.widget.Button;
The Android Open Source Project0c908882009-03-03 19:32:16 -080030
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080031class BrowserYesNoPreference extends DialogPreference {
Pankaj Gargb3b57462014-11-18 17:28:30 -080032 private SharedPreferences mPrefs;
33 private Context mContext;
The Android Open Source Project0c908882009-03-03 19:32:16 -080034
35 // This is the constructor called by the inflater
36 public BrowserYesNoPreference(Context context, AttributeSet attrs) {
37 super(context, attrs);
Pankaj Gargb3b57462014-11-18 17:28:30 -080038 mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
39 mContext = context;
40 }
41
42 @Override
Pankaj Garg32e1b942015-06-03 18:13:24 -070043 protected View onCreateView(ViewGroup group) {
44 View child = super.onCreateView(group);
45 View titleView = child.findViewById(android.R.id.title);
46 if (titleView instanceof Button) {
47 Button btn = (Button) titleView;
48 final BrowserYesNoPreference pref = this;
49 btn.setOnClickListener(
50 new View.OnClickListener() {
51 @Override
52 public void onClick(View v) {
53 pref.onClick();
54 }
55 }
56 );
57 }
58
59 return child;
60 }
61
62 @Override
63 protected void onClick() {
64 super.onClick();
65 }
66
67 @Override
Pankaj Gargb3b57462014-11-18 17:28:30 -080068 protected View onCreateDialogView() {
69 if (PreferenceKeys.PREF_CLEAR_SELECTED_DATA.equals(getKey())) {
70 String dialogMessage = mContext.getString(R.string.pref_privacy_clear_selected_dlg);
71 boolean itemSelected = false;
72
73 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_CACHE, false)) {
74 dialogMessage = dialogMessage.concat("\n\t" +
75 mContext.getString(R.string.pref_privacy_clear_cache));
76 itemSelected = true;
77 }
78 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_COOKIES, false)) {
79 dialogMessage = dialogMessage.concat("\n\t" +
80 mContext.getString(R.string.pref_privacy_clear_cookies));
81 itemSelected = true;
82 }
83 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY, false)) {
84 dialogMessage = dialogMessage.concat("\n\t" +
85 mContext.getString(R.string.pref_privacy_clear_history));
86 itemSelected = true;
87 }
88 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_FORM_DATA, false)) {
89 dialogMessage = dialogMessage.concat("\n\t" +
90 mContext.getString(R.string.pref_privacy_clear_form_data));
91 itemSelected = true;
92 }
93 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_PASSWORDS, false)) {
94 dialogMessage = dialogMessage.concat("\n\t" +
95 mContext.getString(R.string.pref_privacy_clear_passwords));
96 itemSelected = true;
97 }
98 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_GEOLOCATION_ACCESS,
99 false)) {
100 dialogMessage = dialogMessage.concat("\n\t" +
101 mContext.getString(R.string.pref_privacy_clear_geolocation_access));
102 itemSelected = true;
103 }
104
105 if (!itemSelected) {
106 setDialogMessage(R.string.pref_select_items);
107 } else {
108 setDialogMessage(dialogMessage);
109 }
110 }
111
112 return super.onCreateDialogView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800113 }
114
115 @Override
116 protected void onDialogClosed(boolean positiveResult) {
117 super.onDialogClosed(positiveResult);
118
Pankaj Garge2305022015-03-20 14:11:01 -0700119 if (!positiveResult)
120 return;
121
Vivek Sekharb7499802014-04-08 07:48:38 -0700122 if (callChangeListener(positiveResult)) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700123 setEnabled(false);
John Reck35e9dd62011-04-25 09:01:54 -0700124 BrowserSettings settings = BrowserSettings.getInstance();
Pankaj Gargb3b57462014-11-18 17:28:30 -0800125 if (PreferenceKeys.PREF_CLEAR_SELECTED_DATA.equals(getKey())) {
126 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_CACHE, false)) {
127 settings.clearCache();
128 settings.clearDatabases();
129 }
130 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_COOKIES, false)) {
131 settings.clearCookies();
132 }
133 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY, false)) {
134 settings.clearHistory();
135 }
136 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_FORM_DATA, false)) {
137 settings.clearFormData();
138 }
139 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_PASSWORDS, false)) {
140 settings.clearPasswords();
141 }
142 if (mPrefs.getBoolean(PreferenceKeys.PREF_PRIVACY_CLEAR_GEOLOCATION_ACCESS,
143 false)) {
144 settings.clearLocationAccess();
145 }
146
147 setEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700148 } else if (PreferenceKeys.PREF_RESET_DEFAULT_PREFERENCES.equals(
The Android Open Source Project0c908882009-03-03 19:32:16 -0800149 getKey())) {
John Reck35e9dd62011-04-25 09:01:54 -0700150 settings.resetDefaultPreferences();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800151 setEnabled(true);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800152 }
153 }
154 }
155}