Methods Summary |
---|
boolean | animateAdd(RecyclerView.ViewHolder vh)
final boolean[] result = new boolean[1];
runTestOnUiThread(new Runnable() {
@Override
public void run() {
result[0] = mAnimator.animateAdd(vh);
}
});
return result[0];
|
boolean | animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY)
final boolean[] result = new boolean[1];
runTestOnUiThread(new Runnable() {
@Override
public void run() {
result[0] = mAnimator.animateChange(oldHolder, newHolder, fromX, fromY, toX, toY);
}
});
return result[0];
|
boolean | animateMove(RecyclerView.ViewHolder vh, int fromX, int fromY, int toX, int toY)
final boolean[] result = new boolean[1];
runTestOnUiThread(new Runnable() {
@Override
public void run() {
result[0] = mAnimator.animateMove(vh, fromX, fromY, toX, toY);
}
});
return result[0];
|
boolean | animateRemove(RecyclerView.ViewHolder vh)
final boolean[] result = new boolean[1];
runTestOnUiThread(new Runnable() {
@Override
public void run() {
result[0] = mAnimator.animateRemove(vh);
}
});
return result[0];
|
public void | cancelAfter(int count, RecyclerView.ViewHolder toCancel)
cancelTest(false, count, toCancel);
|
public void | cancelBefore(int count, RecyclerView.ViewHolder toCancel)
cancelTest(true, count, toCancel);
|
public void | cancelChangeBothTest(boolean before)
ViewHolder vh = createViewHolder(1);
ViewHolder vh2 = createViewHolder(1);
expectItems(vh, vh2);
assertTrue(animateChange(vh, vh2, 20, 20, 100, 100));
cancelTest(before, 2, vh, vh2);
|
public void | cancelChangeNewTest(boolean before)
ViewHolder vh = createViewHolder(1);
ViewHolder vh2 = createViewHolder(1);
expectItems(vh, vh2);
assertTrue(animateChange(vh, vh2, 20, 20, 100, 100));
cancelTest(before, 2, vh2);
|
public void | cancelChangeOldTest(boolean before)
ViewHolder vh = createViewHolder(1);
ViewHolder vh2 = createViewHolder(1);
expectItems(vh, vh2);
assertTrue(animateChange(vh, vh2, 20, 20, 100, 100));
cancelTest(before, 2, vh);
|
public void | cancelTest(boolean before, int count, RecyclerView.ViewHolder toCancel)
if (before) {
endAnimations(toCancel);
runAndWait(count, 1);
} else {
runAndWait(count, 1, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
endAnimations(toCancel);
}
});
}
|
void | checkForMainThreadException()
if (mainThreadException != null) {
throw mainThreadException;
}
|
private android.support.v7.widget.DefaultItemAnimatorTest$ViewHolder | createViewHolder(int pos)
final ViewHolder vh = mAdapter.createViewHolder(mDummyParent, 1);
runTestOnUiThread(new Runnable() {
@Override
public void run() {
mAdapter.bindViewHolder(vh, pos);
mDummyParent.addView(vh.itemView);
}
});
return vh;
|
void | endAnimations(RecyclerView.ViewHolder vhs)
runTestOnUiThread(new Runnable() {
@Override
public void run() {
for (RecyclerView.ViewHolder vh : vhs) {
mAnimator.endAnimation(vh);
}
}
});
|
void | expectItems(RecyclerView.ViewHolder viewHolders)
mExpectedItems.addAll(Arrays.asList(viewHolders));
|
void | postExceptionToInstrumentation(java.lang.Throwable t)
if (mainThreadException == null) {
mainThreadException = t;
} else {
Log.e(TAG, "skipping secondary main thread exception", t);
}
|
void | runAndWait(int itemCount, int seconds)
runAndWait(itemCount, seconds, null);
|
void | runAndWait(int itemCount, int seconds, android.support.v7.widget.DefaultItemAnimatorTest$ThrowingRunnable postRun)
runTestOnUiThread(new Runnable() {
@Override
public void run() {
mAnimator.runPendingAnimations();
if (postRun != null) {
try {
postRun.run();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
}
});
waitForItems(itemCount, seconds);
checkForMainThreadException();
|
public void | runTestOnUiThread(java.lang.Runnable r)
if (Looper.myLooper() == Looper.getMainLooper()) {
r.run();
} else {
super.runTestOnUiThread(r);
}
|
protected void | setUp()
super.setUp();
mAnimator = new DefaultItemAnimator();
mAdapter = new Adapter(20);
mDummyParent = getActivity().mContainer;
mAnimator.setListener(new RecyclerView.ItemAnimator.ItemAnimatorListener() {
@Override
public void onRemoveFinished(RecyclerView.ViewHolder item) {
try {
assertTrue(mRemoveFinished.add(item));
onFinished(item);
} catch (Throwable t) {
postExceptionToInstrumentation(t);
}
}
@Override
public void onAddFinished(RecyclerView.ViewHolder item) {
try {
assertTrue(mAddFinished.add(item));
onFinished(item);
} catch (Throwable t) {
postExceptionToInstrumentation(t);
}
}
@Override
public void onMoveFinished(RecyclerView.ViewHolder item) {
try {
assertTrue(mMoveFinished.add(item));
onFinished(item);
} catch (Throwable t) {
postExceptionToInstrumentation(t);
}
}
@Override
public void onChangeFinished(RecyclerView.ViewHolder item) {
try {
assertTrue(mChangeFinished.add(item));
onFinished(item);
} catch (Throwable t) {
postExceptionToInstrumentation(t);
}
}
private void onFinished(RecyclerView.ViewHolder item) {
assertNotNull(mExpectedItems.remove(item));
mExpectedItemCount.release(1);
}
});
|
protected void | tearDown()
getInstrumentation().waitForIdleSync();
super.tearDown();
try {
checkForMainThreadException();
} catch (Exception e) {
throw e;
} catch (Throwable throwable) {
throw new Exception(throwable);
}
|
public void | testAnimateAdd()
ViewHolder vh = createViewHolder(1);
expectItems(vh);
assertTrue(animateAdd(vh));
assertTrue(mAnimator.isRunning());
runAndWait(1, 1);
|
public void | testAnimateChange()
ViewHolder vh = createViewHolder(1);
ViewHolder vh2 = createViewHolder(2);
expectItems(vh, vh2);
assertTrue(animateChange(vh, vh2, 0, 0, 100, 100));
assertTrue(mAnimator.isRunning());
runAndWait(2, 1);
|
public void | testAnimateMove()
ViewHolder vh = createViewHolder(1);
expectItems(vh);
assertTrue(animateMove(vh, 0, 0, 100, 100));
assertTrue(mAnimator.isRunning());
runAndWait(1, 1);
|
public void | testAnimateRemove()
ViewHolder vh = createViewHolder(1);
expectItems(vh);
assertTrue(animateRemove(vh));
assertTrue(mAnimator.isRunning());
runAndWait(1, 1);
|
public void | testCancelAddAfter()
final ViewHolder vh = createViewHolder(1);
expectItems(vh);
assertTrue(animateAdd(vh));
cancelAfter(1, vh);
|
public void | testCancelAddBefore()
final ViewHolder vh = createViewHolder(1);
expectItems(vh);
assertTrue(animateAdd(vh));
cancelBefore(1, vh);
|
public void | testCancelChangeBothAfter()
cancelChangeBothTest(false);
|
public void | testCancelChangeBothBefore()
cancelChangeBothTest(true);
|
public void | testCancelChangeNewAfter()
cancelChangeNewTest(false);
|
public void | testCancelChangeNewBefore()
cancelChangeNewTest(true);
|
public void | testCancelChangeOldAfter()
cancelChangeOldTest(false);
|
public void | testCancelChangeOldBefore()
cancelChangeOldTest(true);
|
public void | testCancelMoveAfter()
ViewHolder vh = createViewHolder(1);
expectItems(vh);
assertTrue(animateMove(vh, 10, 10, 100, 100));
cancelAfter(1, vh);
|
public void | testCancelMoveBefore()
ViewHolder vh = createViewHolder(1);
expectItems(vh);
assertTrue(animateMove(vh, 10, 10, 100, 100));
cancelBefore(1, vh);
|
public void | testCancelRemove()
ViewHolder vh = createViewHolder(1);
expectItems(vh);
assertTrue(animateRemove(vh));
endAnimations(vh);
runAndWait(1, 1);
|
void | waitForItems(int itemCount, int seconds)
assertTrue("all vh animations should end",
mExpectedItemCount.tryAcquire(itemCount, seconds, TimeUnit.SECONDS));
assertEquals("all expected finish events should happen", 0, mExpectedItems.size());
// wait one more second for unwanted
assertFalse("should not receive any more permits",
mExpectedItemCount.tryAcquire(1, 2, TimeUnit.SECONDS));
|