Example usage for android.util SparseBooleanArray get

List of usage examples for android.util SparseBooleanArray get

Introduction

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

Prototype

public boolean get(int key) 

Source Link

Document

Gets the boolean mapped from the specified key, or false if no such mapping has been made.

Usage

From source file:Main.java

public static SparseBooleanArray cloneSBArray(SparseBooleanArray arr) {
    try {//w  w  w  .ja  va2s .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:org.kontalk.util.SystemUtils.java

/**
 * Provides clone functionality for the {@link SparseBooleanArray}.
 * See https://code.google.com/p/android/issues/detail?id=39242
 *//*from  ww  w .  j  a v a 2  s.  c  o m*/
public static SparseBooleanArray cloneSparseBooleanArray(SparseBooleanArray array) {
    final SparseBooleanArray clone = new SparseBooleanArray();

    synchronized (array) {
        final int size = array.size();
        for (int i = 0; i < size; i++) {
            int key = array.keyAt(i);
            clone.put(key, array.get(key));
        }
    }

    return clone;
}

From source file:ca.rmen.android.networkmonitor.app.prefs.SelectFieldsActivity.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Log.v(TAG, "onListItemClick: clicked on view " + v + " at position " + position + " with id " + id);
    View okButton = findViewById(R.id.ok);
    SparseBooleanArray checkedItemPositions = l.getCheckedItemPositions();
    for (int i = 0; i < checkedItemPositions.size(); i++) {
        if (checkedItemPositions.get(checkedItemPositions.keyAt(i))) {
            okButton.setEnabled(true);//from   ww  w  . ja v  a2s . c om
            return;
        }
    }
    okButton.setEnabled(false);
}

From source file:com.pindroid.fragment.SelectTagsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.menu_selecttags_ok:

        Set<String> tags = new HashSet<String>();

        SparseBooleanArray checked = getListView().getCheckedItemPositions();

        for (int i = 0; i < getListAdapter().getCount(); i++) {
            if (checked.get(i)) {
                Cursor c = (Cursor) getListAdapter().getItem(i);
                String n = c.getString(c.getColumnIndex(Tag.Name));

                tags.add(n);/*from  w  ww .ja v a  2 s  .c  om*/
            }
        }

        tagsSelectedListener.onTagsSelected(tags);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.connectsdk.smarthomesampler.fragment.SetupMultiChoiceFragment.java

@OnClick(R.id.btnNext)
public void onNextStep() {
    SparseBooleanArray checked = listView.getCheckedItemPositions();
    ids.clear();/* w  w w. j  a v a 2  s  . c  om*/
    if (adapter != null) {
        for (int i = 0; i < checked.size(); i++) {
            if (checked.get(checked.keyAt(i))) {
                T device = adapter.getItem(checked.keyAt(i));
                ids.add(getDeviceId(device));
            }
        }
    }
    save();
}

From source file:ca.rmen.android.networkmonitor.app.prefs.FilterColumnActivity.java

public void onOk(@SuppressWarnings("UnusedParameters") View v) {
    Log.v(TAG, "onOk");
    // Update the preference for values to filter, for this particular column.

    // Build a list of all the values the user selected.
    SparseBooleanArray checkedPositions = mListView.getCheckedItemPositions();
    final List<String> selectedValues = new ArrayList<>(mListView.getCount());
    for (int i = 0; i < mListView.getCount(); i++) {
        if (checkedPositions.get(i))
            selectedValues.add(((FilterListItem) mListView.getAdapter().getItem(i)).value);
    }/*  w w  w .  j ava  2  s  . c o m*/
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            // Update the filter preference for this column.
            String columnName = getIntent().getExtras().getString(EXTRA_COLUMN_NAME);
            NetMonPreferences.getInstance(FilterColumnActivity.this).setColumnFilterValues(columnName,
                    selectedValues);
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            setResult(Activity.RESULT_OK);
            finish();
        }
    }.execute();
}

From source file:net.potterpcs.recipebook.ImporterActivity.java

public void onImportButton(View v) {
    // We can't simply use getCheckedItemIds(), because it only works
    // if the ListAdapter has stable IDs, and ArrayAdapters don't.
    // So, we have to use getCheckedItemPositions instead, and loop
    // through the array.
    SparseBooleanArray sba = getListView().getCheckedItemPositions();
    ArrayList<Recipe> selectedRecipes = new ArrayList<Recipe>();
    for (int i = 0; i < sba.size(); i++) {
        if (sba.get(i)) {
            selectedRecipes.add(importedRecipes.get(i));
        }//from   ww w  .j a  v  a2 s . c om
    }
    data.insertImportedRecipes(selectedRecipes);
    finish();
}

From source file:eu.power_switch.gui.dialog.AddSsidDialog.java

private ArrayList<String> getSelectedSSIDs() {
    ArrayList<String> selectedSSIDs = new ArrayList<>();

    // manual/*  w w  w  .ja  va  2 s .  c  om*/
    String manualSsid = editText_ssid.getText().toString().trim();
    if (!TextUtils.isEmpty(manualSsid)) {
        selectedSSIDs.add(manualSsid);
    }

    // available networks
    int len = listView.getCount();
    SparseBooleanArray checked = listView.getCheckedItemPositions();
    for (int i = 0; i < len; i++) {
        if (checked.get(i)) {
            String item = ssids.get(i);
            /* do whatever you want with the checked item */
            selectedSSIDs.add(item);
        }
    }

    return selectedSSIDs;
}

From source file:net.lacolaco.smileessence.activity.EditExtractionActivity.java

public void deleteSelectedItems() {
    SparseBooleanArray checkedItems = getListView().getCheckedItemPositions();
    adapter.setNotifiable(false);//  w  w w.ja v a2s.  co m
    for (int i = adapter.getCount() - 1; i > -1; i--) {
        if (checkedItems.get(i)) {
            ExtractionWord extractionWord = adapter.removeItem(i);
            extractionWord.delete();
        }
    }
    adapter.setNotifiable(true);
    adapter.notifyDataSetChanged();
    updateListView();
}

From source file:net.lacolaco.smileessence.activity.EditTemplateActivity.java

public void deleteSelectedItems() {
    SparseBooleanArray checkedItems = getListView().getCheckedItemPositions();
    adapter.setNotifiable(false);/*from w  w  w.  j  a  va  2s  . c o  m*/
    for (int i = adapter.getCount() - 1; i > -1; i--) {
        if (checkedItems.get(i)) {
            Template template = adapter.removeItem(i);
            template.delete();
        }
    }
    adapter.setNotifiable(true);
    adapter.notifyDataSetChanged();
    updateListView();
}