[IL4] Move handleNonSpecialCharacter to InputLogic.

Bug: 8636060
Change-Id: I9c6869c85db49d7f87e95a421389eaf47ae3ab2e
main
Jean Chalard 2013-12-19 16:37:07 +09:00
parent 0e82fa273d
commit 37d3f1bd02
2 changed files with 69 additions and 71 deletions

View File

@ -636,7 +636,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mDisplayOrientation = conf.orientation; mDisplayOrientation = conf.orientation;
mHandler.startOrientationChanging(); mHandler.startOrientationChanging();
mInputLogic.mConnection.beginBatchEdit(); mInputLogic.mConnection.beginBatchEdit();
commitTyped(LastComposedWord.NOT_A_SEPARATOR); mInputLogic.commitTyped(LastComposedWord.NOT_A_SEPARATOR);
mInputLogic.mConnection.finishComposingText(); mInputLogic.mConnection.finishComposingText();
mInputLogic.mConnection.endBatchEdit(); mInputLogic.mConnection.endBatchEdit();
if (isShowingOptionDialog()) { if (isShowingOptionDialog()) {
@ -1267,19 +1267,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE); mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE);
} }
private void commitTyped(final String separatorString) {
if (!mInputLogic.mWordComposer.isComposingWord()) return;
final String typedWord = mInputLogic.mWordComposer.getTypedWord();
if (typedWord.length() > 0) {
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.getInstance().onWordFinished(typedWord,
mInputLogic.mWordComposer.isBatchMode());
}
commitChosenWord(typedWord, LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD,
separatorString);
}
}
// Called from the KeyboardSwitcher which needs to know auto caps state to display // Called from the KeyboardSwitcher which needs to know auto caps state to display
// the right layout. // the right layout.
public int getCurrentAutoCapsState() { public int getCurrentAutoCapsState() {
@ -1442,49 +1429,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mInputLogic.onCodeInput(primaryCode, x, y, mHandler, mKeyboardSwitcher, mSubtypeSwitcher); mInputLogic.onCodeInput(primaryCode, x, y, mHandler, mKeyboardSwitcher, mSubtypeSwitcher);
} }
// TODO[IL]: Move this to InputLogic and make it private again.
public boolean handleNonSpecialCharacter(final int primaryCode, final int x, final int y,
final int spaceState) {
mInputLogic.mSpaceState = SpaceState.NONE;
final boolean didAutoCorrect;
final SettingsValues settingsValues = mSettings.getCurrent();
if (settingsValues.isWordSeparator(primaryCode)
|| Character.getType(primaryCode) == Character.OTHER_SYMBOL) {
didAutoCorrect = handleSeparator(primaryCode, x, y, spaceState);
} else {
didAutoCorrect = false;
if (SpaceState.PHANTOM == spaceState) {
if (settingsValues.mIsInternal) {
if (mInputLogic.mWordComposer.isComposingWord()
&& mInputLogic.mWordComposer.isBatchMode()) {
LatinImeLoggerUtils.onAutoCorrection("",
mInputLogic.mWordComposer.getTypedWord(), " ",
mInputLogic.mWordComposer);
}
}
if (mInputLogic.mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
// If we are in the middle of a recorrection, we need to commit the recorrection
// first so that we can insert the character at the current cursor position.
mInputLogic.resetEntireInputState(settingsValues,
mInputLogic.mLastSelectionStart, mInputLogic.mLastSelectionEnd);
} else {
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
}
}
final int keyX, keyY;
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
if (keyboard != null && keyboard.hasProximityCharsCorrection(primaryCode)) {
keyX = x;
keyY = y;
} else {
keyX = Constants.NOT_A_COORDINATE;
keyY = Constants.NOT_A_COORDINATE;
}
handleCharacter(primaryCode, keyX, keyY, spaceState);
}
return didAutoCorrect;
}
// Called from PointerTracker through the KeyboardActionListener interface // Called from PointerTracker through the KeyboardActionListener interface
@Override @Override
public void onTextInput(final String rawText) { public void onTextInput(final String rawText) {
@ -1547,7 +1491,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// word, the user would probably have gestured instead. // word, the user would probably have gestured instead.
commitCurrentAutoCorrection(LastComposedWord.NOT_A_SEPARATOR); commitCurrentAutoCorrection(LastComposedWord.NOT_A_SEPARATOR);
} else { } else {
commitTyped(LastComposedWord.NOT_A_SEPARATOR); mInputLogic.commitTyped(LastComposedWord.NOT_A_SEPARATOR);
} }
} }
final int codePointBeforeCursor = mInputLogic.mConnection.getCodePointBeforeCursor(); final int codePointBeforeCursor = mInputLogic.mConnection.getCodePointBeforeCursor();
@ -1850,7 +1794,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return false; return false;
} }
private void handleCharacter(final int primaryCode, final int x, final int y, // TODO[IL]: Move to InputLogic and make private again.
public void handleCharacter(final int primaryCode, final int x, final int y,
final int spaceState) { final int spaceState) {
// TODO: refactor this method to stop flipping isComposingWord around all the time, and // TODO: refactor this method to stop flipping isComposingWord around all the time, and
// make it shorter (possibly cut into several pieces). Also factor handleNonSpecialCharacter // make it shorter (possibly cut into several pieces). Also factor handleNonSpecialCharacter
@ -1985,7 +1930,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
// Returns true if we do an autocorrection, false otherwise. // Returns true if we do an autocorrection, false otherwise.
private boolean handleSeparator(final int primaryCode, final int x, final int y, // TODO[IL]: Move to InputLogic and make private again
public boolean handleSeparator(final int primaryCode, final int x, final int y,
final int spaceState) { final int spaceState) {
boolean didAutoCorrect = false; boolean didAutoCorrect = false;
final SettingsValues currentSettings = mSettings.getCurrent(); final SettingsValues currentSettings = mSettings.getCurrent();
@ -2007,7 +1953,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
commitCurrentAutoCorrection(separator); commitCurrentAutoCorrection(separator);
didAutoCorrect = true; didAutoCorrect = true;
} else { } else {
commitTyped(StringUtils.newSingleCodePointString(primaryCode)); mInputLogic.commitTyped(StringUtils.newSingleCodePointString(primaryCode));
} }
} }
@ -2071,7 +2017,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void handleClose() { private void handleClose() {
// TODO: Verify that words are logged properly when IME is closed. // TODO: Verify that words are logged properly when IME is closed.
commitTyped(LastComposedWord.NOT_A_SEPARATOR); mInputLogic.commitTyped(LastComposedWord.NOT_A_SEPARATOR);
requestHideSelf(0); requestHideSelf(0);
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
if (mainKeyboardView != null) { if (mainKeyboardView != null) {
@ -2450,7 +2396,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
/** /**
* Commits the chosen word to the text field and saves it for later retrieval. * Commits the chosen word to the text field and saves it for later retrieval.
*/ */
private void commitChosenWord(final String chosenWord, final int commitType, // TODO[IL]: Move to InputLogic and make public again
public void commitChosenWord(final String chosenWord, final int commitType,
final String separatorString) { final String separatorString) {
final SuggestedWords suggestedWords = mInputLogic.mSuggestedWords; final SuggestedWords suggestedWords = mInputLogic.mSuggestedWords;
mInputLogic.mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan( mInputLogic.mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
@ -2887,7 +2834,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void launchKeyboardedDialogActivity(final Class<? extends Activity> activityClass) { public void launchKeyboardedDialogActivity(final Class<? extends Activity> activityClass) {
// Put the text in the attached EditText into a safe, saved state before switching to a // Put the text in the attached EditText into a safe, saved state before switching to a
// new activity that will also use the soft keyboard. // new activity that will also use the soft keyboard.
commitTyped(LastComposedWord.NOT_A_SEPARATOR); mInputLogic.commitTyped(LastComposedWord.NOT_A_SEPARATOR);
launchSubActivity(activityClass); launchSubActivity(activityClass);
} }

View File

@ -194,14 +194,17 @@ public final class InputLogic {
} else { } else {
// No action label, and the action from imeOptions is NONE: this is a regular // No action label, and the action from imeOptions is NONE: this is a regular
// enter key that should input a carriage return. // enter key that should input a carriage return.
didAutoCorrect = handleNonSpecialCharacter(Constants.CODE_ENTER, x, y, spaceState); didAutoCorrect = handleNonSpecialCharacter(settingsValues,
Constants.CODE_ENTER, x, y, spaceState, keyboardSwitcher);
} }
break; break;
case Constants.CODE_SHIFT_ENTER: case Constants.CODE_SHIFT_ENTER:
didAutoCorrect = handleNonSpecialCharacter(Constants.CODE_ENTER, x, y, spaceState); didAutoCorrect = handleNonSpecialCharacter(settingsValues,
Constants.CODE_ENTER, x, y, spaceState, keyboardSwitcher);
break; break;
default: default:
didAutoCorrect = handleNonSpecialCharacter(primaryCode, x, y, spaceState); didAutoCorrect = handleNonSpecialCharacter(settingsValues,
primaryCode, x, y, spaceState, keyboardSwitcher);
break; break;
} }
switcher.onCodeInput(primaryCode); switcher.onCodeInput(primaryCode);
@ -224,15 +227,50 @@ public final class InputLogic {
* manage keyboard-related stuff like shift, language switch, settings, layout switch, or * manage keyboard-related stuff like shift, language switch, settings, layout switch, or
* any key that results in multiple code points like the ".com" key. * any key that results in multiple code points like the ".com" key.
* *
* @param code the code point associated with the key. * @param codePoint the code point associated with the key.
* @param x the x-coordinate of the key press, or Contants.NOT_A_COORDINATE if not applicable. * @param x the x-coordinate of the key press, or Contants.NOT_A_COORDINATE if not applicable.
* @param y the y-coordinate of the key press, or Contants.NOT_A_COORDINATE if not applicable. * @param y the y-coordinate of the key press, or Contants.NOT_A_COORDINATE if not applicable.
* @param spaceState the space state at start of the batch input. * @param spaceState the space state at start of the batch input.
* @return whether this caused an auto-correction to happen. * @return whether this caused an auto-correction to happen.
*/ */
private boolean handleNonSpecialCharacter(final int code, final int x, final int y, private boolean handleNonSpecialCharacter(final SettingsValues settingsValues,
final int spaceState) { final int codePoint, final int x, final int y, final int spaceState,
return mLatinIME.handleNonSpecialCharacter(code, x, y, spaceState); // TODO: remove this argument.
final KeyboardSwitcher keyboardSwitcher) {
mSpaceState = SpaceState.NONE;
final boolean didAutoCorrect;
if (settingsValues.isWordSeparator(codePoint)
|| Character.getType(codePoint) == Character.OTHER_SYMBOL) {
didAutoCorrect = mLatinIME.handleSeparator(codePoint, x, y, spaceState);
} else {
didAutoCorrect = false;
if (SpaceState.PHANTOM == spaceState) {
if (settingsValues.mIsInternal) {
if (mWordComposer.isComposingWord() && mWordComposer.isBatchMode()) {
LatinImeLoggerUtils.onAutoCorrection("", mWordComposer.getTypedWord(), " ",
mWordComposer);
}
}
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
// If we are in the middle of a recorrection, we need to commit the recorrection
// first so that we can insert the character at the current cursor position.
resetEntireInputState(settingsValues, mLastSelectionStart, mLastSelectionEnd);
} else {
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
}
}
final int keyX, keyY;
final Keyboard keyboard = keyboardSwitcher.getKeyboard();
if (keyboard != null && keyboard.hasProximityCharsCorrection(codePoint)) {
keyX = x;
keyY = y;
} else {
keyX = Constants.NOT_A_COORDINATE;
keyY = Constants.NOT_A_COORDINATE;
}
mLatinIME.handleCharacter(codePoint, keyX, keyY, spaceState);
}
return didAutoCorrect;
} }
/** /**
@ -483,4 +521,17 @@ public final class InputLogic {
mConnection.commitText(StringUtils.newSingleCodePointString(code), 1); mConnection.commitText(StringUtils.newSingleCodePointString(code), 1);
} }
} }
// TODO: Make this private
public void commitTyped(final String separatorString) {
if (!mWordComposer.isComposingWord()) return;
final String typedWord = mWordComposer.getTypedWord();
if (typedWord.length() > 0) {
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.getInstance().onWordFinished(typedWord, mWordComposer.isBatchMode());
}
mLatinIME.commitChosenWord(typedWord, LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD,
separatorString);
}
}
} }