Example usage for android.util SparseBooleanArray valueAt

List of usage examples for android.util SparseBooleanArray valueAt

Introduction

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

Prototype

public boolean valueAt(int index) 

Source Link

Document

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

Usage

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);//from  ww  w  . j av  a2  s  . c om
        }
    }
    return trueSet;
}

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));
    }/*from  w  w w. j a  v  a  2  s .co  m*/
    return map;
}

From source file:Main.java

/**
 * Method to avoid a bug on pre ICS//from www .j a  va  2 s. com
 * 
 * @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

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));
        }//w w  w  .j  ava  2  s  . c om
    }
    return positions;
}

From source file:Main.java

/**
 * Convert SparseBooleanArray to the List which contains indexes whose values are true
 * @param sparseCheckedArray/*  w w w  .j a  v  a  2  s  .com*/
 * @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: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 va2 s  .c om*/
        }
    }
    return ArrayUtils.toPrimitive(selectedIndexes.toArray(new Integer[selectedIndexes.size()]));
}

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
 *//*  w w w  .j a v  a2  s .co  m*/
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:net.sf.sprockets.util.SparseArrays.java

/**
 * Get the values of the SparseBooleanArray.
 *///from w  ww . jav  a 2  s  .  c o  m
public static boolean[] values(SparseBooleanArray array) {
    boolean[] vals = new boolean[array.size()];
    for (int i = 0; i < vals.length; i++) {
        vals[i] = array.valueAt(i);
    }
    return vals;
}

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

/**
 * Get the keys of the SparseBooleanArray which have the value.
 *//* w  w w  . ja va 2  s .  c o  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();
}

From source file:nl.mpcjanssen.simpletask.util.Util.java

public static ArrayList<String> getCheckedItems(ListView listView, boolean checked) {
    SparseBooleanArray checks = listView.getCheckedItemPositions();
    ArrayList<String> items = new ArrayList<String>();
    for (int i = 0; i < checks.size(); i++) {
        String item = (String) listView.getAdapter().getItem(checks.keyAt(i));
        if (checks.valueAt(i) && checked) {
            items.add(item);//www .  jav a2  s.  c  o  m
        } else if (!checks.valueAt(i) && !checked) {
            items.add(item);
        }
    }
    return items;
}