| LEFT | RIGHT |
| 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 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 { | 43 { |
| 44 super(context, attrs, defStyle); | 44 super(context, attrs, defStyle); |
| 45 } | 45 } |
| 46 | 46 |
| 47 @Override | 47 @Override |
| 48 protected void onAttachedToActivity() | 48 protected void onAttachedToActivity() |
| 49 { | 49 { |
| 50 super.onAttachedToActivity(); | 50 super.onAttachedToActivity(); |
| 51 this.apiKey = this.getKey().substring(this.getKey().lastIndexOf(".api") + 4)
; | 51 this.apiKey = this.getKey().substring(this.getKey().lastIndexOf(".api") + 4)
; |
| 52 this.setEnabled(false); | 52 this.setEnabled(false); |
| 53 this.recheckValue(); | 53 this.refreshValue(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 private void recheckValue() | 56 private void refreshValue() |
| 57 { | 57 { |
| 58 AddOnBridge.queryBoolean(this, "get" + this.apiKey); | 58 AddOnBridge.queryBoolean(this, this.apiKey); |
| 59 } | 59 } |
| 60 | 60 |
| 61 @Override | 61 @Override |
| 62 protected void onClick() | 62 protected void onClick() |
| 63 { | 63 { |
| 64 super.onClick(); | 64 super.onClick(); |
| 65 AddOnBridge.setBoolean(this, "set" + this.apiKey, this.isChecked()); | 65 AddOnBridge.setBoolean(this, this.apiKey, this.isChecked()); |
| 66 this.recheckValue(); | 66 this.refreshValue(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 @Override | 69 @Override |
| 70 public void onApiRequestSucceeded(NativeJSObject jsObject) | 70 public void onApiRequestSucceeded(NativeJSObject jsObject) |
| 71 { | 71 { |
| 72 if (jsObject.has("value")) | 72 if (jsObject.has("value")) |
| 73 { | 73 { |
| 74 final boolean enabled = AddOnBridge.getBooleanFromJSObject(jsObject, "valu
e", false); | 74 final boolean enabled = AddOnBridge.getBooleanFromJsObject(jsObject, "valu
e", false); |
| 75 | 75 |
| 76 ThreadUtils.postToUiThread(new Runnable() | 76 ThreadUtils.postToUiThread(new Runnable() |
| 77 { | 77 { |
| 78 @Override | 78 @Override |
| 79 public void run() | 79 public void run() |
| 80 { | 80 { |
| 81 AbpCheckBoxPreference.this.setChecked(enabled); | 81 AbpCheckBoxPreference.this.setChecked(enabled); |
| 82 AbpCheckBoxPreference.this.setEnabled(true); | 82 AbpCheckBoxPreference.this.setEnabled(true); |
| 83 } | 83 } |
| 84 }); | 84 }); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 @Override | 88 @Override |
| 89 public void onApiRequestFailed(String errorMessage) | 89 public void onApiRequestFailed(String errorMessage) |
| 90 { | 90 { |
| 91 // Currently ignored | 91 // Currently ignored |
| 92 } | 92 } |
| 93 } | 93 } |
| LEFT | RIGHT |