Java Code Examples for android.support.v7.widget.RecyclerView#invalidateItemDecorations()

The following examples show how to use android.support.v7.widget.RecyclerView#invalidateItemDecorations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StaggeredLayoutManagerUtils.java    From RecyclerViewTools with Apache License 2.0 5 votes vote down vote up
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

         View v1 = recyclerView.getChildAt(0);
         View v2 = recyclerView.getChildAt(recyclerView.getChildCount() - 1);

         int i1 = recyclerView.getChildAdapterPosition(v1);
         int i2 = recyclerView.getChildAdapterPosition(v2);

         if (position >= i1 && position <= i2) {
            ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).invalidateSpanAssignments();
            recyclerView.invalidateItemDecorations();
            recyclerView.removeOnScrollListener(this);
         }
      }
 
Example 2
Source File: DragSortRecycler.java    From OmniList with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    debugLog("onTouchEvent");

    if ((e.getAction() == MotionEvent.ACTION_UP) ||
            (e.getAction() == MotionEvent.ACTION_CANCEL)) {
        if ((e.getAction() == MotionEvent.ACTION_UP) && selectedDragItemPos != -1) {
            int newPos = getNewPostion(rv);
            if (moveInterface != null)
                moveInterface.onItemMoved(selectedDragItemPos, newPos);
        }

        setIsDragging(false);
        selectedDragItemPos = -1;
        floatingItem = null;
        rv.invalidateItemDecorations();
        return;
    }


    fingerY = (int) e.getY();

    if (floatingItem != null) {
        floatingItemBounds.top = fingerY - fingerOffsetInViewY;

        if (floatingItemBounds.top < -floatingItemStatingBounds.height() / 2) //Allow half the view out the top
            floatingItemBounds.top = -floatingItemStatingBounds.height() / 2;

        floatingItemBounds.bottom = floatingItemBounds.top + floatingItemStatingBounds.height();

        floatingItem.setBounds(floatingItemBounds);
    }

    //Do auto scrolling at end of list
    float scrollAmount = 0;
    if (fingerY > (rv.getHeight() * (1 - autoScrollWindow))) {
        scrollAmount = (fingerY - (rv.getHeight() * (1 - autoScrollWindow)));
    } else if (fingerY < (rv.getHeight() * autoScrollWindow)) {
        scrollAmount = (fingerY - (rv.getHeight() * autoScrollWindow));
    }
    debugLog("Scroll: " + scrollAmount);

    scrollAmount *= autoScrollSpeed;
    rv.scrollBy(0, (int) scrollAmount);

    rv.invalidateItemDecorations();// Redraw
}
 
Example 3
Source File: DragSortRecycler.java    From Muzesto with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    debugLog("onTouchEvent");

    if ((e.getAction() == MotionEvent.ACTION_UP) ||
            (e.getAction() == MotionEvent.ACTION_CANCEL)) {
        if ((e.getAction() == MotionEvent.ACTION_UP) && selectedDragItemPos != -1) {
            int newPos = getNewPostion(rv);
            if (moveInterface != null)
                moveInterface.onItemMoved(selectedDragItemPos, newPos);
        }

        setIsDragging(false);
        selectedDragItemPos = -1;
        floatingItem = null;
        rv.invalidateItemDecorations();
        return;
    }


    fingerY = (int) e.getY();

    if (floatingItem != null) {
        floatingItemBounds.top = fingerY - fingerOffsetInViewY;

        if (floatingItemBounds.top < -floatingItemStatingBounds.height() / 2) //Allow half the view out the top
            floatingItemBounds.top = -floatingItemStatingBounds.height() / 2;

        floatingItemBounds.bottom = floatingItemBounds.top + floatingItemStatingBounds.height();

        floatingItem.setBounds(floatingItemBounds);
    }

    //Do auto scrolling at end of list
    float scrollAmount = 0;
    if (fingerY > (rv.getHeight() * (1 - autoScrollWindow))) {
        scrollAmount = (fingerY - (rv.getHeight() * (1 - autoScrollWindow)));
    } else if (fingerY < (rv.getHeight() * autoScrollWindow)) {
        scrollAmount = (fingerY - (rv.getHeight() * autoScrollWindow));
    }
    debugLog("Scroll: " + scrollAmount);

    scrollAmount *= autoScrollSpeed;
    rv.scrollBy(0, (int) scrollAmount);

    rv.invalidateItemDecorations();// Redraw
}
 
