From e360389bd9c2322976447f6c3bff218342ef1af4 Mon Sep 17 00:00:00 2001 From: Manabu-GT Date: Sun, 14 Dec 2014 00:11:12 +0900 Subject: [PATCH] fix: prevent clicks while an animation is in progress Closes #7 --- .../expandabletextview/ExpandableTextView.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/src/main/java/com/ms/square/android/expandabletextview/ExpandableTextView.java b/lib/src/main/java/com/ms/square/android/expandabletextview/ExpandableTextView.java index ad1227e..3395357 100644 --- a/lib/src/main/java/com/ms/square/android/expandabletextview/ExpandableTextView.java +++ b/lib/src/main/java/com/ms/square/android/expandabletextview/ExpandableTextView.java @@ -25,6 +25,7 @@ import android.text.TextUtils; import android.util.AttributeSet; import android.util.SparseBooleanArray; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.animation.AlphaAnimation; @@ -72,6 +73,8 @@ public class ExpandableTextView extends LinearLayout implements View.OnClickList private float mAnimAlphaStart; + private boolean mAnimating; + /* For saving collapsed status when used in ListView */ private SparseBooleanArray mCollapsedStatus; private int mPosition; @@ -104,6 +107,9 @@ public void onClick(View view) { mCollapsedStatus.put(mPosition, mCollapsed); } + // mark that the animation is in progress + mAnimating = true; + Animation animation; if (mCollapsed) { animation = new ExpandCollapseAnimation(this, getHeight(), mCollapsedHeight); @@ -122,6 +128,8 @@ public void onAnimationStart(Animation animation) { public void onAnimationEnd(Animation animation) { // clear animation here to avoid repeated applyTransformation() calls clearAnimation(); + // clear the animation flag + mAnimating = false; } @Override public void onAnimationRepeat(Animation animation) { } @@ -131,6 +139,13 @@ public void onAnimationRepeat(Animation animation) { } startAnimation(animation); } + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + // while an animation is in progress, intercept all the touch events to children to + // prevent extra clicks during the animation + return mAnimating; + } + @Override protected void onFinishInflate() { findViews();