Example usage for android.util SparseBooleanArray append

List of usage examples for android.util SparseBooleanArray append

Introduction

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

Prototype

public void append(int key, boolean value) 

Source Link

Document

Puts a key/value pair into the array, optimizing for the case where the key is greater than all existing keys in the array.

Usage

From source file:Main.java

/**
 * Method to avoid a bug on pre ICS/*from   www  .  j  a  v a 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:es.ugr.swad.swadroid.modules.tests.TestsMake.java

private SparseBooleanArray getCheckedItemPositions(LinearLayout parent) {
    SparseBooleanArray checkedItems = new SparseBooleanArray();
    int childCount = parent.getChildCount();
    CheckableLinearLayout tv;//w w w .j  a  va 2 s.c  o  m

    for (int i = 0; i < childCount; i++) {
        tv = (CheckableLinearLayout) parent.getChildAt(i);
        checkedItems.append(i, tv.isChecked());
    }

    return checkedItems;
}

From source file:org.chromium.chrome.browser.tabmodel.TabPersistentStore.java

/**
 * Extracts the tab information from a given tab state stream.
 *
 * @param stream   The stream pointing to the tab state file to be parsed.
 * @param callback A callback to be streamed updates about the tab state information being read.
 * @param tabIds   A mapping of tab ID to whether the tab is an off the record tab.
 * @param forMerge Whether this state file was read as part of a merge.
 * @return The next available tab ID based on the maximum ID referenced in this state file.
 *//*w ww  . ja v a2  s  .  co m*/
public static int readSavedStateFile(DataInputStream stream, @Nullable OnTabStateReadCallback callback,
        @Nullable SparseBooleanArray tabIds, boolean forMerge) throws IOException {
    if (stream == null)
        return 0;
    long time = SystemClock.uptimeMillis();
    int nextId = 0;
    boolean skipUrlRead = false;
    boolean skipIncognitoCount = false;
    final int version = stream.readInt();
    if (version != SAVED_STATE_VERSION) {
        // We don't support restoring Tab data from before M18.
        if (version < 3)
            return 0;
        // Older versions are missing newer data.
        if (version < 5)
            skipIncognitoCount = true;
        if (version < 4)
            skipUrlRead = true;
    }

    final int count = stream.readInt();
    final int incognitoCount = skipIncognitoCount ? -1 : stream.readInt();
    final int incognitoActiveIndex = stream.readInt();
    final int standardActiveIndex = stream.readInt();
    if (count < 0 || incognitoActiveIndex >= count || standardActiveIndex >= count) {
        throw new IOException();
    }

    for (int i = 0; i < count; i++) {
        int id = stream.readInt();
        String tabUrl = skipUrlRead ? "" : stream.readUTF();
        if (id >= nextId)
            nextId = id + 1;
        if (tabIds != null)
            tabIds.append(id, true);

        Boolean isIncognito = (incognitoCount < 0) ? null : i < incognitoCount;
        if (callback != null) {
            callback.onDetailsRead(i, id, tabUrl, isIncognito, i == standardActiveIndex,
                    i == incognitoActiveIndex);
        }
    }

    if (forMerge) {
        logExecutionTime("ReadMergedStateTime", time);
        int tabCount = count + ((incognitoCount > 0) ? incognitoCount : 0);
        RecordHistogram.recordLinearCountHistogram("Android.TabPersistentStore.MergeStateTabCount", tabCount, 1,
                200, 200);
    }

    logExecutionTime("ReadSavedStateTime", time);

    return nextId;
}