Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions sparkbutton/src/main/java/at/connyduck/sparkbutton/SparkButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,25 +254,26 @@ public void setEventListener(SparkEventListener listener) {

@Override
public void onClick(View v) {
if (imageResourceIdInactive != INVALID_RESOURCE_ID) {
isChecked = !isChecked;
boolean shouldPlayAnimation = listener == null || listener.onEvent(this, isChecked);

imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive);
if(shouldPlayAnimation) {
if (imageResourceIdInactive != INVALID_RESOURCE_ID) {
isChecked = !isChecked;

if (animatorSet != null) {
animatorSet.cancel();
}
if (isChecked) {
sparkAnimationView.setVisibility(VISIBLE);
playAnimation();
imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive);

if (animatorSet != null) {
animatorSet.cancel();
}
if (isChecked) {
sparkAnimationView.setVisibility(VISIBLE);
playAnimation();
} else {
sparkAnimationView.setVisibility(INVISIBLE);
}
} else {
sparkAnimationView.setVisibility(INVISIBLE);
playAnimation();
}
} else {
playAnimation();
}
if (listener != null) {
listener.onEvent(this, isChecked);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
import androidx.annotation.NonNull;

public interface SparkEventListener {
void onEvent(@NonNull SparkButton button, boolean buttonState);
boolean onEvent(@NonNull SparkButton button, boolean buttonState);
}