Example usage for android.view ActionMode finish

List of usage examples for android.view ActionMode finish

Introduction

In this page you can find the example usage for android.view ActionMode finish.

Prototype

public abstract void finish();

Source Link

Document

Finish and close this action mode.

Usage

From source file:com.matthewmitchell.peercoin_android_wallet.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override//ww  w.  j a v a  2 s .  c  om
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today)
                        : dateFormat.format(time)) + ", " + timeFormat.format(time) : null);

                final Coin value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getWalletAddressOfReceived(tx, wallet)
                        : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null);

                serializedTx = tx.unsafePeercoinSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString())));

                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = getResources().getDimensionPixelSize(R.dimen.bitmap_dialog_qr_size);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}

From source file:org.alfresco.mobile.android.application.fragments.actions.NodeActions.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    String label = null;//from  w ww . j  a  v a  2s.c  o m
    Boolean b = false;
    switch (item.getItemId()) {
    case R.id.menu_node_details:
        NodeDetailsFragment.with(getActivity()).node(selectedItems.get(0)).display();
        break;
    case R.id.menu_action_update:
        label = AnalyticsManager.ACTION_UPDATE;
        update(getActivity().getSupportFragmentManager().findFragmentByTag(PagerNodeDetailsFragment.TAG));
        b = true;
        break;
    case R.id.menu_action_sync_group_sync:
        label = AnalyticsManager.ACTION_SYNC;
        sync(true);
        b = true;
        break;
    case R.id.menu_action_sync_group_unsync:
        label = AnalyticsManager.ACTION_UNSYNC;
        sync(false);
        b = true;
        break;
    case R.id.menu_action_favorite_group_favorite:
        label = AnalyticsManager.ACTION_FAVORITE;
        favorite(true);
        b = true;
        break;
    case R.id.menu_action_favorite_group_unfavorite:
        label = AnalyticsManager.ACTION_UNFAVORITE;
        favorite(false);
        b = true;
        break;
    case R.id.menu_action_like_group_like:
        label = AnalyticsManager.ACTION_LIKE;
        like(true);
        b = true;
        break;
    case R.id.menu_action_like_group_unlike:
        label = AnalyticsManager.ACTION_UNLIKE;
        like(false);
        b = true;
        break;
    case R.id.menu_action_download_all:
    case R.id.menu_action_download:
        label = AnalyticsManager.ACTION_DOWNLOAD;
        download();
        b = true;
        break;
    case R.id.menu_action_edit:
        label = AnalyticsManager.ACTION_EDIT;
        edit(getActivity(), parentFolder, selectedItems.get(0));
        b = true;
        break;
    case R.id.menu_action_delete:
    case R.id.menu_action_delete_folder:
        label = AnalyticsManager.ACTION_DELETE;
        delete(getActivity(), getFragment(), new ArrayList<Node>(selectedItems));
        b = true;
        break;
    case R.id.menu_workflow_review_attachments:
        label = AnalyticsManager.ACTION_START_REVIEW;
        startReview();
        b = true;
        break;
    default:
        break;
    }
    if (b) {
        // Analytics
        AnalyticsHelper.reportOperationEvent(getActivity(), AnalyticsManager.CATEGORY_DOCUMENT_MANAGEMENT,
                AnalyticsManager.ACTION_MULTI_SELECT, label, selectedItems.size(), false);

        selectedItems.clear();
        selectedDocument.clear();
        selectedFolder.clear();
        mode.finish();
    }
    return b;
}

