Skip to content

Commit d19b719

Browse files
SerchinasticoSerchinastico
authored andcommitted
Issue #2 React to checked changes instead of click ones
1 parent 9f6cabf commit d19b719

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

coolswitch/src/main/java/com/serchinastico/coolswitch/CoolSwitch.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.view.View;
2929
import android.view.animation.DecelerateInterpolator;
3030
import android.view.animation.Interpolator;
31+
import android.widget.CompoundButton;
3132
import android.widget.ToggleButton;
3233

3334
import com.nineoldandroids.animation.ObjectAnimator;
@@ -38,7 +39,7 @@
3839
*
3940
* @author Sergio Gutiérrez Mota.
4041
*/
41-
public class CoolSwitch extends ToggleButton implements View.OnClickListener {
42+
public class CoolSwitch extends ToggleButton implements CompoundButton.OnCheckedChangeListener {
4243

4344
private static final long BACKGROUND_OPAQUE_TO_TRANSPARENT_ANIMATION_DURATION_MS = 200;
4445
private static final long BACKGROUND_TRANSPARENT_TO_OPAQUE_ANIMATION_DURATION_MS = 200;
@@ -94,9 +95,8 @@ private void initialize(Context context, AttributeSet attrs) {
9495

9596
private void initialize() {
9697
backgroundAlpha = isChecked() ? MAX_BACKGROUND_ALPHA : MIN_BACKGROUND_ALPHA;
97-
9898
setBackgroundColor(Color.argb(0, 0, 0, 0));
99-
setOnClickListener(this);
99+
setOnCheckedChangeListener(this);
100100
}
101101

102102
public boolean addAnimationListener(AnimationListener listener) {
@@ -141,7 +141,7 @@ protected void onDraw(@NonNull Canvas canvas) {
141141
}
142142

143143
@Override
144-
public void onClick(View v) {
144+
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
145145
setEnabled(false);
146146

147147
if (hasValidTargetViewIds() && !hasLoadedTargetViews()) {

sample/src/main/java/com/serchinastico/sample/SampleActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18-
import android.support.v7.app.ActionBarActivity;
1918
import android.os.Bundle;
20-
import android.util.Log;
19+
import android.support.v7.app.ActionBarActivity;
2120

2221
import com.serchinastico.coolswitch.CoolSwitch;
2322

0 commit comments

Comments
 (0)