List of usage examples for android.util SparseBooleanArray valueAt
public boolean valueAt(int index)
0...size()-1
, returns the value from the index
th key-value mapping that this SparseBooleanArray stores. From source file:com.vmihalachi.turboeditor.fragment.NavigationDrawerListFragment.java
/** * {@inheritDoc}// www . ja va2 s.c o m */ @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.im_remove: // File paths saved in preferences String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity()); // We get the checked positions SparseBooleanArray checkedItems = getListView().getCheckedItemPositions(); // If we have some checked positions if (checkedItems != null) { for (int i = 0; i < checkedItems.size(); i++) { // check if the value is checked if (checkedItems.valueAt(i)) { // remove the checked path, but don't refresh the list removePath(savedPaths[checkedItems.keyAt(i)], false); } } // In the end refresh the list refreshList(); } // Close the action mode actionMode.finish(); return true; default: return false; } }
From source file:org.spinsuite.bchat.view.FV_ThreadIndex.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override/*from w ww .jav a 2 s . c o m*/ public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { // Capture total checked items final int checkedCount = getListView().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_Adapter.toggleSelection(position); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.action_delete: SparseBooleanArray selectedItems = m_Adapter.getSelectedItems(); String[] ids = new String[selectedItems.size()]; for (int i = (selectedItems.size() - 1); i >= 0; i--) { if (selectedItems.valueAt(i)) { DisplayBChatThreadListItem selectedItem = m_Adapter.getItem(selectedItems.keyAt(i)); // Add Value ids[i] = selectedItem.getSPS_BC_Request_UUID(); // Remove Item m_Adapter.remove(selectedItem); } } // Delete Records in DB if (ids.length > 0) { BCMessageHandle.getInstance(m_ctx).deleteRequest(ids); } mode.finish(); return true; default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.bc_thread_list_selected, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { m_Adapter.removeSelection(); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); }
From source file:com.bitants.wally.fragments.SavedImagesFragment.java
@Override public boolean onActionItemClicked(final ActionMode mode, MenuItem item) { if (R.id.menu_delete == item.getItemId()) { int size = 0; SparseBooleanArray checkedItems = recyclerSavedImagesAdapter.getSelectedItems(); for (int i = 0; i < checkedItems.size(); i++) { if (checkedItems.valueAt(i)) { size++;/*from w w w.j av a 2 s. co m*/ } } String quantityString = getResources().getQuantityString(R.plurals.wallpapers, size); String title = String.format(getString(R.string.dialog_delete_title), quantityString); FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager != null) { final MaterialDialogFragment materialDialogFragment = new MaterialDialogFragment(); materialDialogFragment.setPrimaryColor(getResources().getColor(R.color.Dialog_Button_Delete)); materialDialogFragment.setTitle(title); materialDialogFragment.setPositiveButton(R.string.dialog_delete_positive, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { SparseBooleanArray checkedItems = recyclerSavedImagesAdapter.getSelectedItems(); for (int index = 0; index < checkedItems.size(); index++) { if (checkedItems.valueAt(index)) { Uri contentUri = recyclerSavedImagesAdapter .getItem(checkedItems.keyAt(index)); getActivity().getContentResolver().delete(contentUri, null, null); } } mode.finish(); getImages(0, null); getActivity().sendBroadcast(new Intent(FileReceiver.GET_FILES)); } }); materialDialogFragment.setNegativeButton(R.string.dialog_delete_negative, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { materialDialogFragment.dismiss(); } }); materialDialogFragment.show(fragmentManager, MaterialDialogFragment.TAG); } } return false; }
From source file:com.musenkishi.wally.fragments.SavedImagesFragment.java
@Override public boolean onActionItemClicked(final ActionMode mode, MenuItem item) { if (R.id.menu_delete == item.getItemId()) { int size = 0; SparseBooleanArray checkedItems = recyclerSavedImagesAdapter.getSelectedItems(); for (int i = 0; i < checkedItems.size(); i++) { if (checkedItems.valueAt(i)) { size++;/* w w w . j a v a2 s . c om*/ } } String quantityString = getResources().getQuantityString(R.plurals.wallpapers, size); String title = String.format(getString(R.string.dialog_delete_title), quantityString); FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager != null) { final MaterialDialogFragment materialDialogFragment = new MaterialDialogFragment(); materialDialogFragment.setPrimaryColor(getResources().getColor(R.color.Dialog_Button_Delete)); materialDialogFragment.setTitle(title); materialDialogFragment.setPositiveButton(R.string.dialog_delete_positive, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { SparseBooleanArray checkedItems = recyclerSavedImagesAdapter.getSelectedItems(); for (int index = 0; index < checkedItems.size(); index++) { if (checkedItems.valueAt(index)) { Uri contentUri = recyclerSavedImagesAdapter .getItem(checkedItems.keyAt(index)); getActivity().getContentResolver().delete(contentUri, null, null); } } mode.finish(); getImages(0, null); getActivity().sendBroadcast(new Intent(FileChangeReceiver.FILES_CHANGED)); } }); materialDialogFragment.setNegativeButton(R.string.dialog_delete_negative, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { materialDialogFragment.dismiss(); } }); materialDialogFragment.show(fragmentManager, MaterialDialogFragment.TAG); } } return false; }
From source file:com.android.contacts.SimImportFragment.java
private void updateToolbarWithCurrentSelections() { // The ListView keeps checked state for items that are disabled but we only want to // consider items that don't exist in the current account when updating the toolbar int importableCount = 0; final SparseBooleanArray checked = mListView.getCheckedItemPositions(); for (int i = 0; i < checked.size(); i++) { if (checked.valueAt(i) && !mAdapter.existsInCurrentAccount(checked.keyAt(i))) { importableCount++;//www . j a v a2 s . c o m } } if (importableCount == 0) { mImportButton.setVisibility(View.GONE); mToolbar.setTitle(R.string.sim_import_title_none_selected); } else { mToolbar.setTitle(String.valueOf(importableCount)); mImportButton.setVisibility(View.VISIBLE); } }
From source file:de.vanita5.twittnuker.activity.support.DraftsActivity.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case MENU_DELETE: { final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment(); final Bundle args = new Bundle(); args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds()); f.setArguments(args);//from w ww .j a v a2s. c o m f.show(getSupportFragmentManager(), "delete_drafts_confirm"); break; } case MENU_SEND: { final Cursor c = mAdapter.getCursor(); if (c == null || c.isClosed()) return false; final SparseBooleanArray checked = mListView.getCheckedItemPositions(); final List<DraftItem> list = new ArrayList<DraftItem>(); final DraftItem.CursorIndices indices = new DraftItem.CursorIndices(c); for (int i = 0, j = checked.size(); i < j; i++) { if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) { list.add(new DraftItem(c, indices)); } } if (sendDrafts(list)) { final Where where = Where.in(new Column(Drafts._ID), new RawItemArray(mListView.getCheckedItemIds())); mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null); } break; } default: { return false; } } mode.finish(); return true; }
From source file:org.getlantern.firetweet.activity.support.DraftsActivity.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case MENU_DELETE: { final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment(); final Bundle args = new Bundle(); args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds()); f.setArguments(args);//w w w . j a v a 2s.com f.show(getSupportFragmentManager(), "delete_drafts_confirm"); break; } case MENU_SEND: { final Cursor c = mAdapter.getCursor(); if (c == null || c.isClosed()) return false; final SparseBooleanArray checked = mListView.getCheckedItemPositions(); final List<DraftItem> list = new ArrayList<>(); final DraftItem.CursorIndices indices = new DraftItem.CursorIndices(c); for (int i = 0, j = checked.size(); i < j; i++) { if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) { list.add(new DraftItem(c, indices)); } } if (sendDrafts(list)) { final Expression where = Expression.in(new Column(Drafts._ID), new RawItemArray(mListView.getCheckedItemIds())); mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null); } break; } default: { return false; } } mode.finish(); return true; }
From source file:au.org.ala.fielddata.mobile.ViewSavedRecordsActivity.java
private int countSelected() { int count = 0; SparseBooleanArray selected = getListView().getCheckedItemPositions(); for (int i = 0; i < selected.size(); i++) { // Ignore the first item as it is help text. if (selected.keyAt(i) > 0) { if (selected.valueAt(i)) { count++;// w w w .j ava 2 s .c o m } } } return count; }
From source file:com.serenegiant.aceparrot.ScriptFragment.java
/** * ???/* ww w. ja va 2 s. c om*/ * @return */ private ScriptHelper.ScriptRec[] getSelectedScripts() { ScriptHelper.ScriptRec[] result = null; if (mScriptListView != null) { final SparseBooleanArray ids = mScriptListView.getCheckedItemPositions(); final int n = ids != null ? ids.size() : 0; if (n > 0) { final List<ScriptHelper.ScriptRec> list = new ArrayList<ScriptHelper.ScriptRec>(); for (int i = 0; i < n; i++) { if (ids.valueAt(i)) { final Object obj = mScriptListView.getItemAtPosition(ids.keyAt(i)); if (obj instanceof ScriptHelper.ScriptRec) { list.add((ScriptHelper.ScriptRec) obj); } } } final int m = list.size(); if (m > 0) { result = new ScriptHelper.ScriptRec[m]; list.toArray(result); } } } return result; }
From source file:org.mariotaku.twidere.fragment.support.DraftsFragment.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case MENU_DELETE: { final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment(); final Bundle args = new Bundle(); args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds()); f.setArguments(args);/* w w w.j a v a 2 s .c o m*/ f.show(getChildFragmentManager(), "delete_drafts_confirm"); break; } case MENU_SEND: { final Cursor c = mAdapter.getCursor(); if (c == null || c.isClosed()) return false; final SparseBooleanArray checked = mListView.getCheckedItemPositions(); final List<DraftItem> list = new ArrayList<>(); final DraftItem.CursorIndices indices = new DraftItem.CursorIndices(c); for (int i = 0, j = checked.size(); i < j; i++) { if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) { list.add(new DraftItem(c, indices)); } } if (sendDrafts(list)) { final Expression where = Expression.in(new Column(Drafts._ID), new RawItemArray(mListView.getCheckedItemIds())); mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null); } break; } default: { return false; } } mode.finish(); return true; }