run keyboard listeners on background executor
This commit is contained in:
parent
39bc067405
commit
7a825231fb
|
@ -19,18 +19,22 @@ import android.view.KeyEvent;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputConnection;
|
import android.view.inputmethod.InputConnection;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
|
|
||||||
public class EditMessage extends EmojiWrapperEditText {
|
public class EditMessage extends EmojiWrapperEditText {
|
||||||
|
|
||||||
private static final InputFilter SPAN_FILTER = (source, start, end, dest, dstart, dend) -> source instanceof Spanned ? source.toString() : source;
|
private static final InputFilter SPAN_FILTER = (source, start, end, dest, dstart, dend) -> source instanceof Spanned ? source.toString() : source;
|
||||||
|
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
protected Handler mTypingHandler = new Handler();
|
protected Handler mTypingHandler = new Handler();
|
||||||
protected KeyboardListener keyboardListener;
|
protected KeyboardListener keyboardListener;
|
||||||
private OnCommitContentListener mCommitContentListener = null;
|
private OnCommitContentListener mCommitContentListener = null;
|
||||||
private String[] mimeTypes = null;
|
private String[] mimeTypes = null;
|
||||||
private boolean isUserTyping = false;
|
private boolean isUserTyping = false;
|
||||||
protected Runnable mTypingTimeout = new Runnable() {
|
private final Runnable mTypingTimeout = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (isUserTyping && keyboardListener != null) {
|
if (isUserTyping && keyboardListener != null) {
|
||||||
|
@ -72,14 +76,19 @@ public class EditMessage extends EmojiWrapperEditText {
|
||||||
return AUTOFILL_TYPE_NONE;
|
return AUTOFILL_TYPE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
|
public void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
|
||||||
super.onTextChanged(text, start, lengthBefore, lengthAfter);
|
super.onTextChanged(text, start, lengthBefore, lengthAfter);
|
||||||
lastInputWasTab = false;
|
lastInputWasTab = false;
|
||||||
if (this.mTypingHandler != null && this.keyboardListener != null) {
|
if (this.mTypingHandler != null && this.keyboardListener != null) {
|
||||||
|
executor.execute(() -> triggerKeyboardEvents(text.length()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void triggerKeyboardEvents(final int length) {
|
||||||
this.mTypingHandler.removeCallbacks(mTypingTimeout);
|
this.mTypingHandler.removeCallbacks(mTypingTimeout);
|
||||||
this.mTypingHandler.postDelayed(mTypingTimeout, Config.TYPING_TIMEOUT * 1000);
|
this.mTypingHandler.postDelayed(mTypingTimeout, Config.TYPING_TIMEOUT * 1000);
|
||||||
final int length = text.length();
|
|
||||||
if (!isUserTyping && length > 0) {
|
if (!isUserTyping && length > 0) {
|
||||||
this.isUserTyping = true;
|
this.isUserTyping = true;
|
||||||
this.keyboardListener.onTypingStarted();
|
this.keyboardListener.onTypingStarted();
|
||||||
|
@ -89,7 +98,6 @@ public class EditMessage extends EmojiWrapperEditText {
|
||||||
}
|
}
|
||||||
this.keyboardListener.onTextChanged();
|
this.keyboardListener.onTextChanged();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void setKeyboardListener(KeyboardListener listener) {
|
public void setKeyboardListener(KeyboardListener listener) {
|
||||||
this.keyboardListener = listener;
|
this.keyboardListener = listener;
|
||||||
|
|
Loading…
Reference in New Issue