Example usage for android.util SparseBooleanArray keyAt

List of usage examples for android.util SparseBooleanArray keyAt

Introduction

In this page you can find the example usage for android.util SparseBooleanArray keyAt.

Prototype

public int keyAt(int index) 

Source Link

Document

Given an index in the range 0...size()-1, returns the key from the indexth key-value mapping that this SparseBooleanArray stores.

Usage

From source file:Main.java

public static Map<Integer, Boolean> toMap(SparseBooleanArray array) {
    Map<Integer, Boolean> map = Maps.newHashMap();
    for (int i = 0; i < array.size(); i++) {
        map.put(array.keyAt(i), array.valueAt(i));
    }// w  w w.ja v  a 2  s. c  o m
    return map;
}

From source file:Main.java

/**
 * Method to avoid a bug on pre ICS// ww  w.j a v a2  s . c  om
 * 
 * @see https://code.google.com/p/android/issues/detail?id=27112
 */
public static SparseBooleanArray copySparseBooleanArray(SparseBooleanArray sba) {
    SparseBooleanArray out = new SparseBooleanArray(sba.size());
    for (int i = 0; i < sba.size(); i++) {
        out.append(sba.keyAt(i), sba.valueAt(i));
    }
    return out;
}

From source file:Main.java

/**
 * Convert SparseBooleanArray to the List which contains indexes whose values are true
 * @param sparseCheckedArray/*from  w w w.  ja  v  a 2s. c  om*/
 * @return
 */
public static List<Integer> convertToCheckedIndexList(SparseBooleanArray sparseCheckedArray) {

    List<Integer> checkList = new ArrayList<>();
    for (int i = 0; i < sparseCheckedArray.size(); i++) {
        int index = sparseCheckedArray.keyAt(i);
        if (sparseCheckedArray.valueAt(i)) {
            checkList.add(index);
        }
    }

    return checkList;
}

From source file:Main.java

public static Set<Integer> toSet(SparseBooleanArray array) {
    Set<Integer> trueSet = Sets.newHashSet();
    for (int i = 0; i < array.size(); i++) {
        if (array.valueAt(i)) {
            int position = array.keyAt(i);
            trueSet.add(position);/* ww w  .  j a v  a 2  s  .  c o  m*/
        }
    }
    return trueSet;
}

From source file:Main.java

public static List<Integer> getAbsListViewCheckedItemPositions(AbsListView absListView) {
    SparseBooleanArray checked = absListView.getCheckedItemPositions();
    List<Integer> positions = new ArrayList<>();
    int checkedSize = checked.size();
    for (int i = 0; i < checkedSize; ++i) {
        if (checked.valueAt(i)) {
            positions.add(checked.keyAt(i));
        }//from  www.j  a  v  a2s.c o m
    }
    return positions;
}

From source file:net.sf.sprockets.util.SparseArrays.java

/**
 * Get the keys of the SparseBooleanArray.
 *///ww  w.j a  va  2 s . c  o  m
public static int[] keys(SparseBooleanArray array) {
    int[] keys = new int[array.size()];
    for (int i = 0; i < keys.length; i++) {
        keys[i] = array.keyAt(i);
    }
    return keys;
}

From source file:Main.java

public static SparseBooleanArray cloneSBArray(SparseBooleanArray arr) {
    try {//from   w  w  w. ja v a2  s . c  o m
        return arr.clone();
    } catch (Exception e) {
        // Happens when using HC - should clone manually
        int size = arr.size();
        SparseBooleanArray clone = new SparseBooleanArray();
        for (int i = 0; i < size; i++) {
            if (arr.get(arr.keyAt(i))) {
                clone.put(arr.keyAt(i), true);
            }
        }
        return clone;
    }
}

From source file:net.sf.sprockets.util.SparseArrays.java

/**
 * Get the first key of the SparseBooleanArray which has the value.
 *
 * @return {@link Integer#MIN_VALUE} if the value is not found
 *///from  w w  w.j a va 2 s  .c om
private static int firstKey(SparseBooleanArray array, boolean value) {
    int size = array.size();
    for (int i = 0; i < size; i++) {
        if (array.valueAt(i) == value) {
            return array.keyAt(i);
        }
    }
    return Integer.MIN_VALUE;
}

From source file:sg.fxl.topeka.helper.AnswerHelper.java

public static int[] getSelectedIndexes(SparseBooleanArray checkedItems) {
    List<Integer> selectedIndexes = new ArrayList<>();
    if (checkedItems != null) {
        for (int i = 0; i < checkedItems.size(); i++) {
            if (checkedItems.valueAt(i)) {
                selectedIndexes.add(checkedItems.keyAt(i));
            }/*from w  w  w.ja  va  2  s.c  o  m*/
        }
    }
    return ArrayUtils.toPrimitive(selectedIndexes.toArray(new Integer[selectedIndexes.size()]));
}

From source file:net.sf.sprockets.util.SparseArrays.java

/**
 * Get the keys of the SparseBooleanArray which have the value.
 *//*ww w .  j  a  va 2  s.co m*/
private static int[] keys(SparseBooleanArray array, boolean value) {
    int size = array.size();
    ArrayIntList keys = new ArrayIntList(size);
    for (int i = 0; i < size; i++) {
        if (array.valueAt(i) == value) {
            keys.add(array.keyAt(i));
        }
    }
    return keys.toArray();
}