Example usage for android.view KeyEvent META_CTRL_ON

List of usage examples for android.view KeyEvent META_CTRL_ON

Introduction

In this page you can find the example usage for android.view KeyEvent META_CTRL_ON.

Prototype

int META_CTRL_ON

To view the source code for android.view KeyEvent META_CTRL_ON.

Click Source Link

Document

This mask is used to check whether one of the CTRL meta keys is pressed.

Usage

From source file:org.connectbot.util.TerminalTextViewOverlay.java

@Override
@TargetApi(12)//from   w  ww.j a  va  2  s . c om
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((MotionEventCompat.getSource(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL:
            // Process scroll wheel movement:
            float yDistance = MotionEventCompat.getAxisValue(event, MotionEvent.AXIS_VSCROLL);

            vt320 vtBuffer = (vt320) terminalView.bridge.buffer;
            boolean mouseReport = vtBuffer.isMouseReportEnabled();
            if (mouseReport) {
                int row = (int) Math.floor(event.getY() / terminalView.bridge.charHeight);
                int col = (int) Math.floor(event.getX() / terminalView.bridge.charWidth);

                vtBuffer.mouseWheel(yDistance > 0, col, row,
                        (event.getMetaState() & KeyEvent.META_CTRL_ON) != 0,
                        (event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0,
                        (event.getMetaState() & KeyEvent.META_META_ON) != 0);
                return true;
            }
        }
    }

    return super.onGenericMotionEvent(event);
}

From source file:org.connectbot.util.TerminalTextViewOverlay.java

/**
 * @param event//w ww.  ja  va 2 s. c  o m
 * @param bridge
 * @return True if the event is handled.
 */
@TargetApi(14)
private boolean onMouseEvent(MotionEvent event, TerminalBridge bridge) {
    int row = (int) Math.floor(event.getY() / bridge.charHeight);
    int col = (int) Math.floor(event.getX() / bridge.charWidth);
    int meta = event.getMetaState();
    boolean shiftOn = (meta & KeyEvent.META_SHIFT_ON) != 0;
    vt320 vtBuffer = (vt320) bridge.buffer;
    boolean mouseReport = vtBuffer.isMouseReportEnabled();

    // MouseReport can be "defeated" using the shift key.
    if (!mouseReport || shiftOn) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (event.getButtonState() == MotionEvent.BUTTON_TERTIARY) {
                // Middle click pastes.
                pasteClipboard();
                return true;
            }

            // Begin "selection mode"

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                closeSelectionActionMode();
            }
        } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
            // In the middle of selection.

            if (selectionActionMode == null) {
                selectionActionMode = startActionMode(new TextSelectionActionModeCallback());
            }

            int selectionStart = getSelectionStart();
            int selectionEnd = getSelectionEnd();

            if (selectionStart > selectionEnd) {
                int tempStart = selectionStart;
                selectionStart = selectionEnd;
                selectionEnd = tempStart;
            }

            currentSelection = getText().toString().substring(selectionStart, selectionEnd);
        }
    } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
        terminalView.viewPager.setPagingEnabled(false);
        vtBuffer.mousePressed(col, row, mouseEventToJavaModifiers(event));
        return true;
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
        terminalView.viewPager.setPagingEnabled(true);
        vtBuffer.mouseReleased(col, row);
        return true;
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        int buttonState = event.getButtonState();
        int button = (buttonState & MotionEvent.BUTTON_PRIMARY) != 0 ? 0
                : (buttonState & MotionEvent.BUTTON_SECONDARY) != 0 ? 1
                        : (buttonState & MotionEvent.BUTTON_TERTIARY) != 0 ? 2 : 3;
        vtBuffer.mouseMoved(button, col, row, (meta & KeyEvent.META_CTRL_ON) != 0,
                (meta & KeyEvent.META_SHIFT_ON) != 0, (meta & KeyEvent.META_META_ON) != 0);
        return true;
    }

    return false;
}

From source file:org.connectbot.util.TerminalTextViewOverlay.java

/**
 * Takes an android mouse event and produces a Java InputEvent modifiers int which can be
 * passed to vt320.//from   w w  w. j  a  v  a2  s .co  m
 * @param mouseEvent The {@link MotionEvent} which should be a mouse click or release.
 * @return A Java InputEvent modifier int. See
 * http://docs.oracle.com/javase/7/docs/api/java/awt/event/InputEvent.html
 */
@TargetApi(14)
private static int mouseEventToJavaModifiers(MotionEvent mouseEvent) {
    if (MotionEventCompat.getSource(mouseEvent) != InputDevice.SOURCE_MOUSE)
        return 0;

    int mods = 0;

    // See http://docs.oracle.com/javase/7/docs/api/constant-values.html
    int buttonState = mouseEvent.getButtonState();
    if ((buttonState & MotionEvent.BUTTON_PRIMARY) != 0)
        mods |= 16;
    if ((buttonState & MotionEvent.BUTTON_SECONDARY) != 0)
        mods |= 8;
    if ((buttonState & MotionEvent.BUTTON_TERTIARY) != 0)
        mods |= 4;

    // Note: Meta and Ctrl are intentionally swapped here to keep logic in vt320 simple.
    int meta = mouseEvent.getMetaState();
    if ((meta & KeyEvent.META_META_ON) != 0)
        mods |= 2;
    if ((meta & KeyEvent.META_SHIFT_ON) != 0)
        mods |= 1;
    if ((meta & KeyEvent.META_CTRL_ON) != 0)
        mods |= 4;

    return mods;
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

private int getMetaState(boolean shifted) {
    int meta = 0;
    if (shifted)/*from  w ww.  java  2 s .c om*/
        meta |= KeyEvent.META_SHIFT_ON | KeyEvent.META_SHIFT_LEFT_ON;
    if (mModCtrl)
        meta |= KeyEvent.META_CTRL_ON | KeyEvent.META_CTRL_LEFT_ON;
    if (mModAlt)
        meta |= KeyEvent.META_ALT_ON | KeyEvent.META_ALT_LEFT_ON;
    if (mModMeta)
        meta |= KeyEvent.META_META_ON | KeyEvent.META_META_LEFT_ON;
    return meta;
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

private void sendCtrlKey(InputConnection ic, boolean isDown, boolean chording) {
    if (chording && delayChordingCtrlModifier())
        return;// w  w w  .  j  a va 2 s  .co m

    int key = sKeyboardSettings.chordingCtrlKey;
    if (key == 0)
        key = KeyEvent.KEYCODE_CTRL_LEFT;
    int meta = KeyEvent.META_CTRL_ON | KeyEvent.META_CTRL_LEFT_ON;
    if (isDown) {
        sendKeyDown(ic, key, meta);
    } else {
        sendKeyUp(ic, key, meta);
    }
}