diff options
Diffstat (limited to 'java')
3 files changed, 233 insertions, 159 deletions
diff --git a/java/src/com/android/inputmethod/event/InputTransaction.java b/java/src/com/android/inputmethod/event/InputTransaction.java index cdff265c6..b18bf5638 100644 --- a/java/src/com/android/inputmethod/event/InputTransaction.java +++ b/java/src/com/android/inputmethod/event/InputTransaction.java @@ -33,7 +33,7 @@ public class InputTransaction { // Initial conditions public final SettingsValues mSettingsValues; - public final Event mEvent; + private final Event mEvent; public final long mTimestamp; public final int mSpaceState; public final int mShiftState; @@ -42,6 +42,7 @@ public class InputTransaction { private int mRequiredShiftUpdate = SHIFT_NO_UPDATE; private boolean mRequiresUpdateSuggestions = false; private boolean mDidAffectContents = false; + private boolean mDidAutoCorrect = false; public InputTransaction(final SettingsValues settingsValues, final Event event, final long timestamp, final int spaceState, final int shiftState) { @@ -97,4 +98,19 @@ public class InputTransaction { public boolean didAffectContents() { return mDidAffectContents; } + + /** + * Indicate that this transaction performed an auto-correction. + */ + public void setDidAutoCorrect() { + mDidAutoCorrect = true; + } + + /** + * Find out whether this transaction performed an auto-correction. + * @return Whether this transaction performed an auto-correction. + */ + public boolean didAutoCorrect() { + return mDidAutoCorrect; + } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 719aeac77..4adc28d7a 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -248,7 +248,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen break; case MSG_RESET_CACHES: final SettingsValues settingsValues = latinIme.mSettings.getCurrent(); - if (latinIme.mInputLogic.retryResetCachesAndReturnSuccess(settingsValues, + if (latinIme.mInputLogic.retryResetCachesAndReturnSuccess( msg.arg1 == 1 /* tryResumeSuggestions */, msg.arg2 /* remainingTries */, this /* handler */)) { // If we were able to reset the caches, then we can reload the keyboard. @@ -752,8 +752,30 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen loadKeyboard(); } + /** + * A class that holds information to pass from onStartInputInternal to onStartInputViewInternal + * + * OnStartInput needs to reload the settings and that will prevent onStartInputViewInternal + * from comparing the old settings with the new ones, so we use this memory to pass the + * necessary information along. + */ + private static class EditorChangeInfo { + public final boolean mIsSameInputType; + public final boolean mHasSameOrientation; + public EditorChangeInfo(final boolean isSameInputType, final boolean hasSameOrientation) { + mIsSameInputType = isSameInputType; + mHasSameOrientation = hasSameOrientation; + } + } + + private EditorChangeInfo mLastEditorChangeInfo; + private void onStartInputInternal(final EditorInfo editorInfo, final boolean restarting) { super.onStartInput(editorInfo, restarting); + SettingsValues currentSettingsValues = mSettings.getCurrent(); + mLastEditorChangeInfo = new EditorChangeInfo( + currentSettingsValues.isSameInputType(editorInfo), + currentSettingsValues.hasSameOrientation(getResources().getConfiguration())); } @SuppressWarnings("deprecation") @@ -763,9 +785,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final KeyboardSwitcher switcher = mKeyboardSwitcher; switcher.updateKeyboardTheme(); final MainKeyboardView mainKeyboardView = switcher.getMainKeyboardView(); - // If we are starting input in a different text field from before, we'll have to reload - // settings, so currentSettingsValues can't be final. - SettingsValues currentSettingsValues = mSettings.getCurrent(); if (editorInfo == null) { Log.e(TAG, "Null EditorInfo in onStartInputView()"); @@ -808,7 +827,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen accessUtils.onStartInputViewInternal(mainKeyboardView, editorInfo, restarting); } - final boolean inputTypeChanged = !currentSettingsValues.isSameInputType(editorInfo); + final boolean inputTypeChanged = !mLastEditorChangeInfo.mIsSameInputType; final boolean isDifferentTextField = !restarting || inputTypeChanged; if (isDifferentTextField) { mSubtypeSwitcher.updateParametersOnStartInputView(); @@ -853,13 +872,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen canReachInputConnection = true; } - if (isDifferentTextField || - !currentSettingsValues.hasSameOrientation(getResources().getConfiguration())) { + if (isDifferentTextField || !mLastEditorChangeInfo.mHasSameOrientation) { loadSettings(); } + final SettingsValues currentSettingsValues = mSettings.getCurrent(); if (isDifferentTextField) { mainKeyboardView.closing(); - currentSettingsValues = mSettings.getCurrent(); if (currentSettingsValues.mAutoCorrectionEnabledPerUserSettings) { suggest.setAutoCorrectionThreshold( diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index dee7cd466..5c719edb9 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -426,121 +426,15 @@ public final class InputLogic { cancelDoubleSpacePeriodCountdown(); } - boolean didAutoCorrect = false; if (processedEvent.isConsumed()) { - // A consumed event may have text to commit and an update to the composing state, so - // we evaluate both. With some combiners, it's possible than an event contains both - // and we enter both of the following if clauses. - final CharSequence textToCommit = processedEvent.getTextToCommit(); - if (!TextUtils.isEmpty(textToCommit)) { - mConnection.commitText(textToCommit, 1); - inputTransaction.setDidAffectContents(); - } - if (mWordComposer.isComposingWord()) { - mConnection.setComposingText(mWordComposer.getTypedWord(), 1); - inputTransaction.setDidAffectContents(); - inputTransaction.setRequiresUpdateSuggestions(); - } + handleConsumedEvent(processedEvent, inputTransaction); } else if (processedEvent.isFunctionalKeyEvent()) { - // A special key, like delete, shift, emoji, or the settings key. - switch (processedEvent.mKeyCode) { - case Constants.CODE_DELETE: - handleBackspace(inputTransaction, currentKeyboardScriptId); - // Backspace is a functional key, but it affects the contents of the editor. - inputTransaction.setDidAffectContents(); - break; - case Constants.CODE_SHIFT: - performRecapitalization(inputTransaction.mSettingsValues); - inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW); - if (mSuggestedWords.mIsPrediction) { - inputTransaction.setRequiresUpdateSuggestions(); - } - break; - case Constants.CODE_CAPSLOCK: - // Note: Changing keyboard to shift lock state is handled in - // {@link KeyboardSwitcher#onCodeInput(int)}. - break; - case Constants.CODE_SYMBOL_SHIFT: - // Note: Calling back to the keyboard on the symbol Shift key is handled in - // {@link #onPressKey(int,int,boolean)} and {@link #onReleaseKey(int,boolean)}. - break; - case Constants.CODE_SWITCH_ALPHA_SYMBOL: - // Note: Calling back to the keyboard on symbol key is handled in - // {@link #onPressKey(int,int,boolean)} and {@link #onReleaseKey(int,boolean)}. - break; - case Constants.CODE_SETTINGS: - onSettingsKeyPressed(); - break; - case Constants.CODE_SHORTCUT: - // We need to switch to the shortcut IME. This is handled by LatinIME since the - // input logic has no business with IME switching. - break; - case Constants.CODE_ACTION_NEXT: - performEditorAction(EditorInfo.IME_ACTION_NEXT); - break; - case Constants.CODE_ACTION_PREVIOUS: - performEditorAction(EditorInfo.IME_ACTION_PREVIOUS); - break; - case Constants.CODE_LANGUAGE_SWITCH: - handleLanguageSwitchKey(); - break; - case Constants.CODE_EMOJI: - // Note: Switching emoji keyboard is being handled in - // {@link KeyboardState#onCodeInput(int,int)}. - break; - case Constants.CODE_ALPHA_FROM_EMOJI: - // Note: Switching back from Emoji keyboard to the main keyboard is being - // handled in {@link KeyboardState#onCodeInput(int,int)}. - break; - case Constants.CODE_SHIFT_ENTER: - // TODO: remove this object - final Event tmpEvent = Event.createSoftwareKeypressEvent(Constants.CODE_ENTER, - processedEvent.mKeyCode, processedEvent.mX, processedEvent.mY, - processedEvent.isKeyRepeat()); - final InputTransaction tmpTransaction = new InputTransaction( - inputTransaction.mSettingsValues, tmpEvent, - inputTransaction.mTimestamp, inputTransaction.mSpaceState, - inputTransaction.mShiftState); - didAutoCorrect = handleNonSpecialCharacter(tmpTransaction, handler); - // Shift + Enter is treated as a functional key but it results in adding a new - // line, so that does affect the contents of the editor. - inputTransaction.setDidAffectContents(); - break; - default: - throw new RuntimeException("Unknown key code : " + processedEvent.mKeyCode); - } + handleFunctionalEvent(processedEvent, inputTransaction, currentKeyboardScriptId, + handler); } else { - inputTransaction.setDidAffectContents(); - switch (processedEvent.mCodePoint) { - case Constants.CODE_ENTER: - final EditorInfo editorInfo = getCurrentInputEditorInfo(); - final int imeOptionsActionId = - InputTypeUtils.getImeOptionsActionIdFromEditorInfo(editorInfo); - if (InputTypeUtils.IME_ACTION_CUSTOM_LABEL == imeOptionsActionId) { - // Either we have an actionLabel and we should performEditorAction with - // actionId regardless of its value. - performEditorAction(editorInfo.actionId); - } else if (EditorInfo.IME_ACTION_NONE != imeOptionsActionId) { - // We didn't have an actionLabel, but we had another action to execute. - // EditorInfo.IME_ACTION_NONE explicitly means no action. In contrast, - // EditorInfo.IME_ACTION_UNSPECIFIED is the default value for an action, so it - // means there should be an action and the app didn't bother to set a specific - // code for it - presumably it only handles one. It does not have to be treated - // in any specific way: anything that is not IME_ACTION_NONE should be sent to - // performEditorAction. - performEditorAction(imeOptionsActionId); - } else { - // No action label, and the action from imeOptions is NONE: this is a regular - // enter key that should input a carriage return. - didAutoCorrect = handleNonSpecialCharacter(inputTransaction, handler); - } - break; - default: - didAutoCorrect = handleNonSpecialCharacter(inputTransaction, handler); - break; - } + handleNonFunctionalEvent(processedEvent, inputTransaction, handler); } - if (!didAutoCorrect && processedEvent.mKeyCode != Constants.CODE_SHIFT + if (!inputTransaction.didAutoCorrect() && processedEvent.mKeyCode != Constants.CODE_SHIFT && processedEvent.mKeyCode != Constants.CODE_CAPSLOCK && processedEvent.mKeyCode != Constants.CODE_SWITCH_ALPHA_SYMBOL) mLastComposedWord.deactivate(); @@ -686,6 +580,153 @@ public final class InputLogic { } /** + * Handle a consumed event. + * + * Consumed events represent events that have already been consumed, typically by the + * combining chain. + * + * @param event The event to handle. + * @param inputTransaction The transaction in progress. + */ + private void handleConsumedEvent(final Event event, final InputTransaction inputTransaction) { + // A consumed event may have text to commit and an update to the composing state, so + // we evaluate both. With some combiners, it's possible than an event contains both + // and we enter both of the following if clauses. + final CharSequence textToCommit = event.getTextToCommit(); + if (!TextUtils.isEmpty(textToCommit)) { + mConnection.commitText(textToCommit, 1); + inputTransaction.setDidAffectContents(); + } + if (mWordComposer.isComposingWord()) { + mConnection.setComposingText(mWordComposer.getTypedWord(), 1); + inputTransaction.setDidAffectContents(); + inputTransaction.setRequiresUpdateSuggestions(); + } + } + + /** + * Handle a functional key event. + * + * A functional event is a special key, like delete, shift, emoji, or the settings key. + * Non-special keys are those that generate a single code point. + * This includes all letters, digits, punctuation, separators, emoji. It excludes keys that + * manage keyboard-related stuff like shift, language switch, settings, layout switch, or + * any key that results in multiple code points like the ".com" key. + * + * @param event The event to handle. + * @param inputTransaction The transaction in progress. + */ + private void handleFunctionalEvent(final Event event, final InputTransaction inputTransaction, + // TODO: remove these arguments + final int currentKeyboardScriptId, final LatinIME.UIHandler handler) { + switch (event.mKeyCode) { + case Constants.CODE_DELETE: + handleBackspaceEvent(event, inputTransaction, currentKeyboardScriptId); + // Backspace is a functional key, but it affects the contents of the editor. + inputTransaction.setDidAffectContents(); + break; + case Constants.CODE_SHIFT: + performRecapitalization(inputTransaction.mSettingsValues); + inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW); + if (mSuggestedWords.mIsPrediction) { + inputTransaction.setRequiresUpdateSuggestions(); + } + break; + case Constants.CODE_CAPSLOCK: + // Note: Changing keyboard to shift lock state is handled in + // {@link KeyboardSwitcher#onCodeInput(int)}. + break; + case Constants.CODE_SYMBOL_SHIFT: + // Note: Calling back to the keyboard on the symbol Shift key is handled in + // {@link #onPressKey(int,int,boolean)} and {@link #onReleaseKey(int,boolean)}. + break; + case Constants.CODE_SWITCH_ALPHA_SYMBOL: + // Note: Calling back to the keyboard on symbol key is handled in + // {@link #onPressKey(int,int,boolean)} and {@link #onReleaseKey(int,boolean)}. + break; + case Constants.CODE_SETTINGS: + onSettingsKeyPressed(); + break; + case Constants.CODE_SHORTCUT: + // We need to switch to the shortcut IME. This is handled by LatinIME since the + // input logic has no business with IME switching. + break; + case Constants.CODE_ACTION_NEXT: + performEditorAction(EditorInfo.IME_ACTION_NEXT); + break; + case Constants.CODE_ACTION_PREVIOUS: + performEditorAction(EditorInfo.IME_ACTION_PREVIOUS); + break; + case Constants.CODE_LANGUAGE_SWITCH: + handleLanguageSwitchKey(); + break; + case Constants.CODE_EMOJI: + // Note: Switching emoji keyboard is being handled in + // {@link KeyboardState#onCodeInput(int,int)}. + break; + case Constants.CODE_ALPHA_FROM_EMOJI: + // Note: Switching back from Emoji keyboard to the main keyboard is being + // handled in {@link KeyboardState#onCodeInput(int,int)}. + break; + case Constants.CODE_SHIFT_ENTER: + // TODO: remove this object + final Event tmpEvent = Event.createSoftwareKeypressEvent(Constants.CODE_ENTER, + event.mKeyCode, event.mX, event.mY, event.isKeyRepeat()); + handleNonSpecialCharacterEvent(tmpEvent, inputTransaction, handler); + // Shift + Enter is treated as a functional key but it results in adding a new + // line, so that does affect the contents of the editor. + inputTransaction.setDidAffectContents(); + break; + default: + throw new RuntimeException("Unknown key code : " + event.mKeyCode); + } + } + + /** + * Handle an event that is not a functional event. + * + * These events are generally events that cause input, but in some cases they may do other + * things like trigger an editor action. + * + * @param event The event to handle. + * @param inputTransaction The transaction in progress. + */ + private void handleNonFunctionalEvent(final Event event, + final InputTransaction inputTransaction, + // TODO: remove this argument + final LatinIME.UIHandler handler) { + inputTransaction.setDidAffectContents(); + switch (event.mCodePoint) { + case Constants.CODE_ENTER: + final EditorInfo editorInfo = getCurrentInputEditorInfo(); + final int imeOptionsActionId = + InputTypeUtils.getImeOptionsActionIdFromEditorInfo(editorInfo); + if (InputTypeUtils.IME_ACTION_CUSTOM_LABEL == imeOptionsActionId) { + // Either we have an actionLabel and we should performEditorAction with + // actionId regardless of its value. + performEditorAction(editorInfo.actionId); + } else if (EditorInfo.IME_ACTION_NONE != imeOptionsActionId) { + // We didn't have an actionLabel, but we had another action to execute. + // EditorInfo.IME_ACTION_NONE explicitly means no action. In contrast, + // EditorInfo.IME_ACTION_UNSPECIFIED is the default value for an action, so it + // means there should be an action and the app didn't bother to set a specific + // code for it - presumably it only handles one. It does not have to be treated + // in any specific way: anything that is not IME_ACTION_NONE should be sent to + // performEditorAction. + performEditorAction(imeOptionsActionId); + } else { + // No action label, and the action from imeOptions is NONE: this is a regular + // enter key that should input a carriage return. + handleNonSpecialCharacterEvent(event, inputTransaction, handler); + } + break; + default: + handleNonSpecialCharacterEvent(event, inputTransaction, handler); + break; + } + } + + /** * Handle inputting a code point to the editor. * * Non-special keys are those that generate a single code point. @@ -693,21 +734,19 @@ public final class InputLogic { * manage keyboard-related stuff like shift, language switch, settings, layout switch, or * any key that results in multiple code points like the ".com" key. * + * @param event The event to handle. * @param inputTransaction The transaction in progress. - * @return whether this caused an auto-correction to happen. */ - private boolean handleNonSpecialCharacter(final InputTransaction inputTransaction, + private void handleNonSpecialCharacterEvent(final Event event, + final InputTransaction inputTransaction, // TODO: remove this argument final LatinIME.UIHandler handler) { - final int codePoint = inputTransaction.mEvent.mCodePoint; + final int codePoint = event.mCodePoint; mSpaceState = SpaceState.NONE; - final boolean didAutoCorrect; if (inputTransaction.mSettingsValues.isWordSeparator(codePoint) || Character.getType(codePoint) == Character.OTHER_SYMBOL) { - didAutoCorrect = handleSeparator(inputTransaction, - inputTransaction.mEvent.isSuggestionStripPress(), handler); + handleSeparatorEvent(event, inputTransaction, handler); } else { - didAutoCorrect = false; if (SpaceState.PHANTOM == inputTransaction.mSpaceState) { if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) { // If we are in the middle of a recorrection, we need to commit the recorrection @@ -718,22 +757,23 @@ public final class InputLogic { commitTyped(inputTransaction.mSettingsValues, LastComposedWord.NOT_A_SEPARATOR); } } - handleNonSeparator(inputTransaction.mSettingsValues, inputTransaction); + handleNonSeparatorEvent(event, inputTransaction.mSettingsValues, inputTransaction); } - return didAutoCorrect; } /** * Handle a non-separator. + * @param event The event to handle. * @param settingsValues The current settings values. * @param inputTransaction The transaction in progress. */ - private void handleNonSeparator(final SettingsValues settingsValues, + private void handleNonSeparatorEvent(final Event event, final SettingsValues settingsValues, final InputTransaction inputTransaction) { - final int codePoint = inputTransaction.mEvent.mCodePoint; + final int codePoint = event.mCodePoint; // TODO: refactor this method to stop flipping isComposingWord around all the time, and - // make it shorter (possibly cut into several pieces). Also factor handleNonSpecialCharacter - // which has the same name as other handle* methods but is not the same. + // make it shorter (possibly cut into several pieces). Also factor + // handleNonSpecialCharacterEvent which has the same name as other handle* methods but is + // not the same. boolean isComposingWord = mWordComposer.isComposingWord(); // TODO: remove isWordConnector() and use isUsuallyFollowedBySpace() instead. @@ -780,7 +820,7 @@ public final class InputLogic { resetComposingState(false /* alsoResetLastComposedWord */); } if (isComposingWord) { - mWordComposer.applyProcessedEvent(inputTransaction.mEvent); + mWordComposer.applyProcessedEvent(event); // If it's the first letter, make note of auto-caps state if (mWordComposer.isSingleLetter()) { mWordComposer.setCapitalizedModeAtStartComposingTime(inputTransaction.mShiftState); @@ -788,10 +828,10 @@ public final class InputLogic { mConnection.setComposingText(getTextWithUnderline( mWordComposer.getTypedWord()), 1); } else { - final boolean swapWeakSpace = tryStripSpaceAndReturnWhetherShouldSwapInstead( + final boolean swapWeakSpace = tryStripSpaceAndReturnWhetherShouldSwapInstead(event, inputTransaction); - if (swapWeakSpace && trySwapSwapperAndSpace(inputTransaction)) { + if (swapWeakSpace && trySwapSwapperAndSpace(event, inputTransaction)) { mSpaceState = SpaceState.WEAK; } else { sendKeyCodePoint(settingsValues, codePoint); @@ -804,17 +844,14 @@ public final class InputLogic { /** * Handle input of a separator code point. + * @param event The event to handle. * @param inputTransaction The transaction in progress. - * @param isFromSuggestionStrip whether this code point comes from the suggestion strip. - * @return whether this caused an auto-correction to happen. */ - private boolean handleSeparator(final InputTransaction inputTransaction, - final boolean isFromSuggestionStrip, + private void handleSeparatorEvent(final Event event, final InputTransaction inputTransaction, // TODO: remove this argument final LatinIME.UIHandler handler) { - final int codePoint = inputTransaction.mEvent.mCodePoint; + final int codePoint = event.mCodePoint; final SettingsValues settingsValues = inputTransaction.mSettingsValues; - boolean didAutoCorrect = false; final boolean wasComposingWord = mWordComposer.isComposingWord(); // We avoid sending spaces in languages without spaces if we were composing. final boolean shouldAvoidSendingCode = Constants.CODE_SPACE == codePoint @@ -832,14 +869,14 @@ public final class InputLogic { final String separator = shouldAvoidSendingCode ? LastComposedWord.NOT_A_SEPARATOR : StringUtils.newSingleCodePointString(codePoint); commitCurrentAutoCorrection(settingsValues, separator, handler); - didAutoCorrect = true; + inputTransaction.setDidAutoCorrect(); } else { commitTyped(settingsValues, StringUtils.newSingleCodePointString(codePoint)); } } - final boolean swapWeakSpace = tryStripSpaceAndReturnWhetherShouldSwapInstead( + final boolean swapWeakSpace = tryStripSpaceAndReturnWhetherShouldSwapInstead(event, inputTransaction); final boolean isInsideDoubleQuoteOrAfterDigit = Constants.CODE_DOUBLE_QUOTE == codePoint @@ -864,10 +901,10 @@ public final class InputLogic { promotePhantomSpace(settingsValues); } - if (tryPerformDoubleSpacePeriod(inputTransaction)) { + if (tryPerformDoubleSpacePeriod(event, inputTransaction)) { mSpaceState = SpaceState.DOUBLE; inputTransaction.setRequiresUpdateSuggestions(); - } else if (swapWeakSpace && trySwapSwapperAndSpace(inputTransaction)) { + } else if (swapWeakSpace && trySwapSwapperAndSpace(event, inputTransaction)) { mSpaceState = SpaceState.SWAP_PUNCTUATION; mSuggestionStripViewAccessor.setNeutralSuggestionStrip(); } else if (Constants.CODE_SPACE == codePoint) { @@ -910,17 +947,16 @@ public final class InputLogic { } inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW); - return didAutoCorrect; } /** * Handle a press on the backspace key. + * @param event The event to handle. * @param inputTransaction The transaction in progress. */ - private void handleBackspace(final InputTransaction inputTransaction, + private void handleBackspaceEvent(final Event event, final InputTransaction inputTransaction, // TODO: remove this argument, put it into settingsValues final int currentKeyboardScriptId) { - final Event event = inputTransaction.mEvent; mSpaceState = SpaceState.NONE; mDeleteCount++; @@ -1071,16 +1107,18 @@ public final class InputLogic { * * This method will check that there are two characters before the cursor and that the first * one is a space before it does the actual swapping. + * @param event The event to handle. * @param inputTransaction The transaction in progress. * @return true if the swap has been performed, false if it was prevented by preliminary checks. */ - private boolean trySwapSwapperAndSpace(final InputTransaction inputTransaction) { + private boolean trySwapSwapperAndSpace(final Event event, + final InputTransaction inputTransaction) { final int codePointBeforeCursor = mConnection.getCodePointBeforeCursor(); if (Constants.CODE_SPACE != codePointBeforeCursor) { return false; } mConnection.deleteSurroundingText(1, 0); - final String text = inputTransaction.mEvent.getTextToCommit() + " "; + final String text = event.getTextToCommit() + " "; mConnection.commitText(text, 1); inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW); return true; @@ -1088,13 +1126,14 @@ public final class InputLogic { /* * Strip a trailing space if necessary and returns whether it's a swap weak space situation. + * @param event The event to handle. * @param inputTransaction The transaction in progress. * @return whether we should swap the space instead of removing it. */ - private boolean tryStripSpaceAndReturnWhetherShouldSwapInstead( + private boolean tryStripSpaceAndReturnWhetherShouldSwapInstead(final Event event, final InputTransaction inputTransaction) { - final int codePoint = inputTransaction.mEvent.mCodePoint; - final boolean isFromSuggestionStrip = inputTransaction.mEvent.isSuggestionStripPress(); + final int codePoint = event.mCodePoint; + final boolean isFromSuggestionStrip = event.isSuggestionStripPress(); if (Constants.CODE_ENTER == codePoint && SpaceState.SWAP_PUNCTUATION == inputTransaction.mSpaceState) { mConnection.removeTrailingSpace(); @@ -1139,14 +1178,16 @@ public final class InputLogic { * these conditions are fulfilled, this method applies the transformation and returns true. * Otherwise, it does nothing and returns false. * + * @param event The event to handle. * @param inputTransaction The transaction in progress. * @return true if we applied the double-space-to-period transformation, false otherwise. */ - private boolean tryPerformDoubleSpacePeriod(final InputTransaction inputTransaction) { + private boolean tryPerformDoubleSpacePeriod(final Event event, + final InputTransaction inputTransaction) { // Check the setting, the typed character and the countdown. If any of the conditions is // not fulfilled, return false. if (!inputTransaction.mSettingsValues.mUseDoubleSpacePeriod - || Constants.CODE_SPACE != inputTransaction.mEvent.mCodePoint + || Constants.CODE_SPACE != event.mCodePoint || !isDoubleSpacePeriodCountdownActive(inputTransaction)) { return false; } @@ -1974,14 +2015,13 @@ public final class InputLogic { * This method handles the retry, and re-schedules a new retry if we still can't access. * We only retry up to 5 times before giving up. * - * @param settingsValues the current values of the settings. * @param tryResumeSuggestions Whether we should resume suggestions or not. * @param remainingTries How many times we may try again before giving up. * @return whether true if the caches were successfully reset, false otherwise. */ // TODO: make this private - public boolean retryResetCachesAndReturnSuccess(final SettingsValues settingsValues, - final boolean tryResumeSuggestions, final int remainingTries, + public boolean retryResetCachesAndReturnSuccess(final boolean tryResumeSuggestions, + final int remainingTries, // TODO: remove these arguments final LatinIME.UIHandler handler) { final boolean shouldFinishComposition = mConnection.hasSelection() |