|
28 | 28 | import android.view.View; |
29 | 29 | import android.view.animation.DecelerateInterpolator; |
30 | 30 | import android.view.animation.Interpolator; |
| 31 | +import android.widget.CompoundButton; |
31 | 32 | import android.widget.ToggleButton; |
32 | 33 |
|
33 | 34 | import com.nineoldandroids.animation.ObjectAnimator; |
|
38 | 39 | * |
39 | 40 | * @author Sergio Gutiérrez Mota. |
40 | 41 | */ |
41 | | -public class CoolSwitch extends ToggleButton implements View.OnClickListener { |
| 42 | +public class CoolSwitch extends ToggleButton implements CompoundButton.OnCheckedChangeListener { |
42 | 43 |
|
43 | 44 | private static final long BACKGROUND_OPAQUE_TO_TRANSPARENT_ANIMATION_DURATION_MS = 200; |
44 | 45 | private static final long BACKGROUND_TRANSPARENT_TO_OPAQUE_ANIMATION_DURATION_MS = 200; |
@@ -94,9 +95,8 @@ private void initialize(Context context, AttributeSet attrs) { |
94 | 95 |
|
95 | 96 | private void initialize() { |
96 | 97 | backgroundAlpha = isChecked() ? MAX_BACKGROUND_ALPHA : MIN_BACKGROUND_ALPHA; |
97 | | - |
98 | 98 | setBackgroundColor(Color.argb(0, 0, 0, 0)); |
99 | | - setOnClickListener(this); |
| 99 | + setOnCheckedChangeListener(this); |
100 | 100 | } |
101 | 101 |
|
102 | 102 | public boolean addAnimationListener(AnimationListener listener) { |
@@ -141,7 +141,7 @@ protected void onDraw(@NonNull Canvas canvas) { |
141 | 141 | } |
142 | 142 |
|
143 | 143 | @Override |
144 | | - public void onClick(View v) { |
| 144 | + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
145 | 145 | setEnabled(false); |
146 | 146 |
|
147 | 147 | if (hasValidTargetViewIds() && !hasLoadedTargetViews()) { |
|
0 commit comments