Methods Summary |
---|
void | checkForMainThreadException()
if (mainThreadException != null) {
throw mainThreadException;
}
|
public android.graphics.Rect | getDecoratedRecyclerViewBounds()
return new Rect(
mRecyclerView.getPaddingLeft(),
mRecyclerView.getPaddingTop(),
mRecyclerView.getPaddingLeft() + mRecyclerView.getWidth(),
mRecyclerView.getPaddingTop() + mRecyclerView.getHeight()
);
|
protected android.widget.FrameLayout | getRecyclerViewContainer()
return getActivity().mContainer;
|
public boolean | isMainThread()
return Looper.myLooper() == Looper.getMainLooper();
|
void | postExceptionToInstrumentation(java.lang.Throwable t)
if (mainThreadException != null) {
Log.e(TAG, "receiving another main thread exception. dropping.", t);
} else {
Log.e(TAG, "captured exception on main thread", t);
mainThreadException = t;
}
if (mRecyclerView != null && mRecyclerView
.getLayoutManager() instanceof TestLayoutManager) {
TestLayoutManager lm = (TestLayoutManager) mRecyclerView.getLayoutManager();
// finish all layouts so that we get the correct exception
while (lm.layoutLatch.getCount() > 0) {
lm.layoutLatch.countDown();
}
}
|
public void | removeRecyclerView()
if (mRecyclerView == null) {
return;
}
if (!isMainThread()) {
getInstrumentation().waitForIdleSync();
}
runTestOnUiThread(new Runnable() {
@Override
public void run() {
try {
final RecyclerView.Adapter adapter = mRecyclerView.getAdapter();
if (adapter instanceof AttachDetachCountingAdapter) {
((AttachDetachCountingAdapter) adapter).getCounter()
.validateRemaining(mRecyclerView);
}
getActivity().mContainer.removeAllViews();
} catch (Throwable t) {
postExceptionToInstrumentation(t);
}
}
});
mRecyclerView = null;
|
public void | requestLayoutOnUIThread(android.view.View view)
try {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
view.requestLayout();
}
});
} catch (Throwable throwable) {
Log.e(TAG, "", throwable);
}
|
public void | runTestOnUiThread(java.lang.Runnable r)
if (Looper.myLooper() == Looper.getMainLooper()) {
r.run();
} else {
super.runTestOnUiThread(r);
}
|
public void | scrollBy(int dt)
try {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
if (mRecyclerView.getLayoutManager().canScrollHorizontally()) {
mRecyclerView.scrollBy(dt, 0);
} else {
mRecyclerView.scrollBy(0, dt);
}
}
});
} catch (Throwable throwable) {
Log.e(TAG, "", throwable);
}
|
void | scrollToPosition(int position)
runTestOnUiThread(new Runnable() {
@Override
public void run() {
mRecyclerView.getLayoutManager().scrollToPosition(position);
}
});
|
void | setAdapter(RecyclerView.Adapter adapter)
runTestOnUiThread(new Runnable() {
@Override
public void run() {
mRecyclerView.setAdapter(adapter);
}
});
|
void | setHasTransientState(android.view.View view, boolean value)
try {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
ViewCompat.setHasTransientState(view, value);
}
});
} catch (Throwable throwable) {
Log.e(TAG, "", throwable);
}
|
public void | setRecyclerView(RecyclerView recyclerView)
setRecyclerView(recyclerView, true);
|
public void | setRecyclerView(RecyclerView recyclerView, boolean assignDummyPool)
setRecyclerView(recyclerView, true, true);
|
public void | setRecyclerView(RecyclerView recyclerView, boolean assignDummyPool, boolean addPositionCheckItemAnimator)
mRecyclerView = recyclerView;
if (assignDummyPool) {
RecyclerView.RecycledViewPool pool = new RecyclerView.RecycledViewPool() {
@Override
public RecyclerView.ViewHolder getRecycledView(int viewType) {
RecyclerView.ViewHolder viewHolder = super.getRecycledView(viewType);
if (viewHolder == null) {
return null;
}
viewHolder.addFlags(RecyclerView.ViewHolder.FLAG_BOUND);
viewHolder.mPosition = 200;
viewHolder.mOldPosition = 300;
viewHolder.mPreLayoutPosition = 500;
return viewHolder;
}
@Override
public void putRecycledView(RecyclerView.ViewHolder scrap) {
super.putRecycledView(scrap);
}
};
mRecyclerView.setRecycledViewPool(pool);
}
if (addPositionCheckItemAnimator) {
mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
RecyclerView.ViewHolder vh = parent.getChildViewHolder(view);
if (!vh.isRemoved()) {
assertNotSame("If getItemOffsets is called, child should have a valid"
+ " adapter position unless it is removed",
vh.getAdapterPosition(), RecyclerView.NO_POSITION);
}
}
});
}
mAdapterHelper = recyclerView.mAdapterHelper;
runTestOnUiThread(new Runnable() {
@Override
public void run() {
getActivity().mContainer.addView(recyclerView);
}
});
|
void | smoothScrollToPosition(int position)
Log.d(TAG, "SMOOTH scrolling to " + position);
runTestOnUiThread(new Runnable() {
@Override
public void run() {
mRecyclerView.smoothScrollToPosition(position);
}
});
while (mRecyclerView.getLayoutManager().isSmoothScrolling() ||
mRecyclerView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
if (mDebug) {
Log.d(TAG, "SMOOTH scrolling step");
}
Thread.sleep(200);
}
Log.d(TAG, "SMOOTH scrolling done");
getInstrumentation().waitForIdleSync();
|
void | swapAdapter(RecyclerView.Adapter adapter, boolean removeAndRecycleExistingViews)
runTestOnUiThread(new Runnable() {
@Override
public void run() {
try {
mRecyclerView.swapAdapter(adapter, removeAndRecycleExistingViews);
} catch (Throwable t) {
postExceptionToInstrumentation(t);
}
}
});
checkForMainThreadException();
|
protected void | tearDown()
if (mRecyclerView != null) {
try {
removeRecyclerView();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
getInstrumentation().waitForIdleSync();
super.tearDown();
try {
checkForMainThreadException();
} catch (Exception e) {
throw e;
} catch (Throwable throwable) {
throw new Exception(throwable);
}
|
void | waitForAnimations(int seconds)
final CountDownLatch latch = new CountDownLatch(2);
boolean running = mRecyclerView.mItemAnimator
.isRunning(new RecyclerView.ItemAnimator.ItemAnimatorFinishedListener() {
@Override
public void onAnimationsFinished() {
latch.countDown();
}
});
if (running) {
latch.await(seconds, TimeUnit.SECONDS);
}
|