/** * select's a provided item, this won't notify the adapter * * @param item the item to select * @param considerSelectableFlag true if the select method should not select an item if its not selectable */ public void select(Item item, boolean considerSelectableFlag) { if (considerSelectableFlag && !item.isSelectable()) { return; } item.withSetSelected(true); if (mSelectionListener != null) { mSelectionListener.onSelectionChanged(item, true); } }
/** * implements the basic behavior of a CAB and multi select behavior onLongClick * * @param act the current Activity * @param position the position of the clicked item * @return the initialized ActionMode or null if nothing was done */ public ActionMode onLongClick(AppCompatActivity act, int position) { if (mActionMode == null && mFastAdapter.getItem(position).isSelectable()) { //may check if actionMode is already displayed mActionMode = act.startSupportActionMode(mInternalCallback); //we have to select this on our own as we will consume the event mSelectExtension.select(position); // update title checkActionMode(act, 1); //we consume this event so the normal onClick isn't called anymore return mActionMode; } return mActionMode; }
/** * implements the basic behavior of a CAB and multi select behavior, * including logics if the clicked item is collapsible * * @param act the current Activity * @param item the current item * @return null if nothing was done, or a boolean to inform if the event was consumed */ public Boolean onClick(AppCompatActivity act, IItem item) { //if we are current in CAB mode, and we remove the last selection, we want to finish the actionMode if (mActionMode != null && (mSelectExtension.getSelectedItems().size() == 1) && item.isSelected()) { mActionMode.finish(); mSelectExtension.deselect(); return true; } if (mActionMode != null) { // calculate the selection count for the action mode // because current selection is not reflecting the future state yet! int selected = mSelectExtension.getSelectedItems().size(); if (item.isSelected()) selected--; else if (item.isSelectable()) selected++; checkActionMode(act, selected); } return null; }
/** * will take care to save the long pressed index * or to select all items in the range between the current long pressed item and the last long pressed item * * @param index the index of the long pressed item * @param selectItem true, if the item at the index should be selected, false if this was already done outside of this helper or is not desired * @return true, if the long press was handled */ public boolean onLongClick(int index, boolean selectItem) { if (mLastLongPressIndex == null) { // we only consider long presses on not selected items if (mFastAdapter.getAdapterItem(index).isSelectable()) { mLastLongPressIndex = index; // we select this item as well if (selectItem) mFastAdapter.select(index); if (mActionModeHelper != null) mActionModeHelper.checkActionMode(null); // works with null as well, as the ActionMode is active for sure! return true; } } else if (mLastLongPressIndex != index) { // select all items in the range between the two long clicks selectRange(mLastLongPressIndex, index, true); // reset the index mLastLongPressIndex = null; } return false; }
if (header.isExpanded()) { for (int i = 0; i < subItems; i++) { if (((IItem) header.getSubItems().get(i)).isSelectable()) { SelectExtension extension = (SelectExtension) adapter.getExtension(SelectExtension.class); if (extension != null) { if (((IItem) header.getSubItems().get(i)).isSelectable()) { ((IItem) header.getSubItems().get(i)).withSetSelected(select);
if (!item.isSelectable()) { return;
/** * selects an item and remembers its position in the selections list * * @param adapter adapter holding this item (or it's parent) * @param item the item to select * @param position the global position (or < 0 if the item is not displayed) * @param fireEvent true if the onClick listener should be called * @param considerSelectableFlag true if the select method should not select an item if its not selectable */ public void select(IAdapter<Item> adapter, Item item, int position, boolean fireEvent, boolean considerSelectableFlag) { if (considerSelectableFlag && !item.isSelectable()) { return; } item.withSetSelected(true); mFastAdapter.notifyItemChanged(position); if (mSelectionListener != null) mSelectionListener.onSelectionChanged(item, true); if (mFastAdapter.getOnClickListener() != null && fireEvent) { mFastAdapter.getOnClickListener().onClick(null, adapter, item, position); } }
for (int i = from; i <= to; i++) { item = mFastAdapter.getAdapterItem(i); if (item.isSelectable()) { if (select) { mFastAdapter.select(i);