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: Typos, extra-summary into strings.xml. Created March 20, 2015, 11:54 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.preference.PreferenceManager;
26 import android.util.AttributeSet;
27 import android.util.Log;
28 import android.view.View;
29
30 public class AbpCheckBoxPreference extends CustomCheckBoxPreference implements
31 AdblockPlusApiCallback
32 {
33 private static final String TAG = "AdblockBrowser.AbpCheckBoxPreference";
34 private String apiKey = "";
35
36 public AbpCheckBoxPreference(Context context)
37 {
38 super(context);
39 }
40
41 public AbpCheckBoxPreference(Context context, AttributeSet attrs)
42 {
43 super(context, attrs);
44 }
45
46 public AbpCheckBoxPreference(Context context, AttributeSet attrs, int defStyle )
47 {
48 super(context, attrs, defStyle);
49 }
50
51 @Override
52 protected void onAttachedToActivity()
53 {
54 super.onAttachedToActivity();
55 }
56
57 @Override
58 protected void onAttachedToHierarchy(PreferenceManager preferenceManager)
59 {
60 super.onAttachedToHierarchy(preferenceManager);
61 this.apiKey = this.getKey().substring(this.getKey().lastIndexOf('.') + 1);
62 this.setEnabled(false);
63 this.recheckValue();
64 Log.d(TAG, "ApiKey: " + this.apiKey);
65 }
66
67 @Override
68 protected void onBindView(View view)
69 {
70 super.onBindView(view);
71 }
72
73 private void recheckValue()
74 {
75 AddonBridge.queryBoolean(this, "query_" + this.apiKey);
76 }
77
78 @Override
79 protected void onClick()
80 {
81 super.onClick();
82 AddonBridge.setBoolean(this, "change_" + this.apiKey, this.isChecked());
83 this.recheckValue();
84 }
85
86 @Override
87 public void onApiRequestSucceeded(NativeJSObject jsObject)
88 {
89 Log.d(TAG, "Result: " + jsObject);
90 if (jsObject.has("value"))
91 {
92 final boolean enabled = AddonBridge.getBooleanFromJSObject(jsObject, "valu e", false);
93
94 ThreadUtils.postToUiThread(new Runnable()
95 {
96 @Override
97 public void run()
98 {
99 AbpCheckBoxPreference.this.setChecked(enabled);
100 AbpCheckBoxPreference.this.setEnabled(true);
101 }
102 });
103 }
104 }
105
106 @Override
107 public void onApiRequestFailed(String errorMessage)
108 {
109 // Currently ignored
110 }
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld