@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT) @Test public void hiddenNoneRemoveViewAccessibility() throws Throwable { final Config config = new Config(); int adapterSize = 1000; final boolean[] firstItemSpecialSize = new boolean[] {false}; TestAdapter adapter = new TestAdapter(adapterSize) { @Override public void onBindViewHolder(@NonNull TestViewHolder holder, int position) { super.onBindViewHolder(holder, position); ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); if (!(lp instanceof ViewGroup.MarginLayoutParams)) { lp = new ViewGroup.MarginLayoutParams(0, 0); holder.itemView.setLayoutParams(lp); } ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) lp; final int maxSize; if (config.mOrientation == HORIZONTAL) { maxSize = mRecyclerView.getWidth(); mlp.height = ViewGroup.MarginLayoutParams.MATCH_PARENT; } else { maxSize = mRecyclerView.getHeight(); mlp.width = ViewGroup.MarginLayoutParams.MATCH_PARENT; } final int desiredSize; if (position == 0 && firstItemSpecialSize[0]) { desiredSize = maxSize / 3; } else { desiredSize = maxSize / 8; } if (config.mOrientation == HORIZONTAL) { mlp.width = desiredSize; } else { mlp.height = desiredSize; } } @Override public void onBindViewHolder(TestViewHolder holder, int position, List<Object> payloads) { onBindViewHolder(holder, position); } }; adapter.setHasStableIds(false); config.adapter(adapter); setupByConfig(config, true); final DummyItemAnimator itemAnimator = new DummyItemAnimator(); mRecyclerView.setItemAnimator(itemAnimator); final int childBeingPushOut = mLayoutManager.getChildCount() - 1; RecyclerView.ViewHolder itemViewHolder = mRecyclerView .findViewHolderForAdapterPosition(childBeingPushOut); final int originalAccessibility = ViewCompat.getImportantForAccessibility( itemViewHolder.itemView); assertTrue(ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO == originalAccessibility || ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES == originalAccessibility); itemAnimator.expect(DummyItemAnimator.MOVE_START, 1); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { firstItemSpecialSize[0] = true; mTestAdapter.notifyItemChanged(0, "XXX"); } }); itemAnimator.waitFor(DummyItemAnimator.MOVE_START); waitOneCycle(); assertTrue(itemAnimator.getMovesAnimations().contains(itemViewHolder)); assertEquals(ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS, ViewCompat.getImportantForAccessibility(itemViewHolder.itemView)); mLayoutManager.expectLayouts(2); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { mTestAdapter.notifyItemChanged(0, "XXX"); } }); mLayoutManager.waitForLayout(1); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { itemAnimator.endAnimations(); } }); smoothScrollToPosition(childBeingPushOut); RecyclerView.ViewHolder itemViewHolder2 = mRecyclerView .findViewHolderForAdapterPosition(childBeingPushOut); assertSame(itemViewHolder, itemViewHolder2); final int newAccessibility = ViewCompat.getImportantForAccessibility( itemViewHolder.itemView); assertTrue(ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO == newAccessibility || ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES == newAccessibility); }
@Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()); linearSmoothScroller.setTargetPosition(position); startSmoothScroll(linearSmoothScroller); }
LinearLayoutManager extends RecyclerView.LayoutManager implements
        ItemTouchHelper.ViewDropHandler, RecyclerView.SmoothScroller.ScrollVectorProvider { @Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()); linearSmoothScroller.setTargetPosition(position); startSmoothScroll(linearSmoothScroller); } }
LinearLayoutManager extends RecyclerView.LayoutManager implements
        ItemTouchHelper.ViewDropHandler, RecyclerView.SmoothScroller.ScrollVectorProvider { @Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()); linearSmoothScroller.setTargetPosition(position); startSmoothScroll(linearSmoothScroller); } LinearLayoutManager(Context context);  LinearLayoutManager(Context context, @RecyclerView.Orientation int orientation,
            boolean reverseLayout);  LinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr,
            int defStyleRes); }