From source file:com.theelix.libreexplorer.ActionModeCallback.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    SparseBooleanArray checkedArray = listView.getCheckedItemPositions();
    final List<File> selectedFiles = new ArrayList<>();
    final ArrayList<Uri> selectedUris = new ArrayList<>();
    for (int i = 0; i < listView.getCount(); i++) {
        if (checkedArray.get(i)) {
            selectedFiles.add((File) listView.getItemAtPosition(i));
            selectedUris.add(android.net.Uri.fromFile((File) listView.getItemAtPosition(i)));
        }/*from  w w w . ja  va 2s  .c om*/
    }

    switch (item.getItemId()) {
    case R.id.toolbar_menu_copy:
        FileManager.prepareCopy(selectedFiles.toArray(new File[selectedFiles.size()]));
        break;
    case R.id.toolbar_menu_cut:
        FileManager.prepareCut(selectedFiles.toArray(new File[selectedFiles.size()]));
        break;
    case R.id.toolbar_menu_delete:
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        if (selectedFiles.size() > 1) {
            builder.setMessage(mContext.getString(R.string.delete_dialog_multiple) + " " + selectedFiles.size()
                    + " " + mContext.getString(R.string.delete_dialog_items) + "?");
        } else
            builder.setMessage(mContext.getString(R.string.delete_dialog_single));

        builder.setPositiveButton(mContext.getString(R.string.dialog_ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        DeleteTask task = new DeleteTask(mContext,
                                selectedFiles.toArray(new File[selectedFiles.size()]));
                        task.execute();

                    }
                });
        builder.setNegativeButton(mContext.getString(R.string.dialog_cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        builder.show();
        break;
    case R.id.toolbar_menu_rename:
        DialogFragment renameDialog = new RenameDialog();
        ((RenameDialog) renameDialog).setSelectedFiles(selectedFiles.toArray());
        renameDialog.show(((FileManagerActivity) mContext).getSupportFragmentManager(), "rename_dialog");
        break;
    case R.id.toolbar_menu_details:
        DialogFragment detailsDialog = new DetailsDialog();
        ((DetailsDialog) detailsDialog).setTargetFile(selectedFiles.get(0));
        detailsDialog.show(((FileManagerActivity) mContext).getSupportFragmentManager(), "details_dialog");
        break;
    case R.id.toolbar_menu_share:
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, selectedUris);
        shareIntent.setType("*/*");
        mContext.startActivity(Intent.createChooser(shareIntent, "Share to..."));
        break;

    }
    mode.finish();
    return true;
}

