Android - исправление четких предложений кандидатов в BaseInputConnection при нажатии EnterAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 Android - исправление четких предложений кандидатов в BaseInputConnection при нажатии Enter

Сообщение Anonymous »

Я использую BaseInputConnection для реализации предложений по вводу для пользовательского виджета ввода текста. Однако возврат/деление не обрабатываются автоматически, поэтому я реализую их в sendKeyEvent() следующим образом:
public class CustomInputConnection extends BaseInputConnection {

public CustomInputConnection(View view, boolean fullEditor) {
super(view, fullEditor);
}

@Override
public boolean sendKeyEvent(KeyEvent event) {
int action = event.getAction();
int keycode = event.getKeyCode();

// If this is backspace/del or if the key has a character representation,
// need to update the underlying Editable (i.e. the local representation of the text
// being edited). Some IMEs like Jellybean stock IME and Samsung IME mix in delete
// KeyPress events instead of calling deleteSurroundingText.
if (action == KeyEvent.ACTION_DOWN && keycode == KeyEvent.KEYCODE_DEL) {
Log.i("Foo", "delete < ");
deleteSurroundingText(1, 0);
} else if (action == KeyEvent.ACTION_DOWN && keycode == KeyEvent.KEYCODE_FORWARD_DEL) {
Log.i("Foo", "delete >");
deleteSurroundingText(0, 1);
} else if (action == KeyEvent.ACTION_DOWN && keycode == KeyEvent.KEYCODE_ENTER) {
Log.i("Foo", "enter");

// None of these works:

//setComposingText("", 0);

//beginBatchEdit();
//finishComposingText();
//endBatchEdit();

//CharSequence beforCursorText = getTextBeforeCursor(100, 0);
//CharSequence afterCursorText = getTextAfterCursor(100, 0);
//deleteSurroundingText(beforCursorText.length(), afterCursorText.length());

//deleteSurroundingText(100, 100);
}
return true;
}

@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
Log.i("Foo", "onCommitText: " + text.toString());
return true;
}

@Override
public boolean endBatchEdit() {
String text = getTextBeforeCursor(100, 0).toString();
Log.i("Foo", "onEditText: " + text);
return super.endBatchEdit();
}
}


Когда я набираю «привет», затем нажимаю и набираю «abc», я ожидаю увидеть «abc», но вместо этого пишет «helloabc». Мне не удалось получить эту работу.
Вот пример вывода:
onEditText: h
onEditText: h
onEditText: he
onEditText: he
onEditText: hel
onEditText: hel
onEditText: hel
onEditText: hell
onEditText: hell
onEditText: hell
onEditText: hello
onEditText: hello
enter
onEditText:
onEditText:
onEditText: helloa
onEditText: helloa
onEditText: helloab
onEditText: helloab
onEditText: helloabx
onEditText: helloabx

Вот как я создаю InputConnection:
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT
| EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN
| EditorInfo.IME_ACTION_DONE;
// fullEditor is false, but we might set this to true for enabling
// text selection, and copy/paste. Lets see.
return new CustomInputConnection(this, false);
}

Что я делаю не так? Как мне заставить это работать?
Как будто IME запоминает введенные данные и игнорирует входное соединение.
Я хочу чтобы очистить предложения по вводу и полностью сбросить состояние BaseInputConnection. Как мне это сделать?


Подробнее здесь: https://stackoverflow.com/questions/792 ... hen-pressi
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»