Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
inputLogic.onCodeInput(
settings.current, event,
keyboardSwitcher.getKeyboardShiftMode(), // TODO: this is not necessarily correct for a hardware keyboard right now
keyboardSwitcher.getCurrentKeyboardScript(),
latinIME.mHandler
)
return true
Expand Down Expand Up @@ -337,7 +336,7 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
inputLogic.finishInput()
val newPosition = connection.expectedSelectionStart + moveSteps
connection.setSelection(newPosition, newPosition)
inputLogic.restartSuggestionsOnWordTouchedByCursor(settings.current, keyboardSwitcher.currentKeyboardScript)
inputLogic.restartSuggestionsOnWordTouchedByCursor(settings.current)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void updateKeyboardTheme(@NonNull Context displayContext) {
if (themeUpdated) {
Settings settings = Settings.getInstance();
settings.loadSettings(displayContext, settings.getCurrent().mLocale,
settings.getCurrent().mInputAttributes);
settings.getCurrent().mInputAttributes, settings.getCurrent().mCurrentKeyboardScript);
if (mKeyboardView != null)
mLatinIME.setInputView(onCreateInputView(displayContext, mIsHardwareAcceleratedDrawingEnabled));
}
Expand Down Expand Up @@ -759,7 +759,7 @@ public View onCreateInputView(@NonNull Context displayContext, final boolean isH
if (mThemeNeedsReload) // necessary in some cases (e.g. theme switch) when mThemeNeedsReload is set
// before first keyboard load
Settings.getInstance().loadSettings(displayContext, Settings.getValues().mLocale,
Settings.getValues().mInputAttributes);
Settings.getValues().mInputAttributes, Settings.getValues().mCurrentKeyboardScript);

updateKeyboardThemeAndContextThemeWrapper(displayContext, KeyboardTheme.getKeyboardTheme(displayContext));
mCurrentInputView = (InputView) LayoutInflater.from(mThemeContext).inflate(R.layout.input_view, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class KeyboardWrapperView @JvmOverloads constructor(
// Force reload settings synchronously to ensure the new scale is used immediately
val settings = Settings.getInstance()
val values = Settings.getValues()
settings.loadSettings(context, values.mLocale, values.mInputAttributes)
settings.loadSettings(context, values.mLocale, values.mInputAttributes, values.mCurrentKeyboardScript)
KeyboardSwitcher.getInstance().setOneHandedModeEnabled(true, true)
}
else -> x = 0f
Expand Down
13 changes: 5 additions & 8 deletions app/src/main/java/helium314/keyboard/latin/LatinIME.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ public void handleMessage(@NonNull final Message msg) {
break;
case MSG_RESUME_SUGGESTIONS:
latinIme.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
latinIme.mSettings.getCurrent(),
latinIme.mKeyboardSwitcher.getCurrentKeyboardScript());
latinIme.mSettings.getCurrent());
break;
case MSG_REOPEN_DICTIONARIES:
// We need to re-evaluate the currently composing word in case the script has
Expand Down Expand Up @@ -593,7 +592,8 @@ private void loadSettings() {
final EditorInfo editorInfo = getCurrentInputEditorInfo();
final InputAttributes inputAttributes = new InputAttributes(
editorInfo, isFullscreenMode(), getPackageName());
mSettings.loadSettings(this, locale, inputAttributes);
final String currentKeyboardScript = mKeyboardSwitcher.getCurrentKeyboardScript();
mSettings.loadSettings(this, locale, inputAttributes, currentKeyboardScript);
final SettingsValues currentSettingsValues = mSettings.getCurrent();
AudioAndHapticFeedbackManager.getInstance().onSettingsChanged(currentSettingsValues);
// This method is called on startup and language switch, before the new layout
Expand Down Expand Up @@ -1515,8 +1515,7 @@ public void onEvent(@NonNull final Event event) {
mRichImm.switchToShortcutIme(this);
}
final InputTransaction completeInputTransaction = mInputLogic.onCodeInput(mSettings.getCurrent(), event,
mKeyboardSwitcher.getKeyboardShiftMode(),
mKeyboardSwitcher.getCurrentKeyboardScript(), mHandler);
mKeyboardSwitcher.getKeyboardShiftMode(), mHandler);
updateStateAfterInputTransaction(completeInputTransaction);
mKeyboardSwitcher.onEvent(event, getCurrentAutoCapsState(), getCurrentRecapitalizeState());
}
Expand All @@ -1527,8 +1526,7 @@ public void onTextInput(final String rawText) {
final InputTransaction completeInputTransaction = mInputLogic.onTextInput(mSettings.getCurrent(), event,
mKeyboardSwitcher.getKeyboardShiftMode(), mHandler);
updateStateAfterInputTransaction(completeInputTransaction);
mInputLogic.restartSuggestionsOnWordTouchedByCursor(mSettings.getCurrent(),
mKeyboardSwitcher.getCurrentKeyboardScript());
mInputLogic.restartSuggestionsOnWordTouchedByCursor(mSettings.getCurrent());
mKeyboardSwitcher.onEvent(event, getCurrentAutoCapsState(), getCurrentRecapitalizeState());
}

