Methods Summary |
---|
protected long | getTimeout()Timeout length, based on when the animation should reasonably be complete.
return ANIM_DURATION + ANIM_DELAY + FUTURE_RELEASE_DELAY;
|
public void | setUp()Sets up the fields used by each test. Subclasses must override this method to create
the protected mAnimator object used in all tests. Overrides must create that animator
and then call super.setup(), where further properties are set on that animator.
final BasicAnimatorActivity activity = getActivity();
Button button = (Button) activity.findViewById(R.id.animatingButton);
mAnimator = button.animate().x(100).y(100);
super.setUp();
// mListener is the main testing mechanism of this file. The asserts of each test
// are embedded in the listener callbacks that it implements.
mListener = new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
// This should only be called on an animation that has not yet been started
assertFalse(mStarted);
assertTrue(mRunning);
mStarted = true;
}
@Override
public void onAnimationCancel(Animator animation) {
// This should only be called on an animation that has been started and not
// yet canceled or ended
assertFalse(mCanceled);
assertTrue(mRunning);
assertTrue(mStarted);
mCanceled = true;
}
@Override
public void onAnimationEnd(Animator animation) {
// This should only be called on an animation that has been started and not
// yet ended
assertTrue(mRunning);
assertTrue(mStarted);
mRunning = false;
mStarted = false;
super.onAnimationEnd(animation);
}
};
mAnimator.setListener(mListener);
mAnimator.setDuration(ANIM_DURATION);
mFuture = new FutureWaiter();
mRunning = false;
mCanceled = false;
mStarted = false;
|
public void | testCancel()Verify that calling cancel on an unstarted animator does nothing.
mAnimator.cancel();
|
public void | testPlayingCancel()Verify that canceling an animator that is playing does the right thing.
mFutureListener = new FutureReleaseListener(mFuture);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Handler handler = new Handler();
mAnimator.setListener(mFutureListener);
mRunning = true;
mAnimator.start();
handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
} catch (junit.framework.AssertionFailedError e) {
mFuture.setException(new RuntimeException(e));
}
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
|
public void | testPlayingDelayedCancel()Same as testPlayingCancel, but with a startDelayed animator
mAnimator.setStartDelay(ANIM_DELAY);
mFutureListener = new FutureReleaseListener(mFuture);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Handler handler = new Handler();
mAnimator.setListener(mFutureListener);
mRunning = true;
mAnimator.start();
handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
} catch (junit.framework.AssertionFailedError e) {
mFuture.setException(new RuntimeException(e));
}
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
|
public void | testPlayingDelayedCancelMidDelay()Same as testPlayingDelayedCancel, but cancel during the startDelay period
mAnimator.setStartDelay(ANIM_DELAY);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
// Set the listener to automatically timeout after an uncanceled animation
// would have finished. This tests to make sure that we're not calling
// the listeners with cancel/end callbacks since they won't be called
// with the start event.
mFutureListener = new FutureReleaseListener(mFuture, getTimeout());
Handler handler = new Handler();
mRunning = true;
mAnimator.start();
handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DELAY);
} catch (junit.framework.AssertionFailedError e) {
mFuture.setException(new RuntimeException(e));
}
}
});
mFuture.get(getTimeout() + 100, TimeUnit.MILLISECONDS);
|
public void | testStartCancel()Verify that calling cancel on a started animator does the right thing.
mFutureListener = new FutureReleaseListener(mFuture);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
mRunning = true;
mAnimator.start();
mAnimator.cancel();
mFuture.release();
} catch (junit.framework.AssertionFailedError e) {
mFuture.setException(new RuntimeException(e));
}
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
|
public void | testStartDelayedCancel()Same as testStartCancel, but with a startDelayed animator
mFutureListener = new FutureReleaseListener(mFuture);
mAnimator.setStartDelay(ANIM_DELAY);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
mRunning = true;
mAnimator.start();
mAnimator.cancel();
mFuture.release();
} catch (junit.framework.AssertionFailedError e) {
mFuture.setException(new RuntimeException(e));
}
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
|
public void | testStartDelayedDoubleCancel()Same as testStartDoubleCancel, but with a startDelayed animator
mAnimator.setStartDelay(ANIM_DELAY);
mFutureListener = new FutureReleaseListener(mFuture);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
mRunning = true;
mAnimator.start();
mAnimator.cancel();
mAnimator.cancel();
mFuture.release();
} catch (junit.framework.AssertionFailedError e) {
mFuture.setException(new RuntimeException(e));
}
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
|
public void | testStartDoubleCancel()Verifies that canceling a started animation after it has already been canceled
does nothing.
mFutureListener = new FutureReleaseListener(mFuture);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
mRunning = true;
mAnimator.start();
mAnimator.cancel();
mAnimator.cancel();
mFuture.release();
} catch (junit.framework.AssertionFailedError e) {
mFuture.setException(new RuntimeException(e));
}
}
});
mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
|