AutoCancelTestpublic class AutoCancelTest extends android.test.ActivityInstrumentationTestCase2
Fields Summary |
---|
boolean | mAnimX1Canceled | boolean | mAnimXY1Canceled | boolean | mAnimX2Canceled | boolean | mAnimXY2Canceled | private static final long | START_DELAY | private static final long | DELAYED_START_DURATION | private static final long | FUTURE_TIMEOUT | HashMap | mCanceledMap | private AnimatorListenerAdapter | mCanceledListener |
Constructors Summary |
---|
public AutoCancelTest()
super(BasicAnimatorActivity.class);
|
Methods Summary |
---|
public void | setX(float x)
| public void | setY(float y)
| public void | setZ(float z)
| ObjectAnimator | setupAnimator(long startDelay, java.lang.String properties)
ObjectAnimator returnVal;
if (properties.length == 1) {
returnVal = ObjectAnimator.ofFloat(this, properties[0], 0, 1);
} else {
PropertyValuesHolder[] pvhArray = new PropertyValuesHolder[properties.length];
for (int i = 0; i < properties.length; i++) {
pvhArray[i] = PropertyValuesHolder.ofFloat(properties[i], 0, 1);
}
returnVal = ObjectAnimator.ofPropertyValuesHolder(this, pvhArray);
}
returnVal.setAutoCancel(true);
returnVal.setStartDelay(startDelay);
returnVal.addListener(mCanceledListener);
return returnVal;
| private void | setupAnimators(long startDelay, boolean startLater, FutureWaiter future)
// Animators to be auto-canceled
final ObjectAnimator animX1 = setupAnimator(startDelay, "x");
final ObjectAnimator animY1 = setupAnimator(startDelay, "y");
final ObjectAnimator animXY1 = setupAnimator(startDelay, "x", "y");
final ObjectAnimator animXZ1 = setupAnimator(startDelay, "x", "z");
animX1.start();
animY1.start();
animXY1.start();
animXZ1.start();
final ObjectAnimator animX2 = setupAnimator(0, "x");
animX2.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
// We expect only animX1 to be canceled at this point
if (mCanceledMap.get(animX1) == null ||
mCanceledMap.get(animX1) != true ||
mCanceledMap.get(animY1) != null ||
mCanceledMap.get(animXY1) != null ||
mCanceledMap.get(animXZ1) != null) {
future.set(false);
}
}
});
final ObjectAnimator animXY2 = setupAnimator(0, "x", "y");
animXY2.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
// We expect only animXY1 to be canceled at this point
if (mCanceledMap.get(animXY1) == null ||
mCanceledMap.get(animXY1) != true ||
mCanceledMap.get(animY1) != null ||
mCanceledMap.get(animXZ1) != null) {
future.set(false);
}
}
@Override
public void onAnimationEnd(Animator animation) {
// Release future if not done already via failures during start
future.release();
}
});
if (startLater) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
animX2.start();
animXY2.start();
}
}, DELAYED_START_DURATION);
} else {
animX2.start();
animXY2.start();
}
| public void | testAutoCancel()
final FutureWaiter future = new FutureWaiter();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
setupAnimators(0, false, future);
} catch (Exception e) {
future.setException(e);
}
}
});
assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS));
| public void | testAutoCancelDelayed()
final FutureWaiter future = new FutureWaiter();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
setupAnimators(START_DELAY, false, future);
} catch (Exception e) {
future.setException(e);
}
}
});
assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS));
| public void | testAutoCancelDelayedTestLater()
final FutureWaiter future = new FutureWaiter();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
setupAnimators(START_DELAY, true, future);
} catch (Exception e) {
future.setException(e);
}
}
});
assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS));
| public void | testAutoCancelTestLater()
final FutureWaiter future = new FutureWaiter();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
setupAnimators(0, true, future);
} catch (Exception e) {
future.setException(e);
}
}
});
assertTrue(future.get(FUTURE_TIMEOUT, TimeUnit.MILLISECONDS));
|
|