summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android/widget/ToggleSwitch.java
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-08 03:38:44 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-08 04:31:04 -0600
commitb6ed17884fc550361e793fab45cd08fce49e6ce5 (patch)
tree6970d9b1e2403b39277ea1fb28b4aabe293ba0ca /app/src/main/java/com/wireguard/android/widget/ToggleSwitch.java
parent668d90f0633401a4b0e11e94b697162420d5726c (diff)
ToggleSwitch: Improve reliability
It's not great, but it's better than it was. Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/widget/ToggleSwitch.java')
-rw-r--r--app/src/main/java/com/wireguard/android/widget/ToggleSwitch.java25
1 files changed, 5 insertions, 20 deletions
diff --git a/app/src/main/java/com/wireguard/android/widget/ToggleSwitch.java b/app/src/main/java/com/wireguard/android/widget/ToggleSwitch.java
index 1b3dee71..a8e4e263 100644
--- a/app/src/main/java/com/wireguard/android/widget/ToggleSwitch.java
+++ b/app/src/main/java/com/wireguard/android/widget/ToggleSwitch.java
@@ -22,25 +22,15 @@ import android.util.AttributeSet;
import android.widget.Switch;
public class ToggleSwitch extends Switch {
- private boolean hasPendingStateChange;
private boolean isRestoringState;
private OnBeforeCheckedChangeListener listener;
- public ToggleSwitch(final Context context) {
- super(context);
- }
-
public ToggleSwitch(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
- public ToggleSwitch(final Context context, final AttributeSet attrs, final int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- }
-
- public ToggleSwitch(final Context context, final AttributeSet attrs, final int defStyleAttr,
- final int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
+ public ToggleSwitch(final Context context) {
+ this(context, null);
}
@Override
@@ -48,28 +38,23 @@ public class ToggleSwitch extends Switch {
isRestoringState = true;
super.onRestoreInstanceState(state);
isRestoringState = false;
-
}
@Override
public void setChecked(final boolean checked) {
+ if (checked == isChecked())
+ return;
if (isRestoringState || listener == null) {
super.setChecked(checked);
return;
}
- if (hasPendingStateChange)
- return;
- hasPendingStateChange = true;
setEnabled(false);
listener.onBeforeCheckedChanged(this, checked);
}
public void setCheckedInternal(final boolean checked) {
- if (hasPendingStateChange) {
- setEnabled(true);
- hasPendingStateChange = false;
- }
super.setChecked(checked);
+ setEnabled(true);
}
public void setOnBeforeCheckedChangeListener(final OnBeforeCheckedChangeListener listener) {