@Override
 public void commitTyped() {
   if (typedText.length() > 0) {
     commitText(typedText, typedText.length());
     clearTypedText();
   }
 }
  @Override
  public int translateKeyDown(int unicodeChar) {
    if (!Strings.isEmpty(typedText)) {
      char accent = typedText.charAt(typedText.length() - 1);
      int composed = KeyEvent.getDeadChar(accent, unicodeChar);

      if (composed != 0) {
        unicodeChar = composed;
        typedText.setLength(typedText.length() - 1);
      }
    }

    return unicodeChar;
  }
 @Override
 public void handleClear() {
   typedText.setLength(0);
   final InputConnection ic = getCurrentInputConnection();
   ic.setSelection(0, 0);
   ic.deleteSurroundingText(MAX_INT, MAX_INT);
 }
  @Override
  public boolean handleBackspace() {
    boolean changed = false;

    int length = typedText.length();

    final InputConnection ic = getCurrentInputConnection();
    if (length > 1) {
      typedText.delete(length - 1, length);
      ic.setComposingText(typedText, 1);
      changed = true;
    } else if (length > 0) {
      clearTypedText();
      commitText(ic, "", 0);
      changed = true;
    }

    return changed;
  }
 @Override
 public void append(char primaryCode) {
   typedText.append(primaryCode);
   getCurrentInputConnection().setComposingText(typedText, 1);
 }