List of usage examples for android.util SparseBooleanArray size
public int size()
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 ww w. j a v a2s . com*/ } } return ArrayUtils.toPrimitive(selectedIndexes.toArray(new Integer[selectedIndexes.size()])); }
From source file:Main.java
/** * Checks whether a provided answer is correct. * * @param checkedItems The items that were selected. * @param answerIds The actual correct answer ids. * @return <code>true</code> if correct else <code>false</code>. *//*w ww . ja v a 2 s.c om*/ public static boolean isAnswerCorrect(SparseBooleanArray checkedItems, int[] answerIds) { if (null == checkedItems || null == answerIds) { Log.i(TAG, "isAnswerCorrect got a null parameter input."); return false; } for (int answer : answerIds) { if (0 > checkedItems.indexOfKey(answer)) { return false; } } return checkedItems.size() == answerIds.length; }
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 w w w. j ava 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: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);// w w w .j ava 2s . c o m } else if (!checks.valueAt(i) && !checked) { items.add(item); } } return items; }
From source file:org.akop.crosswords.fragment.BaseFragment.java
protected void putSparseBooleanArray(Bundle bundle, String prefix, SparseBooleanArray array) { int size = array.size(); int keys[] = new int[size]; boolean values[] = new boolean[size]; for (int i = 0; i < size; i++) { keys[i] = array.keyAt(i);/*from w w w . j a v a 2 s . c o m*/ values[i] = array.valueAt(i); } bundle.putIntArray(prefix + "_keys", keys); bundle.putBooleanArray(prefix + "_values", values); }
From source file:com.andremion.louvre.sample.MediaTypeFilterDialog.java
@NonNull private String[] parseToArray(@NonNull SparseBooleanArray selectedTypes) { List<String> selectedTypeList = new ArrayList<>(); for (int i = 0; i < selectedTypes.size(); i++) { int key = selectedTypes.keyAt(i); if (selectedTypes.get(key, false)) { selectedTypeList.add(Louvre.IMAGE_TYPES[key]); }//from w w w .ja v a 2 s . com } String[] array = new String[selectedTypeList.size()]; selectedTypeList.toArray(array); return array; }
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);// w w w . j av a 2 s . c o m return; } } okButton.setEnabled(false); }
From source file:com.test.weeklly.gplus.ListPeopleActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.person_list_activity); mListItems = new ArrayList<String>(); mListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, mListItems);//from w ww . j a v a 2 s . c o m mPersonListView = (ListView) findViewById(R.id.person_list); mPersonListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); mPersonListView.setAdapter(mListAdapter); mPlusClientFragment = PlusClientFragment.getPlusClientFragment(this, MomentUtil.VISIBLE_ACTIVITIES); done = (Button) findViewById(R.id.done); done.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String str = ""; SparseBooleanArray checked = mPersonListView.getCheckedItemPositions(); int size = checked.size(); // number of name-value pairs in the array for (int i = 0; i < size; i++) { int key = checked.keyAt(i); boolean value = checked.get(key); if (value) { str += "\n" + mListItems.get(key); done.setText(str); Intent returnIntent = new Intent(); returnIntent.putExtra("result", str); setResult(RESULT_OK, returnIntent); finish(); } //doSomethingWithSelectedIndex(key); } } }); }
From source file:de.vanita5.twittnuker.popup.AccountSelectorPopupWindow.java
@NonNull public long[] getSelectedAccountIds() { final long[] accountIds = new long[mGridView.getCheckedItemCount()]; final SparseBooleanArray positions = mGridView.getCheckedItemPositions(); for (int i = 0, j = positions.size(), k = 0; i < j; i++) { if (positions.valueAt(i)) { accountIds[k++] = mAdapter.getItem(positions.keyAt(i)).account_id; }//from www.j ava 2 s.co m } return accountIds; }
From source file:com.nagopy.android.mypkgs.ApplicationListFragment.java
@SuppressWarnings("unchecked") @NonNull/* w w w . j a v a 2 s . co m*/ <T> List<T> getCheckedItemList(@NonNull ListView listView) { List<T> checkedItemList = new ArrayList<>(); SparseBooleanArray checkedItemPositions = listView.getCheckedItemPositions(); for (int i = 0; i < checkedItemPositions.size(); i++) { if (checkedItemPositions.valueAt(i)) { checkedItemList.add((T) listView.getItemAtPosition(checkedItemPositions.keyAt(i))); } } return checkedItemList; }