List of usage examples for android.util SparseBooleanArray keyAt
public int keyAt(int index)
0...size()-1
, returns the key from the index
th key-value mapping that this SparseBooleanArray stores. From source file:org.dvbviewer.controller.ui.fragments.RecordingList.java
@Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: Log.i(RecordingList.class.getSimpleName(), "onClick"); SparseBooleanArray checkedPositions = getListView().getCheckedItemPositions(); Log.i(RecordingList.class.getSimpleName(), "items selected: " + checkedPositions.size()); if (checkedPositions != null && checkedPositions.size() > 0) { int size = checkedPositions.size(); RecordingDeleter deleter = new RecordingDeleter(this); List<Recording> recordings = new ArrayList<Recording>(); for (int i = 0; i < size; i++) { if (checkedPositions.valueAt(i)) { recordings.add(mAdapter.getItem(checkedPositions.keyAt(i))); }// www . ja va 2 s . c o m } Recording[] array = new Recording[recordings.size()]; deleter.execute(recordings.toArray(array)); } mode.finish(); break; case DialogInterface.BUTTON_NEGATIVE: // No button clicked break; } }
From source file:com.aimfire.gallery.ThumbsFragment.java
/** * delete current file//www . j a v a 2 s . co m */ private void deleteFiles() { final SparseBooleanArray checkedItems = mGridView.getCheckedItemPositions(); ArrayList<File> mediaFiles = new ArrayList<File>(); for (int i = 0; i < checkedItems.size(); i++) { final boolean isChecked = checkedItems.valueAt(i); if (isChecked) { int position = checkedItems.keyAt(i); File file = new File(mMediaList.get(position)); if (file.exists()) { mediaFiles.add(file); } } } final ArrayList<File> mediaFilesToDelete = mediaFiles; AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle); alertDialogBuilder.setTitle(R.string.delete); alertDialogBuilder.setMessage(mediaFilesToDelete.size() + " " + getString(R.string.warning_items_delete)); alertDialogBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { /* * delete sbs/cvr, thumbnail, preview and exported files */ for (File mediaFile : mediaFilesToDelete) { String mediaFilePath = mediaFile.getAbsolutePath(); MediaScanner.deleteFile(mediaFilePath); } updateGridView(null, mGridView.getFirstVisiblePosition()); } }); alertDialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //do nothing } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }
From source file:org.spinsuite.bchat.view.FV_Thread.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (m_view != null) return m_view; // Inflate/* w w w . j a v a2s .co m*/ m_view = inflater.inflate(R.layout.v_business_chat_thread, container, false); // Scroll lv_Thread = (ListView) m_view.findViewById(R.id.lv_Thread); et_Message = (EditText) m_view.findViewById(R.id.et_Message); ib_Send = (ImageButton) m_view.findViewById(R.id.ib_Send); // Listener ib_Send.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (et_Message.getText() == null || et_Message.getText().toString().trim().length() == 0) return; // Send Message sendMessage(null); } }); // Hide Separator lv_Thread.setDividerHeight(0); lv_Thread.setDivider(null); lv_Thread.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); lv_Thread.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3) { DisplayBChatThreadItem item = (DisplayBChatThreadItem) m_ThreadAdapter.getItem(position); // Show Image String fileName = item.getFileName(); if (fileName != null && fileName.length() > 0) { String m_FilePath = Env.getBC_IMG_DirectoryPathName(m_ctx); File file = new File(m_FilePath + File.separator + fileName); // Show AttachmentHandler.showAttachment(m_ctx, Uri.fromFile(file)); } } }); // lv_Thread.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { // Capture total checked items final int checkedCount = lv_Thread.getCheckedItemCount(); // Set the CAB title according to total checked items mode.setTitle(checkedCount + " " + getString(R.string.BChat_Selected)); // Calls toggleSelection method from ListViewAdapter Class m_ThreadAdapter.toggleSelection(position); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.action_delete: SparseBooleanArray selectedItems = m_ThreadAdapter.getSelectedItems(); StringBuffer inClause = new StringBuffer(); for (int i = (selectedItems.size() - 1); i >= 0; i--) { if (selectedItems.valueAt(i)) { DisplayBChatThreadItem selectedItem = m_ThreadAdapter.getItem(selectedItems.keyAt(i)); // Add Separator if (inClause.length() > 0) { inClause.append(", "); } // Add Value inClause.append("'").append(selectedItem.getSPS_BC_Message_UUID()).append("'"); // Remove Item m_ThreadAdapter.remove(selectedItem); } } // Delete Records in DB if (inClause.length() > 0) { BCMessageHandle.getInstance(m_ctx).deleteMessage(m_Request, "SPS_BC_Message_UUID IN(" + inClause.toString() + ")"); } mode.finish(); return true; case R.id.action_copy: selectedItems = m_ThreadAdapter.getSelectedItems(); boolean justOne = selectedItems.size() == 1; StringBuffer text = new StringBuffer(); for (int i = (selectedItems.size() - 1); i >= 0; i--) { if (selectedItems.valueAt(i)) { DisplayBChatThreadItem selectedItem = m_ThreadAdapter.getItem(selectedItems.keyAt(i)); // Valid File if (selectedItem.getFileName() != null) continue; // Add New Line if (text.length() > 0) { text.append(Env.NL); } // Add to Text if (justOne) { text.append(selectedItem.getText()); } else { text.append(selectedItem.getCopy()); } } } // Add To Clipboard if (text.length() > 0) { Env.setClipboardText(m_ctx, text.toString()); } mode.finish(); return true; default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.bc_thread_selected, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { m_ThreadAdapter.removeSelection(); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); // Return return m_view; }
From source file:org.totschnig.myexpenses.fragment.TransactionList.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override//ww w . j av a 2 s . c o m 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))); }//w w w . j a v a 2s . 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);//w w w . j a v a2 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: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;/*w w w . ja va 2 s.c o m*/ } 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 av a 2 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: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 www . java 2s . c o m break; } } } configureMenuInternal(menu, hasChildren); } }
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 w ww . ja va2 s . com 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; } } } }