Expand Down Expand Up @@ -1694,7 +1692,6 @@ public void pickSuggestionManually(final SuggestedWordInfo suggestionInfo) {
final InputTransaction completeInputTransaction = mInputLogic.onPickSuggestionManually(
mSettings.getCurrent(), suggestionInfo,
mKeyboardSwitcher.getKeyboardShiftMode(),
mKeyboardSwitcher.getCurrentKeyboardScript(),
mHandler);
updateStateAfterInputTransaction(completeInputTransaction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ public InputTransaction onTextInput(final SettingsValues settingsValues, final E
// interface
public InputTransaction onPickSuggestionManually(final SettingsValues settingsValues,
final SuggestedWordInfo suggestionInfo, final int keyboardShiftState,
final String currentKeyboardScript, final LatinIME.UIHandler handler) {
final LatinIME.UIHandler handler) {
final String currentKeyboardScript = settingsValues.mCurrentKeyboardScript;
if (isInlineEmojiSearchAction()) {
deleteTextReplacedByEmoji();
}
Expand All @@ -321,7 +322,7 @@ public InputTransaction onPickSuggestionManually(final SettingsValues settingsVa
// Rely on onCodeInput to do the complicated swapping/stripping logic
// consistently.
final Event event = Event.createPunctuationSuggestionPickedEvent(suggestionInfo);
return onCodeInput(settingsValues, event, keyboardShiftState, currentKeyboardScript, handler);
return onCodeInput(settingsValues, event, keyboardShiftState, handler);
}

final Event event = Event.createSuggestionPickedEvent(suggestionInfo);
Expand Down Expand Up @@ -509,7 +510,8 @@ public boolean moveCursorByAndReturnIfInsideComposingWord(int distance) {
*/
public InputTransaction onCodeInput(final SettingsValues settingsValues,
@NonNull final Event event, final int keyboardShiftMode,
final String currentKeyboardScript, final LatinIME.UIHandler handler) {
final LatinIME.UIHandler handler) {
final String currentKeyboardScript = settingsValues.mCurrentKeyboardScript;
mWordBeingCorrectedByCursor = null;
mJustRevertedACommit = false;
final Event processedEvent = mWordComposer.processEvent(event);
Expand Down Expand Up @@ -540,7 +542,7 @@ public InputTransaction onCodeInput(final SettingsValues settingsValues,
if (currentEvent.isConsumed()) {
handleConsumedEvent(currentEvent, inputTransaction);
} else if (currentEvent.isFunctionalKeyEvent()) {
handleFunctionalEvent(currentEvent, inputTransaction, currentKeyboardScript, handler);
handleFunctionalEvent(currentEvent, inputTransaction, handler);
} else {
handleNonFunctionalEvent(currentEvent, inputTransaction, handler);
}
Expand All @@ -552,7 +554,7 @@ public InputTransaction onCodeInput(final SettingsValues settingsValues,
if (!mConnection.hasSlowInputConnection() && !mWordComposer.isComposingWord()
&& (settingsValues.isWordCodePoint(processedEvent.getCodePoint())
|| processedEvent.getKeyCode() == KeyCode.DELETE)) {
mWordBeingCorrectedByCursor = getWordAtCursor(settingsValues, currentKeyboardScript);
mWordBeingCorrectedByCursor = getWordAtCursor(settingsValues);
}
if (!inputTransaction.didAutoCorrect() && processedEvent.getKeyCode() != KeyCode.SHIFT
&& processedEvent.getKeyCode() != KeyCode.CAPS_LOCK
Expand Down Expand Up @@ -940,11 +942,12 @@ private void handleShowTranslateLanguages() {
* @param inputTransaction The transaction in progress.
*/
private void handleFunctionalEvent(final Event event, final InputTransaction inputTransaction,
final String currentKeyboardScript, final LatinIME.UIHandler handler) {
final LatinIME.UIHandler handler) {
final String currentKeyboardScript = inputTransaction.getSettingsValues().mCurrentKeyboardScript;
final int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyCode.DELETE:
handleBackspaceEvent(event, inputTransaction, currentKeyboardScript);
handleBackspaceEvent(event, inputTransaction);
// Backspace is a functional key, but it affects the contents of the editor.
inputTransaction.setDidAffectContents();
break;
Expand Down Expand Up @@ -1021,7 +1024,7 @@ private void handleFunctionalEvent(final Event event, final InputTransaction inp
// fake delete keypress to remove the text
final Event backspaceEvent = Event.createSoftwareKeypressEvent(KeyCode.DELETE, 0,
event.getX(), event.getY(), event.isKeyRepeat());
handleBackspaceEvent(backspaceEvent, inputTransaction, currentKeyboardScript);
handleBackspaceEvent(backspaceEvent, inputTransaction);
inputTransaction.setDidAffectContents();
}
break;
Expand Down Expand Up @@ -1595,8 +1598,8 @@ private void handleSeparatorEvent(final Event event, final InputTransaction inpu
* @param event The event to handle.
* @param inputTransaction The transaction in progress.
*/
private void handleBackspaceEvent(final Event event, final InputTransaction inputTransaction,
final String currentKeyboardScript) {
private void handleBackspaceEvent(final Event event, final InputTransaction inputTransaction) {
final String currentKeyboardScript = inputTransaction.getSettingsValues().mCurrentKeyboardScript;
mSpaceState = SpaceState.NONE;
mDeleteCount++;

Expand Down Expand Up @@ -1668,8 +1671,7 @@ private void handleBackspaceEvent(final Event event, final InputTransaction inpu
// (non-revert) backspace handling.
if (inputTransaction.getSettingsValues().needsToLookupSuggestions()
&& inputTransaction.getSettingsValues().mSpacingAndPunctuations.mCurrentLanguageHasSpaces) {
restartSuggestionsOnWordTouchedByCursor(inputTransaction.getSettingsValues(),
currentKeyboardScript);
restartSuggestionsOnWordTouchedByCursor(inputTransaction.getSettingsValues());
}
return;
}
Expand Down Expand Up @@ -1754,7 +1756,7 @@ private void handleBackspaceEvent(final Event event, final InputTransaction inpu
// consider unlearning here because we may have already reached
// the previous word, and will lose it after next deletion.
hasUnlearnedWordBeingDeleted |= unlearnWordBeingDeleted(
inputTransaction.getSettingsValues(), currentKeyboardScript);
inputTransaction.getSettingsValues());
sendDownUpKeyEvent(KeyEvent.KEYCODE_DEL);
totalDeletedLength++;
}
Expand Down Expand Up @@ -1791,7 +1793,7 @@ private void handleBackspaceEvent(final Event event, final InputTransaction inpu
// consider unlearning here because we may have already reached
// the previous word, and will lose it after next deletion.
hasUnlearnedWordBeingDeleted |= unlearnWordBeingDeleted(
inputTransaction.getSettingsValues(), currentKeyboardScript);
inputTransaction.getSettingsValues());
final int codePointBeforeCursorToDeleteAgain = mConnection.getCodePointBeforeCursor();
if (codePointBeforeCursorToDeleteAgain != Constants.NOT_A_CODE) {
final int lengthToDeleteAgain = codePointBeforeCursor > 0xFE00
Expand All @@ -1807,19 +1809,19 @@ private void handleBackspaceEvent(final Event event, final InputTransaction inpu
}
if (!hasUnlearnedWordBeingDeleted) {
// Consider unlearning the word being deleted (if we have not done so already).
unlearnWordBeingDeleted(
inputTransaction.getSettingsValues(), currentKeyboardScript);
unlearnWordBeingDeleted(inputTransaction.getSettingsValues());
}
if (mConnection.hasSlowInputConnection()) {
mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
} else if (inputTransaction.getSettingsValues().needsToLookupSuggestions()
&& inputTransaction.getSettingsValues().mSpacingAndPunctuations.mCurrentLanguageHasSpaces) {
restartSuggestionsOnWordTouchedByCursor(inputTransaction.getSettingsValues(), currentKeyboardScript);
restartSuggestionsOnWordTouchedByCursor(inputTransaction.getSettingsValues());
}
}
}

String getWordAtCursor(final SettingsValues settingsValues, final String currentKeyboardScript) {
String getWordAtCursor(final SettingsValues settingsValues) {
final String currentKeyboardScript = settingsValues.mCurrentKeyboardScript;
if (!mConnection.hasSelection()
&& settingsValues.needsToLookupSuggestions()
&& settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) {
Expand All @@ -1832,8 +1834,8 @@ String getWordAtCursor(final SettingsValues settingsValues, final String current
return "";
}

boolean unlearnWordBeingDeleted(
final SettingsValues settingsValues, final String currentKeyboardScript) {
boolean unlearnWordBeingDeleted(final SettingsValues settingsValues) {
final String currentKeyboardScript = settingsValues.mCurrentKeyboardScript;
if (mConnection.hasSlowInputConnection()) {
// TODO: Refactor unlearning so that it does not incur any extra calls
// to the InputConnection. That way it can still be performed on a slow
Expand All @@ -1845,7 +1847,7 @@ boolean unlearnWordBeingDeleted(
// entered the composing state yet), unlearn the word.
// TODO: Consider tracking whether or not this word was typed by the user.
if (!mConnection.isCursorFollowedByWordCharacter(settingsValues.mSpacingAndPunctuations)) {
final String wordBeingDeleted = getWordAtCursor(settingsValues, currentKeyboardScript);
final String wordBeingDeleted = getWordAtCursor(settingsValues);
if (!TextUtils.isEmpty(wordBeingDeleted)) {
unlearnWord(wordBeingDeleted, settingsValues, Constants.EVENT_BACKSPACE);
return true;
Expand Down Expand Up @@ -2186,9 +2188,8 @@ && isInlineEmojiSearchAction()) {
*
* @param settingsValues the current values of the settings.
*/
public void restartSuggestionsOnWordTouchedByCursor(final SettingsValues settingsValues,
// TODO: remove this argument, put it into settingsValues
final String currentKeyboardScript) {
public void restartSuggestionsOnWordTouchedByCursor(final SettingsValues settingsValues) {
final String currentKeyboardScript = settingsValues.mCurrentKeyboardScript;
// HACK: We may want to special-case some apps that exhibit bad behavior in case
// of
// recorrection. This is a temporary, stopgap measure that will be removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import helium314.keyboard.latin.utils.Log;
import helium314.keyboard.latin.utils.ResourceUtils;
import helium314.keyboard.latin.utils.RunInLocaleKt;
import helium314.keyboard.latin.utils.ScriptUtils;
import helium314.keyboard.latin.utils.StatsUtils;
import helium314.keyboard.latin.utils.SubtypeSettings;
import helium314.keyboard.latin.utils.ToolbarKey;
Expand Down Expand Up @@ -276,7 +277,7 @@ public void onSharedPreferenceChanged(final SharedPreferences prefs, final Strin
return;
}
ToolbarUtilsKt.clearCustomToolbarKeyCodes();
loadSettings(mContext, mSettingsValues.mLocale, mSettingsValues.mInputAttributes);
loadSettings(mContext, mSettingsValues.mLocale, mSettingsValues.mInputAttributes, mSettingsValues.mCurrentKeyboardScript);
StatsUtils.onLoadSettings(mSettingsValues);
} finally {
mSettingsValuesLock.unlock();
Expand All @@ -295,18 +296,18 @@ public void loadSettings(final Context context) {
return;
final Locale locale = ConfigurationCompatKt.locale(context.getResources().getConfiguration());
final InputAttributes inputAttributes = new InputAttributes(new EditorInfo(), false, context.getPackageName());
loadSettings(context, locale, inputAttributes);
loadSettings(context, locale, inputAttributes, ScriptUtils.SCRIPT_UNKNOWN);
}

public void loadSettings(final Context context, final Locale locale,
@NonNull final InputAttributes inputAttributes) {
@NonNull final InputAttributes inputAttributes, final String currentKeyboardScript) {
mSettingsValuesLock.lock();
mContext = context;
try {
final SharedPreferences prefs = mPrefs;
Log.i(TAG, "loadSettings");
mSettingsValues = RunInLocaleKt.runInLocale(context, locale,
ctx -> new SettingsValues(ctx, prefs, ctx.getResources(), inputAttributes));
ctx -> new SettingsValues(ctx, prefs, ctx.getResources(), inputAttributes, currentKeyboardScript));
} finally {
mSettingsValuesLock.unlock();
}
Expand Down
Loading
Loading