1
0
Fork 0

Small fixes (#242)

* fixed the main view not showing up in some cases

* fixed crashing when changing the theme

* fixed 1-key not working after using it in 123 mode, then switching to ABC mode

* fixed auto-space not working with the on screen punctuation keys

* fixed on-screen punctuation keys erasing the previously typed, but unaccepted word

* fixed more auto-space issues

* fixed key repeating being reset incorrectly when holding some key

* fixed pressing 1-key accepted even if there are no more emoji, in Predictive Mode
This commit is contained in:
Dimo Karaivanov 2023-04-28 09:31:50 +03:00 committed by GitHub
parent cf5682d808
commit 1fa1e7c6e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 22 deletions

View file

@ -50,6 +50,7 @@ abstract class KeyPadHandler extends InputMethodService {
@Override @Override
public boolean onEvaluateInputViewShown() { public boolean onEvaluateInputViewShown() {
super.onEvaluateInputViewShown(); super.onEvaluateInputViewShown();
onRestart(getCurrentInputEditorInfo());
return mEditing != EDITING_DIALER && mEditing != NON_EDIT; return mEditing != EDITING_DIALER && mEditing != NON_EDIT;
} }
@ -170,8 +171,14 @@ abstract class KeyPadHandler extends InputMethodService {
return true; return true;
} }
resetKeyRepeat();
ignoreNextKeyUp = keyCode; ignoreNextKeyUp = keyCode;
if (Key.isNumber(keyCode)) {
numKeyRepeatCounter = 0;
lastNumKeyCode = 0;
} else {
keyRepeatCounter = 0;
lastKeyCode = 0;
}
if (handleHotkey(keyCode, true)) { if (handleHotkey(keyCode, true)) {
return true; return true;

View file

@ -213,7 +213,7 @@ public class TraditionalT9 extends KeyPadHandler {
mInputMode.onAcceptSuggestion(word); mInputMode.onAcceptSuggestion(word);
commitCurrentSuggestion(); commitCurrentSuggestion();
autoCorrectSpace(word, true, -1, false, false); autoCorrectSpace(word, true);
resetKeyRepeat(); resetKeyRepeat();
return true; return true;
@ -287,7 +287,7 @@ public class TraditionalT9 extends KeyPadHandler {
// Automatically accept the current word, when the next one is a space or punctuation, // Automatically accept the current word, when the next one is a space or punctuation,
// instead of requiring "OK" before that. // instead of requiring "OK" before that.
if (mInputMode.shouldAcceptCurrentSuggestion(key, hold, repeat > 0)) { if (mInputMode.shouldAcceptCurrentSuggestion(key, hold, repeat > 0)) {
autoCorrectSpace(acceptIncompleteSuggestion(), false, key, hold, repeat > 0); autoCorrectSpace(acceptIncompleteSuggestion(), false);
currentWord = ""; currentWord = "";
} }
@ -319,7 +319,7 @@ public class TraditionalT9 extends KeyPadHandler {
return false; return false;
} }
autoCorrectSpace(acceptIncompleteSuggestion(), false, -1, false, false); autoCorrectSpace(acceptIncompleteSuggestion(), false);
sendDownUpKeyEvents(keyCode); sendDownUpKeyEvents(keyCode);
return true; return true;
} }
@ -330,9 +330,13 @@ public class TraditionalT9 extends KeyPadHandler {
return false; return false;
} }
autoCorrectSpace(acceptIncompleteSuggestion(), false, -1, false, false); // accept the previously typed word (if any)
autoCorrectSpace(acceptIncompleteSuggestion(), false);
// "type" and accept the text
mInputMode.onAcceptSuggestion(text);
textField.setText(text); textField.setText(text);
autoCorrectSpace(text, false, -1, false, false); autoCorrectSpace(text, true);
return true; return true;
} }
@ -556,6 +560,7 @@ public class TraditionalT9 extends KeyPadHandler {
mInputMode = InputMode.getInstance(settings, mLanguage, allowedInputModes.get(modeIndex)); mInputMode = InputMode.getInstance(settings, mLanguage, allowedInputModes.get(modeIndex));
mInputMode.defaultTextCase(); mInputMode.defaultTextCase();
resetKeyRepeat();
} }
// save the settings for the next time // save the settings for the next time
@ -623,12 +628,12 @@ public class TraditionalT9 extends KeyPadHandler {
} }
private void autoCorrectSpace(String currentWord, boolean isWordAcceptedManually, int incomingKey, boolean hold, boolean repeat) { private void autoCorrectSpace(String currentWord, boolean isWordAcceptedManually) {
if (mInputMode.shouldDeletePrecedingSpace(inputType)) { if (mInputMode.shouldDeletePrecedingSpace(inputType)) {
textField.deletePrecedingSpace(currentWord); textField.deletePrecedingSpace(currentWord);
} }
if (mInputMode.shouldAddAutoSpace(inputType, textField, isWordAcceptedManually, incomingKey, hold, repeat)) { if (mInputMode.shouldAddAutoSpace(inputType, textField, isWordAcceptedManually)) {
textField.setText(" "); textField.setText(" ");
} }
} }

