private ActionMode checkActionMode(AppCompatActivity act, int selected) { if (selected == 0) { if (mActionMode != null) { mActionMode.finish(); mActionMode = null; } } else if (mActionMode == null) { if (act != null) // without an activity, we cannot start the action mode mActionMode = act.startSupportActionMode(mInternalCallback); } updateTitle(selected); return mActionMode; }
/** * 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; }
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Target t = (Target) mTargetAdapter.getItem(position); if (t.getType() == Target.Type.NETWORK) { if (mActionMode == null) targetAliasPrompt(t); return true; } if (mActionMode == null) { mTargetAdapter.clearSelection(); mActionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(mActionModeCallback); } mTargetAdapter.toggleSelection(position); return true; } });
private void startSupportActionModeIfNeeded() { if (choiceActionMode == null) { if (multiChoiceModeCallback == null) { throw new IllegalStateException("No callback set"); } choiceActionMode = activity.startSupportActionMode(multiChoiceModeCallback); } }
boolean createMultiSelectActionMode() { mActionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) {
void setItemChecked(final int position, final boolean checked) { if (checked) { checkedItems.add(position); } else { checkedItems.remove(position); } final RecyclerView.Adapter adapter = binding == null ? null : binding.tunnelList.getAdapter(); if (actionMode == null && !checkedItems.isEmpty() && getActivity() != null) { ((AppCompatActivity) getActivity()).startSupportActionMode(this); } else if (actionMode != null && checkedItems.isEmpty()) { actionMode.finish(); } if (adapter != null) adapter.notifyItemChanged(position); updateTitle(actionMode); }