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

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

Issue 4920541991403520: Create a minimal settings UI (Closed)
Patch Set: Addressed issues Created March 22, 2015, 3:32 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 package org.adblockplus.browser;
19
20 import org.mozilla.gecko.preferences.CustomCheckBoxPreference;
21 import org.mozilla.gecko.util.NativeJSObject;
22 import org.mozilla.gecko.util.ThreadUtils;
23
24 import android.content.Context;
25 import android.util.AttributeSet;
26
27 public class AbpCheckBoxPreference extends CustomCheckBoxPreference implements
28 AdblockPlusApiCallback
29 {
30 private String apiKey = "";
31
32 public AbpCheckBoxPreference(Context context)
33 {
34 super(context);
35 }
36
37 public AbpCheckBoxPreference(Context context, AttributeSet attrs)
38 {
39 super(context, attrs);
40 }
41
42 public AbpCheckBoxPreference(Context context, AttributeSet attrs, int defStyle )
43 {
44 super(context, attrs, defStyle);
45 }
46
47 @Override
48 protected void onAttachedToActivity()
49 {
50 super.onAttachedToActivity();
51 this.apiKey = this.getKey().substring(this.getKey().lastIndexOf(".api") + 4) ;
52 this.setEnabled(false);
53 this.recheckValue();
54 }
55
56 private void recheckValue()
57 {
58 AddOnBridge.queryBoolean(this, "get" + this.apiKey);
59 }
60
61 @Override
62 protected void onClick()
63 {
64 super.onClick();
65 AddOnBridge.setBoolean(this, "set" + this.apiKey, this.isChecked());
66 this.recheckValue();
67 }
68
69 @Override
70 public void onApiRequestSucceeded(NativeJSObject jsObject)
71 {
72 if (jsObject.has("value"))
73 {
74 final boolean enabled = AddOnBridge.getBooleanFromJSObject(jsObject, "valu e", false);
75
76 ThreadUtils.postToUiThread(new Runnable()
77 {
78 @Override
79 public void run()
80 {
81 AbpCheckBoxPreference.this.setChecked(enabled);
82 AbpCheckBoxPreference.this.setEnabled(true);
83 }
84 });
85 }
86 }
87
88 @Override
89 public void onApiRequestFailed(String errorMessage)
90 {
91 // Currently ignored
92 }
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld