Skip to content

Commit

Permalink
#38 Disable click during animation (#39)
Browse files Browse the repository at this point in the history
Will need some improvements in the code though.
  • Loading branch information
ayltai authored and JoaquimLey committed Sep 4, 2017
1 parent a059959 commit 16cafd2
Showing 1 changed file with 66 additions and 16 deletions.
82 changes: 66 additions & 16 deletions faboptions/src/main/java/com/joaquimley/faboptions/FabOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import android.support.v7.widget.AppCompatImageView;
import android.transition.ChangeBounds;
import android.transition.ChangeTransform;
import android.transition.Transition;
import android.transition.TransitionManager;
import android.transition.TransitionSet;
import android.util.AttributeSet;
Expand All @@ -60,6 +61,7 @@ public class FabOptions extends FrameLayout implements View.OnClickListener {
private static final int NO_DIMENSION = 0;
private static final long CLOSE_MORPH_TRANSFORM_DURATION = 70;

private boolean mIsAnimating;
private boolean mIsOpen;
private View.OnClickListener mListener;

Expand Down Expand Up @@ -221,16 +223,20 @@ private boolean styleButton(int buttonIndex, @ColorRes int color) {

@Override
public void onClick(View v) {
if (v.getId() == R.id.faboptions_fab) {
if (mIsOpen) {
close();
if (!mIsAnimating) {
mIsAnimating = true;

if (v.getId() == R.id.faboptions_fab) {
if (mIsOpen) {
close();
} else {
open();
}
} else {
open();
}
} else {
if (mListener != null && mIsOpen) {
mListener.onClick(v);
close();
if (mListener != null && mIsOpen) {
mListener.onClick(v);
close();
}
}
}
}
Expand All @@ -251,13 +257,35 @@ private void open() {
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
TransitionManager.beginDelayedTransition(this, new OpenMorphTransition(mButtonContainer));
final TransitionSet transitionSet = new OpenMorphTransition(mButtonContainer);
transitionSet.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(final Transition transition) {
}

@Override
public void onTransitionEnd(final Transition transition) {
mIsAnimating = false;
}

@Override
public void onTransitionCancel(final Transition transition) {
}

@Override
public void onTransitionPause(final Transition transition) {
}

@Override
public void onTransitionResume(final Transition transition) {
}
});

TransitionManager.beginDelayedTransition(this, transitionSet);
}
animateBackground(true);
animateButtons(true);
// } else {
// openCompatAnimation();
// }

mIsOpen = true;
}

Expand All @@ -270,9 +298,31 @@ private void close() {
mFab.setImageResource(R.drawable.faboptions_ic_overflow);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
TransitionManager.beginDelayedTransition(this, new CloseMorphTransition(mButtonContainer));
// } else {
// closeCompatAnimation();
final TransitionSet transitionSet = new CloseMorphTransition(mButtonContainer);
transitionSet.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(final Transition transition) {
}

@Override
public void onTransitionEnd(final Transition transition) {
mIsAnimating = false;
}

@Override
public void onTransitionCancel(final Transition transition) {
}

@Override
public void onTransitionPause(final Transition transition) {
}

@Override
public void onTransitionResume(final Transition transition) {
}
});

TransitionManager.beginDelayedTransition(this, transitionSet);
}
animateButtons(false);
animateBackground(false);
Expand Down

0 comments on commit 16cafd2

Please sign in to comment.