View file

@ -84,7 +84,7 @@ abstract public class InputMode {
// Interaction with the IME. Return "true" if it should perform the respective action. // Interaction with the IME. Return "true" if it should perform the respective action.
public boolean shouldAcceptCurrentSuggestion(int key, boolean hold, boolean repeat) { return false; } public boolean shouldAcceptCurrentSuggestion(int key, boolean hold, boolean repeat) { return false; }
public boolean shouldAddAutoSpace(InputType inputType, TextField textField, boolean isWordAcceptedManually, int incomingKey, boolean hold, boolean repeat) { return false; } public boolean shouldAddAutoSpace(InputType inputType, TextField textField, boolean isWordAcceptedManually) { return false; }
public boolean shouldDeletePrecedingSpace(InputType inputType) { return false; } public boolean shouldDeletePrecedingSpace(InputType inputType) { return false; }
public boolean shouldSelectNextSuggestion() { return false; } public boolean shouldSelectNextSuggestion() { return false; }

View file

@ -214,6 +214,7 @@ public class ModePredictive extends InputMode {
private final Handler handleSuggestions = new Handler(Looper.getMainLooper()) { private final Handler handleSuggestions = new Handler(Looper.getMainLooper()) {
@Override @Override
public void handleMessage(Message m) { public void handleMessage(Message m) {
digitSequence = predictions.getDigitSequence();
suggestions.clear(); suggestions.clear();
suggestions.addAll(predictions.getList()); suggestions.addAll(predictions.getList());
@ -289,13 +290,13 @@ public class ModePredictive extends InputMode {
@Override @Override
public boolean shouldAddAutoSpace(InputType inputType, TextField textField, boolean isWordAcceptedManually, int incomingKey, boolean hold, boolean repeat) { public boolean shouldAddAutoSpace(InputType inputType, TextField textField, boolean isWordAcceptedManually) {
return autoSpace return autoSpace
.setLastWord(lastAcceptedWord) .setLastWord(lastAcceptedWord)
.setLastSequence(lastAcceptedSequence) .setLastSequence(lastAcceptedSequence)
.setInputType(inputType) .setInputType(inputType)
.setTextField(textField) .setTextField(textField)
.shouldAddAutoSpace(isWordAcceptedManually, incomingKey, hold, repeat); .shouldAddAutoSpace(isWordAcceptedManually);
} }

View file

@ -2,13 +2,14 @@ package io.github.sspanak.tt9.ime.modes.helpers;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import io.github.sspanak.tt9.Logger;
import io.github.sspanak.tt9.ime.helpers.InputType; import io.github.sspanak.tt9.ime.helpers.InputType;
import io.github.sspanak.tt9.ime.helpers.TextField; import io.github.sspanak.tt9.ime.helpers.TextField;
import io.github.sspanak.tt9.preferences.SettingsStore; import io.github.sspanak.tt9.preferences.SettingsStore;
public class AutoSpace { public class AutoSpace {
private final Pattern nextIsPunctuation = Pattern.compile("\\p{Punct}"); private final Pattern isNumber = Pattern.compile("\\s*\\d+\\s*");
private final Pattern isPunctuation = Pattern.compile("\\p{Punct}");
private final SettingsStore settings; private final SettingsStore settings;
private InputType inputType; private InputType inputType;
@ -48,20 +49,19 @@ public class AutoSpace {
* *
* See the helper functions for the list of rules. * See the helper functions for the list of rules.
*/ */
public boolean shouldAddAutoSpace(boolean isWordAcceptedManually, int incomingKey, boolean hold, boolean repeat) { public boolean shouldAddAutoSpace(boolean isWordAcceptedManually) {
String previousChars = textField.getPreviousChars(2); String previousChars = textField.getPreviousChars(2);
String nextChars = textField.getNextChars(2); String nextChars = textField.getNextChars(2);
Logger.d("shouldAddAutoSpace", "next chars: '" + nextChars + "'");
return return
settings.getAutoSpace() settings.getAutoSpace()
&& !hold && !isNumber.matcher(previousChars).find()
&& ( && (
shouldAddAutoSpaceAfterPunctuation(previousChars, incomingKey, repeat) shouldAddAutoSpaceAfterPunctuation(previousChars)
|| shouldAddAutoSpaceAfterWord(isWordAcceptedManually) || shouldAddAutoSpaceAfterWord(isWordAcceptedManually)
) )
&& !nextChars.startsWith(" ") && !nextChars.startsWith(" ")
&& !nextIsPunctuation.matcher(nextChars).find(); && !isPunctuation.matcher(nextChars).find();
} }
@ -71,10 +71,10 @@ public class AutoSpace {
* The rules are similar to the ones in the standard Android keyboard (with some exceptions, * The rules are similar to the ones in the standard Android keyboard (with some exceptions,
* because we are not using a QWERTY keyboard here). * because we are not using a QWERTY keyboard here).
*/ */
private boolean shouldAddAutoSpaceAfterPunctuation(String previousChars, int incomingKey, boolean repeat) { private boolean shouldAddAutoSpaceAfterPunctuation(String previousChars) {
return return
(incomingKey != 0 || repeat) !inputType.isSpecialized()
&& !inputType.isSpecialized() && !previousChars.endsWith(" ") && !previousChars.endsWith("\n") && !previousChars.endsWith("\t")
&& ( && (
previousChars.endsWith(".") previousChars.endsWith(".")
|| previousChars.endsWith(",") || previousChars.endsWith(",")

View file

@ -58,6 +58,10 @@ public class Predictions {
return this; return this;
} }
public String getDigitSequence() {
return digitSequence;
}
public Predictions setIsStemFuzzy(boolean yes) { public Predictions setIsStemFuzzy(boolean yes) {
this.isStemFuzzy = yes; this.isStemFuzzy = yes;
return this; return this;

View file

@ -8,6 +8,7 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.app.AppCompatDelegate;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
@ -40,9 +41,15 @@ public class PreferencesActivity extends AppCompatActivity implements Preference
DictionaryDb.normalizeWordFrequencies(settings); DictionaryDb.normalizeWordFrequencies(settings);
InputModeValidator.validateEnabledLanguages(settings, settings.getEnabledLanguageIds()); InputModeValidator.validateEnabledLanguages(settings, settings.getEnabledLanguageIds());
validateFunctionKeys();
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
validateFunctionKeys();
// changing the theme causes onCreate(), which displays the MainSettingsScreen,
// but leaves the old "back" history, which is no longer valid,
// so we must reset it
getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
buildLayout(); buildLayout();
} }

View file

@ -34,6 +34,7 @@ public class MainSettingsScreen extends BaseScreenFragment {
@Override @Override
public void onResume() { public void onResume() {
init(); // changing the theme recreates the PreferencesActivity, making "this.activity" NULL, so we reinitialize it.
super.onResume(); super.onResume();
createSettingsSection(); createSettingsSection();
} }