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

Delta Between Two Patch Sets: mobile/android/thirdparty/org/adblockplus/browser/AbpCheckBoxPreference.java

Issue 4920541991403520: Create a minimal settings UI (Closed)
Left Patch Set: Added missing slashes Created March 21, 2015, 1:52 a.m.
Right Patch Set: Removed default case Created March 22, 2015, 9:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.browser; 18 package org.adblockplus.browser;
19 19
20 import org.mozilla.gecko.preferences.CustomCheckBoxPreference; 20 import org.mozilla.gecko.preferences.CustomCheckBoxPreference;
21 import org.mozilla.gecko.util.NativeJSObject; 21 import org.mozilla.gecko.util.NativeJSObject;
22 import org.mozilla.gecko.util.ThreadUtils; 22 import org.mozilla.gecko.util.ThreadUtils;
23 23
24 import android.content.Context; 24 import android.content.Context;
25 import android.preference.PreferenceManager;
26 import android.util.AttributeSet; 25 import android.util.AttributeSet;
27 import android.util.Log;
28 import android.view.View;
29 26
30 public class AbpCheckBoxPreference extends CustomCheckBoxPreference implements 27 public class AbpCheckBoxPreference extends CustomCheckBoxPreference implements
31 AdblockPlusApiCallback 28 AdblockPlusApiCallback
32 { 29 {
33 private static final String TAG = "AdblockBrowser.AbpCheckBoxPreference";
34 private String apiKey = ""; 30 private String apiKey = "";
35 31
36 public AbpCheckBoxPreference(Context context) 32 public AbpCheckBoxPreference(Context context)
37 { 33 {
38 super(context); 34 super(context);
39 } 35 }
40 36
41 public AbpCheckBoxPreference(Context context, AttributeSet attrs) 37 public AbpCheckBoxPreference(Context context, AttributeSet attrs)
42 { 38 {
43 super(context, attrs); 39 super(context, attrs);
44 } 40 }
45 41
46 public AbpCheckBoxPreference(Context context, AttributeSet attrs, int defStyle ) 42 public AbpCheckBoxPreference(Context context, AttributeSet attrs, int defStyle )
47 { 43 {
48 super(context, attrs, defStyle); 44 super(context, attrs, defStyle);
49 } 45 }
50 46
51 @Override 47 @Override
52 protected void onAttachedToActivity() 48 protected void onAttachedToActivity()
53 { 49 {
54 super.onAttachedToActivity(); 50 super.onAttachedToActivity();
51 this.apiKey = this.getKey().substring(this.getKey().lastIndexOf(".api") + 4) ;
52 this.setEnabled(false);
53 this.refreshValue();
55 } 54 }
56 55
57 @Override 56 private void refreshValue()
58 protected void onAttachedToHierarchy(PreferenceManager preferenceManager)
59 { 57 {
60 super.onAttachedToHierarchy(preferenceManager); 58 AddOnBridge.queryBoolean(this, this.apiKey);
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 } 59 }
77 60
78 @Override 61 @Override
79 protected void onClick() 62 protected void onClick()
80 { 63 {
81 super.onClick(); 64 super.onClick();
82 AddonBridge.setBoolean(this, "change_" + this.apiKey, this.isChecked()); 65 AddOnBridge.setBoolean(this, this.apiKey, this.isChecked());
83 this.recheckValue(); 66 this.refreshValue();
84 } 67 }
85 68
86 @Override 69 @Override
87 public void onApiRequestSucceeded(NativeJSObject jsObject) 70 public void onApiRequestSucceeded(NativeJSObject jsObject)
88 { 71 {
89 Log.d(TAG, "Result: " + jsObject);
90 if (jsObject.has("value")) 72 if (jsObject.has("value"))
91 { 73 {
92 final boolean enabled = AddonBridge.getBooleanFromJSObject(jsObject, "valu e", false); 74 final boolean enabled = AddOnBridge.getBooleanFromJsObject(jsObject, "valu e", false);
93 75
94 ThreadUtils.postToUiThread(new Runnable() 76 ThreadUtils.postToUiThread(new Runnable()
95 { 77 {
96 @Override 78 @Override
97 public void run() 79 public void run()
98 { 80 {
99 AbpCheckBoxPreference.this.setChecked(enabled); 81 AbpCheckBoxPreference.this.setChecked(enabled);
100 AbpCheckBoxPreference.this.setEnabled(true); 82 AbpCheckBoxPreference.this.setEnabled(true);
101 } 83 }
102 }); 84 });
103 } 85 }
104 } 86 }
105 87
106 @Override 88 @Override
107 public void onApiRequestFailed(String errorMessage) 89 public void onApiRequestFailed(String errorMessage)
108 { 90 {
109 // Currently ignored 91 // Currently ignored
110 } 92 }
111 } 93 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld