Java Code Examples for android.view.KeyEvent#KEYCODE_Y

The following examples show how to use android.view.KeyEvent#KEYCODE_Y . 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: Editor.java    From turbo-editor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
    if (event.isCtrlPressed()) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_A:
            case KeyEvent.KEYCODE_X:
            case KeyEvent.KEYCODE_C:
            case KeyEvent.KEYCODE_V:
            case KeyEvent.KEYCODE_Z:
            case KeyEvent.KEYCODE_Y:
            case KeyEvent.KEYCODE_S:
                return true;
            default:
                return false;
        }
    } else {
        switch (keyCode) {
            case KeyEvent.KEYCODE_TAB:
                return true;
            default:
                return false;
        }
    }
}
 
Example 2
Source File: UndoRedoSupportEditText.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (DLog.DEBUG) {
        Log.w(TAG, "onKeyUp " + event);
    }
    if (handleControlKey(keyCode, event, false)) {
        return true;
    }
    if (event.isCtrlPressed() || mKeyListener.mControlKey.isActive()) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_A:
            case KeyEvent.KEYCODE_X:
            case KeyEvent.KEYCODE_C:
            case KeyEvent.KEYCODE_V:
            case KeyEvent.KEYCODE_Z:
            case KeyEvent.KEYCODE_Y:
            case KeyEvent.KEYCODE_S:
            case KeyEvent.KEYCODE_R:
            case KeyEvent.KEYCODE_F:
            case KeyEvent.KEYCODE_L:
                return true;
        }
    } else {
        switch (keyCode) {
            case KeyEvent.KEYCODE_TAB:
                return true;
        }
    }
    return super.onKeyUp(keyCode, event);

}
 
Example 3
Source File: VerticalGridActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (mFragment instanceof NetworkBrowserFragment && (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_BUTTON_Y || keyCode == KeyEvent.KEYCODE_Y)) {
        ((NetworkBrowserFragment)mFragment).showDetails();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 4
Source File: FastEdit.java    From fastedit with Apache License 2.0 4 votes vote down vote up
/**
 * 快捷方式
 *
 * @param ctrl
 * @param alt
 * @param shift
 * @param keyCode
 */
protected boolean onShortKey(boolean ctrl, boolean alt, boolean shift, int keyCode) {
    if (ctrl) {
        if (keyCode == KeyEvent.KEYCODE_A) {
            selectModel.select(0, length());
            postInvalidate();
            return true;


        }
        if (keyCode == KeyEvent.KEYCODE_C) {
            if (selectModel.hasSelect()) {
                try {
                    copy();
                } catch (Exception e) {
                }
                return true;
            }
        }
        if (keyCode == KeyEvent.KEYCODE_X) {
            if (selectModel.hasSelect()) {
                cut();
                return true;
            }
        }
        if (keyCode == KeyEvent.KEYCODE_Z) {
            undo();
            return true;
        }
        if (keyCode == KeyEvent.KEYCODE_Y) {
            redo();
            return true;
        }

    }
    if (shift) {
        try {
            if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
                if (!selectModel.hasSelect()) {
                    selectModel.start(cursorPos);
                }
                selectModel.toLeft(1);
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
                if (!selectModel.hasSelect()) {
                    selectModel.start(cursorPos);
                }
                selectModel.toRight(1);
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
                if (!selectModel.hasSelect()) {
                    selectModel.start(cursorPos);
                }
                selectModel.toUp(1);
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                if (!selectModel.hasSelect()) {
                    selectModel.start(cursorPos);
                }
                selectModel.toDown(1);
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_MOVE_HOME) {
                if (!selectModel.hasSelect()) {
                    selectModel.start(cursorPos);
                }
                selectModel.toHome();
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_MOVE_END) {
                if (!selectModel.hasSelect()) {
                    selectModel.start(cursorPos);
                }
                selectModel.toEnd();
                return true;
            }

        } finally {
            postInvalidate();
        }
    }
    return false;
}
 
Example 5
Source File: TextProcessor.java    From CodeEditor with Apache License 2.0 4 votes vote down vote up
@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.isCtrlPressed()) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_X: // CTRL+X - Cut
                    cut();
                    return true;
                case KeyEvent.KEYCODE_C: // CTRL+C - Copy
                    copy();
                    return true;
                case KeyEvent.KEYCODE_V: // CTRL+V - Paste
                    paste();
                    return true;
                case KeyEvent.KEYCODE_Z: // CTRL+Z - Undo
                    undo();
                    return true;
                case KeyEvent.KEYCODE_Y: // CTRL+Y - Redo
                    redo();
                    return true;
                case KeyEvent.KEYCODE_A: // CTRL+A - Select All
                    selectAll();
                    return true;
                case KeyEvent.KEYCODE_DEL: // CTRL+Delete - Delete Line
                    deleteLine();
                    return true;
                case KeyEvent.KEYCODE_D: // CTRL+D - Duplicate Line
                    duplicateLine();
                    return true;
