List of usage examples for android.view ActionMode finish
public abstract void finish();
From source file:com.notepadlite.NoteListFragment.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void listNotes() { // Get number of files int numOfFiles = getNumOfNotes(getActivity().getFilesDir()); int numOfNotes = numOfFiles; // Get array of file names String[] listOfFiles = getListOfNotes(getActivity().getFilesDir()); ArrayList<String> listOfNotes = new ArrayList<>(); // Remove any files from the list that aren't notes for (int i = 0; i < numOfFiles; i++) { if (NumberUtils.isNumber(listOfFiles[i])) listOfNotes.add(listOfFiles[i]); else/*w w w . ja v a 2 s .c o m*/ numOfNotes--; } // Declare ListView final ListView listView = (ListView) getActivity().findViewById(R.id.listView1); // 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.equals("date")) Arrays.sort(listOfNotesByDate, Collections.reverseOrder()); // 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.equals("name")) { // Copy titles array System.arraycopy(listOfTitlesByDate, 0, listOfTitlesByName, 0, numOfNotes); // Sort titles Arrays.sort(listOfTitlesByName, NoteListItem.NoteComparatorTitle); // 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.equals("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); // 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(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { if (sortBy.equals("date")) { if (directEdit) listener.editNote(finalListByDate[position]); else listener.viewNote(finalListByDate[position]); } else if (sortBy.equals("name")) { if (directEdit) listener.editNote(finalListByName[position]); else listener.viewNote(finalListByName[position]); } } }); // Make ListView handle contextual action bar final ArrayList<String> cab = new ArrayList<>(numOfNotes); 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_export: mode.finish(); // Action picked, so close the CAB listener.exportNote(cab.toArray()); return true; case R.id.action_delete: mode.finish(); // Action picked, so close the CAB listener.deleteNote(cab.toArray()); return true; 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) { // Add/remove filenames to cab array as they are checked/unchecked if (checked) { if (sortBy.equals("date")) cab.add(finalListByDate[position]); if (sortBy.equals("name")) cab.add(finalListByName[position]); } else { if (sortBy.equals("date")) cab.remove(finalListByDate[position]); if (sortBy.equals("name")) cab.remove(finalListByName[position]); } // Update the title in CAB if (cab.size() == 0) mode.setTitle(""); else mode.setTitle(cab.size() + " " + listener.getCabString(cab.size())); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); // If there are no saved notes, then display the empty view if (numOfNotes == 0) { TextView empty = (TextView) getActivity().findViewById(R.id.empty); listView.setEmptyView(empty); } }
From source file:com.anjalimacwan.fragment.NoteListFragment.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void listNotes() { // Get number of files int numOfFiles = getNumOfNotes(getActivity().getFilesDir()); int numOfNotes = numOfFiles; // Get array of file names String[] listOfFiles = getListOfNotes(getActivity().getFilesDir()); ArrayList<String> listOfNotes = new ArrayList<>(); // Remove any files from the list that aren't notes for (int i = 0; i < numOfFiles; i++) { if (NumberUtils.isNumber(listOfFiles[i])) listOfNotes.add(listOfFiles[i]); else/* w w w .ja v a 2 s . com*/ numOfNotes--; } // Declare ListView final ListView listView = (ListView) getActivity().findViewById(R.id.listView1); // 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.equals("date")) Arrays.sort(listOfNotesByDate, Collections.reverseOrder()); // 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.equals("name")) { // Copy titles array System.arraycopy(listOfTitlesByDate, 0, listOfTitlesByName, 0, numOfNotes); // Sort titles Arrays.sort(listOfTitlesByName, NoteListItem.NoteComparatorTitle); // 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.equals("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); // 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(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { if (sortBy.equals("date")) { if (directEdit) listener.editNote(finalListByDate[position]); else listener.viewNote(finalListByDate[position]); } else if (sortBy.equals("name")) { if (directEdit) listener.editNote(finalListByName[position]); else listener.viewNote(finalListByName[position]); } } }); // Make ListView handle contextual action bar if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final ArrayList<String> cab = new ArrayList<>(numOfNotes); 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_export: mode.finish(); // Action picked, so close the CAB listener.exportNote(cab.toArray()); return true; case R.id.action_delete: mode.finish(); // Action picked, so close the CAB listener.deleteNote(cab.toArray()); return true; 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) { // Add/remove filenames to cab array as they are checked/unchecked if (checked) { if (sortBy.equals("date")) cab.add(finalListByDate[position]); if (sortBy.equals("name")) cab.add(finalListByName[position]); } else { if (sortBy.equals("date")) cab.remove(finalListByDate[position]); if (sortBy.equals("name")) cab.remove(finalListByName[position]); } // Update the title in CAB if (cab.size() == 0) mode.setTitle(""); else mode.setTitle(cab.size() + " " + listener.getCabString(cab.size())); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); } // If there are no saved notes, then display the empty view if (numOfNotes == 0) { TextView empty = (TextView) getActivity().findViewById(R.id.empty); listView.setEmptyView(empty); } }
From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvSubkeysFragment.java
private void editKey(final ActionMode mode) { CryptoOperationHelper.Callback<SaveKeyringParcel, EditKeyResult> editKeyCallback = new CryptoOperationHelper.Callback<SaveKeyringParcel, EditKeyResult>() { @Override//w ww.j a v a 2 s .c om public SaveKeyringParcel createOperationInput() { return mEditModeSaveKeyringParcel; } @Override public void onCryptoOperationSuccess(EditKeyResult result) { mode.finish(); result.createNotify(getActivity()).show(); } @Override public void onCryptoOperationCancelled() { mode.finish(); } @Override public void onCryptoOperationError(EditKeyResult result) { mode.finish(); result.createNotify(getActivity()).show(); } @Override public boolean onCryptoSetProgress(String msg, int progress, int max) { return false; } }; mEditKeyHelper = new CryptoOperationHelper<>(1, this, editKeyCallback, R.string.progress_saving); mEditKeyHelper.cryptoOperation(); }
From source file:foundme.uniroma2.it.professore.ReadMessageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_read_message); context = this; Bundle passed = getIntent().getExtras(); Title = passed.getString(Variables_it.COURSE); swipeMsg = (SwipeRefreshLayout) findViewById(R.id.swipe_msg); swipeMsg.setEnabled(false);/* ww w . j a v a 2 s . co m*/ lvMessaggi = (ListView) findViewById(R.id.lvmes); modeCallBack = new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.delete: if (!toEdit.equalsIgnoreCase(Variables_it.NO_MSG)) { try { deleteMsg(toEdit); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } toEdit = null; mode.finish(); break; } return false; } public void onDestroyActionMode(ActionMode mode) { viewList.setBackgroundColor(Color.TRANSPARENT); mode = null; } public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.setTitle(Variables_it.OPTION); mode.getMenuInflater().inflate(R.menu.context, menu); return true; } }; try { getMsg(Title, true); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
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);//from www. jav a 2 s. 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.thialfihar.android.apg.ui.KeyListFragment.java
/** * Show dialog to delete key/*from ww w .j av a2s . c o m*/ * * @param keyRingRowIds */ @TargetApi(11) // TODO: this method needs an overhaul to handle both public and secret keys gracefully! 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) { mode.finish(); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, keyRingRowIds); deleteKeyDialog.show(getActivity().getSupportFragmentManager(), "deleteKeyDialog"); }
From source file:org.mariotaku.twidere.fragment.HostMappingsListFragment.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.delete: { final SharedPreferences.Editor editor = mHostMapping.edit(); final SparseBooleanArray array = mListView.getCheckedItemPositions(); if (array == null) return false; for (int i = 0, size = array.size(); i < size; i++) { if (array.valueAt(i)) { editor.remove(mAdapter.getItem(i)); }// www . j a v a2 s .c o m } editor.apply(); reloadHostMappings(); break; } default: { return false; } } mode.finish(); return true; }
From source file:com.veniosg.dir.android.fragment.SimpleFileListFragment.java
private boolean handleMultipleSelectionAction(ActionMode mode, MenuItem item) { DialogFragment dialog;// w w w .ja v a 2 s . com Bundle args; ArrayList<FileHolder> fItems = getCheckedItems(); switch (item.getItemId()) { case R.id.menu_send: mode.finish(); Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); ArrayList<Uri> uris = new ArrayList<Uri>(); intent.setType("text/plain"); for (FileHolder fh : fItems) { if (!fh.getFile().isDirectory()) uris.add(FileUtils.getUri(fh)); } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); try { startActivity(Intent.createChooser(intent, getString(R.string.send_chooser_title))); return true; } catch (ActivityNotFoundException e) { Toast.makeText(getActivity(), R.string.send_not_available, Toast.LENGTH_SHORT).show(); return true; } case R.id.menu_delete: mode.finish(); dialog = new MultiDeleteDialog(); dialog.setTargetFragment(this, 0); args = new Bundle(); args.putParcelableArrayList(IntentConstants.EXTRA_DIALOG_FILE_HOLDER, new ArrayList<Parcelable>(fItems)); dialog.setArguments(args); dialog.show(getFragmentManager(), MultiDeleteDialog.class.getName()); return true; case R.id.menu_move: mode.finish(); ((FileManagerApplication) getActivity().getApplication()).getCopyHelper().cut(fItems); getActivity().supportInvalidateOptionsMenu(); return true; case R.id.menu_copy: mode.finish(); ((FileManagerApplication) getActivity().getApplication()).getCopyHelper().copy(fItems); getActivity().supportInvalidateOptionsMenu(); return true; case R.id.menu_compress: mode.finish(); dialog = new MultiCompressDialog(); dialog.setTargetFragment(this, 0); args = new Bundle(); args.putParcelableArrayList(IntentConstants.EXTRA_DIALOG_FILE_HOLDER, new ArrayList<Parcelable>(fItems)); dialog.setArguments(args); dialog.show(getFragmentManager(), MultiCompressDialog.class.getName()); return true; default: return false; } }
From source file:org.thialfihar.android.apg.ui.KeyListPublicFragment.java
@TargetApi(11) public void encrypt(ActionMode mode, long[] keyRingRowIds) { // get master key ids from row ids long[] keyRingIds = new long[keyRingRowIds.length]; for (int i = 0; i < keyRingRowIds.length; i++) { keyRingIds[i] = ProviderHelper.getPublicMasterKeyId(getActivity(), keyRingRowIds[i]); }//www .j a v a2s. co m Intent intent = new Intent(getActivity(), EncryptActivity.class); intent.setAction(EncryptActivity.ACTION_ENCRYPT); intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, keyRingIds); // used instead of startActivity set actionbar based on callingPackage startActivityForResult(intent, 0); mode.finish(); }
From source file:com.github.capone.controller.discovery.DiscoveryListFragment.java
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final Server to = adapter.getItem(position); getActivity().startActionMode(new ActionMode.Callback() { @Override//from w ww. j a va2 s.co m public boolean onCreateActionMode(ActionMode mode, Menu menu) { getActivity().getMenuInflater().inflate(R.menu.discovery, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { ServerRecord server = ServerRecord.findByTo(to); if (server == null) { menu.findItem(R.id.remove).setVisible(false); } else { menu.findItem(R.id.add).setVisible(false); } return true; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.add: onAddClicked(to); mode.finish(); return true; case R.id.remove: onRemoveClicked(to); mode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode mode) { } }); return true; }