| 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..b70cb667275ceeec72f98899b7b17861fa589144 |
| --- /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 |
| + 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(".api") + 4); |
| + this.setEnabled(false); |
| + this.recheckValue(); |
| + } |
| + |
| + private void recheckValue() |
| + { |
| + AddOnBridge.queryBoolean(this, "get" + this.apiKey); |
| + } |
| + |
| + @Override |
| + protected void onClick() |
| + { |
| + super.onClick(); |
| + AddOnBridge.setBoolean(this, "set" + 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 |
| + } |
| +} |