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();
}
}
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));
}
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);
}
}
}
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;
}
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));
}
Aggregations