Example usage for android.view KeyEvent KeyEvent

List of usage examples for android.view KeyEvent KeyEvent

Introduction

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

Prototype

private KeyEvent(KeyEvent origEvent, int action) 

Source Link

Document

Copy an existing key event, modifying its action.

Usage

From source file:Main.java

/**
 * Get an unaccepted key code.// www  . j  av  a  2 s  .co  m
 *
 * @param acceptedChars accepted chars array.
 * @return return key code if we find unaccepted one, or return -1.
 */
public static int getUnacceptedKeyCode(char[] acceptedChars) {
    for (int keyCode = KeyEvent.KEYCODE_A; keyCode <= KeyEvent.KEYCODE_Z; keyCode++) {
        KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
        if ('\0' == event.getMatch(acceptedChars)) {
            return keyCode;
        }
    }
    return -1;
}

From source file:com.king.base.util.SystemUtils.java

/**
 * /*  www.  j  av a  2s  .c om*/
 *
 * @param et
 */
public static void deleteClick(EditText et) {
    final KeyEvent keyEventDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL);
    et.onKeyDown(KeyEvent.KEYCODE_DEL, keyEventDown);
}

From source file:love.juhe.androidmonkey.MonkeyKeyEvent.java

/**
 * @return the key event/*from w w w.  j a  va  2 s  .  c  om*/
 */
private KeyEvent getEvent() {
    if (keyEvent == null) {
        if (mDeviceId < 0) {
            keyEvent = new KeyEvent(mAction, mKeyCode);
        } else {
            // for scripts
            keyEvent = new KeyEvent(mDownTime, mEventTime, mAction, mKeyCode, mRepeatCount, mMetaState,
                    mDeviceId, mScancode);
        }
    }
    return keyEvent;
}

From source file:com.achep.acdisplay.services.media.MediaController2.java

/**
 * Emulates hardware buttons' click via broadcast system.
 *
 * @see android.view.KeyEvent//w  w  w . ja  va  2 s.c o m
 */
public static void broadcastMediaAction(@NonNull Context context, int action) {
    int keyCode;
    switch (action) {
    case ACTION_PLAY_PAUSE:
        keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
        break;
    case ACTION_STOP:
        keyCode = KeyEvent.KEYCODE_MEDIA_STOP;
        break;
    case ACTION_SKIP_TO_NEXT:
        keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
        break;
    case ACTION_SKIP_TO_PREVIOUS:
        keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
        break;
    default:
        throw new IllegalArgumentException();
    }

    Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    KeyEvent keyDown = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
    KeyEvent keyUp = new KeyEvent(KeyEvent.ACTION_UP, keyCode);

    context.sendOrderedBroadcast(intent.putExtra(Intent.EXTRA_KEY_EVENT, keyDown), null);
    context.sendOrderedBroadcast(intent.putExtra(Intent.EXTRA_KEY_EVENT, keyUp), null);
}

From source file:com.manning.androidhacks.hack017.CreateAccountActivity.java

@Override
public void scroll(int type) {

    switch (type) {
    case FORWARD:
    default:/*from  w  w  w .  j a  va 2s . co  m*/

        if (mGalleryPosition < mGallery.getCount() - 1) {
            mGallery.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, new KeyEvent(0, 0));
            mGalleryPosition++;
        }
        break;

    case BACKWARD:
        if (mGalleryPosition > 0) {
            mGallery.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, new KeyEvent(0, 0));
            mGalleryPosition--;
        }
    }
}

