List of usage examples for android.view ActionMode setTitle
public abstract void setTitle(@StringRes int resId);
From source file:fr.simon.marquis.secretcodes.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); getSupportActionBar().setTitle(Utils.applyCustomTypeFace(getString(R.string.app_name), this)); setContentView(R.layout.activity_main); mEmptyView = findViewById(R.id.emptyView); mGridView = (GridView) findViewById(R.id.gridView); mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL); mGridView.setAdapter(new SecretCodeAdapter(this, Utils.getSecretCodes(this))); mGridView.setEmptyView(mEmptyView);/* w w w. j a v a 2s.c o m*/ mEmptyView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mEmptyView.setEnabled(false); mEmptyView.animate().alpha(0) .setDuration(getResources().getInteger(android.R.integer.config_longAnimTime)); startService(new Intent(MainActivity.this, CrawlerService.class)); } }); mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String code = ((SecretCode) arg0.getItemAtPosition(arg2)).getCode(); Toast.makeText(MainActivity.this, getString(R.string.execute_code, code), Toast.LENGTH_SHORT) .show(); try { sendBroadcast(new Intent("android.provider.Telephony.SECRET_CODE", Uri.parse("android_secret_code://" + code))); } catch (java.lang.SecurityException se) { Toast.makeText(MainActivity.this, R.string.security_exception, Toast.LENGTH_LONG).show(); } } }); mGridView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { ((SecretCodeAdapter) mGridView.getAdapter()).itemCheckedStateChanged(position, checked); mode.setTitle(Html.fromHtml("<b>" + mGridView.getCheckedItemCount() + "</b>")); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.action_delete: ((SecretCodeAdapter) mGridView.getAdapter()).deleteSelection(getApplicationContext()); mode.finish(); return true; case R.id.action_select_all: boolean check = mGridView.getCheckedItemCount() != mGridView.getCount(); for (int i = 0; i < mGridView.getCount(); i++) { mGridView.setItemChecked(i, check); } return true; default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); if (inflater != null) { inflater.inflate(R.menu.cab, menu); } return true; } @Override public void onDestroyActionMode(ActionMode mode) { ((SecretCodeAdapter) mGridView.getAdapter()).resetSelection(); supportInvalidateOptionsMenu(); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); supportInvalidateOptionsMenu(); }
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.java2 s. co m*/ * 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.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 a v a 2 s . c om 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; }
From source file:com.fusionx.lightirc.ui.UserListFragment.java
@Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { int selectedItemCount = getCheckedItems().size(); if (selectedItemCount != 0) { final String quantityString = getResources().getQuantityString(R.plurals.user_selection, selectedItemCount, selectedItemCount); mode.setTitle(quantityString); mode.getMenu().getItem(1).setVisible(selectedItemCount == 1); mode.getMenu().getItem(2).setVisible(selectedItemCount == 1); }// ww w. ja v a 2 s .c o m }
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. j av a2 s . c om 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; } }); }
From source file:com.btmura.android.reddit.app.NavigationFragment.java
private void prepareMode(ActionMode mode, int checked) { mode.setTitle(getResources().getQuantityString(R.plurals.subreddits, checked, checked)); }
From source file:fr.simon.marquis.preferencesmanager.ui.PreferencesFragment.java
void updateListView(PreferenceFile p, boolean animate) { if (getActivity() == null || getActivity().isFinishing()) { return;/*from w w w .j ava 2s . c o m*/ } if (p == null) { getActivity().finish(); return; } preferenceFile = p; emptyViewText.setText(preferenceFile.isValidPreferenceFile() ? R.string.empty_preference_file_valid : R.string.empty_preference_file_invalid); loadingView.setVisibility(View.GONE); gridView.setVisibility(View.VISIBLE); if (animate) { if (getActivity() != null) { Animation fadeOut = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out); if (fadeOut != null) { loadingView.startAnimation(fadeOut); } Animation fadeIn = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in); if (fadeIn != null) { gridView.startAnimation(fadeIn); } } } gridView.setAdapter(new PreferenceAdapter(getActivity(), this)); gridView.setEmptyView(emptyView); gridView.setOnItemClickListener(new OnItemClickListener() { @SuppressWarnings("unchecked") @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Entry<String, Object> item = (Entry<String, Object>) gridView.getAdapter().getItem(arg2); PreferenceType type = PreferenceType.fromObject(item.getValue()); if (type == PreferenceType.UNSUPPORTED) { Toast.makeText(getActivity(), R.string.preference_unsupported, Toast.LENGTH_SHORT).show(); } else { showPrefDialog(type, true, item.getKey(), item.getValue()); } } }); gridView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { ((PreferenceAdapter) gridView.getAdapter()).itemCheckedStateChanged(position, checked); mode.setTitle(Html.fromHtml("<b>" + gridView.getCheckedItemCount() + "</b>")); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.action_delete: ((PreferenceAdapter) gridView.getAdapter()).deleteSelection(); Utils.savePreferences(preferenceFile, mFile, mPackageName, getActivity()); ((PreferenceAdapter) gridView.getAdapter()).notifyDataSetChanged(); mode.finish(); return true; case R.id.action_select_all: boolean check = gridView.getCheckedItemCount() != gridView.getCount(); for (int i = 0; i < gridView.getCount(); i++) { gridView.setItemChecked(i, check); } return true; default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); if (inflater != null) { inflater.inflate(R.menu.cab, menu); } return true; } @Override public void onDestroyActionMode(ActionMode mode) { ((PreferenceAdapter) gridView.getAdapter()).resetSelection(); getActivity().invalidateOptionsMenu(); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); getActivity().invalidateOptionsMenu(); }
From source file:email.schaal.ocreader.ListActivity.java
@Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.menu_item_list_action, menu); mode.setTitle(String.valueOf(adapter.getSelectedItemsCount())); startDrawer.getDrawerLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); swipeRefreshLayout.setEnabled(false); fab_mark_all_read.setVisibility(View.GONE); ((CoordinatorLayout.LayoutParams) fab_mark_all_read.getLayoutParams()).setBehavior(null); return true;// w w w. j a va 2 s . c o m }
From source file:com.miz.mizuu.fragments.TvShowLibraryFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.image_grid_fragment, container, false); mProgressBar = (ProgressBar) v.findViewById(R.id.progress); mEmptyLibraryLayout = v.findViewById(R.id.empty_library_layout); mEmptyLibraryTitle = (TextView) v.findViewById(R.id.empty_library_title); mEmptyLibraryTitle.setTypeface(TypefaceUtils.getRobotoCondensedRegular(mContext)); mEmptyLibraryDescription = (TextView) v.findViewById(R.id.empty_library_description); mEmptyLibraryDescription.setTypeface(TypefaceUtils.getRobotoLight(mContext)); mAdapter = new LoaderAdapter(mContext); mGridView = (ObservableGridView) v.findViewById(R.id.gridView); mGridView.setAdapter(mAdapter);/* ww w .j a v a 2 s. co m*/ mGridView.setColumnWidth(mImageThumbSize); mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { viewTvShowDetails(arg2, arg1); } }); mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL); mGridView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { mAdapter.setItemChecked(position, checked); mode.setTitle(String.format(getString(R.string.selected), mAdapter.getCheckedItemCount())); } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { getActivity().getMenuInflater().inflate(R.menu.show_library_cab, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.show_add_fav: TvShowDatabaseUtils.setTvShowsFavourite(mContext, mAdapter.getCheckedShows(), true); break; case R.id.show_remove_fav: TvShowDatabaseUtils.setTvShowsFavourite(mContext, mAdapter.getCheckedShows(), false); break; case R.id.show_watched: TvShowDatabaseUtils.setTvShowsWatched(mContext, mAdapter.getCheckedShows(), true); break; case R.id.show_unwatched: TvShowDatabaseUtils.setTvShowsWatched(mContext, mAdapter.getCheckedShows(), false); break; } if (!(id == R.id.watched_menu || id == R.id.favorite_menu)) { mode.finish(); LocalBroadcastUtils.updateTvShowLibrary(mContext); } return true; } @Override public void onDestroyActionMode(ActionMode mode) { mAdapter.clearCheckedItems(); } }); mTvShowLoader = new TvShowLoader(mContext, TvShowLibraryType.fromInt(getArguments().getInt("type")), mCallback); mTvShowLoader.load(); showProgressBar(); return v; }
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/*from w w w . java 2 s . co 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) { } }); }