Java Code Examples for android.view.ActionMode#getMenu()

The following examples show how to use android.view.ActionMode#getMenu() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomActionWebView.java    From CustomActionWebView with MIT License 6 votes vote down vote up
/**
 * 处理item,处理点击
 * @param actionMode
 */
private ActionMode resolveActionMode(ActionMode actionMode) {
    if (actionMode != null) {
        final Menu menu = actionMode.getMenu();
        mActionMode = actionMode;
        menu.clear();
        for (int i = 0; i < mActionList.size(); i++) {
            menu.add(mActionList.get(i));
        }
        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    getSelectedData((String) item.getTitle());
                    releaseAction();
                    return true;
                }
            });
        }
    }
    mActionMode = actionMode;
    return actionMode;
}
 
Example 2
Source File: ReadArticleActivity.java    From android-app with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public void onActionModeStarted(ActionMode mode) {
        if (annotationsEnabled) {
            Menu menu = mode.getMenu();

            mode.getMenuInflater().inflate(R.menu.read_article_activity_annotate, menu);

            MenuItem item = menu.findItem(R.id.menu_annotate);
            item.setOnMenuItemClickListener(i -> {
                webViewContent.evaluateJavascript("invokeAnnotator();", null);
//                mode.finish(); // seems to reset selection too early (not on emulator though)
                return true;
            });
        }

        super.onActionModeStarted(mode);
    }
 
Example 3
Source File: ReadingActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onActionModeStarted(@NonNull ActionMode mode) {
    if (mActionMode == null) {
        mActionMode = mode;
        Menu menu = mode.getMenu();

        menu.clear();

        if (!shouldDisplayFloatingSelectionMenu()) {
            MenuInflater inflater = new MenuInflater(this);

            inflater.inflate(R.menu.text_selection_context_menu, menu);
            mode.setTitle(null);

            menu.findItem(R.id.action_copy_text).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            menu.findItem(R.id.action_select_all_text).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            menu.findItem(R.id.action_add_comment).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            menu.findItem(R.id.action_share_text).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            menu.findItem(R.id.action_add_highlight).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

            if (mHighlightClickedFlag) {
                menu.findItem(R.id.action_add_comment).setVisible(true);
                menu.findItem(R.id.highlight_remove).setVisible(true);
            }
        }
    }

    super.onActionModeStarted(mode);
    for (ActionModeChangeListener actionModeChangeListener : mActionModeChangeListener) {
        actionModeChangeListener.actionModeStarted();
    }
}