From source file:com.lgallardo.youtorrentcontroller.ItemstFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    try {/*from  www . j a v  a  2  s  .  c om*/

        getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

        // Get adapter
        final TorrentListAdapter mAdapter = (TorrentListAdapter) this.getListAdapter();
        getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

            private int nr = 0;

            @Override
            public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {

                if (checked) {
                    nr++;
                    mAdapter.setNewSelection(position, checked);

                } else {
                    nr--;
                    mAdapter.removeSelection(position);
                }

                // Set title with number of items selected
                mode.setTitle("" + nr);

            }

            @Override
            public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
                nr = 0;
                MenuInflater inflater = getActivity().getMenuInflater();
                inflater.inflate(R.menu.main_contextual_action_bar, menu);

                mSwipeRefreshLayout.setEnabled(false);

                ItemstFragment.mActionMode = actionMode;

                return true;

            }

            @Override
            public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
                return true;
            }

            // This actions are click in the torrent list view (CAB)
            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {

                AlertDialog.Builder builder;
                AlertDialog dialog;
                String hashes = null;
                final String hashesStr;

                // Get MainActivity
                final MainActivity m = (MainActivity) getActivity();

                // Get hashes
                for (int i = 0; mAdapter.getCount() > i; i++) {

                    if (mAdapter.isPositionChecked(i)) {

                        if (hashes == null) {
                            hashes = mAdapter.getData()[i].getHash();
                        } else {
                            hashes = hashes + "|" + mAdapter.getData()[i].getHash();
                        }
                    }
                }

                hashesStr = hashes;

                ((MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true);

                switch (item.getItemId()) {

                case R.id.action_pause:
                    m.pauseSelectedTorrents(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_stop:
                    m.stopSelectedTorrents(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_resume:

                    m.startSelectedTorrents(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_delete:

                    if (!getActivity().isFinishing()) {
                        builder = new AlertDialog.Builder(getActivity());

                        // Message
                        builder.setMessage(R.string.dm_deleteSelectedTorrents)
                                .setTitle(R.string.dt_deleteSelectedTorrents);

                        // Cancel
                        builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User canceled the dialog
                            }
                        });

                        // Ok
                        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User accepted the dialog
                                m.deleteSelectedTorrents(hashesStr);

                            }
                        });

                        // Create dialog
                        dialog = builder.create();

                        // Show dialog
                        dialog.show();

                        // Clear selection
                        nr = 0;

                        // Enable SwipeRefresh
                        mSwipeRefreshLayout.setEnabled(true);

                        mAdapter.clearSelection();
                        mode.finish();

                    }

                    return true;
                case R.id.action_delete_drive:

                    if (!getActivity().isFinishing()) {
                        builder = new AlertDialog.Builder(getActivity());

                        // Message
                        builder.setMessage(R.string.dm_deleteDriveSelectedTorrents)
                                .setTitle(R.string.dt_deleteDriveSelectedTorrents);

                        // Cancel
                        builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User canceled the dialog
                            }
                        });

                        // Ok
                        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User accepted the dialog
                                m.deleteDriveSelectedTorrents(hashesStr);

                            }
                        });

                        // Create dialog
                        dialog = builder.create();

                        // Show dialog
                        dialog.show();

                        // Clear selection
                        nr = 0;

                        // Enable SwipeRefresh
                        mSwipeRefreshLayout.setEnabled(true);

                        mAdapter.clearSelection();
                        mode.finish();

                    }

                    return true;

                case R.id.action_increase_prio:
                    m.increasePrioTorrent(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_decrease_prio:
                    m.decreasePrioTorrent(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_max_prio:
                    m.maxPrioTorrent(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_min_prio:
                    m.minPrioTorrent(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;
                case R.id.action_recheck:

                    m.recheckTorrents(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;
                case R.id.action_sequential_download:

                    m.toggleSequentialDownload(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;
                case R.id.action_firts_last_piece_prio:

                    m.toggleFirstLastPiecePrio(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;
                default:
                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);
                    return true;
                }

            }

            @Override
            public void onDestroyActionMode(ActionMode actionMode) {
                if (mAdapter != null) {
                    mAdapter.clearSelection();
                }
                ItemstFragment.mActionMode = null;

                mSwipeRefreshLayout.setEnabled(true);

            }
        });

        getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) {

                if (MainActivity.listViewRefreshing) {
                    return true;
                }
                getListView().setItemChecked(position, !mAdapter.isPositionChecked(position));
                return false;
            }
        });

    } catch (Exception e) {
        getListView().setChoiceMode(ListView.CHOICE_MODE_NONE);
    }
}

