Java Code Examples for android.view.KeyEvent#KEYCODE_D

The following examples show how to use android.view.KeyEvent#KEYCODE_D . 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: EditorActivity.java    From spline with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    switch (keyCode) {
        case KeyEvent.KEYCODE_R:
            mViewModel.addRectLayer();
            return true;
        case KeyEvent.KEYCODE_T:
            mViewModel.addTriangleLayer();
            return true;
        case KeyEvent.KEYCODE_O:
            mViewModel.addOvalLayer();
            return true;
    }

    if (mBinding.documentView.hasFocus()) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_DEL:
            case KeyEvent.KEYCODE_FORWARD_DEL:
                return onContextMenuAction(DELETE);
        }

        if (event.isCtrlPressed()) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_X:
                    return onContextMenuAction(CUT);
                case KeyEvent.KEYCODE_C:
                    return onContextMenuAction(COPY);
                case KeyEvent.KEYCODE_V:
                    return onContextMenuAction(PASTE);
                case KeyEvent.KEYCODE_D:
                    return onContextMenuAction(DUPLICATE);
                case KeyEvent.KEYCODE_G:
                    return onContextMenuAction(GROUP);
            }
        }
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 2
Source File: A2dpSinkActivity.java    From sample-bluetooth-audio with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_P:
            // Enable Pairing mode (discoverable)
            enableDiscoverable();
            return true;
        case KeyEvent.KEYCODE_D:
            // Disconnect any currently connected devices
            disconnectConnectedDevices();
            return true;
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 3
Source File: A2dpSinkActivity.java    From sample-bluetooth-audio with Apache License 2.0 5 votes vote down vote up
private void configureButton() {
    try {
        mPairingButtonDriver = new ButtonInputDriver(BoardDefaults.getGPIOForPairing(),
                Button.LogicState.PRESSED_WHEN_LOW, KeyEvent.KEYCODE_P);
        mPairingButtonDriver.register();
        mDisconnectAllButtonDriver = new ButtonInputDriver(
                BoardDefaults.getGPIOForDisconnectAllBTDevices(),
                Button.LogicState.PRESSED_WHEN_LOW, KeyEvent.KEYCODE_D);
        mDisconnectAllButtonDriver.register();
    } catch (IOException e) {
        Log.w(TAG, "Could not register GPIO button drivers. Use keyboard events to trigger " +
                "the functions instead", e);
    }
}
 
Example 4
Source File: GUIListeners.java    From Beats with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static public int keyCode2Direction(int keyCode) {
	/* interprets a keyCode as a direction
	 * input:   keyCode  - a key code passed to handler           
	 * output: [0 1 2 3] -> [left down up right]; -1 -> unknown
	 */
	switch (keyCode) {
	// WASD, ZX-NM spread, AS-KL spread
	// 12-90 spread, D-Pad
	// Headphone music controller
	case KeyEvent.KEYCODE_A: case KeyEvent.KEYCODE_Z:
	case KeyEvent.KEYCODE_1: case KeyEvent.KEYCODE_DPAD_LEFT:
	case KeyEvent.KEYCODE_MEDIA_PREVIOUS: case KeyEvent.KEYCODE_MEDIA_REWIND:
	case KeyEvent.KEYCODE_BUTTON_X:
		return 0;
	case KeyEvent.KEYCODE_S: case KeyEvent.KEYCODE_X:
	case KeyEvent.KEYCODE_2: case KeyEvent.KEYCODE_DPAD_DOWN:
	case KeyEvent.KEYCODE_MEDIA_STOP:
	case KeyEvent.KEYCODE_BUTTON_A:
		return 1;
	case KeyEvent.KEYCODE_W: case KeyEvent.KEYCODE_N: case KeyEvent.KEYCODE_K:
	case KeyEvent.KEYCODE_9: case KeyEvent.KEYCODE_DPAD_UP:
	case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
	case KeyEvent.KEYCODE_BUTTON_Y:
		return 2;
	case KeyEvent.KEYCODE_D: case KeyEvent.KEYCODE_M: case KeyEvent.KEYCODE_L:
	case KeyEvent.KEYCODE_0: case KeyEvent.KEYCODE_DPAD_RIGHT:
	case KeyEvent.KEYCODE_MEDIA_NEXT: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
	case KeyEvent.KEYCODE_BUTTON_B:
		return 3;
	default:
		return -1;
	}
}
 
Example 5
Source File: NoteViewFragment.java    From Notepad with Apache License 2.0 5 votes vote down vote up
public void dispatchKeyShortcutEvent(int keyCode) {
    switch(keyCode){

            // CTRL+E: Edit
        case KeyEvent.KEYCODE_E:
            Bundle bundle = new Bundle();
            bundle.putString("filename", filename);

            Fragment fragment = new NoteEditFragment();
            fragment.setArguments(bundle);

            getFragmentManager()
                .beginTransaction()
                .replace(R.id.noteViewEdit, fragment, "NoteEditFragment")
                .commit();
            break;

            // CTRL+D: Delete
        case KeyEvent.KEYCODE_D:
            // Show delete dialog
            listener.showDeleteDialog();
            break;

            // CTRL+H: Share
        case KeyEvent.KEYCODE_H:
            // Send a share intent
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_TEXT, contentsOnLoad);
            shareIntent.setType("text/plain");

            // Verify that the intent will resolve to an activity, and send
            if(shareIntent.resolveActivity(getActivity().getPackageManager()) != null)
                startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));

            break;
    }
}
 
Example 6
Source File: Sweep.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_D:
            mPaint.setDither(!mPaint.isDither());
            invalidate();
            return true;
        case KeyEvent.KEYCODE_T:
            mDoTiming = !mDoTiming;
            invalidate();
            return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 7
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;
            }
        }
    }