Index: mobile/android/thirdparty/org/adblockplus/browser/AbpCheckBoxPreference.java |
diff --git a/mobile/android/thirdparty/org/adblockplus/browser/AbpCheckBoxPreference.java b/mobile/android/thirdparty/org/adblockplus/browser/AbpCheckBoxPreference.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..201f194106eed2c2f7bb46cc9949e4e1f72389a8 |
--- /dev/null |
+++ b/mobile/android/thirdparty/org/adblockplus/browser/AbpCheckBoxPreference.java |
@@ -0,0 +1,93 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-2015 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+package org.adblockplus.browser; |
+ |
+import org.mozilla.gecko.preferences.CustomCheckBoxPreference; |
+import org.mozilla.gecko.util.NativeJSObject; |
+import org.mozilla.gecko.util.ThreadUtils; |
+ |
+import android.content.Context; |
+import android.util.AttributeSet; |
+ |
+public class AbpCheckBoxPreference extends CustomCheckBoxPreference implements |
Felix Dahlke
2015/03/22 15:51:45
What's that, 80 columns? :P We do have 100 for Jav
René Jeschke
2015/03/22 16:44:55
Yes, and it would end on column 102 :p
Felix Dahlke
2015/03/22 17:44:34
Touché :P
|
+ AdblockPlusApiCallback |
+{ |
+ private String apiKey = ""; |
+ |
+ public AbpCheckBoxPreference(Context context) |
+ { |
+ super(context); |
+ } |
+ |
+ public AbpCheckBoxPreference(Context context, AttributeSet attrs) |
+ { |
+ super(context, attrs); |
+ } |
+ |
+ public AbpCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) |
+ { |
+ super(context, attrs, defStyle); |
+ } |
+ |
+ @Override |
+ protected void onAttachedToActivity() |
+ { |
+ super.onAttachedToActivity(); |
+ this.apiKey = this.getKey().substring(this.getKey().lastIndexOf('.') + 1); |
+ this.setEnabled(false); |
+ this.recheckValue(); |
+ } |
+ |
+ private void recheckValue() |
Felix Dahlke
2015/03/22 15:51:45
Naming nit: Isn't this rather logically "refreshVa
René Jeschke
2015/03/22 16:44:55
Yup
|
+ { |
+ AddOnBridge.queryBoolean(this, "query_" + this.apiKey); |
+ } |
+ |
+ @Override |
+ protected void onClick() |
Felix Dahlke
2015/03/22 15:51:45
IIRC, setChecked is invoked whenever the value cha
René Jeschke
2015/03/22 16:44:55
Because I call 'setChecked()' to set the checkbox
Felix Dahlke
2015/03/22 17:44:34
Well, you could use super.setChecked. Potentially
René Jeschke
2015/03/22 18:32:41
What I mean is:
If we do put this logic into 'set
Felix Dahlke
2015/03/22 20:10:24
You mean, CheckBoxPreference itself will call setC
René Jeschke
2015/03/22 21:04:45
Ok, as discussed on IRC, we will leave this as is.
|
+ { |
+ super.onClick(); |
+ AddOnBridge.setBoolean(this, "change_" + this.apiKey, this.isChecked()); |
+ this.recheckValue(); |
+ } |
+ |
+ @Override |
+ public void onApiRequestSucceeded(NativeJSObject jsObject) |
+ { |
+ if (jsObject.has("value")) |
+ { |
+ final boolean enabled = AddOnBridge.getBooleanFromJSObject(jsObject, "value", false); |
+ |
+ ThreadUtils.postToUiThread(new Runnable() |
+ { |
+ @Override |
+ public void run() |
+ { |
+ AbpCheckBoxPreference.this.setChecked(enabled); |
+ AbpCheckBoxPreference.this.setEnabled(true); |
+ } |
+ }); |
+ } |
+ } |
+ |
+ @Override |
+ public void onApiRequestFailed(String errorMessage) |
+ { |
+ // Currently ignored |
+ } |
+} |