use of android.view.KeyEvent in project platform_frameworks_base by android.
the class ForwardDeleteTest method forwardDelete.
// Sync the state to the TextView and call onKeyDown with KEYCODE_FORWARD_DEL key event.
// Then update the state to the result of TextView.
private void forwardDelete(final EditorState state, int modifiers) {
mActivity.runOnUiThread(new Runnable() {
public void run() {
mTextView.setText(state.mText, BufferType.EDITABLE);
mTextView.setKeyListener(mKeyListener);
mTextView.setSelection(state.mSelectionStart, state.mSelectionEnd);
}
});
mInstrumentation.waitForIdleSync();
assertTrue(mTextView.hasWindowFocus());
final KeyEvent keyEvent = getKey(KeyEvent.KEYCODE_FORWARD_DEL, modifiers);
mActivity.runOnUiThread(new Runnable() {
public void run() {
mTextView.onKeyDown(keyEvent.getKeyCode(), keyEvent);
}
});
mInstrumentation.waitForIdleSync();
state.mText = mTextView.getText();
state.mSelectionStart = mTextView.getSelectionStart();
state.mSelectionEnd = mTextView.getSelectionEnd();
}
use of android.view.KeyEvent in project httpclient by pixmob.
the class AstroboyMasterConsole method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
// @Inject, @InjectResource, and @InjectExtra injection happens during super.onCreate()
super.onCreate(savedInstanceState);
sayText.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
// Have the remoteControl tell Astroboy to say something
remoteControl.say(textView.getText().toString());
textView.setText(null);
return true;
}
});
brushTeethButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
remoteControl.brushTeeth();
}
});
selfDestructButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
// Self destruct the remoteControl
vibrator.vibrate(2000);
remoteControl.selfDestruct();
}
});
// Fighting the forces of evil deserves its own activity
fightEvilButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
startActivity(new Intent(AstroboyMasterConsole.this, FightForcesOfEvilActivity.class));
}
});
}
use of android.view.KeyEvent in project platform_frameworks_base by android.
the class PhoneWindowManager method dispatchUnhandledKey.
/** {@inheritDoc} */
@Override
public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
// Note: This method is only called if the initial down was unhandled.
if (DEBUG_INPUT) {
Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() + ", flags=" + event.getFlags() + ", keyCode=" + event.getKeyCode() + ", scanCode=" + event.getScanCode() + ", metaState=" + event.getMetaState() + ", repeatCount=" + event.getRepeatCount() + ", policyFlags=" + policyFlags);
}
KeyEvent fallbackEvent = null;
if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
final KeyCharacterMap kcm = event.getKeyCharacterMap();
final int keyCode = event.getKeyCode();
final int metaState = event.getMetaState();
final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0;
// Check for fallback actions specified by the key character map.
final FallbackAction fallbackAction;
if (initialDown) {
fallbackAction = kcm.getFallbackAction(keyCode, metaState);
} else {
fallbackAction = mFallbackActions.get(keyCode);
}
if (fallbackAction != null) {
if (DEBUG_INPUT) {
Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode + " metaState=" + Integer.toHexString(fallbackAction.metaState));
}
final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
fallbackEvent = KeyEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), fallbackAction.keyCode, event.getRepeatCount(), fallbackAction.metaState, event.getDeviceId(), event.getScanCode(), flags, event.getSource(), null);
if (!interceptFallback(win, fallbackEvent, policyFlags)) {
fallbackEvent.recycle();
fallbackEvent = null;
}
if (initialDown) {
mFallbackActions.put(keyCode, fallbackAction);
} else if (event.getAction() == KeyEvent.ACTION_UP) {
mFallbackActions.remove(keyCode);
fallbackAction.recycle();
}
}
}
if (DEBUG_INPUT) {
if (fallbackEvent == null) {
Slog.d(TAG, "No fallback.");
} else {
Slog.d(TAG, "Performing fallback: " + fallbackEvent);
}
}
return fallbackEvent;
}
use of android.view.KeyEvent in project androidannotations by androidannotations.
the class KeyEventsActivityTest method keyUpKeyCodeNameFromMethod.
@Test
public void keyUpKeyCodeNameFromMethod() {
KeyEvent keyEvent = mock(KeyEvent.class);
int keyCode = KeyEvent.KEYCODE_U;
activity.onKeyUp(keyCode, keyEvent);
assertThat(activity.isUKeyUp).isTrue();
}
use of android.view.KeyEvent in project androidannotations by androidannotations.
the class KeyEventsActivityTest method multipleArguments.
@Test
public void multipleArguments() {
KeyEvent keyEvent = mock(KeyEvent.class);
int keyCode = KeyEvent.KEYCODE_W;
int count = 1;
when(keyEvent.getKeyCode()).thenReturn(keyCode);
activity.onKeyMultiple(keyCode, count, keyEvent);
assertThat(activity.isWMultiple).isTrue();
assertThat(activity.isNineMultiple).isFalse();
}
Aggregations