OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 package org.adblockplus.sbrowser.contentblocker; | 18 package org.adblockplus.sbrowser.contentblocker; |
19 | 19 |
20 import java.io.BufferedReader; | 20 import java.io.BufferedReader; |
21 import java.io.IOException; | 21 import java.io.IOException; |
22 import java.io.InputStreamReader; | 22 import java.io.InputStreamReader; |
23 | 23 |
24 import org.adblockplus.sbrowser.contentblocker.engine.Engine; | 24 import org.adblockplus.sbrowser.contentblocker.engine.Engine; |
25 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; | 25 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; |
26 import org.adblockplus.adblockplussbrowser.R; | 26 import org.adblockplus.adblockplussbrowser.R; |
27 | 27 |
28 import android.app.AlertDialog; | 28 import android.app.AlertDialog; |
| 29 import android.app.Dialog; |
29 import android.app.ProgressDialog; | 30 import android.app.ProgressDialog; |
30 import android.content.DialogInterface; | 31 import android.content.DialogInterface; |
31 import android.content.DialogInterface.OnClickListener; | 32 import android.content.DialogInterface.OnClickListener; |
32 import android.content.Intent; | 33 import android.content.Intent; |
33 import android.content.SharedPreferences; | 34 import android.content.SharedPreferences; |
34 import android.net.Uri; | 35 import android.net.Uri; |
35 import android.os.Bundle; | 36 import android.os.Bundle; |
36 import android.preference.PreferenceActivity; | 37 import android.preference.PreferenceActivity; |
37 import android.preference.PreferenceManager; | 38 import android.preference.PreferenceManager; |
38 import android.text.Html; | 39 import android.text.Html; |
39 import android.util.Log; | 40 import android.util.Log; |
40 | 41 |
41 public class MainPreferences extends PreferenceActivity implements | 42 public class MainPreferences extends PreferenceActivity implements |
42 EngineService.OnEngineCreatedCallback, SharedPreferences.OnSharedPreferenceC
hangeListener | 43 EngineService.OnEngineCreatedCallback, SharedPreferences.OnSharedPreferenceC
hangeListener |
43 { | 44 { |
44 private static final String TAG = MainPreferences.class.getSimpleName(); | 45 private static final String TAG = MainPreferences.class.getSimpleName(); |
45 private static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser"; | 46 private static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser"; |
46 private ProgressDialog progressDialog = null; | |
47 private Engine engine = null; | 47 private Engine engine = null; |
48 private AlertDialog setupDialog = null; | 48 private Dialog dialog; |
| 49 private int dialogTitleResId; |
49 | 50 |
50 private SharedPreferences getSharedPreferences() | 51 private SharedPreferences getSharedPreferences() |
51 { | 52 { |
52 return PreferenceManager.getDefaultSharedPreferences(this.getApplicationCont
ext()); | 53 return PreferenceManager.getDefaultSharedPreferences(this.getApplicationCont
ext()); |
53 } | 54 } |
54 | 55 |
55 @Override | 56 @Override |
56 public void onCreate(Bundle savedInstanceState) | 57 public void onCreate(Bundle savedInstanceState) |
57 { | 58 { |
58 super.onCreate(savedInstanceState); | 59 super.onCreate(savedInstanceState); |
(...skipping 19 matching lines...) Expand all Loading... |
78 this.getSharedPreferences() | 79 this.getSharedPreferences() |
79 .edit() | 80 .edit() |
80 .clear() | 81 .clear() |
81 .commit(); | 82 .commit(); |
82 } | 83 } |
83 } | 84 } |
84 | 85 |
85 @Override | 86 @Override |
86 protected void onStart() | 87 protected void onStart() |
87 { | 88 { |
88 this.progressDialog = ProgressDialog.show(this, | 89 this.dialogTitleResId = R.string.initialization_title; |
89 this.getString(R.string.initialization_title), | 90 this.dialog = ProgressDialog.show(this, |
| 91 this.getString(this.dialogTitleResId), |
90 this.getString(R.string.initialization_message)); | 92 this.getString(R.string.initialization_message)); |
91 super.onStart(); | 93 super.onStart(); |
92 this.getSharedPreferences().registerOnSharedPreferenceChangeListener(this); | 94 this.getSharedPreferences().registerOnSharedPreferenceChangeListener(this); |
93 EngineService.startService(this.getApplicationContext(), this); | 95 EngineService.startService(this.getApplicationContext(), this); |
94 } | 96 } |
95 | 97 |
96 @Override | 98 @Override |
97 protected void onStop() | 99 protected void onStop() |
98 { | 100 { |
99 super.onStop(); | 101 super.onStop(); |
100 this.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this)
; | 102 this.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this)
; |
| 103 this.dismissDialog(); |
| 104 } |
| 105 |
| 106 private void dismissDialog() |
| 107 { |
| 108 if (this.dialog != null) |
| 109 { |
| 110 this.dialogTitleResId = 0; |
| 111 this.dialog.dismiss(); |
| 112 this.dialog = null; |
| 113 } |
101 } | 114 } |
102 | 115 |
103 private void checkForCompatibleSBrowserAndProceed() | 116 private void checkForCompatibleSBrowserAndProceed() |
104 { | 117 { |
105 if (!Engine.hasCompatibleSBrowserInstalled(this.getApplicationContext())) | 118 if (!Engine.hasCompatibleSBrowserInstalled(this.getApplicationContext())) |
106 { | 119 { |
107 final AlertDialog d = new AlertDialog.Builder(this) | 120 this.dialogTitleResId = R.string.sbrowser_dialog_title; |
| 121 this.dialog = new AlertDialog.Builder(this) |
108 .setCancelable(false) | 122 .setCancelable(false) |
109 .setTitle(R.string.sbrowser_dialog_title) | 123 .setTitle(this.dialogTitleResId) |
110 .setMessage(Html.fromHtml(this.readTextFile(R.raw.sbrowser_dialog))) | 124 .setMessage(Html.fromHtml(this.readTextFile(R.raw.sbrowser_dialog))) |
111 .setNeutralButton(R.string.sbrowser_dialog_button, new OnClickListener
() | 125 .setNeutralButton(R.string.sbrowser_dialog_button, new OnClickListener
() |
112 { | 126 { |
113 @Override | 127 @Override |
114 public void onClick(DialogInterface dialog, int which) | 128 public void onClick(DialogInterface dialog, int which) |
115 { | 129 { |
116 try | 130 try |
117 { | 131 { |
118 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market:/
/details?id=" | 132 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market:/
/details?id=" |
119 + SBROWSER_APP_ID))); | 133 + SBROWSER_APP_ID))); |
120 } | 134 } |
121 catch (final Throwable t) | 135 catch (final Throwable t) |
122 { | 136 { |
123 startActivity(new Intent(Intent.ACTION_VIEW, Uri | 137 startActivity(new Intent(Intent.ACTION_VIEW, Uri |
124 .parse("https://play.google.com/store/apps/details?id=" + SB
ROWSER_APP_ID))); | 138 .parse("https://play.google.com/store/apps/details?id=" + SB
ROWSER_APP_ID))); |
125 } | 139 } |
126 } | 140 } |
127 }).create(); | 141 }).create(); |
128 d.show(); | 142 this.dialog.show(); |
129 } | 143 } |
130 else | 144 else |
131 { | 145 { |
132 this.checkAAStatusAndProceed(); | 146 this.checkAAStatusAndProceed(); |
133 } | 147 } |
134 } | 148 } |
135 | 149 |
136 private void checkAAStatusAndProceed() | 150 private void checkAAStatusAndProceed() |
137 { | 151 { |
138 final SharedPreferences prefs = this.getSharedPreferences(); | 152 final SharedPreferences prefs = this.getSharedPreferences(); |
139 final String keyAaInfoShown = this.getString(R.string.key_aa_info_shown); | 153 final String keyAaInfoShown = this.getString(R.string.key_aa_info_shown); |
140 final boolean aaInfoShown = prefs.getBoolean(keyAaInfoShown, false); | 154 final boolean aaInfoShown = prefs.getBoolean(keyAaInfoShown, false); |
141 if (!aaInfoShown) | 155 if (!aaInfoShown) |
142 { | 156 { |
143 final AlertDialog d = new AlertDialog.Builder(this) | 157 this.dialogTitleResId = R.string.aa_dialog_title; |
| 158 this.dialog = new AlertDialog.Builder(this) |
144 .setCancelable(false) | 159 .setCancelable(false) |
145 .setTitle(R.string.aa_dialog_title) | 160 .setTitle(this.dialogTitleResId) |
146 .setMessage(Html.fromHtml(this.readTextFile(R.raw.aa_dialog))) | 161 .setMessage(Html.fromHtml(this.readTextFile(R.raw.aa_dialog))) |
147 .setNeutralButton(R.string.aa_dialog_button, new OnClickListener() | 162 .setNeutralButton(R.string.aa_dialog_button, new OnClickListener() |
148 { | 163 { |
149 @Override | 164 @Override |
150 public void onClick(DialogInterface dialog, int which) | 165 public void onClick(DialogInterface dialog, int which) |
151 { | 166 { |
152 prefs.edit() | 167 prefs.edit() |
153 .putBoolean(keyAaInfoShown, true) | 168 .putBoolean(keyAaInfoShown, true) |
154 .commit(); | 169 .commit(); |
155 MainPreferences.this.checkSetupStatus(); | 170 MainPreferences.this.checkSetupStatus(); |
156 } | 171 } |
157 }).create(); | 172 }).create(); |
158 d.show(); | 173 this.dialog.show(); |
159 } | 174 } |
160 else | 175 else |
161 { | 176 { |
162 this.checkSetupStatus(); | 177 this.checkSetupStatus(); |
163 } | 178 } |
164 } | 179 } |
165 | 180 |
166 private void checkSetupStatus() | 181 private void checkSetupStatus() |
167 { | 182 { |
168 final boolean applicationActivated = this.getSharedPreferences() | 183 final boolean applicationActivated = this.getSharedPreferences() |
169 .getBoolean(this.getString(R.string.key_application_activated), false); | 184 .getBoolean(this.getString(R.string.key_application_activated), false); |
170 | 185 |
171 if (!applicationActivated) | 186 if (!applicationActivated) |
172 { | 187 { |
173 Log.d(TAG, "Showing setup dialog"); | 188 Log.d(TAG, "Showing setup dialog"); |
174 this.setupDialog = new AlertDialog.Builder(this) | 189 this.dialogTitleResId = R.string.setup_dialog_title; |
| 190 this.dialog = new AlertDialog.Builder(this) |
175 .setCancelable(false) | 191 .setCancelable(false) |
176 .setTitle(R.string.setup_dialog_title) | 192 .setTitle(this.dialogTitleResId) |
177 .setMessage(Html.fromHtml(this.readTextFile(R.raw.setup_dialog))) | 193 .setMessage(Html.fromHtml(this.readTextFile(R.raw.setup_dialog))) |
178 .setNeutralButton(R.string.setup_dialog_button, new OnClickListener() | 194 .setNeutralButton(R.string.setup_dialog_button, new OnClickListener() |
179 { | 195 { |
180 @Override | 196 @Override |
181 public void onClick(DialogInterface dialog, int which) | 197 public void onClick(DialogInterface dialog, int which) |
182 { | 198 { |
183 Engine.openSBrowserSettings(MainPreferences.this); | 199 Engine.openSBrowserSettings(MainPreferences.this); |
184 } | 200 } |
185 }) | 201 }) |
186 .create(); | 202 .create(); |
187 this.setupDialog.show(); | 203 this.dialog.show(); |
188 } | 204 } |
189 } | 205 } |
190 | 206 |
191 @Override | 207 @Override |
192 public void onEngineCreated(Engine engine, boolean success) | 208 public void onEngineCreated(Engine engine, boolean success) |
193 { | 209 { |
194 Log.d(TAG, "onEngineCreated: " + success); | 210 Log.d(TAG, "onEngineCreated: " + success); |
195 this.engine = success ? engine : null; | 211 this.engine = success ? engine : null; |
196 if (this.progressDialog != null) | 212 if (this.dialogTitleResId == R.string.initialization_title) |
197 { | 213 { |
198 this.progressDialog.dismiss(); | 214 this.dismissDialog(); |
199 this.progressDialog = null; | |
200 | 215 |
201 this.checkForCompatibleSBrowserAndProceed(); | 216 this.checkForCompatibleSBrowserAndProceed(); |
202 } | 217 } |
203 } | 218 } |
204 | 219 |
205 @Override | 220 @Override |
206 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str
ing key) | 221 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str
ing key) |
207 { | 222 { |
208 if (this.getString(R.string.key_automatic_updates).equals(key) && this.engin
e != null) | 223 if (this.getString(R.string.key_automatic_updates).equals(key) && this.engin
e != null) |
209 { | 224 { |
210 this.engine.connectivityChanged(); | 225 this.engine.connectivityChanged(); |
211 } | 226 } |
212 else if (this.getString(R.string.key_acceptable_ads).equals(key)) | 227 else if (this.getString(R.string.key_acceptable_ads).equals(key)) |
213 { | 228 { |
214 boolean enabled = sharedPreferences.getBoolean(key, true); | 229 boolean enabled = sharedPreferences.getBoolean(key, true); |
215 final String id = "url:" + this.engine.getPrefsDefault(Engine.SUBSCRIPTION
S_EXCEPTIONSURL); | 230 final String id = "url:" + this.engine.getPrefsDefault(Engine.SUBSCRIPTION
S_EXCEPTIONSURL); |
216 Log.d(TAG, "Acceptable ads " + (enabled ? "enabled" : "disabled")); | 231 Log.d(TAG, "Acceptable ads " + (enabled ? "enabled" : "disabled")); |
217 this.engine.changeSubscriptionState(id, enabled); | 232 this.engine.changeSubscriptionState(id, enabled); |
218 } | 233 } |
219 else if (this.getString(R.string.key_application_activated).equals(key)) | 234 else if (this.getString(R.string.key_application_activated).equals(key)) |
220 { | 235 { |
221 if (this.setupDialog != null) | 236 if (this.dialogTitleResId == R.string.setup_dialog_title) |
222 { | 237 { |
223 this.setupDialog.dismiss(); | 238 this.dismissDialog(); |
224 this.setupDialog = null; | |
225 } | 239 } |
226 } | 240 } |
227 } | 241 } |
228 | 242 |
229 private String readTextFile(int id) | 243 private String readTextFile(int id) |
230 { | 244 { |
231 try | 245 try |
232 { | 246 { |
233 final BufferedReader r = new BufferedReader(new InputStreamReader(this.get
Resources() | 247 final BufferedReader r = new BufferedReader(new InputStreamReader(this.get
Resources() |
234 .openRawResource(id), "UTF-8")); | 248 .openRawResource(id), "UTF-8")); |
(...skipping 12 matching lines...) Expand all Loading... |
247 r.close(); | 261 r.close(); |
248 } | 262 } |
249 } | 263 } |
250 catch (IOException e) | 264 catch (IOException e) |
251 { | 265 { |
252 Log.e(TAG, "Resource reading failed for: " + id, e); | 266 Log.e(TAG, "Resource reading failed for: " + id, e); |
253 return "..."; | 267 return "..."; |
254 } | 268 } |
255 } | 269 } |
256 } | 270 } |
OLD | NEW |