Skip to content

Commit

Permalink
Fix flicker on input start.
Browse files Browse the repository at this point in the history
  • Loading branch information
codokie committed May 31, 2024
1 parent 4d21c54 commit dc4755b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package helium314.keyboard.latin

import android.content.ClipboardManager
import android.content.Context
import android.text.InputType
import android.text.TextUtils
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -75,7 +74,7 @@ class ClipboardHistoryManager(

private fun updateClipboardSuggestion() {
if (latinIME.mSettings.current?.mSuggestClipboardContent == true) {
latinIME.mHandler?.postUpdateSuggestionStrip(latinIME.currentInputEditorInfo?.inputType ?: InputType.TYPE_NULL)
latinIME.mHandler?.postResumeSuggestions(true)
}
}

Expand Down
25 changes: 3 additions & 22 deletions app/src/main/java/helium314/keyboard/latin/LatinIME.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,8 @@ public static final class UIHandler extends LeakGuardHandlerWrapper<LatinIME> {
private static final int MSG_WAIT_FOR_DICTIONARY_LOAD = 8;
private static final int MSG_DEALLOCATE_MEMORY = 9;
private static final int MSG_SWITCH_LANGUAGE_AUTOMATICALLY = 10;
private static final int MSG_SET_CLIPBOARD_SUGGESTION = 11;

// Update this when adding new messages
private static final int MSG_LAST = MSG_SET_CLIPBOARD_SUGGESTION;
private static final int MSG_LAST = MSG_SWITCH_LANGUAGE_AUTOMATICALLY;

private static final int ARG1_NOT_GESTURE_INPUT = 0;
private static final int ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
Expand Down Expand Up @@ -262,9 +260,6 @@ public void handleMessage(@NonNull final Message msg) {
latinIme.mSettings.getCurrent(),
latinIme.mKeyboardSwitcher.getCurrentKeyboardScript());
break;
case MSG_SET_CLIPBOARD_SUGGESTION:
latinIme.setClipboardSuggestion();
break;
case MSG_REOPEN_DICTIONARIES:
// We need to re-evaluate the currently composing word in case the script has
// changed.
Expand Down Expand Up @@ -312,19 +307,8 @@ public void postReopenDictionaries() {
}

public void postResumeSuggestions(final boolean shouldDelay) {
final LatinIME latinIme = getOwnerInstance();
if (latinIme == null) {
return;
}
final int message;
if (!latinIme.mSettings.getCurrent().isSuggestionsEnabledPerUserSettings()) {
if (latinIme.mSettings.getCurrent().mSuggestClipboardContent)
message = MSG_SET_CLIPBOARD_SUGGESTION;
else return;
} else {
message = MSG_RESUME_SUGGESTIONS;
}
removeMessages(MSG_RESUME_SUGGESTIONS);
final int message = MSG_RESUME_SUGGESTIONS;
if (shouldDelay) {
sendMessageDelayed(obtainMessage(message),
mDelayInMillisecondsToUpdateSuggestions);
Expand Down Expand Up @@ -1000,7 +984,6 @@ void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restart
// initialSelStart and initialSelEnd sometimes are lying. Make a best effort to
// work around this bug.
mInputLogic.mConnection.tryFixLyingCursorPosition();
mHandler.postResumeSuggestions(true /* shouldDelay */);
needToCallLoadKeyboardLater = false;
}
} else {
Expand Down Expand Up @@ -1029,11 +1012,9 @@ void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restart
// Space state must be updated before calling updateShiftState
switcher.requestUpdatingShiftState(getCurrentAutoCapsState(), getCurrentRecapitalizeState());
}
// This will set the punctuation suggestions if next word suggestion is off;
// otherwise it will clear the suggestion strip.
setNeutralSuggestionStrip();

mHandler.cancelUpdateSuggestionStrip();
mHandler.postResumeSuggestions(true /* shouldDelay */);

mainKeyboardView.setMainDictionaryAvailability(mDictionaryFacilitator.hasAtLeastOneInitializedMainDictionary());
mainKeyboardView.setKeyPreviewPopupEnabled(currentSettingsValues.mKeyPreviewPopupOn);
Expand Down

0 comments on commit dc4755b

Please sign in to comment.