KEYCODE_MOVE_END源码实例Demo

android.view.KeyEvent#KEYCODE_MOVE_END源码实例Demo

下面列出了android.view.KeyEvent#KEYCODE_MOVE_END 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: LaunchEnr   文件: FocusHelper.java

/**
 * Helper method to be used for playing sound effects.
 */
@Thunk private static void playSoundEffect(int keyCode, View v) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_PAGE_DOWN:
        case KeyEvent.KEYCODE_MOVE_END:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_MOVE_HOME:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
            break;
        default:
            break;
    }
}
 
源代码2 项目: Trebuchet   文件: FocusHelper.java

/**
 * Helper method to be used for playing sound effects.
 */
@Thunk static void playSoundEffect(int keyCode, View v) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_PAGE_DOWN:
        case KeyEvent.KEYCODE_MOVE_END:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_MOVE_HOME:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
            break;
        default:
            break;
    }
}
 

@Override
public boolean sendKeyEvent(KeyEvent event) {
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_SHIFT_LEFT:
            if (isSelectText())
                selectText(false);
            else
                selectText(true);
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            moveCaretLeft();
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            moveCaretUp();
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            moveCaretRight();
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            moveCaretDown();
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            moveCaret(0);
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            moveCaret(_hDoc.length());
            break;
        default:
            return super.sendKeyEvent(event);
    }
    return true;
}
 

@Override
public boolean sendKeyEvent(KeyEvent event) {
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_SHIFT_LEFT:
            if (isSelectText())
                selectText(false);
            else
                selectText(true);
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            moveCaretLeft();
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            moveCaretUp();
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            moveCaretRight();
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            moveCaretDown();
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            moveCaret(0);
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            moveCaret(_hDoc.length());
            break;
        default:
            return super.sendKeyEvent(event);
    }
    return true;
}
 

public boolean sendKeyEvent(KeyEvent event) {
    if(event.getAction()==KeyEvent.ACTION_UP)
        return super.sendKeyEvent(event);
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_SHIFT_LEFT:
        case KeyEvent.KEYCODE_SHIFT_RIGHT:
            /*if (isSelectText())
                selectText(false);
            else*/
                selectText(true);
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
              _fieldController.moveCaretLeft(true);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            _fieldController.moveCaretUp(true);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            _fieldController.moveCaretRight(true);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            _fieldController.moveCaretDown(true);
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            moveCaret(0);
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            moveCaret(_hDoc.length() - 1);
            break;
        default:
            return super.sendKeyEvent(event);
    }
    return true;
}
 
源代码6 项目: LaunchEnr   文件: FocusLogic.java

/**
 * Returns true only if this utility class handles the key code.
 */
public static boolean shouldConsume(int keyCode) {
    return (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ||
            keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN ||
            keyCode == KeyEvent.KEYCODE_MOVE_HOME || keyCode == KeyEvent.KEYCODE_MOVE_END ||
            keyCode == KeyEvent.KEYCODE_PAGE_UP || keyCode == KeyEvent.KEYCODE_PAGE_DOWN);
}
 
源代码7 项目: Trebuchet   文件: FocusLogic.java

/**
 * Returns true only if this utility class handles the key code.
 */
public static boolean shouldConsume(int keyCode) {
    return (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ||
            keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN ||
            keyCode == KeyEvent.KEYCODE_MOVE_HOME || keyCode == KeyEvent.KEYCODE_MOVE_END ||
            keyCode == KeyEvent.KEYCODE_PAGE_UP || keyCode == KeyEvent.KEYCODE_PAGE_DOWN ||
            keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL);
}
 
源代码8 项目: fastedit   文件: FastEdit.java

void onKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (action) {
        case KeyEvent.ACTION_DOWN: {

            //输入模式
            int unicodeChar = event.getUnicodeChar();
            if (unicodeChar != 0) {

                input((char) unicodeChar);
                event.cancel();
            }
            if (!event.isCanceled() && !event.isCtrlPressed() && !event.isAltPressed()
                    && !event.isShiftPressed()) {
                switch (keyCode) {
                    case KeyEvent.KEYCODE_TAB:
                        //tab
                        input(tabText);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_SPACE:
                        //空格
                        input(' ');
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_ENTER:
                        //enter
                        onKeyCodeEnter(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DEL:
                        //del
                        onKeyCodeDel(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_FORWARD_DEL:
                        //del
                        onKeyCodeForwardDel(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_LEFT:
                        //left
                        onKeyCodeDpadLeft(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_RIGHT:
                        //right
                        onKeyCodeDpadRight(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_UP:
                        //up
                        onKeyCodeDpadUp(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_DOWN:
                        //down
                        onKeyCodeDpadDown(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_VOLUME_DOWN:

                    case KeyEvent.KEYCODE_PAGE_DOWN:
                        //page down
                        onKeyCodePageDown(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_VOLUME_UP:

                    case KeyEvent.KEYCODE_PAGE_UP:
                        //page up
                        onKeyCodePageUp(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_MOVE_HOME:
                        onKeyCodeMoveHome(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_MOVE_END:
                        onKeyCodeMoveEnd(event);
                        event.cancel();
                        break;
                }
            }
            if (!event.isCanceled()) {
                //快捷键模式
                if (onShortKey(event.isCtrlPressed(), event.isAltPressed(), event.isShiftPressed(), keyCode)) {
                    event.cancel();
                }
            }

            break;
        }

    }
}
 
源代码9 项目: fastedit   文件: FastEdit.java

/**
 * 快捷方式
 *
 * @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;
}
 

/**
 * Performs a movement key action.
 * The default implementation decodes the key down and invokes movement actions
 * such as {@link #down} and {@link #up}.
 * {@link #onKeyDown(TextView, Spannable, int, KeyEvent)} calls this method once
 * to handle an {@link KeyEvent#ACTION_DOWN}.
 * {@link #onKeyOther(TextView, Spannable, KeyEvent)} calls this method repeatedly
 * to handle each repetition of an {@link KeyEvent#ACTION_MULTIPLE}.
 *
 * @param widget The text view.
 * @param buffer The text buffer.
 * @param event The key event.
 * @param keyCode The key code.
 * @param movementMetaState The keyboard meta states used for movement.
 * @param event The key event.
 * @return True if the event was handled.
 */
protected boolean handleMovementKey(TextView widget, Spannable buffer,
        int keyCode, int movementMetaState, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return left(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_CTRL_ON)) {
                return leftWord(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return lineStart(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return right(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_CTRL_ON)) {
                return rightWord(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return lineEnd(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return up(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return top(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return down(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return bottom(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_UP:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return pageUp(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return top(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return pageDown(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_ALT_ON)) {
                return bottom(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_HOME:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return home(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_CTRL_ON)) {
                return top(widget, buffer);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_END:
            if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
                return end(widget, buffer);
            } else if (KeyEvent.metaStateHasModifiers(movementMetaState,
                    KeyEvent.META_CTRL_ON)) {
                return bottom(widget, buffer);
            }
            break;
    }
    return false;
}
 
源代码11 项目: LaunchEnr   文件: FocusLogic.java

public static int handleKeyEvent(int keyCode, int [][] map, int iconIdx, int pageIndex,
        int pageCount, boolean isRtl) {

    int cntX = map == null ? -1 : map.length;
    int cntY = map == null ? -1 : map[0].length;

    int newIndex = NOOP;
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            newIndex = handleDpadHorizontal(iconIdx, cntX, cntY, map, -1 /*increment*/, isRtl);
            if (!isRtl && newIndex == NOOP && pageIndex > 0) {
                newIndex = PREVIOUS_PAGE_RIGHT_COLUMN;
            } else if (isRtl && newIndex == NOOP && pageIndex < pageCount - 1) {
                newIndex = NEXT_PAGE_RIGHT_COLUMN;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            newIndex = handleDpadHorizontal(iconIdx, cntX, cntY, map, 1 /*increment*/, isRtl);
            if (!isRtl && newIndex == NOOP && pageIndex < pageCount - 1) {
                newIndex = NEXT_PAGE_LEFT_COLUMN;
            } else if (isRtl && newIndex == NOOP && pageIndex > 0) {
                newIndex = PREVIOUS_PAGE_LEFT_COLUMN;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            newIndex = handleDpadVertical(iconIdx, cntX, cntY, map, 1  /*increment*/);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            newIndex = handleDpadVertical(iconIdx, cntX, cntY, map, -1  /*increment*/);
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            newIndex = handleMoveHome();
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            newIndex = handleMoveEnd();
            break;
        case KeyEvent.KEYCODE_PAGE_DOWN:
            newIndex = handlePageDown(pageIndex, pageCount);
            break;
        case KeyEvent.KEYCODE_PAGE_UP:
            newIndex = handlePageUp(pageIndex);
            break;
        default:
            break;
    }
    return newIndex;
}
 
源代码12 项目: Trebuchet   文件: FocusLogic.java

public static int handleKeyEvent(int keyCode, int cntX, int cntY,
        int [][] map, int iconIdx, int pageIndex, int pageCount, boolean isRtl) {

    if (DEBUG) {
        Log.v(TAG, String.format(
                "handleKeyEvent START: cntX=%d, cntY=%d, iconIdx=%d, pageIdx=%d, pageCnt=%d",
                cntX, cntY, iconIdx, pageIndex, pageCount));
    }

    int newIndex = NOOP;
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            newIndex = handleDpadHorizontal(iconIdx, cntX, cntY, map, -1 /*increment*/);
            if (isRtl && newIndex == NOOP && pageIndex > 0) {
                newIndex = PREVIOUS_PAGE_RIGHT_COLUMN;
            } else if (isRtl && newIndex == NOOP && pageIndex < pageCount - 1) {
                newIndex = NEXT_PAGE_RIGHT_COLUMN;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            newIndex = handleDpadHorizontal(iconIdx, cntX, cntY, map, 1 /*increment*/);
            if (isRtl && newIndex == NOOP && pageIndex < pageCount - 1) {
                newIndex = NEXT_PAGE_LEFT_COLUMN;
            } else if (isRtl && newIndex == NOOP && pageIndex > 0) {
                newIndex = PREVIOUS_PAGE_LEFT_COLUMN;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            newIndex = handleDpadVertical(iconIdx, cntX, cntY, map, 1  /*increment*/);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            newIndex = handleDpadVertical(iconIdx, cntX, cntY, map, -1  /*increment*/);
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            newIndex = handleMoveHome();
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            newIndex = handleMoveEnd();
            break;
        case KeyEvent.KEYCODE_PAGE_DOWN:
            newIndex = handlePageDown(pageIndex, pageCount);
            break;
        case KeyEvent.KEYCODE_PAGE_UP:
            newIndex = handlePageUp(pageIndex);
            break;
        default:
            break;
    }

    if (DEBUG) {
        Log.v(TAG, String.format("handleKeyEvent FINISH: index [%d -> %s]",
                iconIdx, getStringIndex(newIndex)));
    }
    return newIndex;
}
 
源代码评论
动弹
沙发等你来抢
 方法所在类
 同类方法