am da5ccd9f: [HW11] Cleanup

* commit 'da5ccd9f18a697e6f4ff218c8374fd491e934cd9':
  [HW11] Cleanup
This commit is contained in:
Jean Chalard 2014-08-01 13:51:05 +00:00 committed by Android Git Automerger
commit 9557e52ef4

View file

@ -406,10 +406,10 @@ public final class InputLogic {
// TODO: remove these arguments // TODO: remove these arguments
final int currentKeyboardScriptId, final LatinIME.UIHandler handler) { final int currentKeyboardScriptId, final LatinIME.UIHandler handler) {
final Event processedEvent = mWordComposer.processEvent(event); final Event processedEvent = mWordComposer.processEvent(event);
final InputTransaction inputTransaction = new InputTransaction(settingsValues, event, final InputTransaction inputTransaction = new InputTransaction(settingsValues,
SystemClock.uptimeMillis(), mSpaceState, processedEvent, SystemClock.uptimeMillis(), mSpaceState,
getActualCapsMode(settingsValues, keyboardShiftMode)); getActualCapsMode(settingsValues, keyboardShiftMode));
if (event.mKeyCode != Constants.CODE_DELETE if (processedEvent.mKeyCode != Constants.CODE_DELETE
|| inputTransaction.mTimestamp > mLastKeyTime + Constants.LONG_PRESS_MILLISECONDS) { || inputTransaction.mTimestamp > mLastKeyTime + Constants.LONG_PRESS_MILLISECONDS) {
mDeleteCount = 0; mDeleteCount = 0;
} }
@ -420,16 +420,16 @@ public final class InputLogic {
} }
// TODO: Consolidate the double-space period timer, mLastKeyTime, and the space state. // TODO: Consolidate the double-space period timer, mLastKeyTime, and the space state.
if (event.mCodePoint != Constants.CODE_SPACE) { if (processedEvent.mCodePoint != Constants.CODE_SPACE) {
cancelDoubleSpacePeriodCountdown(); cancelDoubleSpacePeriodCountdown();
} }
boolean didAutoCorrect = false; boolean didAutoCorrect = false;
if (event.isFunctionalKeyEvent()) { if (processedEvent.isFunctionalKeyEvent()) {
// A special key, like delete, shift, emoji, or the settings key. // A special key, like delete, shift, emoji, or the settings key.
switch (event.mKeyCode) { switch (processedEvent.mKeyCode) {
case Constants.CODE_DELETE: case Constants.CODE_DELETE:
handleBackspace(inputTransaction, currentKeyboardScriptId, processedEvent); handleBackspace(inputTransaction, currentKeyboardScriptId);
// Backspace is a functional key, but it affects the contents of the editor. // Backspace is a functional key, but it affects the contents of the editor.
inputTransaction.setDidAffectContents(); inputTransaction.setDidAffectContents();
break; break;
@ -479,22 +479,23 @@ public final class InputLogic {
case Constants.CODE_SHIFT_ENTER: case Constants.CODE_SHIFT_ENTER:
// TODO: remove this object // TODO: remove this object
final Event tmpEvent = Event.createSoftwareKeypressEvent(Constants.CODE_ENTER, final Event tmpEvent = Event.createSoftwareKeypressEvent(Constants.CODE_ENTER,
event.mKeyCode, event.mX, event.mY, event.isKeyRepeat()); processedEvent.mKeyCode, processedEvent.mX, processedEvent.mY,
processedEvent.isKeyRepeat());
final InputTransaction tmpTransaction = new InputTransaction( final InputTransaction tmpTransaction = new InputTransaction(
inputTransaction.mSettingsValues, tmpEvent, inputTransaction.mSettingsValues, tmpEvent,
inputTransaction.mTimestamp, inputTransaction.mSpaceState, inputTransaction.mTimestamp, inputTransaction.mSpaceState,
inputTransaction.mShiftState); inputTransaction.mShiftState);
didAutoCorrect = handleNonSpecialCharacter(tmpTransaction, handler, processedEvent); didAutoCorrect = handleNonSpecialCharacter(tmpTransaction, handler);
// Shift + Enter is treated as a functional key but it results in adding a new // 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. // line, so that does affect the contents of the editor.
inputTransaction.setDidAffectContents(); inputTransaction.setDidAffectContents();
break; break;
default: default:
throw new RuntimeException("Unknown key code : " + event.mKeyCode); throw new RuntimeException("Unknown key code : " + processedEvent.mKeyCode);
} }
} else { } else {
inputTransaction.setDidAffectContents(); inputTransaction.setDidAffectContents();
switch (event.mCodePoint) { switch (processedEvent.mCodePoint) {
case Constants.CODE_ENTER: case Constants.CODE_ENTER:
final EditorInfo editorInfo = getCurrentInputEditorInfo(); final EditorInfo editorInfo = getCurrentInputEditorInfo();
final int imeOptionsActionId = final int imeOptionsActionId =
@ -515,21 +516,19 @@ 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(inputTransaction, handler, didAutoCorrect = handleNonSpecialCharacter(inputTransaction, handler);
processedEvent);
} }
break; break;
default: default:
didAutoCorrect = handleNonSpecialCharacter(inputTransaction, handler, didAutoCorrect = handleNonSpecialCharacter(inputTransaction, handler);
processedEvent);
break; break;
} }
} }
if (!didAutoCorrect && event.mKeyCode != Constants.CODE_SHIFT if (!didAutoCorrect && processedEvent.mKeyCode != Constants.CODE_SHIFT
&& event.mKeyCode != Constants.CODE_CAPSLOCK && processedEvent.mKeyCode != Constants.CODE_CAPSLOCK
&& event.mKeyCode != Constants.CODE_SWITCH_ALPHA_SYMBOL) && processedEvent.mKeyCode != Constants.CODE_SWITCH_ALPHA_SYMBOL)
mLastComposedWord.deactivate(); mLastComposedWord.deactivate();
if (Constants.CODE_DELETE != event.mKeyCode) { if (Constants.CODE_DELETE != processedEvent.mKeyCode) {
mEnteredText = null; mEnteredText = null;
} }
mConnection.endBatchEdit(); mConnection.endBatchEdit();
@ -683,16 +682,14 @@ public final class InputLogic {
*/ */
private boolean handleNonSpecialCharacter(final InputTransaction inputTransaction, private boolean handleNonSpecialCharacter(final InputTransaction inputTransaction,
// TODO: remove this argument // TODO: remove this argument
final LatinIME.UIHandler handler, final LatinIME.UIHandler handler) {
// TODO: remove this argument, put it inside the transaction final int codePoint = inputTransaction.mEvent.mCodePoint;
final Event processedEvent) {
final int codePoint = processedEvent.mCodePoint;
mSpaceState = SpaceState.NONE; mSpaceState = SpaceState.NONE;
final boolean didAutoCorrect; final boolean didAutoCorrect;
if (inputTransaction.mSettingsValues.isWordSeparator(codePoint) if (inputTransaction.mSettingsValues.isWordSeparator(codePoint)
|| Character.getType(codePoint) == Character.OTHER_SYMBOL) { || Character.getType(codePoint) == Character.OTHER_SYMBOL) {
didAutoCorrect = handleSeparator(inputTransaction, didAutoCorrect = handleSeparator(inputTransaction,
processedEvent.isSuggestionStripPress(), handler); inputTransaction.mEvent.isSuggestionStripPress(), handler);
} else { } else {
didAutoCorrect = false; didAutoCorrect = false;
if (SpaceState.PHANTOM == inputTransaction.mSpaceState) { if (SpaceState.PHANTOM == inputTransaction.mSpaceState) {
@ -705,7 +702,7 @@ public final class InputLogic {
commitTyped(inputTransaction.mSettingsValues, LastComposedWord.NOT_A_SEPARATOR); commitTyped(inputTransaction.mSettingsValues, LastComposedWord.NOT_A_SEPARATOR);
} }
} }
handleNonSeparator(inputTransaction.mSettingsValues, inputTransaction, processedEvent); handleNonSeparator(inputTransaction.mSettingsValues, inputTransaction);
} }
return didAutoCorrect; return didAutoCorrect;
} }
@ -716,10 +713,8 @@ public final class InputLogic {
* @param inputTransaction The transaction in progress. * @param inputTransaction The transaction in progress.
*/ */
private void handleNonSeparator(final SettingsValues settingsValues, private void handleNonSeparator(final SettingsValues settingsValues,
final InputTransaction inputTransaction, final InputTransaction inputTransaction) {
// TODO: remove this arg, put it into the input transaction final int codePoint = inputTransaction.mEvent.mCodePoint;
final Event processedEvent) {
final int codePoint = processedEvent.mCodePoint;
// 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
// which has the same name as other handle* methods but is not the same. // which has the same name as other handle* methods but is not the same.
@ -769,7 +764,7 @@ public final class InputLogic {
resetComposingState(false /* alsoResetLastComposedWord */); resetComposingState(false /* alsoResetLastComposedWord */);
} }
if (isComposingWord) { if (isComposingWord) {
mWordComposer.applyProcessedEvent(processedEvent); mWordComposer.applyProcessedEvent(inputTransaction.mEvent);
// If it's the first letter, make note of auto-caps state // If it's the first letter, make note of auto-caps state
if (mWordComposer.isSingleLetter()) { if (mWordComposer.isSingleLetter()) {
mWordComposer.setCapitalizedModeAtStartComposingTime(inputTransaction.mShiftState); mWordComposer.setCapitalizedModeAtStartComposingTime(inputTransaction.mShiftState);
@ -778,7 +773,7 @@ public final class InputLogic {
mWordComposer.getTypedWord()), 1); mWordComposer.getTypedWord()), 1);
} else { } else {
final boolean swapWeakSpace = tryStripSpaceAndReturnWhetherShouldSwapInstead( final boolean swapWeakSpace = tryStripSpaceAndReturnWhetherShouldSwapInstead(
inputTransaction, processedEvent.isSuggestionStripPress()); inputTransaction);
if (swapWeakSpace && trySwapSwapperAndSpace(inputTransaction)) { if (swapWeakSpace && trySwapSwapperAndSpace(inputTransaction)) {
mSpaceState = SpaceState.WEAK; mSpaceState = SpaceState.WEAK;
@ -829,7 +824,7 @@ public final class InputLogic {
} }
final boolean swapWeakSpace = tryStripSpaceAndReturnWhetherShouldSwapInstead( final boolean swapWeakSpace = tryStripSpaceAndReturnWhetherShouldSwapInstead(
inputTransaction, isFromSuggestionStrip); inputTransaction);
final boolean isInsideDoubleQuoteOrAfterDigit = Constants.CODE_DOUBLE_QUOTE == codePoint final boolean isInsideDoubleQuoteOrAfterDigit = Constants.CODE_DOUBLE_QUOTE == codePoint
&& mConnection.isInsideDoubleQuoteOrAfterDigit(); && mConnection.isInsideDoubleQuoteOrAfterDigit();
@ -908,9 +903,8 @@ public final class InputLogic {
*/ */
private void handleBackspace(final InputTransaction inputTransaction, private void handleBackspace(final InputTransaction inputTransaction,
// TODO: remove this argument, put it into settingsValues // TODO: remove this argument, put it into settingsValues
final int currentKeyboardScriptId, final int currentKeyboardScriptId) {
// TODO: remove this argument, put it into the transaction final Event event = inputTransaction.mEvent;
final Event processedEvent) {
mSpaceState = SpaceState.NONE; mSpaceState = SpaceState.NONE;
mDeleteCount++; mDeleteCount++;
@ -922,7 +916,7 @@ public final class InputLogic {
// Then again, even in the case of a key repeat, if the cursor is at start of text, it // Then again, even in the case of a key repeat, if the cursor is at start of text, it
// can't go any further back, so we can update right away even if it's a key repeat. // can't go any further back, so we can update right away even if it's a key repeat.
final int shiftUpdateKind = final int shiftUpdateKind =
processedEvent.isKeyRepeat() && mConnection.getExpectedSelectionStart() > 0 event.isKeyRepeat() && mConnection.getExpectedSelectionStart() > 0
? InputTransaction.SHIFT_UPDATE_LATER : InputTransaction.SHIFT_UPDATE_NOW; ? InputTransaction.SHIFT_UPDATE_LATER : InputTransaction.SHIFT_UPDATE_NOW;
inputTransaction.requireShiftUpdate(shiftUpdateKind); inputTransaction.requireShiftUpdate(shiftUpdateKind);
@ -942,7 +936,7 @@ public final class InputLogic {
mDictionaryFacilitator.removeWordFromPersonalizedDicts(rejectedSuggestion); mDictionaryFacilitator.removeWordFromPersonalizedDicts(rejectedSuggestion);
} }
} else { } else {
mWordComposer.applyProcessedEvent(processedEvent); mWordComposer.applyProcessedEvent(event);
} }
if (mWordComposer.isComposingWord()) { if (mWordComposer.isComposingWord()) {
mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1); mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
@ -1079,12 +1073,12 @@ public final class InputLogic {
/* /*
* Strip a trailing space if necessary and returns whether it's a swap weak space situation. * Strip a trailing space if necessary and returns whether it's a swap weak space situation.
* @param inputTransaction The transaction in progress. * @param inputTransaction The transaction in progress.
* @param isFromSuggestionStrip Whether this code point is coming from the suggestion strip.
* @return whether we should swap the space instead of removing it. * @return whether we should swap the space instead of removing it.
*/ */
private boolean tryStripSpaceAndReturnWhetherShouldSwapInstead( private boolean tryStripSpaceAndReturnWhetherShouldSwapInstead(
final InputTransaction inputTransaction, final boolean isFromSuggestionStrip) { final InputTransaction inputTransaction) {
final int codePoint = inputTransaction.mEvent.mCodePoint; final int codePoint = inputTransaction.mEvent.mCodePoint;
final boolean isFromSuggestionStrip = inputTransaction.mEvent.isSuggestionStripPress();
if (Constants.CODE_ENTER == codePoint && if (Constants.CODE_ENTER == codePoint &&
SpaceState.SWAP_PUNCTUATION == inputTransaction.mSpaceState) { SpaceState.SWAP_PUNCTUATION == inputTransaction.mSpaceState) {
mConnection.removeTrailingSpace(); mConnection.removeTrailingSpace();