From source file:com.lgallardo.qbittorrentclient.ItemstFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    try {// ww w  . j a va  2s.  co m

        getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

        // Get adapter
        final TorrentListAdapter mAdapter = (TorrentListAdapter) this.getListAdapter();
        getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

            private int nr = 0;

            @Override
            public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {

                if (checked) {
                    nr++;
                    mAdapter.setNewSelection(position, checked);

                } else {
                    nr--;
                    mAdapter.removeSelection(position);
                }

                // Set title with number of items selected
                mode.setTitle("" + nr);

            }

            @Override
            public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
                nr = 0;
                MenuInflater inflater = getActivity().getMenuInflater();
                inflater.inflate(R.menu.main_contextual_action_bar, menu);

                mSwipeRefreshLayout.setEnabled(false);

                ItemstFragment.mActionMode = actionMode;

                return true;

            }

            @Override
            public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
                if (MainActivity.qb_version.equals("3.2.x")) {
                    menu.findItem(R.id.action_first_last_piece_prio).setVisible(true);
                    menu.findItem(R.id.action_sequential_download).setVisible(true);
                    menu.findItem(R.id.action_label_menu).setVisible(true);
                    menu.findItem(R.id.action_set_label).setVisible(true);
                    menu.findItem(R.id.action_delete_label).setVisible(true);

                    if (Integer.parseInt(MainActivity.qb_api) < 8) {
                        menu.findItem(R.id.action_delete_label).setVisible(false);
                    }

                } else {
                    menu.findItem(R.id.action_first_last_piece_prio).setVisible(false);
                    menu.findItem(R.id.action_sequential_download).setVisible(false);
                    menu.findItem(R.id.action_label_menu).setVisible(false);
                    menu.findItem(R.id.action_set_label).setVisible(false);
                    menu.findItem(R.id.action_delete_label).setVisible(false);
                }
                return true;
            }

            // This actions are click in the torrent list view (CAB)
            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {

                AlertDialog.Builder builder;
                AlertDialog dialog;
                String hashes = null;
                final String hashesStr;

                // Get MainActivity
                final MainActivity m = (MainActivity) getActivity();

                // Get hashes
                for (int i = 0; mAdapter.getCount() > i; i++) {

                    if (mAdapter.isPositionChecked(i)) {

                        if (hashes == null) {
                            hashes = mAdapter.getData()[i].getHash();
                        } else {
                            hashes = hashes + "|" + mAdapter.getData()[i].getHash();
                        }
                    }
                }

                hashesStr = hashes;

                ((MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true);

                switch (item.getItemId()) {

                case R.id.action_pause:
                    m.pauseSelectedTorrents(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_resume:

                    m.startSelectedTorrents(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_delete:

                    if (!getActivity().isFinishing()) {
                        builder = new AlertDialog.Builder(getActivity());

                        // Message
                        builder.setMessage(R.string.dm_deleteSelectedTorrents)
                                .setTitle(R.string.dt_deleteSelectedTorrents);

                        // Cancel
                        builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User canceled the dialog
                            }
                        });

                        // Ok
                        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User accepted the dialog
                                m.deleteSelectedTorrents(hashesStr);

                            }
                        });

                        // Create dialog
                        dialog = builder.create();

                        // Show dialog
                        dialog.show();

                        // Clear selection
                        nr = 0;

                        // Enable SwipeRefresh
                        mSwipeRefreshLayout.setEnabled(true);

                        mAdapter.clearSelection();
                        mode.finish();

                    }

                    return true;
                case R.id.action_delete_drive:

                    if (!getActivity().isFinishing()) {
                        builder = new AlertDialog.Builder(getActivity());

                        // Message
                        builder.setMessage(R.string.dm_deleteDriveSelectedTorrents)
                                .setTitle(R.string.dt_deleteDriveSelectedTorrents);

                        // Cancel
                        builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User canceled the dialog
                            }
                        });

                        // Ok
                        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User accepted the dialog
                                m.deleteDriveSelectedTorrents(hashesStr);

                            }
                        });

                        // Create dialog
                        dialog = builder.create();

                        // Show dialog
                        dialog.show();

                        // Clear selection
                        nr = 0;

                        // Enable SwipeRefresh
                        mSwipeRefreshLayout.setEnabled(true);

                        mAdapter.clearSelection();
                        mode.finish();

                    }

                    return true;

                case R.id.action_increase_prio:
                    m.increasePrioTorrent(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_decrease_prio:
                    m.decreasePrioTorrent(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_max_prio:
                    m.maxPrioTorrent(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_min_prio:
                    m.minPrioTorrent(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_upload_rate_limit:

                    m.uploadRateLimitDialog(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_download_rate_limit:

                    m.downloadRateLimitDialog(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;
                case R.id.action_recheck:

                    m.recheckTorrents(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;
                case R.id.action_sequential_download:

                    m.toggleSequentialDownload(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;
                case R.id.action_first_last_piece_prio:

                    m.toggleFirstLastPiecePrio(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;
                case R.id.action_set_label:

                    m.setLabelDialog(hashes);

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;

                case R.id.action_delete_label:

                    m.setLabel(hashes, " ");

                    // Clear selection
                    nr = 0;

                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);

                    mAdapter.clearSelection();
                    mode.finish();

                    return true;
                default:
                    // Enable SwipeRefresh
                    mSwipeRefreshLayout.setEnabled(true);
                    return true;
                }

            }

            @Override
            public void onDestroyActionMode(ActionMode actionMode) {
                if (mAdapter != null) {
                    mAdapter.clearSelection();
                }
                ItemstFragment.mActionMode = null;

                mSwipeRefreshLayout.setEnabled(true);

            }
        });

        getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) {

                if (MainActivity.listViewRefreshing) {
                    return true;
                }
                getListView().setItemChecked(position, !mAdapter.isPositionChecked(position));
                return false;
            }
        });

    } catch (Exception e) {
        getListView().setChoiceMode(ListView.CHOICE_MODE_NONE);
    }
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

