fixed OK not working in Sonim search fields
This commit is contained in:
parent
3c86d0b0cd
commit
c55a83b5d3
5 changed files with 49 additions and 9 deletions
|
|
@ -49,13 +49,16 @@ public abstract class HotkeyHandler extends TypingHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
int action = textField.getAction();
|
int action = textField.getAction();
|
||||||
boolean actionPerformed = action == TextField.IME_ACTION_ENTER ? appHacks.onEnter() : textField.performAction(action);
|
|
||||||
|
|
||||||
if (actionPerformed && action == TextField.IME_ACTION_ENTER) {
|
if (action == TextField.IME_ACTION_ENTER) {
|
||||||
forceShowWindowIfHidden();
|
boolean actionPerformed = appHacks.onEnter();
|
||||||
|
if (actionPerformed) {
|
||||||
|
forceShowWindowIfHidden();
|
||||||
|
}
|
||||||
|
return actionPerformed;
|
||||||
}
|
}
|
||||||
|
|
||||||
return actionPerformed;
|
return appHacks.onAction(action) || textField.performAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,14 @@ import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import io.github.sspanak.tt9.ime.modes.InputMode;
|
import io.github.sspanak.tt9.ime.modes.InputMode;
|
||||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
|
import io.github.sspanak.tt9.util.DeviceInfo;
|
||||||
|
|
||||||
public class AppHacks {
|
public class AppHacks {
|
||||||
private final EditorInfo editorInfo;
|
private final EditorInfo editorInfo;
|
||||||
private final InputConnection inputConnection;
|
private final InputConnection inputConnection;
|
||||||
private final SettingsStore settings;
|
private final SettingsStore settings;
|
||||||
private final TextField textField;
|
private final TextField textField;
|
||||||
|
private final InputType inputType;
|
||||||
|
|
||||||
|
|
||||||
public AppHacks(SettingsStore settings, InputConnection inputConnection, EditorInfo inputField, TextField textField) {
|
public AppHacks(SettingsStore settings, InputConnection inputConnection, EditorInfo inputField, TextField textField) {
|
||||||
|
|
@ -21,6 +23,7 @@ public class AppHacks {
|
||||||
this.inputConnection = inputConnection;
|
this.inputConnection = inputConnection;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.textField = textField;
|
this.textField = textField;
|
||||||
|
this.inputType = new InputType(inputConnection, inputField);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -70,10 +73,7 @@ public class AppHacks {
|
||||||
|
|
||||||
|
|
||||||
private boolean isMultilineTextInNonSystemApp() {
|
private boolean isMultilineTextInNonSystemApp() {
|
||||||
return
|
return editorInfo != null && !editorInfo.packageName.contains("android") && inputType.isMultilineText();
|
||||||
editorInfo != null
|
|
||||||
&& !editorInfo.packageName.contains("android")
|
|
||||||
&& (editorInfo.inputType & TextField.TYPE_MULTILINE_TEXT) == TextField.TYPE_MULTILINE_TEXT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -85,6 +85,19 @@ public class AppHacks {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isSonimSearchField(int action) {
|
||||||
|
return
|
||||||
|
DeviceInfo.isSonim() &&
|
||||||
|
editorInfo != null && (editorInfo.packageName.startsWith("com.android") || editorInfo.packageName.startsWith("com.sonim"))
|
||||||
|
&& (editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION) == action
|
||||||
|
&& (
|
||||||
|
inputType.isText()
|
||||||
|
// in some apps, they forgot to set the TEXT type, but fortunately, they did set the multiline flag.
|
||||||
|
|| ((editorInfo.inputType & EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS) == EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* isAppField
|
* isAppField
|
||||||
* Detects a particular input field of a particular application.
|
* Detects a particular input field of a particular application.
|
||||||
|
|
@ -126,6 +139,15 @@ public class AppHacks {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean onAction(int action) {
|
||||||
|
if (isSonimSearchField(action)) {
|
||||||
|
return sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onEnter
|
* onEnter
|
||||||
* Tries to guess and send the correct confirmation key code or sequence of key codes,
|
* Tries to guess and send the correct confirmation key code or sequence of key codes,
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import io.github.sspanak.tt9.ime.modes.InputMode;
|
||||||
|
|
||||||
|
|
||||||
public class InputType {
|
public class InputType {
|
||||||
|
private static final int TYPE_MULTILINE_TEXT = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
|
||||||
|
|
||||||
private final InputConnection connection;
|
private final InputConnection connection;
|
||||||
private final EditorInfo field;
|
private final EditorInfo field;
|
||||||
|
|
||||||
|
|
@ -118,6 +120,16 @@ public class InputType {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isText() {
|
||||||
|
return field != null && (field.inputType & android.text.InputType.TYPE_MASK_CLASS) == android.text.InputType.TYPE_CLASS_TEXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isMultilineText() {
|
||||||
|
return field != null && (field.inputType & TYPE_MULTILINE_TEXT) == TYPE_MULTILINE_TEXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isUri() {
|
private boolean isUri() {
|
||||||
return field != null && (field.inputType & android.text.InputType.TYPE_MASK_VARIATION) == android.text.InputType.TYPE_TEXT_VARIATION_URI;
|
return field != null && (field.inputType & android.text.InputType.TYPE_MASK_VARIATION) == android.text.InputType.TYPE_TEXT_VARIATION_URI;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ import io.github.sspanak.tt9.util.Logger;
|
||||||
import io.github.sspanak.tt9.util.Text;
|
import io.github.sspanak.tt9.util.Text;
|
||||||
|
|
||||||
public class TextField {
|
public class TextField {
|
||||||
public static final int TYPE_MULTILINE_TEXT = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
|
|
||||||
public static final int IME_ACTION_ENTER = EditorInfo.IME_MASK_ACTION + 1;
|
public static final int IME_ACTION_ENTER = EditorInfo.IME_MASK_ACTION + 1;
|
||||||
|
|
||||||
private final InputConnection connection;
|
private final InputConnection connection;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ public class DeviceInfo {
|
||||||
return Build.MANUFACTURER.equals("DuoQin") && Build.MODEL.contains("F21");
|
return Build.MANUFACTURER.equals("DuoQin") && Build.MODEL.contains("F21");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isSonim() {
|
||||||
|
return Build.MANUFACTURER.equals("Sonimtech");
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue