@TestTargetNew(
      level = TestLevel.COMPLETE,
      method = "clearMetaKeyState",
      args = {android.text.Editable.class, int.class})
  public void testClearMetaKeyState2() {
    CharSequence str = "123456";
    Editable text = Editable.Factory.getInstance().newEditable(str);
    text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT);
    text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT);
    MetaKeyKeyListener.clearMetaKeyState(text, MetaKeyKeyListener.META_SHIFT_ON);
    assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START));
    assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END));

    str = "abc";
    text = Editable.Factory.getInstance().newEditable(str);
    text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT);
    text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT);
    MetaKeyKeyListener.clearMetaKeyState(text, MetaKeyKeyListener.META_ALT_ON);
    assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START));
    assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END));

    str = "#@%#$^%^";
    text = Editable.Factory.getInstance().newEditable(str);
    text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT);
    text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT);
    MetaKeyKeyListener.clearMetaKeyState(text, MetaKeyKeyListener.META_SYM_ON);
    assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START));
    assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END));
  }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      method = "adjustMetaAfterKeypress",
      args = {android.text.Spannable.class})
  public void testAdjustMetaAfterKeypress() {
    CharSequence str = "123456";
    Spannable content = Editable.Factory.getInstance().newEditable(str);
    content.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT);
    int len = str.length(); // for one line less than 100
    content.setSpan(Selection.SELECTION_END, len, len, Spanned.SPAN_POINT_POINT);
    MetaKeyKeyListener.adjustMetaAfterKeypress(content);
    assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_START));
    assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_END));

    str = "abc";
    content = Editable.Factory.getInstance().newEditable(str);
    content.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT);
    len = str.length(); // for one line less than 100
    content.setSpan(Selection.SELECTION_END, len, len, Spanned.SPAN_POINT_POINT);
    MetaKeyKeyListener.adjustMetaAfterKeypress(content);
    assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_START));
    assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_END));

    str = "#@%#$^%^";
    content = Editable.Factory.getInstance().newEditable(str);
    content.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT);
    len = str.length(); // for one line less than 100
    content.setSpan(Selection.SELECTION_END, len, len, Spanned.SPAN_POINT_POINT);
    MetaKeyKeyListener.adjustMetaAfterKeypress(content);
    assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_START));
    assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_END));
  }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      method = "onKeyUp",
      args = {
        android.view.View.class,
        android.text.Editable.class,
        int.class,
        android.view.KeyEvent.class
      })
  public void testReleaseKey() {
    final CharSequence str = "123456";
    final MetaKeyKeyListener numberKeyListener = new DateKeyListener();
    final View view = new ImageView(getContext());
    final Editable content = Editable.Factory.getInstance().newEditable(str);

    content.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT);
    content.setSpan(Selection.SELECTION_END, 0, 0, Spanned.SPAN_POINT_POINT);
    numberKeyListener.onKeyUp(
        view, content, KeyEvent.KEYCODE_0, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0));
    assertEquals(str.charAt(0), content.charAt(0));

    content.setSpan(Selection.SELECTION_START, 1, 1, Spanned.SPAN_POINT_POINT);
    content.setSpan(Selection.SELECTION_END, 1, 1, Spanned.SPAN_POINT_POINT);
    numberKeyListener.onKeyUp(
        view, content, KeyEvent.KEYCODE_2, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_2));
    assertEquals(str.charAt(1), content.charAt(1));

    content.setSpan(Selection.SELECTION_START, 3, 3, Spanned.SPAN_POINT_POINT);
    content.setSpan(Selection.SELECTION_END, 3, 3, Spanned.SPAN_POINT_POINT);
    numberKeyListener.onKeyUp(
        view, content, KeyEvent.KEYCODE_3, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_3));
    assertEquals(str.charAt(3), content.charAt(3));
  }
 /**
  * @param wrapper InputMethodManagerWrapper that should receive all the call directed to
  *     InputMethodManager.
  * @param embedder The view that is used for callbacks from ImeAdapter.
  */
 public ImeAdapter(InputMethodManagerWrapper wrapper, ImeAdapterDelegate embedder) {
   mInputMethodManagerWrapper = wrapper;
   mViewEmbedder = embedder;
   mInputConnectionFactory = new AdapterInputConnectionFactory();
   mEditable = Editable.Factory.getInstance().newEditable("");
   Selection.setSelection(mEditable, 0);
 }
  protected GeckoInputConnection(View targetView) {
    super(targetView, true);

    mEditableFactory = Editable.Factory.getInstance();
    initEditable("");
    mIMEState = IME_STATE_DISABLED;
    mIMETypeHint = "";
    mIMEActionHint = "";
  }
 public void initEditable(String contents) {
   mEditable = mEditableFactory.newEditable(contents);
   mEditable.setSpan(this, 0, contents.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
   Selection.setSelection(mEditable, contents.length());
 }