LinearLayoutManager extends RecyclerView.LayoutManager implements
        ItemTouchHelper.ViewDropHandler, RecyclerView.SmoothScroller.ScrollVectorProvider { @Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()); linearSmoothScroller.setTargetPosition(position); startSmoothScroll(linearSmoothScroller); } LinearLayoutManager(Context context);  LinearLayoutManager(Context context, @RecyclerView.Orientation int orientation,
            boolean reverseLayout);  LinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr,
            int defStyleRes); @Override boolean isAutoMeasureEnabled(); @Override RecyclerView.LayoutParams generateDefaultLayoutParams(); boolean getRecycleChildrenOnDetach(); void setRecycleChildrenOnDetach(boolean recycleChildrenOnDetach); @Override void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler); @Override void onInitializeAccessibilityEvent(AccessibilityEvent event); @Override Parcelable onSaveInstanceState(); @Override void onRestoreInstanceState(Parcelable state); @Override boolean canScrollHorizontally(); @Override boolean canScrollVertically(); void setStackFromEnd(boolean stackFromEnd); boolean getStackFromEnd(); @RecyclerView.Orientation int getOrientation(); void setOrientation(@RecyclerView.Orientation int orientation); boolean getReverseLayout(); void setReverseLayout(boolean reverseLayout); @Override View findViewByPosition(int position); @Override void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state,
            int position); @Override PointF computeScrollVectorForPosition(int targetPosition); @Override void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state); @Override void onLayoutCompleted(RecyclerView.State state); @Override void scrollToPosition(int position); void scrollToPositionWithOffset(int position, int offset); @Override int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler,
            RecyclerView.State state); @Override int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler,
            RecyclerView.State state); @Override int computeHorizontalScrollOffset(RecyclerView.State state); @Override int computeVerticalScrollOffset(RecyclerView.State state); @Override int computeHorizontalScrollExtent(RecyclerView.State state); @Override int computeVerticalScrollExtent(RecyclerView.State state); @Override int computeHorizontalScrollRange(RecyclerView.State state); @Override int computeVerticalScrollRange(RecyclerView.State state); void setSmoothScrollbarEnabled(boolean enabled); boolean isSmoothScrollbarEnabled(); @Override void collectInitialPrefetchPositions(int adapterItemCount,
            LayoutPrefetchRegistry layoutPrefetchRegistry); void setInitialPrefetchItemCount(int itemCount); int getInitialPrefetchItemCount(); @Override void collectAdjacentPrefetchPositions(int dx, int dy, RecyclerView.State state,
            LayoutPrefetchRegistry layoutPrefetchRegistry); @Override void assertNotInLayoutOrScroll(String message); int findFirstVisibleItemPosition(); int findFirstCompletelyVisibleItemPosition(); int findLastVisibleItemPosition(); int findLastCompletelyVisibleItemPosition(); @Override View onFocusSearchFailed(View focused, int focusDirection,
            RecyclerView.Recycler recycler, RecyclerView.State state); @Override boolean supportsPredictiveItemAnimations(); @RestrictTo(LIBRARY_GROUP) @Override void prepareForDrop(@NonNull View view, @NonNull View target, int x, int y); }
LinearLayoutManager extends RecyclerView.LayoutManager implements
        ItemTouchHelper.ViewDropHandler, RecyclerView.SmoothScroller.ScrollVectorProvider { @Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()); linearSmoothScroller.setTargetPosition(position); startSmoothScroll(linearSmoothScroller); } LinearLayoutManager(Context context);  LinearLayoutManager(Context context, @RecyclerView.Orientation int orientation,
            boolean reverseLayout);  LinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr,
            int defStyleRes); @Override boolean isAutoMeasureEnabled(); @Override RecyclerView.LayoutParams generateDefaultLayoutParams(); boolean getRecycleChildrenOnDetach(); void setRecycleChildrenOnDetach(boolean recycleChildrenOnDetach); @Override void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler); @Override void onInitializeAccessibilityEvent(AccessibilityEvent event); @Override Parcelable onSaveInstanceState(); @Override void onRestoreInstanceState(Parcelable state); @Override boolean canScrollHorizontally(); @Override boolean canScrollVertically(); void setStackFromEnd(boolean stackFromEnd); boolean getStackFromEnd(); @RecyclerView.Orientation int getOrientation(); void setOrientation(@RecyclerView.Orientation int orientation); boolean getReverseLayout(); void setReverseLayout(boolean reverseLayout); @Override View findViewByPosition(int position); @Override void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state,
            int position); @Override PointF computeScrollVectorForPosition(int targetPosition); @Override void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state); @Override void onLayoutCompleted(RecyclerView.State state); @Override void scrollToPosition(int position); void scrollToPositionWithOffset(int position, int offset); @Override int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler,
            RecyclerView.State state); @Override int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler,
            RecyclerView.State state); @Override int computeHorizontalScrollOffset(RecyclerView.State state); @Override int computeVerticalScrollOffset(RecyclerView.State state); @Override int computeHorizontalScrollExtent(RecyclerView.State state); @Override int computeVerticalScrollExtent(RecyclerView.State state); @Override int computeHorizontalScrollRange(RecyclerView.State state); @Override int computeVerticalScrollRange(RecyclerView.State state); void setSmoothScrollbarEnabled(boolean enabled); boolean isSmoothScrollbarEnabled(); @Override void collectInitialPrefetchPositions(int adapterItemCount,
            LayoutPrefetchRegistry layoutPrefetchRegistry); void setInitialPrefetchItemCount(int itemCount); int getInitialPrefetchItemCount(); @Override void collectAdjacentPrefetchPositions(int dx, int dy, RecyclerView.State state,
            LayoutPrefetchRegistry layoutPrefetchRegistry); @Override void assertNotInLayoutOrScroll(String message); int findFirstVisibleItemPosition(); int findFirstCompletelyVisibleItemPosition(); int findLastVisibleItemPosition(); int findLastCompletelyVisibleItemPosition(); @Override View onFocusSearchFailed(View focused, int focusDirection,
            RecyclerView.Recycler recycler, RecyclerView.State state); @Override boolean supportsPredictiveItemAnimations(); @RestrictTo(LIBRARY_GROUP) @Override void prepareForDrop(@NonNull View view, @NonNull View target, int x, int y); static final int HORIZONTAL; static final int VERTICAL; static final int INVALID_OFFSET; }