//                case KeyEvent.KEYCODE_S: // CTRL+S - Save File
//                    codeEditor.saveFile();
//                    return true;
                default:
                    return super.onKeyDown(keyCode, event);
            }
        } else {
            switch (keyCode) {
                case KeyEvent.KEYCODE_TAB: // TAB
                    int start, end;
                    start = Math.max(getSelectionStart(), 0);
                    end = Math.max(getSelectionEnd(), 0);
                    getText().replace(Math.min(start, end),
                            Math.max(start, end), TAB_STR, 0, TAB_STR.length());
                    return true;
                default:
                    try {
                        return super.onKeyDown(keyCode, event);
                    } catch (Exception e) {
                        Logger.error(TAG, e);
                    }
                    return false;
            }
        }
    }
 
Example 6
Source File: UndoRedoSupportEditText.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
     * CTRL + C copy
     * CTRL + V paste
     * CTRL + B: compile
     * CTRL + R generate
     * CTRL + X cut
     * CTRL + Z undo
     * CTRL + Y redo
     * CTRL + Q quit
     * CTRL + S save
     * CTRL + O open
     * CTRL + F find
     * CTRL + H find and replace
     * CTRL + L format code
     * CTRL + G: goto line
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (DLog.DEBUG) Log.w(TAG, "onKeyDown: " + keyCode + " " + event);
        if (handleControlKey(keyCode, event, false)) {
            return true;
        }
        if (event.isCtrlPressed() || mKeyListener.mControlKey.isActive()) {
//            Log.i(TAG, "onKeyDown: process");
            switch (keyCode) {
                case KeyEvent.KEYCODE_A:
                    selectAll();
                    return true;
                case KeyEvent.KEYCODE_X:
                    cut();
                    return true;
                case KeyEvent.KEYCODE_C:
                    copy();
                    return true;
                case KeyEvent.KEYCODE_V:
                    paste();
                    return true;
                case KeyEvent.KEYCODE_G: //go to line
                    if (editorControl != null)
                        editorControl.goToLine();
                    return true;
                case KeyEvent.KEYCODE_L: //format
                    if (editorControl != null)
                        editorControl.formatCode();
                    return true;
                case KeyEvent.KEYCODE_Z:
                    if (canUndo()) {
                        undo();
                    }
                    return true;
                case KeyEvent.KEYCODE_Y:
                    if (canRedo()) {
                        redo();
                    }
                    return true;
                case KeyEvent.KEYCODE_S:
                    if (editorControl != null)
                        editorControl.saveCurrentFile();
                    return true;
                case KeyEvent.KEYCODE_N:
                    if (editorControl != null)
                        editorControl.saveAs();
                    return true;
                default:
                    return super.onKeyDown(keyCode, event);
            }
        } else {
            switch (keyCode) {
                case KeyEvent.KEYCODE_TAB:
                    String textToInsert = mSettings.getTabStr();
                    int start, end;
                    start = Math.max(getSelectionStart(), 0);
                    end = Math.max(getSelectionEnd(), 0);
                    getText().replace(Math.min(start, end), Math.max(start, end),
                            textToInsert, 0, textToInsert.length());
                    return true;
                default:
                    try {
                        return super.onKeyDown(keyCode, event);
                    } catch (Exception e) {
                    }
                    return false;

            }
        }
    }
 
Example 7
Source File: Editor.java    From turbo-editor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {

    if (event.isCtrlPressed()) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_A:
                return onTextContextMenuItem(ID_SELECT_ALL);
            case KeyEvent.KEYCODE_X:
                return onTextContextMenuItem(ID_CUT);
            case KeyEvent.KEYCODE_C:
                return onTextContextMenuItem(ID_COPY);
            case KeyEvent.KEYCODE_V:
                return onTextContextMenuItem(ID_PASTE);
            case KeyEvent.KEYCODE_Z:
                if (getCanUndo()) {
                    return onTextContextMenuItem(ID_UNDO);
                }
            case KeyEvent.KEYCODE_Y:
                if (getCanRedo()) {
                    return onTextContextMenuItem(ID_REDO);
                }
            case KeyEvent.KEYCODE_S:
                getMainActivity().saveTheFile(false);
                return true;
            default:
                return super.onKeyDown(keyCode, event);
        }
    } else {
        switch (keyCode) {
            case KeyEvent.KEYCODE_TAB:
                String textToInsert = "  ";
                int start, end;
                start = Math.max(getSelectionStart(), 0);
                end = Math.max(getSelectionEnd(), 0);
                getText().replace(Math.min(start, end), Math.max(start, end),
                        textToInsert, 0, textToInsert.length());
                return true;
            default:
                return super.onKeyDown(keyCode, event);
        }
    }
}