Example 4
Source File: DragSortRecycler.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    debugLog("onTouchEvent");

    if ((e.getAction() == MotionEvent.ACTION_UP) ||
            (e.getAction() == MotionEvent.ACTION_CANCEL)) {
        if ((e.getAction() == MotionEvent.ACTION_UP) && selectedDragItemPos != -1) {
            int newPos = getNewPostion(rv);
            if (moveInterface != null)
                moveInterface.onItemMoved(selectedDragItemPos, newPos);
        }

        setIsDragging(false);
        selectedDragItemPos = -1;
        floatingItem = null;
        rv.invalidateItemDecorations();
        return;
    }


    fingerY = (int) e.getY();

    if (floatingItem != null) {
        floatingItemBounds.top = fingerY - fingerOffsetInViewY;

        if (floatingItemBounds.top < -floatingItemStatingBounds.height() / 2) //Allow half the view out the top
            floatingItemBounds.top = -floatingItemStatingBounds.height() / 2;

        floatingItemBounds.bottom = floatingItemBounds.top + floatingItemStatingBounds.height();

        floatingItem.setBounds(floatingItemBounds);
    }

    //Do auto scrolling at end of list
    float scrollAmount = 0;
    if (fingerY > (rv.getHeight() * (1 - autoScrollWindow))) {
        scrollAmount = (fingerY - (rv.getHeight() * (1 - autoScrollWindow)));
    } else if (fingerY < (rv.getHeight() * autoScrollWindow)) {
        scrollAmount = (fingerY - (rv.getHeight() * autoScrollWindow));
    }
    debugLog("Scroll: " + scrollAmount);

    scrollAmount *= autoScrollSpeed;
    rv.scrollBy(0, (int) scrollAmount);

    rv.invalidateItemDecorations();// Redraw
}
 
Example 5
Source File: DragSortRecycler.java    From DragSortRecycler with Apache License 2.0 4 votes vote down vote up
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    debugLog("onTouchEvent");

    if ((e.getAction() == MotionEvent.ACTION_UP) ||
            (e.getAction() == MotionEvent.ACTION_CANCEL))
    {
        if ((e.getAction() == MotionEvent.ACTION_UP) && selectedDragItemPos != -1)
        {
            int newPos = getNewPostion(rv);
            if (moveInterface != null)
                moveInterface.onItemMoved(selectedDragItemPos, newPos);
        }

        setIsDragging(false);
        selectedDragItemPos = -1;
        floatingItem = null;
        rv.invalidateItemDecorations();
        return;
    }


    fingerY = (int)e.getY();

    if (floatingItem!=null)
    {
        floatingItemBounds.top = fingerY - fingerOffsetInViewY;

        if (floatingItemBounds.top < -floatingItemStatingBounds.height()/2) //Allow half the view out the top
            floatingItemBounds.top = -floatingItemStatingBounds.height()/2;

        floatingItemBounds.bottom = floatingItemBounds.top + floatingItemStatingBounds.height();

        floatingItem.setBounds(floatingItemBounds);
    }

    //Do auto scrolling at end of list
    float scrollAmount=0;
    if (fingerY > (rv.getHeight() * (1-autoScrollWindow)))
    {
        scrollAmount = (fingerY - (rv.getHeight() * (1-autoScrollWindow)));
    }
    else if (fingerY < (rv.getHeight() * autoScrollWindow))
    {
        scrollAmount = (fingerY - (rv.getHeight() * autoScrollWindow));
    }
    debugLog("Scroll: " + scrollAmount);

    scrollAmount *= autoScrollSpeed;
    rv.scrollBy(0, (int)scrollAmount);

    rv.invalidateItemDecorations();// Redraw
}
 
Example 6
Source File: DragSortRecycler.java    From rox-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    debugLog("onTouchEvent");

    if ((e.getAction() == MotionEvent.ACTION_UP) ||
            (e.getAction() == MotionEvent.ACTION_CANCEL))
    {
        if ((e.getAction() == MotionEvent.ACTION_UP) && selectedDragItemPos != -1)
        {
            int newPos = getNewPostion(rv);
            if (moveInterface != null)
                moveInterface.onItemMoved(selectedDragItemPos, newPos);
        }

        setIsDragging(false);
        selectedDragItemPos = -1;
        floatingItem = null;
        rv.invalidateItemDecorations();
        return;
    }


    fingerY = (int)e.getY();

    if (floatingItem!=null)
    {
        floatingItemBounds.top = fingerY - fingerOffsetInViewY;

        if (floatingItemBounds.top < -floatingItemStatingBounds.height()/2) //Allow half the view out the top
            floatingItemBounds.top = -floatingItemStatingBounds.height()/2;

        floatingItemBounds.bottom = floatingItemBounds.top + floatingItemStatingBounds.height();

        floatingItem.setBounds(floatingItemBounds);
    }

    //Do auto scrolling at end of list
    float scrollAmount=0;
    if (fingerY > (rv.getHeight() * (1-autoScrollWindow)))
    {
        scrollAmount = (fingerY - (rv.getHeight() * (1-autoScrollWindow)));
    }
    else if (fingerY < (rv.getHeight() * autoScrollWindow))
    {
        scrollAmount = (fingerY - (rv.getHeight() * autoScrollWindow));
    }
    debugLog("Scroll: " + scrollAmount);

    scrollAmount *= autoScrollSpeed;
    rv.scrollBy(0, (int)scrollAmount);

    rv.invalidateItemDecorations();// Redraw
}