Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: mobile/android/thirdparty/org/adblockplus/browser/AbpCheckBoxPreference.java

Issue 4920541991403520: Create a minimal settings UI (Closed)
Patch Set: Forgot commenting out Created March 22, 2015, 3:40 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
+ }
+}

Powered by Google App Engine
This is Rietveld