List of usage examples for android.view ActionMode finish
public abstract void finish();
From source file:net.sourceforge.lifeograph.ActivityDiary.java
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.open_entry: { Entry e = Diary.diary.m_entries.get(mCalPagerAdapter.getSelectedDate().m_date + 1); Lifeograph.showElem(e);//from ww w.j av a 2 s .co m return true; } case R.id.create_entry: { Log.d(Lifeograph.TAG, "create entry"); mode.finish(); // Action picked, so close the CAB Entry e = Diary.diary.create_entry(mCalPagerAdapter.getSelectedDate(), "", false); Lifeograph.showElem(e); return true; } case R.id.create_chapter: mode.finish(); // Action picked, so close the CAB createChapter(mCalPagerAdapter.getSelectedDate().m_date); return true; default: return false; } }
From source file:com.vmihalachi.turboeditor.fragment.NavigationDrawerListFragment.java
/** * {@inheritDoc}/*from w w w . j a v a2 s. co m*/ */ @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.im_remove: // File paths saved in preferences String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity()); // We get the checked positions SparseBooleanArray checkedItems = getListView().getCheckedItemPositions(); // If we have some checked positions if (checkedItems != null) { for (int i = 0; i < checkedItems.size(); i++) { // check if the value is checked if (checkedItems.valueAt(i)) { // remove the checked path, but don't refresh the list removePath(savedPaths[checkedItems.keyAt(i)], false); } } // In the end refresh the list refreshList(); } // Close the action mode actionMode.finish(); return true; default: return false; } }
From source file:org.sufficientlysecure.keychain.ui.KeyListFragment.java
/** * Show dialog to delete key//ww w . ja v a2 s . com * * @param masterKeyIds * @param hasSecret must contain whether the list of masterKeyIds contains a secret key or not */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void showDeleteKeyDialog(final ActionMode mode, long[] masterKeyIds, boolean hasSecret) { // Can only work on singular secret keys if (hasSecret && masterKeyIds.length > 1) { AppMsg.makeText(getActivity(), R.string.secret_cannot_multiple, AppMsg.STYLE_ALERT).show(); return; } // Message is received after key is deleted Handler returnHandler = new Handler() { @Override public void handleMessage(Message message) { if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) { mode.finish(); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, masterKeyIds); deleteKeyDialog.show(getActivity().getSupportFragmentManager(), "deleteKeyDialog"); }
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 ava2s . 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:com.farmerbb.notepad.fragment.NoteListFragment.java
private void listNotes() { // Get array of file names String[] listOfFiles = getActivity().getFilesDir().list(); ArrayList<String> listOfNotes = new ArrayList<>(); // Get number of files int numOfNotes = listOfFiles.length; // Remove any files from the list that aren't notes for (String listOfFile : listOfFiles) { if (NumberUtils.isCreatable(listOfFile)) listOfNotes.add(listOfFile); else/*from ww w. j a v a 2 s. co m*/ numOfNotes--; } // Create arrays of note lists String[] listOfNotesByDate = new String[numOfNotes]; String[] listOfNotesByName = new String[numOfNotes]; NoteListItem[] listOfTitlesByDate = new NoteListItem[numOfNotes]; NoteListItem[] listOfTitlesByName = new NoteListItem[numOfNotes]; ArrayList<NoteListItem> list = new ArrayList<>(numOfNotes); for (int i = 0; i < numOfNotes; i++) { listOfNotesByDate[i] = listOfNotes.get(i); } // If sort-by is "by date", sort in reverse order if (sortBy.startsWith("date")) { Arrays.sort(listOfNotesByDate, Collections.reverseOrder()); if (sortBy.endsWith("reversed")) ArrayUtils.reverse(listOfNotesByDate); } // Get array of first lines of each note for (int i = 0; i < numOfNotes; i++) { try { String title = listener.loadNoteTitle(listOfNotesByDate[i]); String date = listener.loadNoteDate(listOfNotesByDate[i]); listOfTitlesByDate[i] = new NoteListItem(title, date); } catch (IOException e) { showToast(R.string.error_loading_list); } } // If sort-by is "by name", sort alphabetically if (sortBy.startsWith("name")) { // Copy titles array System.arraycopy(listOfTitlesByDate, 0, listOfTitlesByName, 0, numOfNotes); // Sort titles Arrays.sort(listOfTitlesByName, NoteListItem.NoteComparatorTitle); if (sortBy.endsWith("reversed")) ArrayUtils.reverse(listOfTitlesByName); // Initialize notes array for (int i = 0; i < numOfNotes; i++) listOfNotesByName[i] = "new"; // Copy filenames array with new sort order of titles and nullify date arrays for (int i = 0; i < numOfNotes; i++) { for (int j = 0; j < numOfNotes; j++) { if (listOfTitlesByName[i].getNote().equals(listOfTitlesByDate[j].getNote()) && listOfNotesByName[i].equals("new")) { listOfNotesByName[i] = listOfNotesByDate[j]; listOfNotesByDate[j] = ""; listOfTitlesByDate[j] = new NoteListItem("", ""); } } } // Populate ArrayList with notes, showing name as first line of the notes list.addAll(Arrays.asList(listOfTitlesByName)); } else if (sortBy.startsWith("date")) list.addAll(Arrays.asList(listOfTitlesByDate)); // Create the custom adapters to bind the array to the ListView final NoteListDateAdapter dateAdapter = new NoteListDateAdapter(getActivity(), list); final NoteListAdapter adapter = new NoteListAdapter(getActivity(), list); // Display the ListView if (showDate) listView.setAdapter(dateAdapter); else listView.setAdapter(adapter); listView.setSelection(ScrollPositions.getInstance().getPosition()); // Finalize arrays to prepare for handling clicked items final String[] finalListByDate = listOfNotesByDate; final String[] finalListByName = listOfNotesByName; // Make ListView handle clicked items listView.setClickable(true); listView.setOnItemClickListener((arg0, arg1, position, arg3) -> { ScrollPositions.getInstance().setPosition(listView.getFirstVisiblePosition()); if (sortBy.startsWith("date")) { if (directEdit) listener.editNote(finalListByDate[position]); else listener.viewNote(finalListByDate[position]); } else if (sortBy.startsWith("name")) { if (directEdit) listener.editNote(finalListByName[position]); else listener.viewNote(finalListByName[position]); } }); // Make ListView handle contextual action bar final ArrayList<String> cab = listener.getCabArray(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { // Respond to clicks on the actions in the CAB switch (item.getItemId()) { case R.id.action_select_all: cab.clear(); for (int i = 0; i < listView.getAdapter().getCount(); i++) { listView.setItemChecked(i, true); } return false; case R.id.action_export: if (cab.size() > 0) { mode.finish(); // Action picked, so close the CAB listener.exportNotes(); return true; } else { showToast(R.string.no_notes_to_export); return false; } case R.id.action_delete: if (cab.size() > 0) { mode.finish(); // Action picked, so close the CAB listener.deleteNotes(); return true; } else { showToast(R.string.no_notes_to_delete); return false; } default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { listener.hideFab(); // Inflate the menu for the CAB MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.context_menu, menu); // Clear any old values from cab array cab.clear(); return true; } @Override public void onDestroyActionMode(ActionMode mode) { listener.showFab(); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (position > -1) { // Add/remove filenames to cab array as they are checked/unchecked if (checked) { if (sortBy.startsWith("date")) cab.add(finalListByDate[position]); if (sortBy.startsWith("name")) cab.add(finalListByName[position]); } else { if (sortBy.startsWith("date")) cab.remove(finalListByDate[position]); if (sortBy.startsWith("name")) cab.remove(finalListByName[position]); } listView.setItemChecked(-1, false); } // Update the title in CAB mode.setTitle(cab.size() + " " + listener.getCabString(cab.size())); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); if (cab.size() > 0) { List<String> cabClone = new ArrayList<>(cab); cab.clear(); String[] array = null; if (sortBy.startsWith("date")) array = finalListByDate; if (sortBy.startsWith("name")) array = finalListByName; if (array != null) { for (String filename : cabClone) { for (int i = 0; i < array.length; i++) { if (filename.equals(array[i])) listView.setItemChecked(i, true); } } } } // If there are no saved notes, then display the empty view if (numOfNotes == 0) { TextView empty = getActivity().findViewById(R.id.empty); listView.setEmptyView(empty); } }
From source file:me.diskstation.ammon.gpsrunner.ui.CalendarFragment.java
@Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { //Run selectedRun = (Run) parent.getItemAtPosition(position); //Run testRun = (Run) parent.getSelectedItem(); ArrayList<Long> selectedIds = new ArrayList<>(); SparseBooleanArray selections = mListView.getCheckedItemPositions(); for (int i = 0; i <= mAdapter.getCount(); i++) { if (selections.get(i)) { Run selectedRun = (Run) mListView.getItemAtPosition(i); selectedIds.add(selectedRun.id); }// w ww . j av a 2 s.c o m } long[] runIds = new long[selectedIds.size()]; for (int i = 0; i < selectedIds.size(); i++) { runIds[i] = selectedIds.get(i); } switch (item.getItemId()) { case R.id.item_open: //Call DetailsTabActivity with runIds = id; Intent intent = new Intent(getActivity(), DetailsTabActivity.class); intent.putExtra("run_ids", runIds); startActivity(intent); mode.finish(); return true; case R.id.item_export_csv: exportRunIds = new Long[runIds.length]; for (int i = 0; i < exportRunIds.length; i++) { exportRunIds[i] = runIds[i]; } if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { exportRuns(); } else { requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, WRITE_EXTERNAL_STORAGE_REQUEST); } mode.finish(); return true; default: return false; } }
From source file:com.google.android.apps.mytracks.util.Api11Adapter.java
@Override public void configureMapViewContextualMenu(final SupportMapFragment fragment, final MapContextActionCallback callback) { fragment.getMap().setOnMarkerDragListener(new OnMarkerDragListener() { private LatLng position; private Marker currentMarker; private ActionMode actionMode; @Override/*from w w w . jav a 2 s .c om*/ public void onMarkerDragStart(Marker marker) { if (null == currentMarker || !marker.getId().equals(currentMarker.getId())) { if (null != actionMode) { actionMode.finish(); } position = marker.getPosition(); currentMarker = marker; marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)); } ((Vibrator) fragment.getActivity().getSystemService(Context.VIBRATOR_SERVICE)).vibrate(50); } @Override public void onMarkerDragEnd(final Marker marker) { if (actionMode != null) { if (null == currentMarker || !marker.getId().equals(currentMarker.getId())) { actionMode.finish(); } else { ((Vibrator) fragment.getActivity().getSystemService(Context.VIBRATOR_SERVICE)).vibrate(50); return; } } ((Vibrator) fragment.getActivity().getSystemService(Context.VIBRATOR_SERVICE)) .vibrate(new long[] { 0, 50, 100, 50, 100 }, -1); actionMode = fragment.getActivity().startActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { callback.onCreate(menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { callback.onPrepare(menu, marker); // Return true to indicate change return true; } @Override public void onDestroyActionMode(ActionMode mode) { actionMode = null; if (null != position) { marker.setPosition(position); position = null; currentMarker = null; } } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { mode.finish(); if (callback.onClick(item, marker)) { position = null; return true; } return false; } }); } @Override public void onMarkerDrag(Marker paramMarker) { } }); fragment.getMap().setOnMapLongClickListener(new OnMapLongClickListener() { private ActionMode actionMode; private Marker marker; @Override public void onMapLongClick(final LatLng point) { if (actionMode != null) { actionMode.finish(); } marker = fragment.getMap().addMarker(new MarkerOptions().position(point).title("New location") .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW))); actionMode = fragment.getActivity().startActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { callback.onCreate(menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { callback.onPrepare(menu, marker); // Return true to indicate change return true; } @Override public void onDestroyActionMode(ActionMode mode) { actionMode = null; if (null != marker) { marker.remove(); } } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { mode.finish(); return callback.onClick(item, marker); } }); } }); }
From source file:de.qspool.clementineremote.ui.fragments.PlaylistFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_playlist, container, false); mPlaylists = mPlaylistManager.getAllPlaylists(); mList = (ListView) view.findViewById(R.id.songs); mEmptyPlaylist = view.findViewById(R.id.playlist_empty); // Add Spinner to toolbar mPlaylistsSpinner = (Spinner) getActivity().findViewById(R.id.toolbar_spinner); mPlaylistsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override//from ww w . j av a2s . c o m public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { updateSongList(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); updatePlaylistSpinner(); // Create the adapter mAdapter = new PlaylistSongAdapter(getActivity(), R.layout.item_playlist, getSelectedPlaylistSongs()); mList.setOnItemClickListener(oiclSong); mList.setAdapter(mAdapter); mList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mList.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override public boolean onActionItemClicked(ActionMode mode, android.view.MenuItem item) { SparseBooleanArray checkedPositions = mList.getCheckedItemPositions(); LinkedList<MySong> selectedSongs = new LinkedList<>(); for (int i = 0; i < checkedPositions.size(); ++i) { int position = checkedPositions.keyAt(i); if (checkedPositions.valueAt(i)) { selectedSongs.add(getSelectedPlaylistSongs().get(position)); } } if (!selectedSongs.isEmpty()) { switch (item.getItemId()) { case R.id.playlist_context_play: playSong(selectedSongs.get(0)); mode.finish(); return true; case R.id.playlist_context_download: LinkedList<String> urls = new LinkedList<>(); for (MySong s : selectedSongs) { urls.add(s.getUrl()); } if (!urls.isEmpty()) { DownloadManager.getInstance().addJob( ClementineMessageFactory.buildDownloadSongsMessage(DownloadItem.Urls, urls)); } mode.finish(); return true; case R.id.playlist_context_remove: Message msg = Message.obtain(); msg.obj = ClementineMessageFactory.buildRemoveMultipleSongsFromPlaylist(getPlaylistId(), selectedSongs); App.ClementineConnection.mHandler.sendMessage(msg); mode.finish(); return true; default: return false; } } return false; } @Override public boolean onCreateActionMode(ActionMode mode, android.view.Menu menu) { android.view.MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.playlist_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, android.view.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) { } }); // Filter the results mAdapter.getFilter().filter(mFilterText); mActionBar.setTitle(""); mActionBar.setSubtitle(""); return view; }
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 .jav a2 s . com*/ 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:com.tweetlanes.android.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;//from w w w . ja v a 2 s.c o m curr.finish(); } }