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:
parent
cf5682d808
commit
1fa1e7c6e6
8 changed files with 47 additions and 22 deletions
|
|
@ -50,6 +50,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
@Override
|
||||
public boolean onEvaluateInputViewShown() {
|
||||
super.onEvaluateInputViewShown();
|
||||
onRestart(getCurrentInputEditorInfo());
|
||||
return mEditing != EDITING_DIALER && mEditing != NON_EDIT;
|
||||
}
|
||||
|
||||
|
|
@ -170,8 +171,14 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
return true;
|
||||
}
|
||||
|
||||
resetKeyRepeat();
|
||||
ignoreNextKeyUp = keyCode;
|
||||
if (Key.isNumber(keyCode)) {
|
||||
numKeyRepeatCounter = 0;
|
||||
lastNumKeyCode = 0;
|
||||
} else {
|
||||
keyRepeatCounter = 0;
|
||||
lastKeyCode = 0;
|
||||
}
|
||||
|
||||
if (handleHotkey(keyCode, true)) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
mInputMode.onAcceptSuggestion(word);
|
||||
commitCurrentSuggestion();
|
||||
autoCorrectSpace(word, true, -1, false, false);
|
||||
autoCorrectSpace(word, true);
|
||||
resetKeyRepeat();
|
||||
|
||||
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,
|
||||
// instead of requiring "OK" before that.
|
||||
if (mInputMode.shouldAcceptCurrentSuggestion(key, hold, repeat > 0)) {
|
||||
autoCorrectSpace(acceptIncompleteSuggestion(), false, key, hold, repeat > 0);
|
||||
autoCorrectSpace(acceptIncompleteSuggestion(), false);
|
||||
currentWord = "";
|
||||
}
|
||||
|
||||
|
|
@ -319,7 +319,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
autoCorrectSpace(acceptIncompleteSuggestion(), false, -1, false, false);
|
||||
autoCorrectSpace(acceptIncompleteSuggestion(), false);
|
||||
sendDownUpKeyEvents(keyCode);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -330,9 +330,13 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
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);
|
||||
autoCorrectSpace(text, false, -1, false, false);
|
||||
autoCorrectSpace(text, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -556,6 +560,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
mInputMode = InputMode.getInstance(settings, mLanguage, allowedInputModes.get(modeIndex));
|
||||
|
||||
mInputMode.defaultTextCase();
|
||||
resetKeyRepeat();
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
textField.deletePrecedingSpace(currentWord);
|
||||
}
|
||||
|
||||
if (mInputMode.shouldAddAutoSpace(inputType, textField, isWordAcceptedManually, incomingKey, hold, repeat)) {
|
||||
if (mInputMode.shouldAddAutoSpace(inputType, textField, isWordAcceptedManually)) {
|
||||
textField.setText(" ");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ abstract public class InputMode {
|
|||
|
||||
// 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 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 shouldSelectNextSuggestion() { return false; }
|
||||
|
||||
|
|
|
|||
|
|
@ -214,6 +214,7 @@ public class ModePredictive extends InputMode {
|
|||
private final Handler handleSuggestions = new Handler(Looper.getMainLooper()) {
|
||||
@Override
|
||||
public void handleMessage(Message m) {
|
||||
digitSequence = predictions.getDigitSequence();
|
||||
suggestions.clear();
|
||||
suggestions.addAll(predictions.getList());
|
||||
|
||||
|
|
@ -289,13 +290,13 @@ public class ModePredictive extends InputMode {
|
|||
|
||||
|
||||
@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
|
||||
.setLastWord(lastAcceptedWord)
|
||||
.setLastSequence(lastAcceptedSequence)
|
||||
.setInputType(inputType)
|
||||
.setTextField(textField)
|
||||
.shouldAddAutoSpace(isWordAcceptedManually, incomingKey, hold, repeat);
|
||||
.shouldAddAutoSpace(isWordAcceptedManually);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ package io.github.sspanak.tt9.ime.modes.helpers;
|
|||
|
||||
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.TextField;
|
||||
import io.github.sspanak.tt9.preferences.SettingsStore;
|
||||
|
||||
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 InputType inputType;
|
||||
|
|
@ -48,20 +49,19 @@ public class AutoSpace {
|
|||
*
|
||||
* 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 nextChars = textField.getNextChars(2);
|
||||
Logger.d("shouldAddAutoSpace", "next chars: '" + nextChars + "'");
|
||||
|
||||
return
|
||||
settings.getAutoSpace()
|
||||
&& !hold
|
||||
&& !isNumber.matcher(previousChars).find()
|
||||
&& (
|
||||
shouldAddAutoSpaceAfterPunctuation(previousChars, incomingKey, repeat)
|
||||
shouldAddAutoSpaceAfterPunctuation(previousChars)
|
||||
|| shouldAddAutoSpaceAfterWord(isWordAcceptedManually)
|
||||
)
|
||||
&& !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,
|
||||
* because we are not using a QWERTY keyboard here).
|
||||
*/
|
||||
private boolean shouldAddAutoSpaceAfterPunctuation(String previousChars, int incomingKey, boolean repeat) {
|
||||
private boolean shouldAddAutoSpaceAfterPunctuation(String previousChars) {
|
||||
return
|
||||
(incomingKey != 0 || repeat)
|
||||
&& !inputType.isSpecialized()
|
||||
!inputType.isSpecialized()
|
||||
&& !previousChars.endsWith(" ") && !previousChars.endsWith("\n") && !previousChars.endsWith("\t")
|
||||
&& (
|
||||
previousChars.endsWith(".")
|
||||
|| previousChars.endsWith(",")
|
||||
|
|
|
|||
|
|
@ -58,6 +58,10 @@ public class Predictions {
|
|||
return this;
|
||||
}
|
||||
|
||||
public String getDigitSequence() {
|
||||
return digitSequence;
|
||||
}
|
||||
|
||||
public Predictions setIsStemFuzzy(boolean yes) {
|
||||
this.isStemFuzzy = yes;
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import androidx.appcompat.app.ActionBar;
|
|||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
|
@ -40,9 +41,15 @@ public class PreferencesActivity extends AppCompatActivity implements Preference
|
|||
DictionaryDb.normalizeWordFrequencies(settings);
|
||||
|
||||
InputModeValidator.validateEnabledLanguages(settings, settings.getEnabledLanguageIds());
|
||||
validateFunctionKeys();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ public class MainSettingsScreen extends BaseScreenFragment {
|
|||
|
||||
@Override
|
||||
public void onResume() {
|
||||
init(); // changing the theme recreates the PreferencesActivity, making "this.activity" NULL, so we reinitialize it.
|
||||
super.onResume();
|
||||
createSettingsSection();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue