fixed OK key typing new lines instead of performing an action in some apps
This commit is contained in:
parent
caad8a5446
commit
a3724bb80c
7 changed files with 57 additions and 29 deletions
|
|
@ -43,13 +43,19 @@ public abstract class HotkeyHandler extends TypingHandler {
|
|||
@Override public boolean onOK() {
|
||||
suggestionOps.cancelDelayedAccept();
|
||||
|
||||
if (suggestionOps.isEmpty()) {
|
||||
int action = textField.getAction();
|
||||
return action == TextField.IME_ACTION_ENTER ? appHacks.onEnter() : textField.performAction(action);
|
||||
} else {
|
||||
if (!suggestionOps.isEmpty()) {
|
||||
onAcceptSuggestionManually(suggestionOps.acceptCurrent(), KeyEvent.KEYCODE_ENTER);
|
||||
return true;
|
||||
}
|
||||
|
||||
int action = textField.getAction();
|
||||
boolean actionPerformed = action == TextField.IME_ACTION_ENTER ? appHacks.onEnter() : textField.performAction(action);
|
||||
|
||||
if (actionPerformed && action == TextField.IME_ACTION_ENTER) {
|
||||
forceShowWindowIfHidden();
|
||||
}
|
||||
|
||||
return actionPerformed;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -69,9 +69,10 @@ public class AppHacks {
|
|||
}
|
||||
|
||||
|
||||
private boolean isMultilineTextField() {
|
||||
private boolean isMultilineTextInNonSystemApp() {
|
||||
return
|
||||
editorInfo != null
|
||||
&& !editorInfo.packageName.contains("android")
|
||||
&& (editorInfo.inputType & TextField.TYPE_MULTILINE_TEXT) == TextField.TYPE_MULTILINE_TEXT;
|
||||
}
|
||||
|
||||
|
|
@ -133,30 +134,23 @@ public class AppHacks {
|
|||
* it does nothing.
|
||||
*/
|
||||
public boolean onEnter() {
|
||||
if (isTermux()) {
|
||||
sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
|
||||
return true;
|
||||
} else if (settings.getFbMessengerHack() && isMessenger()) {
|
||||
if (settings.getFbMessengerHack() && isMessenger()) {
|
||||
return onEnterFbMessenger();
|
||||
} else if (settings.getGoogleChatHack() && isGoogleChat()) {
|
||||
return onEnterGoogleChat();
|
||||
} else if (isMultilineTextField()) {
|
||||
return onEnterMultilineText();
|
||||
} else if (isTermux() || isMultilineTextInNonSystemApp()) {
|
||||
// 1. Termux supports only ENTER, so we convert DPAD_CENTER for it.
|
||||
// 2. Any extra installed apps are likely not designed for hardware keypads, so again,
|
||||
// we don't want to send DPAD_CENTER to them.
|
||||
return sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
|
||||
}
|
||||
|
||||
// The rest of the cases are probably system apps or numeric fields, which should
|
||||
// now how to handle the incoming OK key code, be it ENTER or DPAD_CENTER.
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* In generic text fields, or when no hacks are in effect, we just type a new line,
|
||||
* as one would expect when pressing ENTER.
|
||||
*/
|
||||
private boolean onEnterMultilineText() {
|
||||
return inputConnection != null && inputConnection.commitText("\n", 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* onEnterFbMessenger
|
||||
* Messenger responds only to ENTER, but not DPAD_CENTER, so we make sure to send the correct code,
|
||||
|
|
@ -194,17 +188,18 @@ public class AppHacks {
|
|||
}
|
||||
|
||||
|
||||
private void sendDownUpKeyEvents(int keyCode) {
|
||||
sendDownUpKeyEvents(keyCode, false);
|
||||
private boolean sendDownUpKeyEvents(int keyCode) {
|
||||
return sendDownUpKeyEvents(keyCode, false);
|
||||
}
|
||||
|
||||
|
||||
private void sendDownUpKeyEvents(int keyCode, boolean shift) {
|
||||
private boolean sendDownUpKeyEvents(int keyCode, boolean shift) {
|
||||
if (inputConnection != null) {
|
||||
KeyEvent downEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, keyCode, 0, shift ? KeyEvent.META_SHIFT_ON : 0);
|
||||
KeyEvent upEvent = new KeyEvent(0, 0, KeyEvent.ACTION_UP, keyCode, 0, shift ? KeyEvent.META_SHIFT_ON : 0);
|
||||
inputConnection.sendKeyEvent(downEvent);
|
||||
inputConnection.sendKeyEvent(upEvent);
|
||||
}
|
||||
return inputConnection.sendKeyEvent(downEvent) && inputConnection.sendKeyEvent(upEvent);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -341,8 +341,8 @@ public class TextField {
|
|||
|
||||
int standardAction = field.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
|
||||
switch (standardAction) {
|
||||
case EditorInfo.IME_ACTION_GO:
|
||||
case EditorInfo.IME_ACTION_DONE:
|
||||
case EditorInfo.IME_ACTION_GO:
|
||||
case EditorInfo.IME_ACTION_NEXT:
|
||||
case EditorInfo.IME_ACTION_PREVIOUS:
|
||||
case EditorInfo.IME_ACTION_SEARCH:
|
||||
|
|
|
|||
|
|
@ -148,7 +148,6 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
|||
if (keyId == R.id.soft_key_left_arrow) return tt9.onKeyScrollSuggestion(false, true);
|
||||
if (keyId == R.id.soft_key_right_arrow) return tt9.onKeyScrollSuggestion(false, false);
|
||||
if (keyId == R.id.soft_key_language) return tt9.onKeyNextLanguage(false);
|
||||
if (keyId == R.id.soft_key_ok) return tt9.onOK();
|
||||
if (keyId == R.id.soft_key_settings) return tt9.onKeyShowSettings(false);
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package io.github.sspanak.tt9.ui.main.keys;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
public class SoftOkKey extends SoftKey {
|
||||
|
||||
public SoftOkKey(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SoftOkKey(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public SoftOkKey(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleRelease() {
|
||||
return
|
||||
validateTT9Handler()
|
||||
&& tt9.onKeyDown(KeyEvent.KEYCODE_ENTER, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER))
|
||||
&& tt9.onKeyUp(KeyEvent.KEYCODE_ENTER, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER));
|
||||
}
|
||||
}
|
||||
|
|
@ -301,7 +301,7 @@
|
|||
android:id="@+id/separator_4_2"
|
||||
style="@style/numSeparator" />
|
||||
|
||||
<io.github.sspanak.tt9.ui.main.keys.SoftKey
|
||||
<io.github.sspanak.tt9.ui.main.keys.SoftOkKey
|
||||
android:id="@+id/soft_key_ok"
|
||||
style="@android:style/Widget.Holo.Button.Borderless"
|
||||
android:layout_width="0dp"
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
style="@style/hSeparator"
|
||||
android:background="@drawable/button_separator_dark" />
|
||||
|
||||
<io.github.sspanak.tt9.ui.main.keys.SoftKey
|
||||
<io.github.sspanak.tt9.ui.main.keys.SoftOkKey
|
||||
android:id="@+id/soft_key_ok"
|
||||
style="@android:style/Widget.Holo.Button.Borderless"
|
||||
android:layout_width="0dp"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue