List of usage examples for android.view ActionMode finish
public abstract void finish();
From source file:com.simas.vc.nav_drawer.NavCAB.java
@Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.nav_contextual_action_check_all: { int headerCount = getListView().getHeaderViewsCount(); int childrenCount = getListView().getCount() - getListView().getFooterViewsCount(); // Headers (at the top) and footers (at the bottom) will be skipped with this loop for (int i = headerCount; i < childrenCount; ++i) { getListView().setItemChecked(i, true); }//w w w. j a v a 2 s. co m } return true; case R.id.nav_contextual_action_copy: { // Clone items and add to a list List<NavItem> items = new ArrayList<>(); for (int position : checkedPositions) { int adapterItemPos = position - getListView().getHeaderViewsCount(); // Create a semi-deep item copy NavItem navItem = new NavItem(getAdapter().getItem(adapterItemPos)); items.add(navItem); mModifiedDataSet = true; } // Add the list to other items in adapter MainActivity.sItems.addAll(items); mode.finish(); // Invoke onDestroyActionMode return true; } case R.id.nav_contextual_action_remove: { // Sort checked item positions in descending order Collections.sort(checkedPositions, new Comparator<Integer>() { @Override public int compare(Integer lhs, Integer rhs) { return rhs - lhs; } }); // Remove positions from the end of the adapter list for (int position : checkedPositions) { int adapterItemPos = position - getListView().getHeaderViewsCount(); MainActivity.sItems.remove(adapterItemPos); mModifiedDataSet = true; } mode.finish(); // Invoke onDestroyActionMode return true; } default: return false; } }
From source file:com.tweetlanes.android.core.view.BaseLaneActivity.java
void finishCurrentActionMode() { if (mCurrentActionMode != null) { // This is messy, but to prevent a circular loop, clear // mCurrentActionMode before calling .finish() ActionMode curr = mCurrentActionMode; mCurrentActionMode = null;// w ww . ja v a2 s .c om curr.finish(); } }
From source file:com.veniosg.dir.android.fragment.SideNavFragment.java
private void setListChoiceListener() { getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override//w w w .ja v a2s. c om public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) { menu.clear(); mode.getMenuInflater().inflate(R.menu.cab_bookmarks, menu); if (getListView().getCheckedItemCount() != 1) { menu.removeItem(R.id.menu_open_parent); } return true; } @Override public void onDestroyActionMode(android.view.ActionMode mode) { setStatusBarColour(getActivity(), false); } @Override public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) { setStatusBarColour(getActivity(), true); return true; } @Override public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.menu_delete: long[] ids = getListView().getCheckedItemIds(); for (long id : ids) { getListView().getContext().getContentResolver().delete(BookmarkProvider.CONTENT_URI, BookmarkProvider._ID + "=?", new String[] { "" + id }); } mode.finish(); return true; case R.id.menu_open_parent: int pos = 0; SparseBooleanArray checked = getListView().getCheckedItemPositions(); for (int i = 0; i < getListView().getCount(); i++) { if (checked.get(i)) { pos = i; } } String path = ((Cursor) getListAdapter().getItem(pos)).getString(2); ((BookmarkContract) getActivity()).onBookmarkSelected(new File(path).getParent()); mode.finish(); return true; } return false; } @Override public void onItemCheckedStateChanged(android.view.ActionMode mode, int position, long id, boolean checked) { if (getListView().getCheckedItemCount() != 0) { mode.setTitle(getListView().getCheckedItemCount() + " " + getString(R.string.selected)); // Force actions' refresh mode.invalidate(); } } }); getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); }
From source file:com.shafiq.mytwittle.view.BaseLaneActivity.java
protected void finishCurrentActionMode() { if (mCurrentActionMode != null) { // This is messy, but to prevent a circular loop, clear // mCurrentActionMode before calling .finish() ActionMode curr = mCurrentActionMode; mCurrentActionMode = null;/*w ww .j av a 2s. c o m*/ curr.finish(); } }
From source file:com.nearnotes.NoteList.java
@Override public void onStart() { super.onStart(); mCallback.setActionItems(NOTE_LIST); mSelectedIds = new ArrayList<Long>(); mDbHelper = new NotesDbAdapter(getActivity()); // Create new custom database class for sqlite and pass the current context as a variable mDbHelper.open(); // Gets the writable database Bundle bundle = getArguments();// w w w.ja v a2 s . co m mLongitude = bundle.getDouble("longitude"); mLatitude = bundle.getDouble("latitude"); fillData(mLongitude, mLatitude); mListView = getListView(); getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() { private int nr = 0; @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { mActionModeFlag = false; Log.e("onDestroyActionMode", "onDestroyActionMode"); mAdapter.clearSelection(); } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mActionModeFlag = true; nr = 0; MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.contextual_menu, menu); return true; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.context_delete: for (Long s : mSelectedIds) { mDbHelper.deleteNote(s); if (mDbHelper.fetchSetting() == s) { mDbHelper.removeSetting(); } } nr = 0; mAdapter.clearSelection(); fillData(mLongitude, mLatitude); mode.finish(); return true; case R.id.context_select_all: SparseBooleanArray checkSparse = getListView().getCheckedItemPositions(); for (int i = 0; i < mListView.getCount(); i++) { if (!checkSparse.get(i)) { getListView().setItemChecked(i, true); } } return true; } return false; } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { Log.e("checked", String.valueOf(checked) + " id: " + String.valueOf(id) + " position: " + String.valueOf(position)); if (checked) { nr++; mSelectedIds.add(id); mAdapter.setNewSelection(position, checked); } else { mSelectedIds.remove(id); nr--; mAdapter.removeSelection(position); } TextView tv = (TextView) getActivity().getLayoutInflater().inflate(R.layout.contextual_title, null); tv.setText(nr + " selected"); mode.setCustomView(tv); } }); getListView().setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) { getListView().setItemChecked(position, !mAdapter.isPositionChecked(position)); return false; } }); }
From source file:com.miz.mizuu.fragments.TvShowSeasonsFragment.java
public void onViewCreated(View v, Bundle savedInstanceState) { super.onViewCreated(v, savedInstanceState); mAdapter = new ImageAdapter(mContext); mProgressBar = (ProgressBar) v.findViewById(R.id.progress); mGridView = (GridView) v.findViewById(R.id.gridView); mGridView.setEmptyView(v.findViewById(R.id.progress)); mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL); mGridView.setAdapter(mAdapter);// w ww .j ava2 s. c o m mGridView.setColumnWidth(mImageThumbSize); // Calculate the total column width to set item heights by factor 1.5 mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (mAdapter.getNumColumns() == 0) { final int numColumns = (int) Math .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing)); if (numColumns > 0) { mAdapter.setNumColumns(numColumns); } } } }); mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // Update the selected index variable mSelectedIndex = arg2; // Show the episode browser Activity for the given season getActivity().startActivityForResult(IntentUtils.getTvShowSeasonIntent(getActivity(), mShowId, mItems.get(arg2).getSeason(), mItems.get(arg2).getEpisodeCount(), mToolbarColor), 0); } }); mGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { mGridView.setItemChecked(position, true); return true; } }); mGridView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.seasons_contextual, menu); mContextualActionBarEnabled = true; return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return true; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.watched: changeWatchedStatus(true, new HashSet<Integer>(mCheckedSeasons)); break; case R.id.unwatched: changeWatchedStatus(false, new HashSet<Integer>(mCheckedSeasons)); break; case R.id.remove: removeSelectedSeasons(new HashSet<Integer>(mCheckedSeasons)); break; } mode.finish(); return true; } @Override public void onDestroyActionMode(ActionMode mode) { mContextualActionBarEnabled = false; mCheckedSeasons.clear(); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { mCheckedSeasons.add(mItems.get(position).getSeason()); } else { mCheckedSeasons.remove(mItems.get(position).getSeason()); } int count = mCheckedSeasons.size(); mode.setTitle( count + " " + getResources().getQuantityString(R.plurals.seasons_selected, count, count)); // Nasty hack to update the selected items highlight... mAdapter.notifyDataSetChanged(); } }); // The layout has been created - let's load the data loadSeasons(); }
From source file:org.thialfihar.android.apg.ui.KeyListPublicFragment.java
/** * Show dialog to delete key/*from w w w.ja v a2 s. c o m*/ * * @param keyRingRowIds */ @TargetApi(11) public void showDeleteKeyDialog(final ActionMode mode, long[] keyRingRowIds) { // Message is received after key is deleted Handler returnHandler = new Handler() { @Override public void handleMessage(Message message) { if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) { Bundle returnData = message.getData(); if (returnData != null && returnData.containsKey(DeleteKeyDialogFragment.MESSAGE_NOT_DELETED)) { ArrayList<String> notDeleted = returnData .getStringArrayList(DeleteKeyDialogFragment.MESSAGE_NOT_DELETED); String notDeletedMsg = ""; for (String userId : notDeleted) { notDeletedMsg += userId + "\n"; } Toast.makeText(getActivity(), getString(R.string.error_can_not_delete_contacts, notDeletedMsg) + getResources() .getQuantityString(R.plurals.error_can_not_delete_info, notDeleted.size()), Toast.LENGTH_LONG).show(); mode.finish(); } } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, keyRingRowIds, Id.type.public_key); deleteKeyDialog.show(getActivity().getSupportFragmentManager(), "deleteKeyDialog"); }
From source file:org.mariotaku.twidere.activity.support.DraftsActivity.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case MENU_DELETE: { // TODO confim dialog and image removal final Where where = Where.in(new Column(Drafts._ID), new RawItemArray(mListView.getCheckedItemIds())); mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null); break;/*from w w w .j a v a 2 s . c om*/ } 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:simonlang.coastdove.usagestatistics.ui.app_details.AppUsageDataListFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); this.loaderID = 100; ListView listView = getListView(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override// w w w . ja v a2 s . c om public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { listAdapter().toggleSelected(position); mode.setTitle(listAdapter().selectedCount() + ""); listAdapter().notifyDataSetChanged(); } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.app_usage_data_context_menu, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.item_context_delete: List<AppUsageDataUIContainer> selectedItems = listAdapter().getSelectedItems(); List<Integer> selectedItemsPrimaryKeys = new LinkedList<>(); for (AppUsageDataUIContainer selectedItem : selectedItems) selectedItemsPrimaryKeys.add(selectedItem.id); new SQLiteDataRemover(getActivity(), selectedItemsPrimaryKeys).run(); Toast toast = Toast.makeText(getActivity(), getString(R.string.toast_data_removed), Toast.LENGTH_SHORT); toast.show(); mode.finish(); getLoaderManager().restartLoader(loaderID, getArguments(), AppUsageDataListFragment.this); getListView().invalidate(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode mode) { listAdapter().resetSelected(); } }); }
From source file:com.lithidsw.wallbox.app.randomizer.RandomizerFrag.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { fa = super.getActivity(); mUtils = new Utils(fa); menuHelper = new MenuHelper(fa); ll = (LinearLayout) inflater.inflate(R.layout.randomizer_frag, container, false); prefs = fa.getSharedPreferences(C.PREF, Context.MODE_PRIVATE); adapter = new RandomizerGridAdapter(fa, mGalItems); mGridView = (GridView) ll.findViewById(R.id.grid_view); mTextView = (TextView) ll.findViewById(R.id.no_content); mProgressBar = (ProgressBar) ll.findViewById(R.id.progress); mGridView.setAdapter(adapter);//w w w . j ava2 s.c o m mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL); mGridView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) { } @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { actionMode.setTitle("Choose threads"); mRemoveList.clear(); MenuInflater inflater = actionMode.getMenuInflater(); inflater.inflate(R.menu.randomizer_selection_menu, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { final SparseBooleanArray checked = mGridView.getCheckedItemPositions(); switch (menuItem.getItemId()) { case R.id.action_delete: int size = checked.size(); for (int i = 0; i < size; i++) { int key = checked.keyAt(i); boolean value = checked.get(key); if (value) { new TableHelper(fa).deleteSinglePaper(mGalItems.get(key)[1]); } } actionMode.finish(); new GalLoader().execute(); break; } return false; } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); setHasOptionsMenu(true); if (!prefs.getBoolean(C.PREF_RANDOMIZER_FIRST_RUN_MAIN, false)) { prefs.edit().putBoolean(C.PREF_RANDOMIZER_FIRST_RUN_MAIN, true).commit(); String title = getResources().getString(R.string.main_title_randomize); String message = getResources().getString(R.string.randomizer_description); new CustomDialogs().openFirstDialog(fa, title, message); } return ll; }