trying to fix swipe cursor

This commit is contained in:
dslul 2020-09-08 12:38:04 +02:00
parent 5e2dbda4e0
commit c3276b943b

View file

@ -36,7 +36,6 @@ import android.os.IBinder;
import android.os.Message; import android.os.Message;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.PrintWriterPrinter; import android.util.PrintWriterPrinter;
import android.util.Printer; import android.util.Printer;
@ -246,68 +245,68 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher; final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher;
switch (msg.what) { switch (msg.what) {
case MSG_UPDATE_SUGGESTION_STRIP: case MSG_UPDATE_SUGGESTION_STRIP:
cancelUpdateSuggestionStrip(); cancelUpdateSuggestionStrip();
latinIme.mInputLogic.performUpdateSuggestionStripSync( latinIme.mInputLogic.performUpdateSuggestionStripSync(
latinIme.mSettings.getCurrent(), msg.arg1 /* inputStyle */); latinIme.mSettings.getCurrent(), msg.arg1 /* inputStyle */);
break; break;
case MSG_UPDATE_SHIFT_STATE: case MSG_UPDATE_SHIFT_STATE:
switcher.requestUpdatingShiftState(latinIme.getCurrentAutoCapsState(), switcher.requestUpdatingShiftState(latinIme.getCurrentAutoCapsState(),
latinIme.getCurrentRecapitalizeState());
break;
case MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
if (msg.arg1 == ARG1_NOT_GESTURE_INPUT) {
final SuggestedWords suggestedWords = (SuggestedWords) msg.obj;
latinIme.showSuggestionStrip(suggestedWords);
} else {
latinIme.showGesturePreviewAndSuggestionStrip((SuggestedWords) msg.obj,
msg.arg1 == ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT);
}
break;
case MSG_RESUME_SUGGESTIONS:
latinIme.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
latinIme.mSettings.getCurrent(), false /* forStartInput */,
latinIme.mKeyboardSwitcher.getCurrentKeyboardScriptId());
break;
case MSG_RESUME_SUGGESTIONS_FOR_START_INPUT:
latinIme.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
latinIme.mSettings.getCurrent(), true /* forStartInput */,
latinIme.mKeyboardSwitcher.getCurrentKeyboardScriptId());
break;
case MSG_REOPEN_DICTIONARIES:
// We need to re-evaluate the currently composing word in case the script has
// changed.
postWaitForDictionaryLoad();
latinIme.resetDictionaryFacilitatorIfNecessary();
break;
case MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED:
final SuggestedWords suggestedWords = (SuggestedWords) msg.obj;
latinIme.mInputLogic.onUpdateTailBatchInputCompleted(
latinIme.mSettings.getCurrent(),
suggestedWords, latinIme.mKeyboardSwitcher);
latinIme.onTailBatchInputResultShown(suggestedWords);
break;
case MSG_RESET_CACHES:
final SettingsValues settingsValues = latinIme.mSettings.getCurrent();
if (latinIme.mInputLogic.retryResetCachesAndReturnSuccess(
msg.arg1 == ARG1_TRUE /* tryResumeSuggestions */,
msg.arg2 /* remainingTries */, this /* handler */)) {
// If we were able to reset the caches, then we can reload the keyboard.
// Otherwise, we'll do it when we can.
latinIme.mKeyboardSwitcher.loadKeyboard(latinIme.getCurrentInputEditorInfo(),
settingsValues, latinIme.getCurrentAutoCapsState(),
latinIme.getCurrentRecapitalizeState()); latinIme.getCurrentRecapitalizeState());
} break;
break; case MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
case MSG_WAIT_FOR_DICTIONARY_LOAD: if (msg.arg1 == ARG1_NOT_GESTURE_INPUT) {
Log.i(TAG, "Timeout waiting for dictionary load"); final SuggestedWords suggestedWords = (SuggestedWords) msg.obj;
break; latinIme.showSuggestionStrip(suggestedWords);
case MSG_DEALLOCATE_MEMORY: } else {
latinIme.deallocateMemory(); latinIme.showGesturePreviewAndSuggestionStrip((SuggestedWords) msg.obj,
break; msg.arg1 == ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT);
case MSG_SWITCH_LANGUAGE_AUTOMATICALLY: }
latinIme.switchLanguage((InputMethodSubtype)msg.obj); break;
break; case MSG_RESUME_SUGGESTIONS:
latinIme.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
latinIme.mSettings.getCurrent(), false /* forStartInput */,
latinIme.mKeyboardSwitcher.getCurrentKeyboardScriptId());
break;
case MSG_RESUME_SUGGESTIONS_FOR_START_INPUT:
latinIme.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
latinIme.mSettings.getCurrent(), true /* forStartInput */,
latinIme.mKeyboardSwitcher.getCurrentKeyboardScriptId());
break;
case MSG_REOPEN_DICTIONARIES:
// We need to re-evaluate the currently composing word in case the script has
// changed.
postWaitForDictionaryLoad();
latinIme.resetDictionaryFacilitatorIfNecessary();
break;
case MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED:
final SuggestedWords suggestedWords = (SuggestedWords) msg.obj;
latinIme.mInputLogic.onUpdateTailBatchInputCompleted(
latinIme.mSettings.getCurrent(),
suggestedWords, latinIme.mKeyboardSwitcher);
latinIme.onTailBatchInputResultShown(suggestedWords);
break;
case MSG_RESET_CACHES:
final SettingsValues settingsValues = latinIme.mSettings.getCurrent();
if (latinIme.mInputLogic.retryResetCachesAndReturnSuccess(
msg.arg1 == ARG1_TRUE /* tryResumeSuggestions */,
msg.arg2 /* remainingTries */, this /* handler */)) {
// If we were able to reset the caches, then we can reload the keyboard.
// Otherwise, we'll do it when we can.
latinIme.mKeyboardSwitcher.loadKeyboard(latinIme.getCurrentInputEditorInfo(),
settingsValues, latinIme.getCurrentAutoCapsState(),
latinIme.getCurrentRecapitalizeState());
}
break;
case MSG_WAIT_FOR_DICTIONARY_LOAD:
Log.i(TAG, "Timeout waiting for dictionary load");
break;
case MSG_DEALLOCATE_MEMORY:
latinIme.deallocateMemory();
break;
case MSG_SWITCH_LANGUAGE_AUTOMATICALLY:
latinIme.switchLanguage((InputMethodSubtype)msg.obj);
break;
} }
} }
@ -321,7 +320,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
private void postResumeSuggestionsInternal(final boolean shouldDelay, private void postResumeSuggestionsInternal(final boolean shouldDelay,
final boolean forStartInput) { final boolean forStartInput) {
final LatinIME latinIme = getOwnerInstance(); final LatinIME latinIme = getOwnerInstance();
if (latinIme == null) { if (latinIme == null) {
return; return;
@ -407,7 +406,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
public void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords, public void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords,
final boolean dismissGestureFloatingPreviewText) { final boolean dismissGestureFloatingPreviewText) {
removeMessages(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP); removeMessages(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
final int arg1 = dismissGestureFloatingPreviewText final int arg1 = dismissGestureFloatingPreviewText
? ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT ? ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT
@ -458,7 +457,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
private void executePendingImsCallback(final LatinIME latinIme, final EditorInfo editorInfo, private void executePendingImsCallback(final LatinIME latinIme, final EditorInfo editorInfo,
boolean restarting) { boolean restarting) {
if (mHasPendingFinishInputView) { if (mHasPendingFinishInputView) {
latinIme.onFinishInputViewInternal(mHasPendingFinishInput); latinIme.onFinishInputViewInternal(mHasPendingFinishInput);
} }
@ -882,7 +881,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (DebugFlags.DEBUG_ENABLED) { if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "onStartInputView: editorInfo:" Log.d(TAG, "onStartInputView: editorInfo:"
+ String.format("inputType=0x%08x imeOptions=0x%08x", + String.format("inputType=0x%08x imeOptions=0x%08x",
editorInfo.inputType, editorInfo.imeOptions)); editorInfo.inputType, editorInfo.imeOptions));
Log.d(TAG, "All caps = " Log.d(TAG, "All caps = "
+ ((editorInfo.inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0) + ((editorInfo.inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0)
+ ", sentence caps = " + ", sentence caps = "
@ -1071,8 +1070,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public void onUpdateSelection(final int oldSelStart, final int oldSelEnd, public void onUpdateSelection(final int oldSelStart, final int oldSelEnd,
final int newSelStart, final int newSelEnd, final int newSelStart, final int newSelEnd,
final int composingSpanStart, final int composingSpanEnd) { final int composingSpanStart, final int composingSpanEnd) {
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
composingSpanStart, composingSpanEnd); composingSpanStart, composingSpanEnd);
if (DebugFlags.DEBUG_ENABLED) { if (DebugFlags.DEBUG_ENABLED) {
@ -1088,7 +1087,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final SettingsValues settingsValues = mSettings.getCurrent(); final SettingsValues settingsValues = mSettings.getCurrent();
if (isInputViewShown() if (isInputViewShown()
&& mInputLogic.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, && mInputLogic.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
settingsValues)) { settingsValues)) {
mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(), mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
getCurrentRecapitalizeState()); getCurrentRecapitalizeState());
} }
@ -1356,10 +1355,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public void onMovePointer(int steps) { public void onMovePointer(int steps) {
for (; steps < 0; steps++) if (steps < 0) {
mInputLogic.sendDownUpKeyEvent(KeyEvent.KEYCODE_DPAD_LEFT); int availableCharacters = mInputLogic.mConnection.getTextBeforeCursor(64, 0).length();
for (; steps > 0; steps--) steps = availableCharacters < -steps ? -availableCharacters : steps;
mInputLogic.sendDownUpKeyEvent(KeyEvent.KEYCODE_DPAD_RIGHT); }
else if (steps > 0) {
int availableCharacters = mInputLogic.mConnection.getTextAfterCursor(64, 0).length();
steps = Math.min(availableCharacters, steps);
} else
return;
int newPosition = mInputLogic.mConnection.mExpectedSelStart + steps;
mInputLogic.mConnection.setSelection(newPosition, newPosition);
} }
@Override @Override
@ -1371,12 +1378,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mInputLogic.mConnection.setSelection(start, end); mInputLogic.mConnection.setSelection(start, end);
} }
@Override @Override
public void onUpWithDeletePointerActive() { public void onUpWithDeletePointerActive() {
if (mInputLogic.mConnection.hasSelection()) { if (mInputLogic.mConnection.hasSelection()) {
mInputLogic.sendDownUpKeyEvent(KeyEvent.KEYCODE_DEL); mInputLogic.finishInput();
mInputLogic.sendDownUpKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT); onCodeInput(Constants.CODE_DELETE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false);
} }
} }
@ -1415,7 +1421,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Implementation of {@link KeyboardActionListener}. // Implementation of {@link KeyboardActionListener}.
@Override @Override
public void onCodeInput(final int codePoint, final int x, final int y, public void onCodeInput(final int codePoint, final int x, final int y,
final boolean isKeyRepeat) { final boolean isKeyRepeat) {
// TODO: this processing does not belong inside LatinIME, the caller should be doing this. // TODO: this processing does not belong inside LatinIME, the caller should be doing this.
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
// x and y include some padding, but everything down the line (especially native // x and y include some padding, but everything down the line (especially native
@ -1449,7 +1455,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// public for testing, as we don't want to copy the same logic into test code // public for testing, as we don't want to copy the same logic into test code
@Nonnull @Nonnull
public static Event createSoftwareKeypressEvent(final int keyCodeOrCodePoint, final int keyX, public static Event createSoftwareKeypressEvent(final int keyCodeOrCodePoint, final int keyX,
final int keyY, final boolean isKeyRepeat) { final int keyY, final boolean isKeyRepeat) {
final int keyCode; final int keyCode;
final int codePoint; final int codePoint;
if (keyCodeOrCodePoint <= 0) { if (keyCodeOrCodePoint <= 0) {
@ -1514,7 +1520,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// This method must run on the UI Thread. // This method must run on the UI Thread.
void showGesturePreviewAndSuggestionStrip(@Nonnull final SuggestedWords suggestedWords, void showGesturePreviewAndSuggestionStrip(@Nonnull final SuggestedWords suggestedWords,
final boolean dismissGestureFloatingPreviewText) { final boolean dismissGestureFloatingPreviewText) {
showSuggestionStrip(suggestedWords); showSuggestionStrip(suggestedWords);
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
mainKeyboardView.showGestureFloatingPreviewText(suggestedWords, mainKeyboardView.showGestureFloatingPreviewText(suggestedWords,
@ -1555,7 +1561,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
ImportantNoticeUtils.shouldShowImportantNotice(this, currentSettingsValues); ImportantNoticeUtils.shouldShowImportantNotice(this, currentSettingsValues);
final boolean shouldShowSuggestionCandidates = final boolean shouldShowSuggestionCandidates =
currentSettingsValues.mInputAttributes.mShouldShowSuggestions currentSettingsValues.mInputAttributes.mShouldShowSuggestions
&& currentSettingsValues.isSuggestionsEnabledPerUserSettings(); && currentSettingsValues.isSuggestionsEnabledPerUserSettings();
final boolean shouldShowSuggestionsStripUnlessPassword = shouldShowImportantNotice final boolean shouldShowSuggestionsStripUnlessPassword = shouldShowImportantNotice
|| currentSettingsValues.mShowsVoiceInputKey || currentSettingsValues.mShowsVoiceInputKey
|| shouldShowSuggestionCandidates || shouldShowSuggestionCandidates
@ -1569,7 +1575,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final boolean isEmptyApplicationSpecifiedCompletions = final boolean isEmptyApplicationSpecifiedCompletions =
currentSettingsValues.isApplicationSpecifiedCompletionsOn() currentSettingsValues.isApplicationSpecifiedCompletionsOn()
&& suggestedWords.isEmpty(); && suggestedWords.isEmpty();
final boolean noSuggestionsFromDictionaries = suggestedWords.isEmpty() final boolean noSuggestionsFromDictionaries = suggestedWords.isEmpty()
|| suggestedWords.isPunctuationSuggestions() || suggestedWords.isPunctuationSuggestions()
|| isEmptyApplicationSpecifiedCompletions; || isEmptyApplicationSpecifiedCompletions;
@ -1594,7 +1600,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO[IL]: Move this out of LatinIME. // TODO[IL]: Move this out of LatinIME.
public void getSuggestedWords(final int inputStyle, final int sequenceNumber, public void getSuggestedWords(final int inputStyle, final int sequenceNumber,
final OnGetSuggestedWordsCallback callback) { final OnGetSuggestedWordsCallback callback) {
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
if (keyboard == null) { if (keyboard == null) {
callback.onGetSuggestedWords(SuggestedWords.getEmptyInstance()); callback.onGetSuggestedWords(SuggestedWords.getEmptyInstance());
@ -1664,14 +1670,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
*/ */
private void updateStateAfterInputTransaction(final InputTransaction inputTransaction) { private void updateStateAfterInputTransaction(final InputTransaction inputTransaction) {
switch (inputTransaction.getRequiredShiftUpdate()) { switch (inputTransaction.getRequiredShiftUpdate()) {
case InputTransaction.SHIFT_UPDATE_LATER: case InputTransaction.SHIFT_UPDATE_LATER:
mHandler.postUpdateShiftState(); mHandler.postUpdateShiftState();
break; break;
case InputTransaction.SHIFT_UPDATE_NOW: case InputTransaction.SHIFT_UPDATE_NOW:
mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(), mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
getCurrentRecapitalizeState()); getCurrentRecapitalizeState());
break; break;
default: // SHIFT_NO_UPDATE default: // SHIFT_NO_UPDATE
} }
if (inputTransaction.requiresUpdateSuggestions()) { if (inputTransaction.requiresUpdateSuggestions()) {
final int inputStyle; final int inputStyle;
@ -1720,7 +1726,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// release matching call is {@link #onReleaseKey(int,boolean)} below. // release matching call is {@link #onReleaseKey(int,boolean)} below.
@Override @Override
public void onPressKey(final int primaryCode, final int repeatCount, public void onPressKey(final int primaryCode, final int repeatCount,
final boolean isSinglePointer) { final boolean isSinglePointer) {
mKeyboardSwitcher.onPressKey(primaryCode, isSinglePointer, getCurrentAutoCapsState(), mKeyboardSwitcher.onPressKey(primaryCode, isSinglePointer, getCurrentAutoCapsState(),
getCurrentRecapitalizeState()); getCurrentRecapitalizeState());
hapticAndAudioFeedback(primaryCode, repeatCount); hapticAndAudioFeedback(primaryCode, repeatCount);
@ -1831,18 +1837,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void onClick(DialogInterface di, int position) { public void onClick(DialogInterface di, int position) {
di.dismiss(); di.dismiss();
switch (position) { switch (position) {
case 0: case 0:
final Intent intent = IntentUtils.getInputLanguageSelectionIntent( final Intent intent = IntentUtils.getInputLanguageSelectionIntent(
imeId, imeId,
Intent.FLAG_ACTIVITY_NEW_TASK Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
| Intent.FLAG_ACTIVITY_CLEAR_TOP); | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(Intent.EXTRA_TITLE, languageSelectionTitle); intent.putExtra(Intent.EXTRA_TITLE, languageSelectionTitle);
startActivity(intent); startActivity(intent);
break; break;
case 1: case 1:
launchSettings(); launchSettings();
break; break;
} }
} }
}; };
@ -1891,10 +1897,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
void replaceDictionariesForTest(final Locale locale) { void replaceDictionariesForTest(final Locale locale) {
final SettingsValues settingsValues = mSettings.getCurrent(); final SettingsValues settingsValues = mSettings.getCurrent();
mDictionaryFacilitator.resetDictionaries(this, locale, mDictionaryFacilitator.resetDictionaries(this, locale,
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts, settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
false /* forceReloadMainDictionary */, false /* forceReloadMainDictionary */,
settingsValues.mAccount, "", /* dictionaryNamePrefix */ settingsValues.mAccount, "", /* dictionaryNamePrefix */
this /* DictionaryInitializationListener */); this /* DictionaryInitializationListener */);
} }
// DO NOT USE THIS for any other purpose than testing. // DO NOT USE THIS for any other purpose than testing.