Last active
April 17, 2019 16:18
-
-
Save dGorod/ac8d413c8804f2ebb1a0 to your computer and use it in GitHub Desktop.
IdlingResource implementation for Android Espresso test framework. Waits for animation end, if view has one. Useful to test views that have animations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.exsoft.musarium.entity; | |
import android.support.test.espresso.IdlingResource; | |
import android.view.View; | |
import android.view.animation.Animation; | |
/** | |
* Created by Dmitriy Gorodnytskiy on 13-Jan-16. | |
*/ | |
public class AnimationIdlingResource implements IdlingResource { | |
private ResourceCallback callback; | |
public AnimationIdlingResource(View view) { | |
if(view.getAnimation() == null) { | |
callback.onTransitionToIdle(); | |
return; | |
} | |
view.getAnimation().setAnimationListener(new Animation.AnimationListener() { | |
@Override | |
public void onAnimationStart(Animation animation) { } | |
@Override | |
public void onAnimationEnd(Animation animation) { | |
callback.onTransitionToIdle(); | |
} | |
@Override | |
public void onAnimationRepeat(Animation animation) { } | |
}); | |
} | |
@Override | |
public String getName() { | |
return AnimationIdlingResource.class.getName(); | |
} | |
@Override | |
public boolean isIdleNow() { | |
return true; | |
} | |
@Override | |
public void registerIdleTransitionCallback(ResourceCallback callback) { | |
this.callback = callback; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment