Merge "[IL22] Move onTextInput to InputLogic."
commit
84e78cb769
|
@ -1302,35 +1302,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called from PointerTracker through the KeyboardActionListener interface
|
// Called from PointerTracker through the KeyboardActionListener interface
|
||||||
// TODO[IL]: Move this to InputLogic
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextInput(final String rawText) {
|
public void onTextInput(final String rawText) {
|
||||||
mInputLogic.mConnection.beginBatchEdit();
|
mInputLogic.onTextInput(mSettings.getCurrent(), rawText, mKeyboardSwitcher, mHandler);
|
||||||
if (mInputLogic.mWordComposer.isComposingWord()) {
|
|
||||||
mInputLogic.commitCurrentAutoCorrection(mSettings.getCurrent(), rawText, mHandler);
|
|
||||||
} else {
|
|
||||||
mInputLogic.resetComposingState(true /* alsoResetLastComposedWord */);
|
|
||||||
}
|
|
||||||
mHandler.postUpdateSuggestionStrip();
|
|
||||||
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS
|
|
||||||
&& ResearchLogger.RESEARCH_KEY_OUTPUT_TEXT.equals(rawText)) {
|
|
||||||
ResearchLogger.getInstance().onResearchKeySelected(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final String text = specificTldProcessingOnTextInput(rawText);
|
|
||||||
if (SpaceState.PHANTOM == mInputLogic.mSpaceState) {
|
|
||||||
mInputLogic.promotePhantomSpace(mSettings.getCurrent());
|
|
||||||
}
|
|
||||||
mInputLogic.mConnection.commitText(text, 1);
|
|
||||||
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
|
||||||
ResearchLogger.latinIME_onTextInput(text, false /* isBatchMode */);
|
|
||||||
}
|
|
||||||
mInputLogic.mConnection.endBatchEdit();
|
|
||||||
// Space state must be updated before calling updateShiftState
|
|
||||||
mInputLogic.mSpaceState = SpaceState.NONE;
|
|
||||||
mKeyboardSwitcher.updateShiftState();
|
|
||||||
mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT);
|
|
||||||
mInputLogic.mEnteredText = text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1614,25 +1588,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
mInputUpdater.onEndBatchInput(batchPointers);
|
mInputUpdater.onEndBatchInput(batchPointers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String specificTldProcessingOnTextInput(final String text) {
|
|
||||||
if (text.length() <= 1 || text.charAt(0) != Constants.CODE_PERIOD
|
|
||||||
|| !Character.isLetter(text.charAt(1))) {
|
|
||||||
// Not a tld: do nothing.
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
// We have a TLD (or something that looks like this): make sure we don't add
|
|
||||||
// a space even if currently in phantom mode.
|
|
||||||
mInputLogic.mSpaceState = SpaceState.NONE;
|
|
||||||
// TODO: use getCodePointBeforeCursor instead to improve performance and simplify the code
|
|
||||||
final CharSequence lastOne = mInputLogic.mConnection.getTextBeforeCursor(1, 0);
|
|
||||||
if (lastOne != null && lastOne.length() == 1
|
|
||||||
&& lastOne.charAt(0) == Constants.CODE_PERIOD) {
|
|
||||||
return text.substring(1);
|
|
||||||
} else {
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called from PointerTracker through the KeyboardActionListener interface
|
// Called from PointerTracker through the KeyboardActionListener interface
|
||||||
@Override
|
@Override
|
||||||
public void onFinishSlidingInput() {
|
public void onFinishSlidingInput() {
|
||||||
|
|
|
@ -120,6 +120,46 @@ public final class InputLogic {
|
||||||
public void finishInput() {
|
public void finishInput() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* React to a string input.
|
||||||
|
*
|
||||||
|
* This is triggered by keys that input many characters at once, like the ".com" key or
|
||||||
|
* some additional keys for example.
|
||||||
|
*
|
||||||
|
* @param settingsValues the current values of the settings.
|
||||||
|
* @param rawText the text to input.
|
||||||
|
*/
|
||||||
|
public void onTextInput(final SettingsValues settingsValues, final String rawText,
|
||||||
|
// TODO: remove these arguments
|
||||||
|
final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) {
|
||||||
|
mConnection.beginBatchEdit();
|
||||||
|
if (mWordComposer.isComposingWord()) {
|
||||||
|
commitCurrentAutoCorrection(settingsValues, rawText, handler);
|
||||||
|
} else {
|
||||||
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
||||||
|
}
|
||||||
|
handler.postUpdateSuggestionStrip();
|
||||||
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS
|
||||||
|
&& ResearchLogger.RESEARCH_KEY_OUTPUT_TEXT.equals(rawText)) {
|
||||||
|
ResearchLogger.getInstance().onResearchKeySelected(mLatinIME);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final String text = performSpecificTldProcessingOnTextInput(rawText);
|
||||||
|
if (SpaceState.PHANTOM == mSpaceState) {
|
||||||
|
promotePhantomSpace(settingsValues);
|
||||||
|
}
|
||||||
|
mConnection.commitText(text, 1);
|
||||||
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
||||||
|
ResearchLogger.latinIME_onTextInput(text, false /* isBatchMode */);
|
||||||
|
}
|
||||||
|
mConnection.endBatchEdit();
|
||||||
|
// Space state must be updated before calling updateShiftState
|
||||||
|
mSpaceState = SpaceState.NONE;
|
||||||
|
keyboardSwitcher.updateShiftState();
|
||||||
|
keyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT);
|
||||||
|
mEnteredText = text;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* React to a code input. It may be a code point to insert, or a symbolic value that influences
|
* React to a code input. It may be a code point to insert, or a symbolic value that influences
|
||||||
* the keyboard behavior.
|
* the keyboard behavior.
|
||||||
|
@ -1069,6 +1109,38 @@ public final class InputLogic {
|
||||||
mConnection.performEditorAction(actionId);
|
mConnection.performEditorAction(actionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform the processing specific to inputting TLDs.
|
||||||
|
*
|
||||||
|
* Some keys input a TLD (specifically, the ".com" key) and this warrants some specific
|
||||||
|
* processing. First, if this is a TLD, we ignore PHANTOM spaces -- this is done by type
|
||||||
|
* of character in onCodeInput, but since this gets inputted as a whole string we need to
|
||||||
|
* do it here specifically. Then, if the last character before the cursor is a period, then
|
||||||
|
* we cut the dot at the start of ".com". This is because humans tend to type "www.google."
|
||||||
|
* and then press the ".com" key and instinctively don't expect to get "www.google..com".
|
||||||
|
*
|
||||||
|
* @param text the raw text supplied to onTextInput
|
||||||
|
* @return the text to actually send to the editor
|
||||||
|
*/
|
||||||
|
private String performSpecificTldProcessingOnTextInput(final String text) {
|
||||||
|
if (text.length() <= 1 || text.charAt(0) != Constants.CODE_PERIOD
|
||||||
|
|| !Character.isLetter(text.charAt(1))) {
|
||||||
|
// Not a tld: do nothing.
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
// We have a TLD (or something that looks like this): make sure we don't add
|
||||||
|
// a space even if currently in phantom mode.
|
||||||
|
mSpaceState = SpaceState.NONE;
|
||||||
|
// TODO: use getCodePointBeforeCursor instead to improve performance and simplify the code
|
||||||
|
final CharSequence lastOne = mConnection.getTextBeforeCursor(1, 0);
|
||||||
|
if (lastOne != null && lastOne.length() == 1
|
||||||
|
&& lastOne.charAt(0) == Constants.CODE_PERIOD) {
|
||||||
|
return text.substring(1);
|
||||||
|
} else {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a press on the settings key.
|
* Handle a press on the settings key.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue