File tree Expand file tree Collapse file tree 2 files changed +17
-16
lines changed
sparkbutton/src/main/java/at/connyduck/sparkbutton Expand file tree Collapse file tree 2 files changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -254,25 +254,26 @@ public void setEventListener(SparkEventListener listener) {
254254
255255 @ Override
256256 public void onClick (View v ) {
257- if (imageResourceIdInactive != INVALID_RESOURCE_ID ) {
258- isChecked = !isChecked ;
257+ boolean shouldPlayAnimation = listener == null || listener .onEvent (this , isChecked );
259258
260- imageView .setImageResource (isChecked ? imageResourceIdActive : imageResourceIdInactive );
259+ if (shouldPlayAnimation ) {
260+ if (imageResourceIdInactive != INVALID_RESOURCE_ID ) {
261+ isChecked = !isChecked ;
261262
262- if (animatorSet != null ) {
263- animatorSet .cancel ();
264- }
265- if (isChecked ) {
266- sparkAnimationView .setVisibility (VISIBLE );
267- playAnimation ();
263+ imageView .setImageResource (isChecked ? imageResourceIdActive : imageResourceIdInactive );
264+
265+ if (animatorSet != null ) {
266+ animatorSet .cancel ();
267+ }
268+ if (isChecked ) {
269+ sparkAnimationView .setVisibility (VISIBLE );
270+ playAnimation ();
271+ } else {
272+ sparkAnimationView .setVisibility (INVISIBLE );
273+ }
268274 } else {
269- sparkAnimationView . setVisibility ( INVISIBLE );
275+ playAnimation ( );
270276 }
271- } else {
272- playAnimation ();
273- }
274- if (listener != null ) {
275- listener .onEvent (this , isChecked );
276277 }
277278 }
278279
Original file line number Diff line number Diff line change 1717import androidx .annotation .NonNull ;
1818
1919public interface SparkEventListener {
20- void onEvent (@ NonNull SparkButton button , boolean buttonState );
20+ boolean onEvent (@ NonNull SparkButton button , boolean buttonState );
2121}
You can’t perform that action at this time.
0 commit comments