disabled all automatic assistance in our text fields; prevented some unnecessary text operations in input fields where automatic assistance is not possible
This commit is contained in:
parent
f06ee6f4b9
commit
f35b77bfaf
7 changed files with 52 additions and 25 deletions
|
|
@ -7,8 +7,11 @@ import android.view.inputmethod.InputConnection;
|
|||
import io.github.sspanak.tt9.ime.helpers.StandardInputType;
|
||||
|
||||
public class InputType extends StandardInputType {
|
||||
public InputType(InputConnection inputConnection, EditorInfo inputField){
|
||||
private final boolean isUs;
|
||||
|
||||
public InputType(Context context, InputConnection inputConnection, EditorInfo inputField) {
|
||||
super(inputConnection, inputField);
|
||||
isUs = isAppField(context != null ? context.getPackageName() : "", EditorInfo.TYPE_NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -154,8 +157,8 @@ public class InputType extends StandardInputType {
|
|||
}
|
||||
|
||||
|
||||
public boolean isNotUs(Context context) {
|
||||
return !isAppField(context.getPackageName(), EditorInfo.TYPE_NULL);
|
||||
public boolean isUs() {
|
||||
return isUs;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -150,13 +150,13 @@ public class TraditionalT9 extends MainViewHandler {
|
|||
initUi(mInputMode);
|
||||
}
|
||||
|
||||
InputType newInputType = new InputType(connection, field);
|
||||
InputType newInputType = new InputType(getApplicationContext(), connection, field);
|
||||
|
||||
if (newInputType.isText()) {
|
||||
DataStore.loadWordPairs(DictionaryLoader.getInstance(this), LanguageCollection.getAll(settings.getEnabledLanguageIds()));
|
||||
}
|
||||
|
||||
if (newInputType.isNotUs(this)) {
|
||||
if (!newInputType.isUs()) {
|
||||
DictionaryLoader.autoLoad(this, mLanguage);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import io.github.sspanak.tt9.util.Text;
|
|||
public abstract class TypingHandler extends KeyPadHandler {
|
||||
// internal settings/data
|
||||
@NonNull protected AppHacks appHacks = new AppHacks(null, null, null);
|
||||
@NonNull protected InputType inputType = new InputType(null, null);
|
||||
@NonNull protected InputType inputType = new InputType(null, null, null);
|
||||
@NonNull protected TextField textField = new TextField(null, null, null);
|
||||
@NonNull protected TextSelection textSelection = new TextSelection(this,null);
|
||||
@NonNull protected SuggestionOps suggestionOps = new SuggestionOps(null, null, null, null, null);
|
||||
|
|
@ -83,7 +83,7 @@ public abstract class TypingHandler extends KeyPadHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
inputType = new InputType(connection, field);
|
||||
inputType = new InputType(getApplicationContext(), connection, field);
|
||||
textField = new TextField(settings, connection, field);
|
||||
textSelection = new TextSelection(this, connection);
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class TextField extends InputField {
|
|||
public TextField(SettingsStore settings, InputConnection inputConnection, EditorInfo inputField) {
|
||||
super(inputConnection, inputField);
|
||||
|
||||
InputType inputType = new InputType(inputConnection, inputField);
|
||||
InputType inputType = new InputType(null, inputConnection, inputField);
|
||||
isComposingSupported = !inputType.isNumeric() && !inputType.isLimited() && !inputType.isRustDesk() && (settings == null || settings.getAllowComposingText());
|
||||
isNonText = !inputType.isText();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class ModeWords extends ModeCheonjiin {
|
|||
protected ModeWords(SettingsStore settings, Language lang, InputType inputType, TextField textField) {
|
||||
super(settings, inputType, textField);
|
||||
|
||||
autoTextCase = new AutoTextCase(settings);
|
||||
autoTextCase = new AutoTextCase(settings, inputType);
|
||||
|
||||
changeLanguage(lang);
|
||||
defaultTextCase();
|
||||
|
|
|
|||
|
|
@ -51,7 +51,13 @@ public class AutoSpace {
|
|||
* the list of rules.
|
||||
*/
|
||||
public boolean shouldAddTrailingSpace(TextField textField, InputType inputType, boolean isWordAcceptedManually, int nextKey) {
|
||||
if (!isLanguageWithSpaceBetweenWords) {
|
||||
if (
|
||||
!isLanguageWithSpaceBetweenWords
|
||||
|| nextKey == 0
|
||||
|| !settings.getAutoSpace()
|
||||
|| inputType.isSpecialized()
|
||||
|| inputType.isUs()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -59,10 +65,7 @@ public class AutoSpace {
|
|||
Text nextChars = textField.getTextAfterCursor(2);
|
||||
|
||||
return
|
||||
settings.getAutoSpace()
|
||||
&& !inputType.isSpecialized()
|
||||
&& nextKey != 0
|
||||
&& !nextChars.startsWithWhitespace()
|
||||
!nextChars.startsWithWhitespace()
|
||||
&& (
|
||||
shouldAddAfterWord(isWordAcceptedManually, previousChars, nextChars, nextKey)
|
||||
|| shouldAddAfterPunctuation(previousChars, nextChars, nextKey)
|
||||
|
|
@ -75,6 +78,15 @@ public class AutoSpace {
|
|||
* For example, should we transform "word?" to "word ?", or "something(" to "something ("
|
||||
*/
|
||||
public boolean shouldAddBeforePunctuation(InputType inputType, TextField textField) {
|
||||
if (
|
||||
!isLanguageWithSpaceBetweenWords
|
||||
|| !settings.getAutoSpace()
|
||||
|| inputType.isSpecialized()
|
||||
|| inputType.isUs()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String previousChars = textField.getStringBeforeCursor(2);
|
||||
char penultimateChar = previousChars.length() < 2 ? 0 : previousChars.charAt(previousChars.length() - 2);
|
||||
char previousChar = previousChars.isEmpty() ? 0 : previousChars.charAt(previousChars.length() - 1);
|
||||
|
|
@ -84,10 +96,7 @@ public class AutoSpace {
|
|||
}
|
||||
|
||||
return
|
||||
isLanguageWithSpaceBetweenWords
|
||||
&& settings.getAutoSpace()
|
||||
&& !inputType.isSpecialized()
|
||||
&& Character.isAlphabetic(penultimateChar)
|
||||
Character.isAlphabetic(penultimateChar)
|
||||
&& (
|
||||
PRECEDING_SPACE_PUNCTUATION.contains(previousChar)
|
||||
|| (isLanguageFrench && PRECEDING_SPACE_FRENCH_PUNCTUATION.contains(previousChar))
|
||||
|
|
@ -140,20 +149,27 @@ public class AutoSpace {
|
|||
* Determines whether to transform: "word ." to: "word."
|
||||
*/
|
||||
public boolean shouldDeletePrecedingSpace(InputType inputType, TextField textField) {
|
||||
if (
|
||||
!isLanguageWithSpaceBetweenWords
|
||||
|| !settings.getAutoSpace()
|
||||
|| inputType.isSpecialized()
|
||||
|| inputType.isUs()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
String previousChars = textField.getStringBeforeCursor(3);
|
||||
char prePenultimateChar = previousChars.length() < 3 ? 0 : previousChars.charAt(previousChars.length() - 3);
|
||||
char penultimateChar = previousChars.length() < 2 ? 0 : previousChars.charAt(previousChars.length() - 2);
|
||||
char previousChar = previousChars.isEmpty() ? 0 : previousChars.charAt(previousChars.length() - 1);
|
||||
|
||||
return
|
||||
isLanguageWithSpaceBetweenWords
|
||||
&& settings.getAutoSpace()
|
||||
&& !Character.isWhitespace(prePenultimateChar)
|
||||
!Character.isWhitespace(prePenultimateChar)
|
||||
&& Character.isWhitespace(penultimateChar)
|
||||
&& (
|
||||
NO_PRECEDING_SPACE_PUNCTUATION.contains(previousChar)
|
||||
|| (!isLanguageFrench && NOT_FRENCH_NO_PRECEDING_SPACE_PUNCTUATION.contains(previousChar))
|
||||
)
|
||||
&& !inputType.isSpecialized();
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,21 @@
|
|||
package io.github.sspanak.tt9.ime.modes.helpers;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import io.github.sspanak.tt9.hacks.InputType;
|
||||
import io.github.sspanak.tt9.ime.modes.InputMode;
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
import io.github.sspanak.tt9.util.Text;
|
||||
|
||||
public class AutoTextCase {
|
||||
private final SettingsStore settings;
|
||||
@NonNull private final SettingsStore settings;
|
||||
private final boolean isUs;
|
||||
|
||||
|
||||
public AutoTextCase(SettingsStore settingsStore) {
|
||||
public AutoTextCase(@NonNull SettingsStore settingsStore, @Nullable InputType inputType) {
|
||||
settings = settingsStore;
|
||||
isUs = inputType != null && inputType.isUs();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -44,6 +50,8 @@ public class AutoTextCase {
|
|||
!settings.getAutoTextCase()
|
||||
// If the user wants to type in uppercase, this must be for a reason, so we better not override it.
|
||||
|| currentTextCase == InputMode.CASE_UPPER
|
||||
// we do not have text fields that expect sentences, so disable the feature to save some resources
|
||||
|| isUs
|
||||
) {
|
||||
return currentTextCase;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue