Java Code Examples for android.view.inputmethod.InputConnection#performContextMenuAction()

The following examples show how to use android.view.inputmethod.InputConnection#performContextMenuAction() . 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: KeyboardSelectorWidget.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
@Override
    public void onClick(View v) {
        InputConnection ic;
        switch (v.getId()) {
            case R.id.keyboard_selector_top_close_btn:
                close();
                break;
            case R.id.select:
                if (mStatus == Status.direct) {
                    mStatus = Status.select;
                    beginSelect();
                } else {
                    mStatus = Status.direct;
                    cancelSelectWithSelection();
                }
                updateSelector();
                break;
            case R.id.select_all:
                ic = getCurrentIC();
                if (ic == null)
                    return;
                boolean hasSelection = (Boolean) mSelectAll.getTag();
                if (hasSelection) {
                    ic.performContextMenuAction(android.R.id.cut);
                } else {
                    ic.performContextMenuAction(android.R.id.selectAll);
                }
//                cancelSelectWithSelection();
                break;
            case R.id.arrow_up:
                moveCursor(Direct.top);
                break;
            case R.id.arrow_down:
                moveCursor(Direct.bottom);
                break;
            case R.id.arrow_left:
                moveCursor(Direct.left);
                break;
            case R.id.arrow_right:
                moveCursor(Direct.right);
                break;
            case R.id.copy:
                ic = getCurrentIC();
                if (ic == null || TextUtils.isEmpty(ic.getSelectedText(0)))
                    return;
                ic.performContextMenuAction(android.R.id.copy);
                cancelSelectWithSelection();
                Toast.makeText(TestApplication.getInstance(), R.string.keyboard_clipboard_copy_success, Toast.LENGTH_LONG).show();
                break;
            case R.id.paste:
                ic = getCurrentIC();
                if (null == ic) {
                    return;
                }
                LatinIME.getInstance().getInputLogic().onPasteFromClipBoardEvent(ClipManager.getInstance().getPasteTipText());
                ic.performContextMenuAction(android.R.id.paste);
                cancelSelect();
                break;
            case R.id.delete:
                ic = getCurrentIC();
                if (ic != null) {
                    if (TextUtils.isEmpty(ic.getSelectedText(0))) {
                        LatinIME.getInstance().getInputLogic().onDeleteFromClipBoardEvent(ic.getTextBeforeCursor(1, 0).toString());
                    } else {
                        LatinIME.getInstance().getInputLogic().onDeleteFromClipBoardEvent(ic.getSelectedText(0).toString());
                    }
                }
                LatinIME.getInstance().getInputLogic().sendDownUpKeyEvent(KeyEvent.KEYCODE_DEL);
                break;
            default:
                break;
        }

        mHandler.post(this::updateStatus);
    }
 
Example 2
Source File: ImeContainer.java    From mongol-library with MIT License 4 votes vote down vote up
@Override
public void selectAll() {
    InputConnection ic = getInputConnection();
    if (ic == null) return;
    ic.performContextMenuAction(android.R.id.selectAll);
}
 
Example 3
Source File: ImeContainer.java    From mongol-library with MIT License 4 votes vote down vote up
@Override
public void copyText() {
    InputConnection ic = getInputConnection();
    if (ic == null) return;
    ic.performContextMenuAction(android.R.id.copy);
}
 
Example 4
Source File: ImeContainer.java    From mongol-library with MIT License 4 votes vote down vote up
public void cutText() {
    InputConnection ic = getInputConnection();
    if (ic == null) return;
    ic.performContextMenuAction(android.R.id.cut);
}
 
Example 5
Source File: ImeContainer.java    From mongol-library with MIT License 4 votes vote down vote up
@Override
public void pasteText() {
    InputConnection ic = getInputConnection();
    if (ic == null) return;
    ic.performContextMenuAction(android.R.id.paste);
}
 
Example 6
Source File: InputMethodService.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * This is called when the user has selected a context menu item from the
 * extracted text view, when running in fullscreen mode.  The default
 * implementation sends this action to the current InputConnection's
 * {@link InputConnection#performContextMenuAction(int)}, for it
 * to be processed in underlying "real" editor.  Re-implement this to
 * provide whatever behavior you want.
 */
public boolean onExtractTextContextMenuItem(int id) {
    InputConnection ic = getCurrentInputConnection();
    if (ic != null) {
        ic.performContextMenuAction(id);
    }
    return true;
}