List of usage examples for android.util SparseBooleanArray size
public int size()
From source file:org.totschnig.myexpenses.fragment.TransactionList.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override// ww w . j av a 2 s . c om protected void configureMenu11(Menu menu, int count, AbsListView lv) { super.configureMenu11(menu, count, lv); SparseBooleanArray checkedItemPositions = lv.getCheckedItemPositions(); boolean hasSplit = false, hasNotVoid = false; for (int i = 0; i < checkedItemPositions.size(); i++) { if (checkedItemPositions.valueAt(i) && isSplitAtPosition(checkedItemPositions.keyAt(i))) { hasSplit = true; break; } } for (int i = 0; i < checkedItemPositions.size(); i++) { if (checkedItemPositions.valueAt(i) && isVoidAtPosition(checkedItemPositions.keyAt(i))) { hasNotVoid = true; break; } } configureMenuInternal(menu, hasSplit, hasNotVoid, count); }
From source file:com.money.manager.ex.common.AllDataListFragment.java
private ArrayList<Integer> getTransactionIds() { final ArrayList<Integer> transIds = new ArrayList<>(); AllDataAdapter adapter = getAllDataAdapter(); if (adapter == null) return transIds; Cursor cursor = adapter.getCursor(); if (cursor != null) { // get checked items & count from the adapter, not from the list view. // List view only contains the one that was tapped, ignoring the Select All. // SparseBooleanArray positionChecked = getListView().getCheckedItemPositions(); SparseBooleanArray positionChecked = adapter.getPositionsChecked(); // int checkedItemsCount = getListView().getCheckedItemCount(); int checkedItemsCount = positionChecked.size(); for (int i = 0; i < checkedItemsCount; i++) { int position = positionChecked.keyAt(i); // This screws up the selection? // if (getListHeader() != null) // position--; if (cursor.moveToPosition(position)) { transIds.add(cursor.getInt(cursor.getColumnIndex(QueryAllData.ID))); }//from ww w . j a va 2 s .c o m } } return transIds; }
From source file:com.orange.ocara.ui.activity.ResultAuditActivity.java
@AfterViews void setUpChart() { auditChartPager.setAdapter(chartPagerAdapter); auditChartChoices.setAdapter(chartChoicesAdapter); auditChartChoices.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE); checkUniqueChoice(0);/* ww w . j av a 2 s. c om*/ auditChartPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { checkUniqueChoice(position); } @Override public void onPageScrollStateChanged(int state) { } }); auditChartChoices.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Case of Total if (position == 0) { chartPagerAdapter.setCustomStat(null); auditChartPager.setCurrentItem(0, true); checkUniqueChoice(0); return; } final SparseBooleanArray checkedItemPositions = auditChartChoices.getCheckedItemPositions(); List<Integer> selectedItems = new ArrayList<Integer>(); for (int i = 0; i < checkedItemPositions.size(); i++) { // Item position in adapter int pos = checkedItemPositions.keyAt(i); if (pos != 0 && checkedItemPositions.valueAt(i)) { selectedItems.add(pos); } } if (selectedItems.isEmpty()) { selectedItems.add(0); } // One choice checked (other than total) if (selectedItems.size() == 1) { int pos = selectedItems.get(0); chartPagerAdapter.setCustomStat(null); auditChartPager.setCurrentItem(pos, true); } else { // Multiple choices, build custom stats AccessibilityStats custom = new AccessibilityStats(); for (int i : selectedItems) { custom.plus(handicapAggregator.getStat(i - 1)); } chartPagerAdapter.setCustomStat(custom); auditChartPager.setCurrentItem(0, true); auditChartChoices.clearChoices(); for (int i : selectedItems) { auditChartChoices.setItemChecked(i, true); } } } }); }
From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java
/** * Reads the user answer of a question// w w w . j av a2 s . co m * * @param q Question to read the answer */ private void readUserAnswer(TestQuestion q) { LinearLayout testMakeList = (LinearLayout) findViewById(R.id.testMakeList); EditText textAnswer = (EditText) findViewById(R.id.testMakeEditText); List<TestAnswer> la = q.getAnswers(); int checkedListCount, selectedPos; String answerType, userAnswer; SparseBooleanArray checkedItems; answerType = q.getAnswerType(); if (answerType.equals(TestAnswer.TYPE_TEXT) || answerType.equals(TestAnswer.TYPE_INT) || answerType.equals(TestAnswer.TYPE_FLOAT)) { la.get(0).setUserAnswer(String.valueOf(textAnswer.getText())); } else if (answerType.equals(TestAnswer.TYPE_MULTIPLE_CHOICE)) { checkedItems = getCheckedItemPositions(testMakeList); checkedListCount = checkedItems.size(); for (int i = 0; i < checkedListCount; i++) { la.get(i).setUserAnswer(Utils.parseBoolString(checkedItems.get(i, false))); } } else { selectedPos = getCheckedItemPosition(testMakeList); if (selectedPos == -1) { userAnswer = ""; } else { userAnswer = la.get(selectedPos).getAnswer(); } la.get(0).setUserAnswer(userAnswer); } }
From source file:com.hippo.ehviewer.ui.scene.FavoritesScene.java
@Override @Implemented(FabLayout.OnClickFabListener.class) public void onClickSecondaryFab(FabLayout view, FloatingActionButton fab, int position) { Context context = getContext2(); if (null == context || null == mRecyclerView || null == mHelper || !mRecyclerView.isInCustomChoice()) { return;/*from w w w.j a va 2 s . c om*/ } mModifyGiList.clear(); SparseBooleanArray stateArray = mRecyclerView.getCheckedItemPositions(); for (int i = 0, n = stateArray.size(); i < n; i++) { if (stateArray.valueAt(i)) { mModifyGiList.add(mHelper.getDataAt(stateArray.keyAt(i))); } } switch (position) { case 0: { // Delete DeleteDialogHelper helper = new DeleteDialogHelper(); new AlertDialog.Builder(context).setTitle(R.string.delete_favorites_dialog_title) .setMessage(getString(R.string.delete_favorites_dialog_message, mModifyGiList.size())) .setPositiveButton(android.R.string.ok, helper).setOnCancelListener(helper).show(); break; } case 1: { // Move MoveDialogHelper helper = new MoveDialogHelper(); // First is local favorite, the other 10 is cloud favorite String[] array = new String[11]; array[0] = getString(R.string.local_favorites); System.arraycopy(Settings.getFavCat(), 0, array, 1, 10); new AlertDialog.Builder(context).setTitle(R.string.move_favorites_dialog_title).setItems(array, helper) .setOnCancelListener(helper).show(); break; } } }
From source file:org.totschnig.myexpenses.fragment.TransactionList.java
@Override public boolean dispatchCommandMultiple(int command, SparseBooleanArray positions, Long[] itemIds) { MyExpenses ctx = (MyExpenses) getActivity(); FragmentManager fm = ctx.getSupportFragmentManager(); switch (command) { case R.id.DELETE_COMMAND: boolean hasReconciled = false, hasNotVoid = false; for (int i = 0; i < positions.size(); i++) { if (positions.valueAt(i)) { mTransactionsCursor.moveToPosition(positions.keyAt(i)); CrStatus status;// ww w . j a v a2 s.c o m try { status = CrStatus.valueOf(mTransactionsCursor.getString(columnIndexCrStatus)); } catch (IllegalArgumentException ex) { status = CrStatus.UNRECONCILED; } if (status == CrStatus.RECONCILED) { hasReconciled = true; } if (status != CrStatus.VOID) { hasNotVoid = true; } if (hasNotVoid && hasReconciled) break; } } String message = getResources().getQuantityString(R.plurals.warning_delete_transaction, itemIds.length, itemIds.length); if (hasReconciled) { message += " " + getString(R.string.warning_delete_reconciled); } Bundle b = new Bundle(); b.putInt(ConfirmationDialogFragment.KEY_TITLE, R.string.dialog_title_warning_delete_transaction); b.putString(ConfirmationDialogFragment.KEY_MESSAGE, message); b.putInt(ConfirmationDialogFragment.KEY_COMMAND_POSITIVE, R.id.DELETE_COMMAND_DO); b.putInt(ConfirmationDialogFragment.KEY_COMMAND_NEGATIVE, R.id.CANCEL_CALLBACK_COMMAND); b.putInt(ConfirmationDialogFragment.KEY_POSITIVE_BUTTON_LABEL, R.string.menu_delete); if (hasNotVoid) { b.putInt(ConfirmationDialogFragment.KEY_CHECKBOX_LABEL, R.string.mark_void_instead_of_delete); } b.putLongArray(TaskExecutionFragment.KEY_OBJECT_IDS, ArrayUtils.toPrimitive(itemIds)); ConfirmationDialogFragment.newInstance(b).show(getFragmentManager(), "DELETE_TRANSACTION"); return true; /* case R.id.CLONE_TRANSACTION_COMMAND: ctx.startTaskExecution( TaskExecutionFragment.TASK_CLONE, itemIds, null, 0); break;*/ case R.id.SPLIT_TRANSACTION_COMMAND: ctx.contribFeatureRequested(ContribFeature.SPLIT_TRANSACTION, itemIds); break; case R.id.UNDELETE_COMMAND: ctx.startTaskExecution(TaskExecutionFragment.TASK_UNDELETE_TRANSACTION, itemIds, null, 0); break; //super is handling deactivation of mActionMode } return super.dispatchCommandMultiple(command, positions, itemIds); }
From source file:com.hippo.ehviewer.ui.scene.DownloadsScene.java
@Override public void onClickSecondaryFab(FabLayout view, FloatingActionButton fab, int position) { Context context = getContext2(); Activity activity = getActivity2();//from ww w . jav a 2 s .c o m EasyRecyclerView recyclerView = mRecyclerView; if (null == context || null == activity || null == recyclerView) { return; } if (0 == position) { recyclerView.checkAll(); } else { List<DownloadInfo> list = mList; if (list == null) { return; } LongList gidList = null; List<DownloadInfo> downloadInfoList = null; boolean collectGid = position == 1 || position == 2 || position == 3; // Start, Stop, Delete boolean collectDownloadInfo = position == 3 || position == 4; // Delete or Move if (collectGid) { gidList = new LongList(); } if (collectDownloadInfo) { downloadInfoList = new LinkedList<>(); } SparseBooleanArray stateArray = recyclerView.getCheckedItemPositions(); for (int i = 0, n = stateArray.size(); i < n; i++) { if (stateArray.valueAt(i)) { DownloadInfo info = list.get(stateArray.keyAt(i)); if (collectDownloadInfo) { downloadInfoList.add(info); } if (collectGid) { gidList.add(info.gid); } } } switch (position) { case 1: { // Start Intent intent = new Intent(activity, DownloadService.class); intent.setAction(DownloadService.ACTION_START_RANGE); intent.putExtra(DownloadService.KEY_GID_LIST, gidList); activity.startService(intent); // Cancel check mode recyclerView.outOfCustomChoiceMode(); break; } case 2: { // Stop if (null != mDownloadManager) { mDownloadManager.stopRangeDownload(gidList); } // Cancel check mode recyclerView.outOfCustomChoiceMode(); break; } case 3: { // Delete CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(context, getString(R.string.download_remove_dialog_message_2, gidList.size()), getString(R.string.download_remove_dialog_check_text), Settings.getRemoveImageFiles()); DeleteRangeDialogHelper helper = new DeleteRangeDialogHelper(downloadInfoList, gidList, builder); builder.setTitle(R.string.download_remove_dialog_title) .setPositiveButton(android.R.string.ok, helper).show(); break; } case 4: {// Move List<DownloadLabel> labelRawList = EhApplication.getDownloadManager(context).getLabelList(); List<String> labelList = new ArrayList<>(labelRawList.size() + 1); labelList.add(getString(R.string.default_download_label_name)); for (int i = 0, n = labelRawList.size(); i < n; i++) { labelList.add(labelRawList.get(i).getLabel()); } String[] labels = labelList.toArray(new String[labelList.size()]); MoveDialogHelper helper = new MoveDialogHelper(labels, downloadInfoList); new AlertDialog.Builder(context).setTitle(R.string.download_move_dialog_title) .setItems(labels, helper).show(); break; } } } }
From source file:org.totschnig.myexpenses.fragment.CategoryList.java
@Override protected void configureMenu11(Menu menu, int count, AbsListView lv) { super.configureMenu11(menu, count, lv); if (expandableListSelectionType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions(); boolean hasChildren = false; for (int i = 0; i < checkedItemPositions.size(); i++) { if (checkedItemPositions.valueAt(i)) { int position = checkedItemPositions.keyAt(i); long pos = mListView.getExpandableListPosition(position); int groupPos = ExpandableListView.getPackedPositionGroup(pos); if (hasChildren(groupPos)) { hasChildren = true;/*from w w w . ja v a 2 s.c om*/ break; } } } configureMenuInternal(menu, hasChildren); } }
From source file:com.todotxt.todotxttouch.TodoTxtTouch.java
private ArrayList<Task> getCheckedTasks() { ArrayList<Task> result = new ArrayList<Task>(); SparseBooleanArray checkedItems = getListView().getCheckedItemPositions(); for (int i = 0; i < checkedItems.size(); i++) { if (checkedItems.valueAt(i)) { result.add(m_adapter.getItem(checkedItems.keyAt(i))); }//w w w . j a v a 2 s . c o m } return result; }
From source file:org.totschnig.myexpenses.fragment.CategoryList.java
@Override public boolean dispatchCommandMultiple(int command, SparseBooleanArray positions, Long[] itemIds) { ManageCategories ctx = (ManageCategories) getActivity(); ArrayList<Long> idList; switch (command) { case R.id.DELETE_COMMAND: int mappedTransactionsCount = 0, mappedTemplatesCount = 0, hasChildrenCount = 0; idList = new ArrayList<>(); for (int i = 0; i < positions.size(); i++) { Cursor c;//w w w.j a v a 2 s .c om if (positions.valueAt(i)) { boolean deletable = true; int position = positions.keyAt(i); long pos = mListView.getExpandableListPosition(position); int type = ExpandableListView.getPackedPositionType(pos); int group = ExpandableListView.getPackedPositionGroup(pos), child = ExpandableListView.getPackedPositionChild(pos); if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { c = mAdapter.getChild(group, child); c.moveToPosition(child); } else { c = mGroupCursor; c.moveToPosition(group); } long itemId = c.getLong(c.getColumnIndex(KEY_ROWID)); Bundle extras = ctx.getIntent().getExtras(); if ((extras != null && extras.getLong(KEY_ROWID) == itemId) || c.getInt(c.getColumnIndex(DatabaseConstants.KEY_MAPPED_TRANSACTIONS)) > 0) { mappedTransactionsCount++; deletable = false; } else if (c.getInt(c.getColumnIndex(DatabaseConstants.KEY_MAPPED_TEMPLATES)) > 0) { mappedTemplatesCount++; deletable = false; } if (deletable) { if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP && c.getInt(c.getColumnIndex(KEY_CHILD_COUNT)) > 0) { hasChildrenCount++; } idList.add(itemId); } } } if (!idList.isEmpty()) { Long[] objectIds = idList.toArray(new Long[idList.size()]); if (hasChildrenCount > 0) { MessageDialogFragment .newInstance(R.string.dialog_title_warning_delete_main_category, getResources().getQuantityString(R.plurals.warning_delete_main_category, hasChildrenCount, hasChildrenCount), new MessageDialogFragment.Button(android.R.string.yes, R.id.DELETE_COMMAND_DO, objectIds), null, new MessageDialogFragment.Button(android.R.string.no, R.id.CANCEL_CALLBACK_COMMAND, null)) .show(ctx.getSupportFragmentManager(), "DELETE_CATEGORY"); } else { ctx.dispatchCommand(R.id.DELETE_COMMAND_DO, objectIds); } } if (mappedTransactionsCount > 0 || mappedTemplatesCount > 0) { String message = ""; if (mappedTransactionsCount > 0) message += getResources().getQuantityString(R.plurals.not_deletable_mapped_transactions, mappedTransactionsCount, mappedTransactionsCount); if (mappedTemplatesCount > 0) message += getResources().getQuantityString(R.plurals.not_deletable_mapped_templates, mappedTemplatesCount, mappedTemplatesCount); Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show(); } return true; case R.id.SELECT_COMMAND_MULTIPLE: ArrayList<String> labelList = new ArrayList<>(); for (int i = 0; i < positions.size(); i++) { Cursor c; if (positions.valueAt(i)) { int position = positions.keyAt(i); long pos = mListView.getExpandableListPosition(position); int type = ExpandableListView.getPackedPositionType(pos); int group = ExpandableListView.getPackedPositionGroup(pos), child = ExpandableListView.getPackedPositionChild(pos); if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { c = mAdapter.getChild(group, child); c.moveToPosition(child); } else { c = mGroupCursor; c.moveToPosition(group); } labelList.add(c.getString(c.getColumnIndex(KEY_LABEL))); } } Intent intent = new Intent(); intent.putExtra(KEY_CATID, ArrayUtils.toPrimitive(itemIds)); intent.putExtra(KEY_LABEL, TextUtils.join(",", labelList)); ctx.setResult(ManageCategories.RESULT_FIRST_USER, intent); ctx.finish(); return true; case R.id.MOVE_COMMAND: final Long[] excludedIds; final boolean inGroup = expandableListSelectionType == ExpandableListView.PACKED_POSITION_TYPE_GROUP; if (inGroup) { excludedIds = itemIds; } else { idList = new ArrayList<>(); for (int i = 0; i < positions.size(); i++) { if (positions.valueAt(i)) { int position = positions.keyAt(i); long pos = mListView.getExpandableListPosition(position); int group = ExpandableListView.getPackedPositionGroup(pos); mGroupCursor.moveToPosition(group); idList.add(mGroupCursor.getLong(mGroupCursor.getColumnIndex(KEY_ROWID))); } } excludedIds = idList.toArray(new Long[idList.size()]); } Bundle args = new Bundle(3); args.putBoolean(SelectMainCategoryDialogFragment.KEY_WITH_ROOT, !inGroup); args.putLongArray(SelectMainCategoryDialogFragment.KEY_EXCLUDED_ID, ArrayUtils.toPrimitive(excludedIds)); args.putLongArray(TaskExecutionFragment.KEY_OBJECT_IDS, ArrayUtils.toPrimitive(itemIds)); SelectMainCategoryDialogFragment.newInstance(args).show(getFragmentManager(), "SELECT_TARGET"); return true; } return false; }