Example usage for android.support.v4.util SparseArrayCompat remove

List of usage examples for android.support.v4.util SparseArrayCompat remove

Introduction

In this page you can find the example usage for android.support.v4.util SparseArrayCompat remove.

Prototype

public void remove(int i) 

Source Link

Usage

From source file:com.facebook.litho.ComponentHostUtils.java

/**
 * Remove the item at given {@param index}. The item is removed from {@param scrapItems} if the
 * item exists there at given index, otherwise it is removed from {@param items}.
 *//*  w  ww . j a v  a 2  s  .  co m*/
static <T> void removeItem(int index, SparseArrayCompat<T> items, SparseArrayCompat<T> scrapItems) {
    if (existsScrapItemAt(index, scrapItems)) {
        scrapItems.remove(index);
    } else {
        items.remove(index);
    }
}

From source file:com.facebook.litho.ComponentHostUtils.java

/**
 * Moves an item from oldIndex to newIndex. The item is taken from scrapitems if an item exists
 * in scrapItems at oldPosition. Otherwise the item is taken from items. This assumes that there
 * is no item at newIndex for the items array. If that's the case
 * {@link ComponentHostUtils#scrapItemAt(int, SparseArrayCompat, SparseArrayCompat)}
 * has to be called before invoking this.
 *//*from w  w  w  . ja v  a2s  .co  m*/
static <T> void moveItem(int oldIndex, int newIndex, SparseArrayCompat<T> items,
        SparseArrayCompat<T> scrapItems) {
    T itemToMove;

    if (existsScrapItemAt(oldIndex, scrapItems)) {
        // Before moving the item from items we need to check whether an old item has been put in
        // the scrapItems array. If there is an item at oldIndex there, it means that in
        // items at position oldIndex there's now something else and the correct item to move to
        // newIndex is instead in the scrapItems SparseArray.
        itemToMove = scrapItems.get(oldIndex);
        scrapItems.remove(oldIndex);
    } else {
        itemToMove = items.get(oldIndex);
        items.remove(oldIndex);
    }

    items.put(newIndex, itemToMove);
}