public boolean onClick(int id, MenuItem item, View from) {
    super.onClick(id);
    if (from == null || !from.isShown())
        from = findViewById(id);/*from   ww w.j  av  a  2 s  . co  m*/
    if (id != R.id.title_icon && id != android.R.id.home)
        ;
    toggleBookmarks(false);
    OpenFragment f = getSelectedFragment();
    if (f != null && f.onClick(id, from))
        return true;
    if (item != null && f != null && f.onOptionsItemSelected(item))
        return true;
    if (DEBUG)
        Logger.LogDebug("OpenExplorer.onClick(0x" + Integer.toHexString(id) + "," + item + "," + from + ")");
    switch (id) {
    case R.id.menu_debug:
        debugTest();
        break;
    case R.id.title_icon:
    case android.R.id.home:
        toggleBookmarks();
        return true;

    case R.id.menu_multi:
        if (getClipboard().isMultiselect()) {
            getClipboard().stopMultiselect();
            //getClipboard().clear();
            if (!BEFORE_HONEYCOMB && mActionMode != null)
                ((ActionMode) mActionMode).finish();
            return true;
        }

        if (BEFORE_HONEYCOMB || !USE_ACTIONMODE) {
            getClipboard().startMultiselect();
        } else {
            mActionMode = startActionMode(new ActionMode.Callback() {

                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                public void onDestroyActionMode(ActionMode mode) {
                    getClipboard().clear();
                    mActionMode = null;
                }

                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    mode.setTitle(getString(R.string.s_menu_multi) + ": " + getClipboard().size() + " "
                            + getString(R.string.s_files));
                    mode.getMenuInflater().inflate(R.menu.multiselect, menu);
                    //MenuUtils.setMenuVisible(menu, false, R.id.menu_context_paste, R.id.menu_context_unzip);
                    getDirContentFragment(true).changeMultiSelectState(true);
                    return true;
                }

                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    if (getClipboard().size() < 1) {
                        mode.finish();
                        return true;
                    }
                    OpenPath file = getClipboard().get(0); //getMultiSelectHandler().getSelectedFiles();

                    getClipboard().clear();

                    return getDirContentFragment(false).executeMenu(item.getItemId(), mode, file);
                }
            });
        }
        return true;

    case R.id.menu_view_carousel:
        changeViewMode(OpenExplorer.VIEW_CAROUSEL, true);
        return true;

    case R.id.menu_view_grid:
        changeViewMode(OpenExplorer.VIEW_GRID, true);
        return true;

    case R.id.menu_view_list:
        changeViewMode(OpenExplorer.VIEW_LIST, true);
        return true;

    case R.id.menu_view_fullscreen:
        getPreferences().setSetting("global", "pref_fullscreen",
                !getPreferences().getSetting("global", "pref_fullscreen", false));
        goHome();
        return true;

    case R.id.menu_view_split:
        setSetting("pref_basebar", !USE_SPLIT_ACTION_BAR);
        goHome();
        return true;

    //case R.id.menu_global_ops_text:
    //case R.id.menu_global_ops_icon:
    case R.id.title_ops:
        refreshOperations();
        showLogFrag(mOpsFragment, true);
        checkTitleSeparator();
        return true;

    case R.id.title_log:
        if (mLogFragment == null)
            mLogFragment = new LogViewerFragment();
        showLogFrag(mLogFragment, true);
        sendToLogView(null, 0);
        return true;

    /*case R.id.menu_root:
    if(RootManager.Default.isRoot())
    {
       getPreferences().setSetting("global", "pref_root", false);
       showToast(getString(R.string.s_menu_root_disabled));
       RootManager.Default.exitRoot();
       item.setChecked(false);
    } else
    {
       if(RootManager.Default.isRoot() || RootManager.Default.requestRoot())
       {
          getPreferences().setSetting("global", "pref_root", true);
          showToast(getString(R.string.s_menu_root) + "!");
          item.setTitle(getString(R.string.s_menu_root) + "!");
       } else {
          item.setChecked(false);
          showToast("Unable to achieve root.");
       }
    }
    return true;
            
    case R.id.menu_flush:
    ThumbnailCreator.flushCache(getApplicationContext(), true);
    OpenPath.flushDbCache();
    goHome();
    return true;*/

    case R.id.menu_refresh:
        ContentFragment content = getDirContentFragment(true);
        if (content != null) {
            if (DEBUG && IS_DEBUG_BUILD)
                Logger.LogDebug("Refreshing " + content.getPath().getPath());
            FileManager.removeOpenCache(content.getPath().getPath());
            content.getPath().deleteFolderFromDb();
            content.runUpdateTask(true);
            changePath(content.getPath(), false, true);
        }
        mBookmarks.refresh();
        return true;

    case R.id.menu_settings:
        showPreferences(null);
        return true;

    case R.id.menu_search:
        onSearchRequested();
        return true;

    /*case R.id.menu_favorites:
    toggleBookmarks();
    return true;*/

    case R.id.menu_multi_all_delete:
        DialogHandler.showConfirmationDialog(this,
                getResources().getString(R.string.s_confirm_delete,
                        getClipboard().getCount() + " " + getResources().getString(R.string.s_files)),
                getResources().getString(R.string.s_menu_delete_all), new DialogInterface.OnClickListener() { // yes
                    public void onClick(DialogInterface dialog, int which) {
                        getEventHandler().deleteFile(getClipboard(), OpenExplorer.this, false);
                    }
                });
        break;

    case R.id.menu_multi_all_clear:
        getClipboard().clear();
        return true;

    case R.id.menu_multi_all_copy:
        getClipboard().DeleteSource = false;
        getDirContentFragment(false).executeMenu(R.id.content_paste, null,
                getDirContentFragment(false).getPath());
        break;

    case R.id.menu_multi_all_move:
        getClipboard().DeleteSource = true;
        getDirContentFragment(false).executeMenu(R.id.content_paste, null,
                getDirContentFragment(false).getPath());
        break;

    case R.id.title_paste:
    case R.id.title_paste_icon:
    case R.id.title_paste_text:
    case R.id.content_paste:
        //if(BEFORE_HONEYCOMB)
        getClipboard().setCurrentPath(getCurrentPath());
        onClipboardDropdown(from);
        return true;

    //getDirContentFragment(false).executeMenu(R.id.menu_paste, null, mLastPath, mClipboard);
    //return true;

    case R.id.menu_about:
        DialogHandler.showAboutDialog(this);
        return true;

    case R.id.menu_exit:
        DialogHandler.showConfirmationDialog(this, getString(R.string.s_alert_exit),
                getString(R.string.s_menu_exit), getPreferences(), "exit",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                });
        return true;
    case R.id.menu_more:
        showMenu(mOptsMenu, ViewUtils.getFirstView(this, R.id.menu_more, R.id.base_bar, R.id.title_buttons,
                android.R.id.home), true);
        return true;

    default:
        if (f instanceof ContentFragment) {
            ContentFragment cf = (ContentFragment) f;
            if (item.getMenuInfo() != null && cf.onContextItemSelected(item))
                return true;
            else if (cf.onClick(id, from))
                return true;
            else if (cf.onOptionsItemSelected(item))
                return true;
            return cf.executeMenu(id, null, getDirContentFragment(false).getPath());
        } else if (f instanceof TextEditorFragment)
            ((TextEditorFragment) f).onClick(id, from);
        else if (f.onOptionsItemSelected(item))
            return true;
    }

    //showToast("oops");
    return false;
    //return super.onOptionsItemSelected(item);
}