Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
stop an animation on fast subsequent step changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhart committed Dec 19, 2017
1 parent 320b26c commit 6a0eee7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Usage
-----

1. Add jcenter() to repositories block in your gradle file.
2. Add `compile 'com.shuhart.stepview:stepview:1.1.0'` to your dependencies.
2. Add `compile 'com.shuhart.stepview:stepview:1.1.1'` to your dependencies.
2. Add `StepView` into your layouts or view hierarchy.
3. Look into the sample for additional details on how to use and configure the library.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
private int currentStep = 0;

@SuppressLint("SetTextI18n")
@Override
Expand All @@ -27,13 +28,15 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.next).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stepView.go(stepView.getCurrentStep() + 1, true);
currentStep++;
stepView.go(currentStep, true);
}
});
findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stepView.go(stepView.getCurrentStep() - 1, true);
currentStep--;
stepView.go(currentStep, true);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion stepview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ext {
siteUrl = 'https://github.com/shuhart/StepView'
gitUrl = 'https://github.com/shuhart/StepView.git'

libraryVersion = '1.1.0'
libraryVersion = '1.1.1'

developerId = 'shuhart'
developerName = 'Redrick Shuhart'
Expand Down
8 changes: 7 additions & 1 deletion stepview/src/main/java/com/shuhart/stepview/StepView.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.shuhart.stepview.animation.AnimatorListener;
Expand Down Expand Up @@ -142,6 +143,7 @@ public void go(int step, boolean animate) {
if (step >= START_STEP && step < steps.size()) {
if (animate && animationType != ANIMATION_NONE) {
if (Math.abs(step - currentStep) > 1) {
endAnimation();
currentStep = step;
invalidate();
} else {
Expand All @@ -157,10 +159,14 @@ public void go(int step, boolean animate) {
}
}

private void animate(final int step) {
private void endAnimation() {
if (animator != null && animator.isRunning()) {
animator.end();
}
}

private void animate(final int step) {
endAnimation();
animator = getAnimator(step);
if (animator == null) {
return;
Expand Down

0 comments on commit 6a0eee7

Please sign in to comment.