Example usage for android.view ActionMode getMenu

List of usage examples for android.view ActionMode getMenu

Introduction

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

Prototype

public abstract Menu getMenu();

Source Link

Document

Returns the menu of actions that this action mode presents.

Usage

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

@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
    Menu menu = mode.getMenu();
    boolean onlyOneItem = listView.getCheckedItemCount() == 1;
    menu.findItem(R.id.toolbar_menu_rename).setVisible(onlyOneItem);
    menu.findItem(R.id.toolbar_menu_details).setVisible(onlyOneItem);

}

From source file:org.wikipedia.page.shareafact.ShareHandler.java

/**
 * @param mode ActionMode under which this context is starting.
 *///from   w w  w.  j av  a  2s. c  om
public void onTextSelected(ActionMode mode) {
    webViewActionMode = mode;
    Menu menu = mode.getMenu();
    MenuItem shareItem = menu.findItem(R.id.menu_text_select_share);

    if (Prefs.isShareTutorialEnabled()) {
        postShowShareToolTip(shareItem);
        Prefs.setShareTutorialEnabled(false);
    }

    // Provide our own listeners for the copy, define, and share buttons.
    shareItem.setOnMenuItemClickListener(new RequestTextSelectOnMenuItemClickListener(PAYLOAD_PURPOSE_SHARE));
    MenuItem copyItem = menu.findItem(R.id.menu_text_select_copy);
    copyItem.setOnMenuItemClickListener((MenuItem menuItem) -> {
        fragment.getWebView().copyToClipboard();
        FeedbackUtil.showMessage(fragment.getActivity(), R.string.text_copied);
        leaveActionMode();
        return true;
    });
    MenuItem defineItem = menu.findItem(R.id.menu_text_select_define);
    if (shouldEnableWiktionaryDialog()) {
        defineItem.setVisible(true);
        defineItem.setOnMenuItemClickListener(
                new RequestTextSelectOnMenuItemClickListener(PAYLOAD_PURPOSE_DEFINE));
    }
    MenuItem editItem = menu.findItem(R.id.menu_text_edit_here);
    editItem.setOnMenuItemClickListener(
            new RequestTextSelectOnMenuItemClickListener(PAYLOAD_PURPOSE_EDIT_HERE));
    if (!fragment.getPage().isArticle()) {
        editItem.setVisible(false);
    }

    if (funnel == null) {
        createFunnel();
    }
    funnel.logHighlight();
}

From source file:com.nagopy.android.mypkgs.MainActivity.java

@SuppressWarnings("unused")
@Subscribe//from ww w.j  av a 2s .  c o m
public void onItemCheckedStateChanged(MultiChoiceModeListenerEvent.ItemCheckedStateChangedEvent event) {
    ActionMode mode = event.actionMode;
    int checkedItemCount = event.checkedItemCount;
    mode.getMenu().findItem(R.id.action_search).setVisible(checkedItemCount == 1);
}

From source file:com.fusionx.lightirc.ui.UserListFragment.java

@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
    int selectedItemCount = getCheckedItems().size();

    if (selectedItemCount != 0) {
        final String quantityString = getResources().getQuantityString(R.plurals.user_selection,
                selectedItemCount, selectedItemCount);
        mode.setTitle(quantityString);//from  ww  w .java  2 s  .co  m

        mode.getMenu().getItem(1).setVisible(selectedItemCount == 1);
        mode.getMenu().getItem(2).setVisible(selectedItemCount == 1);
    }
}

From source file:net.lp.actionbarpoirot.helpers.FragmentHelperHoneycomb.java

@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
    if (checked) {
        addSelectedPosition(position);/*w  w  w. j  av a2s.  co m*/
    } else {
        removeSelectedPosition(position);
    }

    changeTitle(mode);
    if (mSelectedPositionsUris.size() > 1) {
        //Deactivate the menu items that are not for multiple selection.
        createMenuMultiple(mode.getMenu());
        mActionModeUser.getUiActionManager().enableOnlyActionItemsForMultipleSelection(mode.getMenu());//Not used currently
    } else {
        //Activate all the menu items.
        createMenuSingle(mode.getMenu());
        mActionModeUser.getUiActionManager().enableAllActionItems(mode.getMenu());//Not used currently
    }

}

From source file:pl.bcichecki.rms.client.android.fragments.OutboxMessagesListFragment.java

private void setUpActionModeOnListItems() {
    getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

        @Override/*from w w  w .j  ava 2s.  c  o  m*/
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return performAction(mode, item);
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.fragment_outbox_messages_list_context, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            if (checked) {
                verifyMenuItems(mode.getMenu());
                for (int i = 0; i < getListView().getCheckedItemPositions().size(); i++) {
                    if (i != position) {
                        getListView().setItemChecked(i, false);
                    }
                }
            }
        }

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

        private void verifyMenuItems(Menu menu) {
            Message checkedMessage = getFirstCheckedItem();
            menu.findItem(R.id.fragment_outbox_messages_list_context_menu_archive)
                    .setVisible(!checkedMessage.isArchivedBySender());
        }
    });
}

