Exemplo n.º 1
0
  @SmallTest
  @Feature({"TextInput", "Main"})
  public void testGuessedKeyCodeFromTyping() throws Throwable {
    assertEquals(-1, getTypedKeycodeGuess(null, ""));
    assertEquals(KeyEvent.KEYCODE_X, getTypedKeycodeGuess(null, "x"));
    assertEquals(-1, getTypedKeycodeGuess(null, "xyz"));

    assertEquals(-1, getTypedKeycodeGuess("abc", "abc"));
    assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("abc", ""));

    assertEquals(KeyEvent.KEYCODE_H, getTypedKeycodeGuess("", "h"));
    assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("h", ""));
    assertEquals(KeyEvent.KEYCODE_E, getTypedKeycodeGuess("h", "he"));
    assertEquals(KeyEvent.KEYCODE_L, getTypedKeycodeGuess("he", "hel"));
    assertEquals(KeyEvent.KEYCODE_O, getTypedKeycodeGuess("hel", "helo"));
    assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("helo", "hel"));
    assertEquals(KeyEvent.KEYCODE_L, getTypedKeycodeGuess("hel", "hell"));
    assertEquals(KeyEvent.KEYCODE_L, getTypedKeycodeGuess("hell", "helll"));
    assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("helll", "hell"));
    assertEquals(KeyEvent.KEYCODE_O, getTypedKeycodeGuess("hell", "hello"));

    assertEquals(KeyEvent.KEYCODE_X, getTypedKeycodeGuess("xxx", "xxxx"));
    assertEquals(KeyEvent.KEYCODE_X, getTypedKeycodeGuess("xxx", "xxxxx"));
    assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("xxx", "xx"));
    assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("xxx", "x"));

    assertEquals(KeyEvent.KEYCODE_Y, getTypedKeycodeGuess("xxx", "xxxy"));
    assertEquals(KeyEvent.KEYCODE_Y, getTypedKeycodeGuess("xxx", "xxxxy"));
    assertEquals(-1, getTypedKeycodeGuess("xxx", "xy"));
    assertEquals(-1, getTypedKeycodeGuess("xxx", "y"));

    assertEquals(-1, getTypedKeycodeGuess("foo", "bar"));
    assertEquals(-1, getTypedKeycodeGuess("foo", "bars"));
    assertEquals(-1, getTypedKeycodeGuess("foo", "ba"));

    // Some characters also require modifiers so we have to check the full event.
    KeyEvent ev = ImeAdapter.getTypedKeyEventGuess(null, "!");
    assertEquals(KeyEvent.KEYCODE_1, ev.getKeyCode());
    assertTrue(ev.isShiftPressed());
  }
Exemplo n.º 2
0
 private int getTypedKeycodeGuess(String before, String after) {
   KeyEvent ev = ImeAdapter.getTypedKeyEventGuess(before, after);
   if (ev == null) return -1;
   return ev.getKeyCode();
 }