List of usage examples for android.view ActionMode finish
public abstract void finish();
From source file:uk.org.downiesoft.slideshow.SlidesFragment.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s . c o m*/ */ @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.context_set_wallpaper: Bitmap bitmap = mImageViews[mCurrentView].getSnapshot(); if (bitmap != null) { BitmapManager.setWallpaper(getActivity(), bitmap); } else { Toast.makeText(getActivity(), R.string.text_wallpaper_failed, Toast.LENGTH_SHORT).show(); } break; case R.id.context_take_snapshot: BitmapManager.saveSnapshot(getActivity(), sPresentation, getCurrentImage(), mImageViews[mCurrentView]); break; case R.id.action_properties: BitmapManager.displayBitmapProperties(getActivity(), this.sPresentation, sPresentation.getCurrentSlideIndex()); break; case R.id.action_add_favourite: ListPresentation favourites = FavouritesManager.getInstance(getActivity()); favourites.add(sPresentation.getFullPath(getCurrentImage()).getPath()); favourites.save(true); Toast.makeText(getActivity(), R.string.text_added_favourite, Toast.LENGTH_SHORT).show(); break; default: return false; } mode.finish(); return true; }
From source file:com.rappsantiago.weighttracker.progress.HistoryFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_history, container, false); mListView = (ListView) view;/*from www . j a va 2 s.c o m*/ if (null != mFabVisibilityListener) { mListView.setOnScrollListener(mFabVisibilityListener.getDefaulScrollListener()); } mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { mCursorAdapter.addSelectedId(id); } else { mCursorAdapter.removeSelectedId(id); } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.progress_list_context_menu, menu); mCursorAdapter.startMultipleSelection(); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { Set<Long> selectedIds = mCursorAdapter.getSelectedIds(); switch (item.getItemId()) { case R.id.action_delete: long[] arrSelectedIds = Util.convertLongSetToArray(selectedIds); Intent deleteProgressIntent = WeightTrackerSaveService.createBulkDeleteProgressIntent( getActivity(), arrSelectedIds, MainActivity.class, MainActivity.CALLBACK_ACTION_BULK_DELETE_PROGRESS); getActivity().startService(deleteProgressIntent); break; default: return false; } mode.finish(); return true; } @Override public void onDestroyActionMode(ActionMode mode) { mCursorAdapter.stopMultipleSelection(); } }); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent editProgressIntent = new Intent(getContext(), AddEditProgressActivity.class); editProgressIntent.putExtra(AddEditProgressActivity.EXTRA_EXISTING_PROGRESS_ID, id); startActivity(editProgressIntent); } }); mCursorAdapter = new HistoryCursorAdapter(getContext()); mListView.setAdapter(mCursorAdapter); return view; }
From source file:de.qspool.clementineremote.ui.fragments.GlobalSearchFragment.java
@SuppressLint({ "InlinedApi", "NewApi" }) @Override// w w w . j av a2s.com public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_global_search, container, false); mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.global_search_refresh_layout); mEmptyView = (SwipeRefreshLayout) view.findViewById(R.id.global_search_empty); mSwipeRefreshLayout.setColorSchemeResources(R.color.orange); mEmptyView.setColorSchemeResources(R.color.orange); mSwipeRefreshLayout.setEnabled(true); mEmptyView.setEnabled(true); mEmptyText = (TextView) view.findViewById(R.id.global_search_empty_txt); mList = (ListView) view.findViewById(R.id.global_search); mList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { SongSelectItem item = mAdapters.getLast().getItem(position); if (item.getLevel() == mMaxLevels - 1) { Message msg = Message.obtain(); LinkedList<ClementineRemoteProtocolBuffer.SongMetadata> songs = new LinkedList<>(); songs.add(GlobalSearchManager.getInstance().getRequest().getSongFromUrl(item.getUrl())); msg.obj = ClementineMessageFactory .buildInsertSongs(App.Clementine.getPlaylistManager().getActivePlaylistId(), songs); App.ClementineConnection.mHandler.sendMessage(msg); String text = getActivity().getResources().getQuantityString(R.plurals.songs_added, 1, 1); Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); } else { GlobalSearchQuery globalSearchQuery = new GlobalSearchQuery(getActivity(), mQueryId); globalSearchQuery.openDatabase(); globalSearchQuery.setLevel(mAdapters.size()); globalSearchQuery.setSelection(item.getSelection()); mAdapters.add(new DynamicSongQueryAdapter(getActivity(), globalSearchQuery)); showList(); } } }); mList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mList.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onActionItemClicked(ActionMode mode, android.view.MenuItem item) { SparseBooleanArray checkedPositions = mList.getCheckedItemPositions(); final LinkedList<SongSelectItem> selectedItems = new LinkedList<>(); for (int i = 0; i < checkedPositions.size(); ++i) { int position = checkedPositions.keyAt(i); if (checkedPositions.valueAt(i)) { selectedItems.add(mAdapters.getLast().getItem(position)); } } for (SongSelectItem songItem : selectedItems) { OnSongSelectFinishedListener listener; switch (item.getItemId()) { case R.id.global_search_context_add: listener = new OnSongSelectFinishedListener() { @Override public void OnSongSelectFinished(LinkedList<SongSelectItem> l) { addSongsToPlaylist(l); } }; break; default: return false; } queryItems(songItem, listener); } mode.finish(); return true; } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.global_search_context_menu, menu); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getActivity().getWindow() .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.grey_cab_status)); } return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getActivity().getWindow() .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.actionbar_dark)); } } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { } }); GlobalSearchManager.getInstance().addOnGlobalSearchResponseListerner(this); setHasOptionsMenu(true); mActionBar.setTitle(""); mActionBar.setSubtitle("/"); return view; }
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);//w w w.jav 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<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);//from www . j a va2s . 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<>(); 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:de.vanita5.twittnuker.fragment.support.StatusFragment.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case android.R.id.copyUrl: { final int start = mTextView.getSelectionStart(), end = mTextView.getSelectionEnd(); final SpannableString string = SpannableString.valueOf(mTextView.getText()); final URLSpan[] spans = string.getSpans(start, end, URLSpan.class); if (spans == null || spans.length != 1) return true; ClipboardUtils.setText(getActivity(), spans[0].getURL()); mode.finish(); return true; }//from w w w .j a va 2 s . co m } return false; }
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);/*ww w . ja v a2s . c om*/ 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; }
From source file:com.miz.mizuu.fragments.TvShowEpisodesFragment.java
public void onViewCreated(View v, Bundle savedInstanceState) { super.onViewCreated(v, savedInstanceState); if (MizLib.isTablet(mContext) && !MizLib.isPortrait(mContext)) { v.findViewById(R.id.container).setBackgroundColor(Color.parseColor("#05FFFFFF")); }//from w w w . ja v a 2s . co m mAdapter = new ImageAdapter(mContext); mProgressBar = (ProgressBar) v.findViewById(R.id.progress); mGridView = (GridView) v.findViewById(R.id.gridView); mGridView.setColumnWidth(mImageThumbSize); mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL); mGridView.setEmptyView(v.findViewById(R.id.progress)); mGridView.setAdapter(mAdapter); if (mUseGridView) { // 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); mResizedWidth = (int) (((mGridView.getWidth() - (numColumns * mImageThumbSpacing)) / numColumns) * 1.1); // * 1.1 is a hack to make images look slightly less blurry mResizedHeight = (int) (mResizedWidth / 1.778); } } } }); } else { mGridView.setNumColumns(1); mAdapter.setNumColumns(1); } mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Intent i = new Intent(mContext, TvShowEpisodeDetails.class); i.putExtra(SHOW_ID, mShowId); i.putExtra("episode", mEpisodeLoader.getResults().get(arg2).getEpisode()); i.putExtra("season", mSeason); getActivity().startActivityForResult(i, 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.episodes_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>(mCheckedEpisodes)); break; case R.id.unwatched: changeWatchedStatus(false, new HashSet<Integer>(mCheckedEpisodes)); break; case R.id.remove: removeSelectedEpisodes(new HashSet<Integer>(mCheckedEpisodes)); break; case R.id.identify: identify(new HashSet<Integer>(mCheckedEpisodes)); break; } mode.finish(); // Make the seasons grid refresh mBus.post(new com.miz.mizuu.TvShowEpisode()); return true; } @Override public void onDestroyActionMode(ActionMode mode) { mContextualActionBarEnabled = false; mCheckedEpisodes.clear(); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) mCheckedEpisodes.add(mEpisodeLoader.getResults().get(position).getEpisode()); else mCheckedEpisodes.remove(mEpisodeLoader.getResults().get(position).getEpisode()); int count = mCheckedEpisodes.size(); mode.setTitle( count + " " + getResources().getQuantityString(R.plurals.episodes_selected, count, count)); // Nasty hack to update the selected items highlight... mAdapter.notifyDataSetChanged(); } }); // The layout has been created - let's load the data loadEpisodes(); }
From source file:org.mariotaku.twidere.fragment.DraftsFragment.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.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. co m f.show(getChildFragmentManager(), "delete_drafts_confirm"); break; } case R.id.send: { final Cursor c = mAdapter.getCursor(); if (c == null || c.isClosed()) return false; final SparseBooleanArray checked = mListView.getCheckedItemPositions(); final List<Draft> list = new ArrayList<>(); final DraftCursorIndices indices = new DraftCursorIndices(c); for (int i = 0, j = checked.size(); i < j; i++) { if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) { list.add(indices.newObject(c)); } } 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: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//w w w .ja v a 2s.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; } }); }