Skip to content

Commit

Permalink
fix: prevent clicks while an animation is in progress
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
Manabu-GT committed Dec 13, 2014
1 parent da1229b commit e360389
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) { }
Expand All @@ -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();
Expand Down

0 comments on commit e360389

Please sign in to comment.