From source file:pl.bcichecki.rms.client.android.fragments.InboxMessagesListFragment.java

private void setUpActionModeOnListItems() {
    getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

        @Override//  www .j a v  a  2 s .  co  m
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return performAction(mode, item);
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.fragment_inbox_messages_list_context, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            if (checked) {
                verifyMenuItems(mode.getMenu());
                for (int i = 0; i < getListView().getCheckedItemPositions().size(); i++) {
                    if (i != position) {
                        getListView().setItemChecked(i, false);
                    }
                }
            }
        }

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

        private void verifyMenuItems(Menu menu) {
            Message checkedMessage = getFirstCheckedItem();
            menu.findItem(R.id.fragment_inbox_messages_list_context_menu_archive)
                    .setVisible(!checkedMessage.isArchivedBySender());
        }
    });
}

From source file:org.jraf.android.bikey.app.ride.list.RideListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setEmptyText(getString(R.string.ride_list_empty));

    ListView listView = getListView();
    listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        @Override//from   w  ww  .  j  a va 2s  . c o m
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.setTitle(R.string.ride_list_title);
            int quantity = getListView().getCheckedItemCount();
            mode.setSubtitle(
                    getResources().getQuantityString(R.plurals.ride_list_cab_subtitle, quantity, quantity));
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.ride_list_contextual, menu);
            return true;
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            int quantity = getListView().getCheckedItemCount();
            mode.setSubtitle(
                    getResources().getQuantityString(R.plurals.ride_list_cab_subtitle, quantity, quantity));
            // Enable share / edit if only one item is selected (can't share / edit several items at the same time)
            mode.getMenu().findItem(R.id.action_share).setVisible(quantity == 1);
            mode.getMenu().findItem(R.id.action_edit).setVisible(quantity == 1);
            // Enable merge only if several items are selected
            mode.getMenu().findItem(R.id.action_merge).setVisible(quantity > 1);
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            long[] checkedItemIds = getListView().getCheckedItemIds();
            long checkedItemId = checkedItemIds[0];
            Uri checkedItemUri = ContentUris.withAppendedId(RideColumns.CONTENT_URI, checkedItemId);
            switch (item.getItemId()) {
            case R.id.action_delete:
                getCallbacks().showDeleteDialog(checkedItemIds);
                mode.finish();
                return true;

            case R.id.action_share:
                getCallbacks().showShareDialog(checkedItemUri);
                mode.finish();
                return true;

            case R.id.action_edit:
                getCallbacks().edit(checkedItemUri);
                mode.finish();
                return true;

            case R.id.action_merge:
                getCallbacks().showMergeDialog(checkedItemIds);
                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

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

From source file:pl.bcichecki.rms.client.android.fragments.EventsListFragment.java

private void setUpActionModeOnListItems() {
    getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

        @Override/*from  w w w .  j ava2  s .c o  m*/
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return performAction(mode, item);
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.fragment_events_list_context, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            if (checked) {
                verifyMenuItems(mode.getMenu());
                for (int i = 0; i < getListView().getCheckedItemPositions().size(); i++) {
                    if (i != position) {
                        getListView().setItemChecked(i, false);
                    }
                }
            }
        }

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

        private void verifyMenuItems(Menu menu) {
            Event checkedEvent = getFirstCheckedItem();
            menu.findItem(R.id.fragment_events_list_context_menu_archive)
                    .setVisible(!checkedEvent.isArchived());
            menu.findItem(R.id.fragment_events_list_context_menu_edit)
                    .setVisible(!checkedEvent.isArchived() || !checkedEvent.isLocked());
            menu.findItem(R.id.fragment_events_list_context_menu_lock).setVisible(!checkedEvent.isLocked());
            menu.findItem(R.id.fragment_events_list_context_menu_share).setVisible(!checkedEvent.isArchived());
            menu.findItem(R.id.fragment_events_list_context_menu_unlock).setVisible(checkedEvent.isLocked());
        }
    });
}

From source file:org.readium.sdk.android.biblemesh.WebViewActivity.java

@Override
public void onActionModeStarted(ActionMode mode) {
    if (mActionMode == null) {
        mActionMode = mode;//from   ww w . j  a  va2 s .com
        Menu menu = mode.getMenu();
        // Remove the default menu items (select all, copy, paste, search)
        menu.clear();

        // If you want to keep any of the defaults,
        // remove the items you don't want individually:
        // menu.removeItem(android.R.id.[id_of_item_to_remove])

        // Inflate your own menu items
        mode.getMenuInflater().inflate(R.menu.context_menu, menu);

        MenuItem item = menu.findItem(R.id.highlight_item);
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                mReadiumJSApi.highlightSelection();
                return true;
            }
        });
    }

    super.onActionModeStarted(mode);
}