use of android.support.v7.view.ActionMode in project Osmand by osmandapp.
the class FavoritesTreeFragment method deleteFavoritesAction.
private void deleteFavoritesAction() {
int size = getSelectedFavoritesCount();
if (groupsToDelete.size() + size > 0) {
AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setMessage(getString(R.string.favorite_delete_multiple, size, groupsToDelete.size()));
b.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (actionMode != null) {
actionMode.finish();
}
deleteFavorites();
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.show();
}
}
use of android.support.v7.view.ActionMode in project android_packages_apps_Updater by LineageOS.
the class UpdatesListAdapter method startActionMode.
private void startActionMode(final UpdateInfo update, final boolean canDelete) {
if (mActionMode != null) {
Log.d(TAG, "Action mode already enabled");
return;
}
mSelectedDownload = update.getDownloadId();
notifyItemChanged(update.getDownloadId());
// Hide Action Bar not to steal the focus when using a D-pad
final boolean showActionBar;
if (mActivity.getSupportActionBar() != null && mActivity.getSupportActionBar().isShowing()) {
showActionBar = true;
mActivity.getSupportActionBar().hide();
} else {
showActionBar = false;
}
mActionMode = mActivity.startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.menu_action_mode, menu);
menu.findItem(R.id.menu_delete_action).setVisible(canDelete);
menu.findItem(R.id.menu_copy_url).setVisible(update.getAvailableOnline());
menu.findItem(R.id.menu_export_update).setVisible(update.getPersistentStatus() == UpdateStatus.Persistent.VERIFIED);
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.menu_delete_action:
getDeleteDialog(update.getDownloadId()).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mode.finish();
}
}).show();
return true;
case R.id.menu_copy_url:
Utils.addToClipboard(mActivity, mActivity.getString(R.string.label_download_url), update.getDownloadUrl(), mActivity.getString(R.string.toast_download_url_copied));
mode.finish();
return true;
case R.id.menu_export_update:
// TODO: start exporting once the permission has been granted
boolean hasPermission = PermissionsUtils.checkAndRequestStoragePermission(mActivity, 0);
if (hasPermission) {
exportUpdate(update);
}
return true;
}
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mSelectedDownload = null;
mActionMode = null;
notifyItemChanged(update.getDownloadId());
if (showActionBar) {
mActivity.getSupportActionBar().show();
}
}
});
}
use of android.support.v7.view.ActionMode in project orgzly-android by orgzly.
the class NoteListFragment method onSaveInstanceState.
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
/* Selection could be null if fragment is in back stack and there's configuration change. */
if (mSelection != null) {
mSelection.saveIds(outState);
}
/* Save action mode state (move mode). */
if (mActionModeListener != null) {
ActionMode actionMode = mActionModeListener.getActionMode();
outState.putBoolean("actionModeMove", actionMode != null && "M".equals(actionMode.getTag()));
}
}
use of android.support.v7.view.ActionMode in project actor-platform by actorapp.
the class MessagesDefaultFragment method onLongClick.
@Override
public boolean onLongClick(final Message message, final boolean hasMyReaction) {
if (actionMode == null) {
messagesAdapter.clearSelection();
messagesAdapter.setSelected(message, true);
actionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
getActivity().getMenuInflater().inflate(R.menu.messages_context, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
Message[] selected = messagesAdapter.getSelected();
if (selected.length > 0) {
actionMode.setTitle("" + selected.length);
}
boolean isAllText = true;
for (Message k : selected) {
if (!(k.getContent() instanceof TextContent)) {
isAllText = false;
break;
}
}
menu.findItem(R.id.copy).setVisible(isAllText);
menu.findItem(R.id.quote).setVisible(isAllText);
menu.findItem(R.id.forward).setVisible(selected.length == 1 || isAllText);
menu.findItem(R.id.like).setVisible(selected.length == 1);
return false;
}
@Override
public boolean onActionItemClicked(final ActionMode actionMode, MenuItem menuItem) {
if (menuItem.getItemId() == R.id.delete) {
Message[] selected = messagesAdapter.getSelected();
final long[] rids = new long[selected.length];
for (int i = 0; i < rids.length; i++) {
rids[i] = selected[i].getRid();
}
new AlertDialog.Builder(getActivity()).setMessage(getString(R.string.alert_delete_messages_text).replace("{0}", "" + rids.length)).setPositiveButton(R.string.alert_delete_messages_yes, (dialog, which) -> {
messenger().deleteMessages(peer, rids);
actionMode.finish();
}).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
return true;
} else if (menuItem.getItemId() == R.id.copy) {
String text = messenger().getFormatter().formatMessagesExport(messagesAdapter.getSelected());
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Messages", text);
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.toast_messages_copied, Toast.LENGTH_SHORT).show();
actionMode.finish();
return true;
} else if (menuItem.getItemId() == R.id.like) {
Message currentMessage = messagesAdapter.getSelected()[0];
if (hasMyReaction) {
ActorSDK.sharedActor().getMessenger().removeReaction(getPeer(), currentMessage.getRid(), "\u2764").start(new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
}
@Override
public void onError(Exception e) {
}
});
} else {
ActorSDK.sharedActor().getMessenger().addReaction(getPeer(), currentMessage.getRid(), "\u2764").start(new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
}
@Override
public void onError(Exception e) {
}
});
}
actionMode.finish();
return true;
} else if (menuItem.getItemId() == R.id.quote) {
String rawQuote = "";
int i = 0;
for (Message m : messagesAdapter.getSelected()) {
if (m.getContent() instanceof TextContent) {
UserVM user = users().get(m.getSenderId());
String nick = user.getNick().get();
String name = (nick != null && !nick.isEmpty()) ? "@" + nick : user.getName().get();
String text = ((TextContent) m.getContent()).getText();
rawQuote = rawQuote + name + ": " + text + "\n";
}
}
Fragment fragment = getParentFragment();
if (fragment instanceof MessagesFragmentCallback) {
((MessagesFragmentCallback) fragment).onMessageQuote(rawQuote);
}
actionMode.finish();
return true;
} else if (menuItem.getItemId() == R.id.forward) {
Intent i = new Intent(getActivity(), ShareActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (messagesAdapter.getSelected().length == 1) {
Message m = messagesAdapter.getSelected()[0];
if (m.getContent() instanceof TextContent) {
UserVM user = users().get(m.getSenderId());
String nick = user.getNick().get();
String name = (nick != null && !nick.isEmpty()) ? "@".concat(nick) : user.getName().get();
String text = ((TextContent) m.getContent()).getText();
String forward = name.concat(": ").concat(text).concat("\n");
i.putExtra(Intents.EXTRA_FORWARD_TEXT, forward);
i.putExtra(Intents.EXTRA_FORWARD_TEXT_RAW, forward);
} else if (!(m.getContent() instanceof UnsupportedContent)) {
AbsContent fileMessage = m.getContent();
try {
i.putExtra(Intents.EXTRA_FORWARD_CONTENT, AbsContent.serialize(fileMessage));
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
String quote = "";
String rawQuote = "";
int j = 0;
for (Message m : messagesAdapter.getSelected()) {
if (m.getContent() instanceof TextContent) {
UserVM user = users().get(m.getSenderId());
String nick = user.getNick().get();
String name = (nick != null && !nick.isEmpty()) ? "@".concat(nick) : user.getName().get();
String text = ((TextContent) m.getContent()).getText();
quote = quote.concat(name).concat(": ").concat(text);
rawQuote = rawQuote.concat(name).concat(": ").concat(text).concat("\n");
if (j++ != messagesAdapter.getSelectedCount() - 1) {
quote += ";\n";
} else {
quote += "\n";
}
}
}
i.putExtra(Intents.EXTRA_FORWARD_TEXT, quote);
i.putExtra(Intents.EXTRA_FORWARD_TEXT_RAW, rawQuote);
}
actionMode.finish();
startActivity(i);
getActivity().finish();
return true;
}
return false;
}
@Override
public void onDestroyActionMode(ActionMode actionMode) {
MessagesDefaultFragment.this.actionMode = null;
messagesAdapter.clearSelection();
}
});
} else {
if (messagesAdapter.isSelected(message)) {
messagesAdapter.setSelected(message, false);
if (messagesAdapter.getSelectedCount() == 0) {
actionMode.finish();
actionMode = null;
} else {
actionMode.invalidate();
}
} else {
messagesAdapter.setSelected(message, true);
actionMode.invalidate();
}
}
return true;
}
Aggregations