List of usage examples for android.view ActionMode getMenuInflater
public abstract MenuInflater getMenuInflater();
From source file:com.btmura.android.reddit.app.CommentListFragment.java
@Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { if (controller.getAdapter().getCursor() == null) { getListView().clearChoices();//from www .j a v a 2s .co m return false; } MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.comment_action_menu, menu); return true; }
From source file:org.mariotaku.twidere.fragment.DraftsFragment.java
@Override public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { mode.getMenuInflater().inflate(R.menu.action_multi_select_drafts, menu); return true;/*from ww w.j a va2 s. c o m*/ }
From source file:org.getlantern.firetweet.fragment.CustomTabsFragment.java
@Override public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { mode.getMenuInflater().inflate(R.menu.action_multi_select_items, menu); return true;//from w w w . j a v a 2s . c o m }
From source file:org.adaway.ui.hosts.HostsSourcesFragment.java
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Store activity this.mActivity = this.getActivity(); // Create fragment view View view = inflater.inflate(R.layout.hosts_sources_fragment, container, false); /*//w w w . j a va 2s . c om * Configure recycler view. */ // Store recycler view RecyclerView recyclerView = view.findViewById(R.id.hosts_sources_list); recyclerView.setHasFixedSize(true); // Defile recycler layout LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.mActivity); recyclerView.setLayoutManager(linearLayoutManager); // Create recycler adapter ListAdapter adapter = new HostsSourcesAdapter(this); recyclerView.setAdapter(adapter); /* * Create action mode. */ // Create action mode callback to display edit/delete menu this.mActionCallback = new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { // Get menu inflater MenuInflater inflater = actionMode.getMenuInflater(); // Set action mode title actionMode.setTitle(R.string.checkbox_list_context_title); // Inflate edit/delete menu inflater.inflate(R.menu.checkbox_list_context, menu); // Return action created return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { // Nothing special to do return false; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem item) { // Check item identifier switch (item.getItemId()) { case R.id.checkbox_list_context_edit: HostsSourcesFragment.this.editSource(); return true; case R.id.checkbox_list_context_delete: HostsSourcesFragment.this.deleteSource(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode actionMode) { // Clear view background color if (HostsSourcesFragment.this.mActionSourceView != null) { HostsSourcesFragment.this.mActionSourceView.setBackgroundColor(Color.TRANSPARENT); } // Clear current source and its view HostsSourcesFragment.this.mActionSource = null; HostsSourcesFragment.this.mActionSourceView = null; // Clear action mode HostsSourcesFragment.this.mActionMode = null; } }; /* * Add floating action button. */ // Get floating action button FloatingActionButton button = view.findViewById(R.id.hosts_sources_add); // Set click listener to display menu add entry button.setOnClickListener(actionButton -> { // Display menu add entry HostsSourcesFragment.this.addSource(); }); /* * Load data. */ // Get view model and bind it to the list view this.mViewModel = ViewModelProviders.of(this).get(HostsSourcesViewModel.class); this.mViewModel.getHostsSources().observe(this, adapter::submitList); // Return fragment view return view; }
From source file:com.irateam.vkplayer.activities.ListActivity.java
@Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { actionMode = mode;// w w w . j ava2s.c om mode.getMenuInflater().inflate(R.menu.menu_list_context, menu); return true; }
From source file:uk.org.downiesoft.slideshow.SlidesFragment.java
/** * {@inheritDoc}// w w w . j a va 2 s . com */ @Override public boolean onCreateActionMode(ActionMode p1, Menu p2) { MenuInflater inflater = p1.getMenuInflater(); inflater.inflate(R.menu.slides_context, p2); // Window window = getActivity().getWindow(); // int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE // | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // | View.SYSTEM_UI_FLAG_LOW_PROFILE // | View.SYSTEM_UI_FLAG_FULLSCREEN // | View.SYSTEM_UI_FLAG_IMMERSIVE; // window.getDecorView().setSystemUiVisibility(flags); getViewBounds(true, mScratchRects); mImageViews[mPrevView].setTranslationX(mScratchRects[mPrevView].left); mImageViews[mNextView].setTranslationX(mScratchRects[mNextView].left); UiHider.setActionMode(true); return true; }
From source file:biz.wiz.android.wallet.ui.BlockListFragment.java
@Override public void onListItemClick(final ListView l, final View v, final int position, final long id) { final StoredBlock storedBlock = adapter.getItem(position); activity.startActionMode(new ActionMode.Callback() { @Override//w w w . ja va2s . c o m public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.blocks_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { mode.setTitle(Integer.toString(storedBlock.getHeight())); mode.setSubtitle(storedBlock.getHeader().getHashAsString()); return true; } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.blocks_context_browse: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( Constants.EXPLORE_BASE_URL + "block/" + storedBlock.getHeader().getHashAsString()))); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { } }); }
From source file:org.jraf.android.bikey.app.ride.list.RideListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); setEmptyText(getString(R.string.ride_list_empty)); ListView listView = getListView(); listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override/*from w w w . jav a 2 s . c o m*/ public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.setTitle(R.string.ride_list_title); int quantity = getListView().getCheckedItemCount(); mode.setSubtitle( getResources().getQuantityString(R.plurals.ride_list_cab_subtitle, quantity, quantity)); MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.ride_list_contextual, menu); return true; } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { int quantity = getListView().getCheckedItemCount(); mode.setSubtitle( getResources().getQuantityString(R.plurals.ride_list_cab_subtitle, quantity, quantity)); // Enable share / edit if only one item is selected (can't share / edit several items at the same time) mode.getMenu().findItem(R.id.action_share).setVisible(quantity == 1); mode.getMenu().findItem(R.id.action_edit).setVisible(quantity == 1); // Enable merge only if several items are selected mode.getMenu().findItem(R.id.action_merge).setVisible(quantity > 1); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { long[] checkedItemIds = getListView().getCheckedItemIds(); long checkedItemId = checkedItemIds[0]; Uri checkedItemUri = ContentUris.withAppendedId(RideColumns.CONTENT_URI, checkedItemId); switch (item.getItemId()) { case R.id.action_delete: getCallbacks().showDeleteDialog(checkedItemIds); mode.finish(); return true; case R.id.action_share: getCallbacks().showShareDialog(checkedItemUri); mode.finish(); return true; case R.id.action_edit: getCallbacks().edit(checkedItemUri); mode.finish(); return true; case R.id.action_merge: getCallbacks().showMergeDialog(checkedItemIds); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(ActionMode mode) { } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); }
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/*from www. j a v a2s.c o m*/ 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.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;// w w w .j a v a 2 s .co 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; }