[HW14] Cleanup
Do away with the didAutoCorrect local variables which are unnatural to return out of all these functions. Change-Id: I22024004d2c489de018beff812c2c589bfd8ca32main
parent
a88e95e07e
commit
dd31a2dedf
|
@ -42,6 +42,7 @@ public class InputTransaction {
|
||||||
private int mRequiredShiftUpdate = SHIFT_NO_UPDATE;
|
private int mRequiredShiftUpdate = SHIFT_NO_UPDATE;
|
||||||
private boolean mRequiresUpdateSuggestions = false;
|
private boolean mRequiresUpdateSuggestions = false;
|
||||||
private boolean mDidAffectContents = false;
|
private boolean mDidAffectContents = false;
|
||||||
|
private boolean mDidAutoCorrect = false;
|
||||||
|
|
||||||
public InputTransaction(final SettingsValues settingsValues, final Event event,
|
public InputTransaction(final SettingsValues settingsValues, final Event event,
|
||||||
final long timestamp, final int spaceState, final int shiftState) {
|
final long timestamp, final int spaceState, final int shiftState) {
|
||||||
|
@ -97,4 +98,19 @@ public class InputTransaction {
|
||||||
public boolean didAffectContents() {
|
public boolean didAffectContents() {
|
||||||
return mDidAffectContents;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,7 +248,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
break;
|
break;
|
||||||
case MSG_RESET_CACHES:
|
case MSG_RESET_CACHES:
|
||||||
final SettingsValues settingsValues = latinIme.mSettings.getCurrent();
|
final SettingsValues settingsValues = latinIme.mSettings.getCurrent();
|
||||||
if (latinIme.mInputLogic.retryResetCachesAndReturnSuccess(settingsValues,
|
if (latinIme.mInputLogic.retryResetCachesAndReturnSuccess(
|
||||||
msg.arg1 == 1 /* tryResumeSuggestions */,
|
msg.arg1 == 1 /* tryResumeSuggestions */,
|
||||||
msg.arg2 /* remainingTries */, this /* handler */)) {
|
msg.arg2 /* remainingTries */, this /* handler */)) {
|
||||||
// If we were able to reset the caches, then we can reload the keyboard.
|
// If we were able to reset the caches, then we can reload the keyboard.
|
||||||
|
|
|
@ -426,18 +426,14 @@ public final class InputLogic {
|
||||||
cancelDoubleSpacePeriodCountdown();
|
cancelDoubleSpacePeriodCountdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean didAutoCorrect;
|
|
||||||
if (processedEvent.isConsumed()) {
|
if (processedEvent.isConsumed()) {
|
||||||
handleConsumedEvent(inputTransaction);
|
handleConsumedEvent(inputTransaction);
|
||||||
didAutoCorrect = false;
|
|
||||||
} else if (processedEvent.isFunctionalKeyEvent()) {
|
} else if (processedEvent.isFunctionalKeyEvent()) {
|
||||||
didAutoCorrect = handleFunctionalEventAndReturnIfDidAutoCorrect(inputTransaction,
|
handleFunctionalEvent(inputTransaction, currentKeyboardScriptId, handler);
|
||||||
currentKeyboardScriptId, handler);
|
|
||||||
} else {
|
} else {
|
||||||
didAutoCorrect = handleNonFunctionalEventAndReturnIfDidAutoCorrect(inputTransaction,
|
handleNonFunctionalEvent(inputTransaction, handler);
|
||||||
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_CAPSLOCK
|
||||||
&& processedEvent.mKeyCode != Constants.CODE_SWITCH_ALPHA_SYMBOL)
|
&& processedEvent.mKeyCode != Constants.CODE_SWITCH_ALPHA_SYMBOL)
|
||||||
mLastComposedWord.deactivate();
|
mLastComposedWord.deactivate();
|
||||||
|
@ -616,14 +612,11 @@ public final class InputLogic {
|
||||||
* 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 inputTransaction The transaction in progress.
|
* @param inputTransaction The transaction in progress.
|
||||||
* @return whether this caused an auto-correction to happen.
|
|
||||||
*/
|
*/
|
||||||
private boolean handleFunctionalEventAndReturnIfDidAutoCorrect(
|
private void handleFunctionalEvent(final InputTransaction inputTransaction,
|
||||||
final InputTransaction inputTransaction,
|
|
||||||
// TODO: remove these arguments
|
// TODO: remove these arguments
|
||||||
final int currentKeyboardScriptId, final LatinIME.UIHandler handler) {
|
final int currentKeyboardScriptId, final LatinIME.UIHandler handler) {
|
||||||
final Event event = inputTransaction.mEvent;
|
final Event event = inputTransaction.mEvent;
|
||||||
boolean didAutoCorrect = false;
|
|
||||||
switch (event.mKeyCode) {
|
switch (event.mKeyCode) {
|
||||||
case Constants.CODE_DELETE:
|
case Constants.CODE_DELETE:
|
||||||
handleBackspace(inputTransaction, currentKeyboardScriptId);
|
handleBackspace(inputTransaction, currentKeyboardScriptId);
|
||||||
|
@ -681,7 +674,7 @@ public final class InputLogic {
|
||||||
inputTransaction.mSettingsValues, tmpEvent,
|
inputTransaction.mSettingsValues, tmpEvent,
|
||||||
inputTransaction.mTimestamp, inputTransaction.mSpaceState,
|
inputTransaction.mTimestamp, inputTransaction.mSpaceState,
|
||||||
inputTransaction.mShiftState);
|
inputTransaction.mShiftState);
|
||||||
didAutoCorrect = handleNonSpecialCharacter(tmpTransaction, handler);
|
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();
|
||||||
|
@ -689,7 +682,6 @@ public final class InputLogic {
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unknown key code : " + event.mKeyCode);
|
throw new RuntimeException("Unknown key code : " + event.mKeyCode);
|
||||||
}
|
}
|
||||||
return didAutoCorrect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -699,15 +691,12 @@ public final class InputLogic {
|
||||||
* things like trigger an editor action.
|
* things like trigger an editor action.
|
||||||
*
|
*
|
||||||
* @param inputTransaction The transaction in progress.
|
* @param inputTransaction The transaction in progress.
|
||||||
* @return whether this caused an auto-correction to happen.
|
|
||||||
*/
|
*/
|
||||||
private boolean handleNonFunctionalEventAndReturnIfDidAutoCorrect(
|
private void handleNonFunctionalEvent(final InputTransaction inputTransaction,
|
||||||
final InputTransaction inputTransaction,
|
|
||||||
// TODO: remove this argument
|
// TODO: remove this argument
|
||||||
final LatinIME.UIHandler handler) {
|
final LatinIME.UIHandler handler) {
|
||||||
final Event event = inputTransaction.mEvent;
|
final Event event = inputTransaction.mEvent;
|
||||||
inputTransaction.setDidAffectContents();
|
inputTransaction.setDidAffectContents();
|
||||||
boolean didAutoCorrect = false;
|
|
||||||
switch (event.mCodePoint) {
|
switch (event.mCodePoint) {
|
||||||
case Constants.CODE_ENTER:
|
case Constants.CODE_ENTER:
|
||||||
final EditorInfo editorInfo = getCurrentInputEditorInfo();
|
final EditorInfo editorInfo = getCurrentInputEditorInfo();
|
||||||
|
@ -729,14 +718,13 @@ 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);
|
handleNonSpecialCharacter(inputTransaction, handler);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
didAutoCorrect = handleNonSpecialCharacter(inputTransaction, handler);
|
handleNonSpecialCharacter(inputTransaction, handler);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return didAutoCorrect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -748,20 +736,16 @@ public final class InputLogic {
|
||||||
* 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 inputTransaction The transaction in progress.
|
* @param inputTransaction The transaction in progress.
|
||||||
* @return whether this caused an auto-correction to happen.
|
|
||||||
*/
|
*/
|
||||||
private boolean handleNonSpecialCharacter(final InputTransaction inputTransaction,
|
private void handleNonSpecialCharacter(final InputTransaction inputTransaction,
|
||||||
// TODO: remove this argument
|
// TODO: remove this argument
|
||||||
final LatinIME.UIHandler handler) {
|
final LatinIME.UIHandler handler) {
|
||||||
final int codePoint = inputTransaction.mEvent.mCodePoint;
|
final int codePoint = inputTransaction.mEvent.mCodePoint;
|
||||||
mSpaceState = SpaceState.NONE;
|
mSpaceState = SpaceState.NONE;
|
||||||
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,
|
handleSeparator(inputTransaction, handler);
|
||||||
inputTransaction.mEvent.isSuggestionStripPress(), handler);
|
|
||||||
} else {
|
} else {
|
||||||
didAutoCorrect = false;
|
|
||||||
if (SpaceState.PHANTOM == inputTransaction.mSpaceState) {
|
if (SpaceState.PHANTOM == inputTransaction.mSpaceState) {
|
||||||
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
|
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
|
||||||
// If we are in the middle of a recorrection, we need to commit the recorrection
|
// If we are in the middle of a recorrection, we need to commit the recorrection
|
||||||
|
@ -774,7 +758,6 @@ public final class InputLogic {
|
||||||
}
|
}
|
||||||
handleNonSeparator(inputTransaction.mSettingsValues, inputTransaction);
|
handleNonSeparator(inputTransaction.mSettingsValues, inputTransaction);
|
||||||
}
|
}
|
||||||
return didAutoCorrect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -859,16 +842,12 @@ public final class InputLogic {
|
||||||
/**
|
/**
|
||||||
* Handle input of a separator code point.
|
* Handle input of a separator code point.
|
||||||
* @param inputTransaction The transaction in progress.
|
* @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,
|
private void handleSeparator(final InputTransaction inputTransaction,
|
||||||
final boolean isFromSuggestionStrip,
|
|
||||||
// TODO: remove this argument
|
// TODO: remove this argument
|
||||||
final LatinIME.UIHandler handler) {
|
final LatinIME.UIHandler handler) {
|
||||||
final int codePoint = inputTransaction.mEvent.mCodePoint;
|
final int codePoint = inputTransaction.mEvent.mCodePoint;
|
||||||
final SettingsValues settingsValues = inputTransaction.mSettingsValues;
|
final SettingsValues settingsValues = inputTransaction.mSettingsValues;
|
||||||
boolean didAutoCorrect = false;
|
|
||||||
final boolean wasComposingWord = mWordComposer.isComposingWord();
|
final boolean wasComposingWord = mWordComposer.isComposingWord();
|
||||||
// We avoid sending spaces in languages without spaces if we were composing.
|
// We avoid sending spaces in languages without spaces if we were composing.
|
||||||
final boolean shouldAvoidSendingCode = Constants.CODE_SPACE == codePoint
|
final boolean shouldAvoidSendingCode = Constants.CODE_SPACE == codePoint
|
||||||
|
@ -886,7 +865,7 @@ public final class InputLogic {
|
||||||
final String separator = shouldAvoidSendingCode ? LastComposedWord.NOT_A_SEPARATOR
|
final String separator = shouldAvoidSendingCode ? LastComposedWord.NOT_A_SEPARATOR
|
||||||
: StringUtils.newSingleCodePointString(codePoint);
|
: StringUtils.newSingleCodePointString(codePoint);
|
||||||
commitCurrentAutoCorrection(settingsValues, separator, handler);
|
commitCurrentAutoCorrection(settingsValues, separator, handler);
|
||||||
didAutoCorrect = true;
|
inputTransaction.setDidAutoCorrect();
|
||||||
} else {
|
} else {
|
||||||
commitTyped(settingsValues,
|
commitTyped(settingsValues,
|
||||||
StringUtils.newSingleCodePointString(codePoint));
|
StringUtils.newSingleCodePointString(codePoint));
|
||||||
|
@ -964,7 +943,6 @@ public final class InputLogic {
|
||||||
}
|
}
|
||||||
|
|
||||||
inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
|
inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
|
||||||
return didAutoCorrect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2028,14 +2006,13 @@ public final class InputLogic {
|
||||||
* This method handles the retry, and re-schedules a new retry if we still can't access.
|
* 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.
|
* 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 tryResumeSuggestions Whether we should resume suggestions or not.
|
||||||
* @param remainingTries How many times we may try again before giving up.
|
* @param remainingTries How many times we may try again before giving up.
|
||||||
* @return whether true if the caches were successfully reset, false otherwise.
|
* @return whether true if the caches were successfully reset, false otherwise.
|
||||||
*/
|
*/
|
||||||
// TODO: make this private
|
// TODO: make this private
|
||||||
public boolean retryResetCachesAndReturnSuccess(final SettingsValues settingsValues,
|
public boolean retryResetCachesAndReturnSuccess(final boolean tryResumeSuggestions,
|
||||||
final boolean tryResumeSuggestions, final int remainingTries,
|
final int remainingTries,
|
||||||
// TODO: remove these arguments
|
// TODO: remove these arguments
|
||||||
final LatinIME.UIHandler handler) {
|
final LatinIME.UIHandler handler) {
|
||||||
final boolean shouldFinishComposition = mConnection.hasSelection()
|
final boolean shouldFinishComposition = mConnection.hasSelection()
|
||||||
|
|
Loading…
Reference in New Issue