Search in sources :

Example 11 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class TransportControlView method sendMediaButtonClick.

private void sendMediaButtonClick(int keyCode) {
    if (mClientIntent == null) {
        // Shouldn't be possible because this view should be hidden in this case.
        Log.e(TAG, "sendMediaButtonClick(): No client is currently registered");
        return;
    }
    // use the registered PendingIntent that will be processed by the registered
    //    media button event receiver, which is the component of mClientIntent
    KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
    Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
    try {
        mClientIntent.send(getContext(), 0, intent);
    } catch (CanceledException e) {
        Log.e(TAG, "Error sending intent for media button down: " + e);
        e.printStackTrace();
    }
    keyEvent = new KeyEvent(KeyEvent.ACTION_UP, keyCode);
    intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
    try {
        mClientIntent.send(getContext(), 0, intent);
    } catch (CanceledException e) {
        Log.e(TAG, "Error sending intent for media button up: " + e);
        e.printStackTrace();
    }
}
Also used : KeyEvent(android.view.KeyEvent) CanceledException(android.app.PendingIntent.CanceledException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 12 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class PasswordEntryKeyboardHelper method sendDownUpKeyEvents.

public void sendDownUpKeyEvents(int keyEventCode) {
    long eventTime = SystemClock.uptimeMillis();
    ViewRootImpl viewRootImpl = mTargetView.getViewRootImpl();
    viewRootImpl.dispatchKeyFromIme(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, keyEventCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
    viewRootImpl.dispatchKeyFromIme(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, keyEventCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
}
Also used : ViewRootImpl(android.view.ViewRootImpl) KeyEvent(android.view.KeyEvent)

Example 13 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class PasswordEntryKeyboardHelper method sendKeyEventsToTarget.

private void sendKeyEventsToTarget(int character) {
    ViewRootImpl viewRootImpl = mTargetView.getViewRootImpl();
    KeyEvent[] events = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD).getEvents(new char[] { (char) character });
    if (events != null) {
        final int N = events.length;
        for (int i = 0; i < N; i++) {
            KeyEvent event = events[i];
            event = KeyEvent.changeFlags(event, event.getFlags() | KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
            viewRootImpl.dispatchKey(event);
        }
    }
}
Also used : ViewRootImpl(android.view.ViewRootImpl) KeyEvent(android.view.KeyEvent)

Example 14 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class TextView method onKeyMultiple.

@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
    KeyEvent down = KeyEvent.changeAction(event, KeyEvent.ACTION_DOWN);
    int which = doKeyDown(keyCode, down, event);
    if (which == 0) {
        // Go through default dispatching.
        return super.onKeyMultiple(keyCode, repeatCount, event);
    }
    if (which == -1) {
        // Consumed the whole thing.
        return true;
    }
    repeatCount--;
    // We are going to dispatch the remaining events to either the input
    // or movement method.  To do this, we will just send a repeated stream
    // of down and up events until we have done the complete repeatCount.
    // It would be nice if those interfaces had an onKeyMultiple() method,
    // but adding that is a more complicated change.
    KeyEvent up = KeyEvent.changeAction(event, KeyEvent.ACTION_UP);
    if (which == 1) {
        // mEditor and mEditor.mInput are not null from doKeyDown
        mEditor.mKeyListener.onKeyUp(this, (Editable) mText, keyCode, up);
        while (--repeatCount > 0) {
            mEditor.mKeyListener.onKeyDown(this, (Editable) mText, keyCode, down);
            mEditor.mKeyListener.onKeyUp(this, (Editable) mText, keyCode, up);
        }
        hideErrorIfUnchanged();
    } else if (which == 2) {
        // mMovement is not null from doKeyDown
        mMovement.onKeyUp(this, (Spannable) mText, keyCode, up);
        while (--repeatCount > 0) {
            mMovement.onKeyDown(this, (Spannable) mText, keyCode, down);
            mMovement.onKeyUp(this, (Spannable) mText, keyCode, up);
        }
    }
    return true;
}
Also used : KeyEvent(android.view.KeyEvent) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Spannable(android.text.Spannable)

Example 15 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityInjectorTest method sendKeyEvent.

/**
     * Sends a {@link KeyEvent} (up and down) to the {@link WebView}.
     *
     * @param keyCode The event key code.
     */
private void sendKeyEvent(WebView webView, int keyCode, int metaState) {
    webView.onKeyDown(keyCode, new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, keyCode, 1, metaState));
    webView.onKeyUp(keyCode, new KeyEvent(0, 0, KeyEvent.ACTION_UP, keyCode, 1, metaState));
}
Also used : KeyEvent(android.view.KeyEvent)

Aggregations

KeyEvent (android.view.KeyEvent)499 View (android.view.View)135 TextView (android.widget.TextView)100 Intent (android.content.Intent)49 DialogInterface (android.content.DialogInterface)36 KeyCharacterMap (android.view.KeyCharacterMap)35 EditText (android.widget.EditText)35 ImageView (android.widget.ImageView)33 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)32 Editable (android.text.Editable)31 Instrumentation (android.app.Instrumentation)30 Paint (android.graphics.Paint)27 OnClickListener (android.view.View.OnClickListener)27 Button (android.widget.Button)26 AlertDialog (android.app.AlertDialog)21 Message (android.os.Message)21 TextWatcher (android.text.TextWatcher)21 LayoutInflater (android.view.LayoutInflater)21 InputMethodManager (android.view.inputmethod.InputMethodManager)20 Test (org.junit.Test)20