From source file:com.fishstix.dosboxfree.ButtonLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);//((action & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT);
    final int pId = ev.getPointerId(pointerIndex) + 1;
    KeyEvent evt = null;/*from w  w  w  .  j ava 2  s. c  om*/
    Message msg = Message.obtain();
    msg.what = DBMain.HANDLER_SEND_KEYCODE;
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN: {
        Log.i("DosBoxTurbo", "button onDown()");
        int x = (int) ev.getX(pointerIndex);//(int) mWrap.getX(ev,pointerIndex);
        int width = getWidth();
        //int y = (int) mWrap.getY(ev,pointerIndex);
        float val = ((float) x / (float) width) * 4f;
        if (val < 1.0) {
            // first button
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_A) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_A);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_A);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_A;
            mDBLauncher.bButtonA.setBackgroundColor(0x80FF0000);
        } else if (val < 2.0) {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_B) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_B);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_B);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_B;
            mDBLauncher.bButtonB.setBackgroundColor(0x80FF0000);
        } else if (val < 3.0) {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_C) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_C);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_C);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_C;
            mDBLauncher.bButtonC.setBackgroundColor(0x80FF0000);
        } else {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_D) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_D);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_D);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_D;
            mDBLauncher.bButtonD.setBackgroundColor(0x80FF0000);
        }
        msg.obj = evt;
        msg.arg1 = 0;
        mDBLauncher.mSurfaceView.virtButton[pointerIndex] = true;
        mDBLauncher.mSurfaceView.mFilterLongClick = true; // prevent long click listener from getting in the way
        mDBLauncher.mHandler.sendMessage(msg);
        return true;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP: {
        Log.i("DosBoxTurbo", "button onUp()");
        msg.arg2 = virtualbutton_hm.get(pId);
        switch (msg.arg2) {
        case HardCodeWrapper.KEYCODE_VIRTUAL_A:
            mDBLauncher.bButtonA.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_B:
            mDBLauncher.bButtonB.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_C:
            mDBLauncher.bButtonC.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_D:
            mDBLauncher.bButtonD.setBackgroundColor(0x80FFFF00);
            break;
        }
        virtualbutton_hm.delete(pId);
        if (msg.arg2 == 0)
            return false;
        evt = new KeyEvent(action, msg.arg2);
        msg.obj = evt;
        msg.arg1 = 1;
        mDBLauncher.mSurfaceView.virtButton[pointerIndex] = false;
        mDBLauncher.mSurfaceView.mFilterLongClick = false;
        mDBLauncher.mHandler.sendMessage(msg);
        return true;
    }
    }
    return false;
}

From source file:com.csipsimple.ui.incall.DtmfDialogFragment.java

@Override
public void onTrigger(int keyCode, int dialTone) {
    Log.i(TAG, "onTrigger, keyCode: " + keyCode + ", dialTone: " + dialTone);
    if (dialPadTextView != null) {
        // Update text view
        KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
        char nbr = event.getNumber();
        StringBuilder sb = new StringBuilder(dialPadTextView.getText());
        sb.append(nbr);//www  .  j a v a2 s .  c om
        dialPadTextView.setText(sb.toString());
    } else {
        Log.e(TAG, "dialpadTextView is null");
    }
    if (getActivity() instanceof OnDtmfListener) {
        Integer callId = getArguments().getInt(EXTRA_CALL_ID);
        if (callId != null) {
            ((OnDtmfListener) getActivity()).OnDtmf(callId, keyCode, dialTone);
        } else {
            Log.w(THIS_FILE, "Impossible to find the call associated to this view");
        }
    }

}

From source file:com.app.blockydemo.ui.fragment.FormulaEditorScriptListFragment.java

@Override
public void onListItemClick(int position) {
    Log.d("catroid", "onListItemClick");
    if (!inContextMode) {
        FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getActivity().getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG);
        if (formulaEditor != null) {
            formulaEditor.addUserVariableToActiveFormula(adapter.getItem(position).getName());
            formulaEditor.updateButtonViewOnKeyboard();
        }// www  .  j  a v  a  2s  .  c om
        KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
        onKey(null, keyEvent.getKeyCode(), keyEvent);
    }

}

From source file:org.catrobat.catroid.ui.fragment.FormulaEditorVariableListFragment.java

@Override
public void onListItemClick(int position) {

    if (!inContextMode) {
        formulaEditorEditText.handleKeyEvent(0, "" + adapter.getItem(position).getName());
        KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
        onKey(null, keyEvent.getKeyCode(), keyEvent);
    }//w w w. j  a v a 2  s  .c  o m

}

From source file:com.app.blockydemo.ui.fragment.FormulaEditorListFragment.java

@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
    FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getActivity().getSupportFragmentManager()
            .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG);
    if (formulaEditor != null) {
        formulaEditor.addResourceToActiveFormula(itemsIds[position]);
        formulaEditor.updateButtonViewOnKeyboard();
    }//from  www .ja  v a2s. c  o  m
    KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
    onKey(null, keyEvent.getKeyCode(), keyEvent);
}