[IL127] Move the double space countdown to InputLogic
Bug: 8636060 Change-Id: Ie193b747bd9d0b5ba6a986b9a3c746c2182742edmain
parent
554346e94c
commit
350d73932d
|
@ -169,7 +169,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
private int mDelayUpdateSuggestions;
|
private int mDelayUpdateSuggestions;
|
||||||
private int mDelayUpdateShiftState;
|
private int mDelayUpdateShiftState;
|
||||||
private long mDoubleSpacePeriodTimerStart;
|
|
||||||
|
|
||||||
public UIHandler(final LatinIME ownerInstance) {
|
public UIHandler(final LatinIME ownerInstance) {
|
||||||
super(ownerInstance);
|
super(ownerInstance);
|
||||||
|
@ -283,10 +282,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE), mDelayUpdateShiftState);
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE), mDelayUpdateShiftState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelUpdateShiftState() {
|
|
||||||
removeMessages(MSG_UPDATE_SHIFT_STATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
public void removeAllMessages() {
|
public void removeAllMessages() {
|
||||||
for (int i = 0; i <= MSG_LAST; ++i) {
|
for (int i = 0; i <= MSG_LAST; ++i) {
|
||||||
|
@ -314,19 +309,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
obtainMessage(MSG_ON_END_BATCH_INPUT, suggestedWords).sendToTarget();
|
obtainMessage(MSG_ON_END_BATCH_INPUT, suggestedWords).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDoubleSpacePeriodTimer() {
|
|
||||||
mDoubleSpacePeriodTimerStart = SystemClock.uptimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancelDoubleSpacePeriodTimer() {
|
|
||||||
mDoubleSpacePeriodTimerStart = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAcceptingDoubleSpacePeriod() {
|
|
||||||
return SystemClock.uptimeMillis() - mDoubleSpacePeriodTimerStart
|
|
||||||
< getOwnerInstance().mSettings.getCurrent().mDoubleSpacePeriodTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Working variables for the following methods.
|
// Working variables for the following methods.
|
||||||
private boolean mIsOrientationChanging;
|
private boolean mIsOrientationChanging;
|
||||||
private boolean mPendingSuccessiveImsCallback;
|
private boolean mPendingSuccessiveImsCallback;
|
||||||
|
@ -882,7 +864,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
setNeutralSuggestionStrip();
|
setNeutralSuggestionStrip();
|
||||||
|
|
||||||
mHandler.cancelUpdateSuggestionStrip();
|
mHandler.cancelUpdateSuggestionStrip();
|
||||||
mHandler.cancelDoubleSpacePeriodTimer();
|
|
||||||
|
|
||||||
mainKeyboardView.setMainDictionaryAvailability(null != suggest
|
mainKeyboardView.setMainDictionaryAvailability(null != suggest
|
||||||
? suggest.mDictionaryFacilitator.hasMainDictionary() : false);
|
? suggest.mDictionaryFacilitator.hasMainDictionary() : false);
|
||||||
|
|
|
@ -96,6 +96,7 @@ public final class InputLogic {
|
||||||
// TODO: This boolean is persistent state and causes large side effects at unexpected times.
|
// TODO: This boolean is persistent state and causes large side effects at unexpected times.
|
||||||
// Find a way to remove it for readability.
|
// Find a way to remove it for readability.
|
||||||
private boolean mIsAutoCorrectionIndicatorOn;
|
private boolean mIsAutoCorrectionIndicatorOn;
|
||||||
|
private long mDoubleSpacePeriodCountdownStart;
|
||||||
|
|
||||||
public InputLogic(final LatinIME latinIME,
|
public InputLogic(final LatinIME latinIME,
|
||||||
final SuggestionStripViewAccessor suggestionStripViewAccessor) {
|
final SuggestionStripViewAccessor suggestionStripViewAccessor) {
|
||||||
|
@ -138,6 +139,7 @@ public final class InputLogic {
|
||||||
// In some cases (namely, after rotation of the device) editorInfo.initialSelStart is lying
|
// In some cases (namely, after rotation of the device) editorInfo.initialSelStart is lying
|
||||||
// so we try using some heuristics to find out about these and fix them.
|
// so we try using some heuristics to find out about these and fix them.
|
||||||
mConnection.tryFixLyingCursorPosition();
|
mConnection.tryFixLyingCursorPosition();
|
||||||
|
cancelDoubleSpacePeriodCountdown();
|
||||||
mInputLogicHandler = new InputLogicHandler(mLatinIME, this);
|
mInputLogicHandler = new InputLogicHandler(mLatinIME, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +408,7 @@ 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 (event.mCodePoint != Constants.CODE_SPACE) {
|
||||||
handler.cancelDoubleSpacePeriodTimer();
|
cancelDoubleSpacePeriodCountdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean didAutoCorrect = false;
|
boolean didAutoCorrect = false;
|
||||||
|
@ -847,7 +849,7 @@ public final class InputLogic {
|
||||||
|
|
||||||
if (Constants.CODE_SPACE == codePoint) {
|
if (Constants.CODE_SPACE == codePoint) {
|
||||||
if (inputTransaction.mSettingsValues.isSuggestionsRequested()) {
|
if (inputTransaction.mSettingsValues.isSuggestionsRequested()) {
|
||||||
if (maybeDoubleSpacePeriod(inputTransaction.mSettingsValues, handler)) {
|
if (maybeDoubleSpacePeriod(inputTransaction)) {
|
||||||
inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
|
inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
|
||||||
mSpaceState = SpaceState.DOUBLE;
|
mSpaceState = SpaceState.DOUBLE;
|
||||||
} else if (!mSuggestedWords.isPunctuationSuggestions()) {
|
} else if (!mSuggestedWords.isPunctuationSuggestions()) {
|
||||||
|
@ -855,7 +857,7 @@ public final class InputLogic {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.startDoubleSpacePeriodTimer();
|
startDoubleSpacePeriodCountdown(inputTransaction);
|
||||||
handler.postUpdateSuggestionStrip();
|
handler.postUpdateSuggestionStrip();
|
||||||
} else {
|
} else {
|
||||||
if (swapWeakSpace) {
|
if (swapWeakSpace) {
|
||||||
|
@ -952,7 +954,7 @@ public final class InputLogic {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (SpaceState.DOUBLE == inputTransaction.mSpaceState) {
|
if (SpaceState.DOUBLE == inputTransaction.mSpaceState) {
|
||||||
handler.cancelDoubleSpacePeriodTimer();
|
cancelDoubleSpacePeriodCountdown();
|
||||||
if (mConnection.revertDoubleSpacePeriod()) {
|
if (mConnection.revertDoubleSpacePeriod()) {
|
||||||
// No need to reset mSpaceState, it has already be done (that's why we
|
// No need to reset mSpaceState, it has already be done (that's why we
|
||||||
// receive it as a parameter)
|
// receive it as a parameter)
|
||||||
|
@ -1100,6 +1102,19 @@ public final class InputLogic {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startDoubleSpacePeriodCountdown(final InputTransaction inputTransaction) {
|
||||||
|
mDoubleSpacePeriodCountdownStart = inputTransaction.mTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelDoubleSpacePeriodCountdown() {
|
||||||
|
mDoubleSpacePeriodCountdownStart = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDoubleSpacePeriodCountdownActive(final InputTransaction inputTransaction) {
|
||||||
|
return inputTransaction.mTimestamp - mDoubleSpacePeriodCountdownStart
|
||||||
|
< inputTransaction.mSettingsValues.mDoubleSpacePeriodTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the double-space-to-period transformation if applicable.
|
* Apply the double-space-to-period transformation if applicable.
|
||||||
*
|
*
|
||||||
|
@ -1112,14 +1127,12 @@ public final class InputLogic {
|
||||||
* method applies the transformation and returns true. Otherwise, it does nothing and
|
* method applies the transformation and returns true. Otherwise, it does nothing and
|
||||||
* returns false.
|
* returns false.
|
||||||
*
|
*
|
||||||
* @param settingsValues the current values of the settings.
|
* @param inputTransaction The transaction in progress.
|
||||||
* @return true if we applied the double-space-to-period transformation, false otherwise.
|
* @return true if we applied the double-space-to-period transformation, false otherwise.
|
||||||
*/
|
*/
|
||||||
private boolean maybeDoubleSpacePeriod(final SettingsValues settingsValues,
|
private boolean maybeDoubleSpacePeriod(final InputTransaction inputTransaction) {
|
||||||
// TODO: remove this argument
|
if (!inputTransaction.mSettingsValues.mUseDoubleSpacePeriod) return false;
|
||||||
final LatinIME.UIHandler handler) {
|
if (!isDoubleSpacePeriodCountdownActive(inputTransaction)) return false;
|
||||||
if (!settingsValues.mUseDoubleSpacePeriod) return false;
|
|
||||||
if (!handler.isAcceptingDoubleSpacePeriod()) return false;
|
|
||||||
// We only do this when we see two spaces and an accepted code point before the cursor.
|
// We only do this when we see two spaces and an accepted code point before the cursor.
|
||||||
// The code point may be a surrogate pair but the two spaces may not, so we need 4 chars.
|
// The code point may be a surrogate pair but the two spaces may not, so we need 4 chars.
|
||||||
final CharSequence lastThree = mConnection.getTextBeforeCursor(4, 0);
|
final CharSequence lastThree = mConnection.getTextBeforeCursor(4, 0);
|
||||||
|
@ -1135,10 +1148,10 @@ public final class InputLogic {
|
||||||
Character.isSurrogatePair(lastThree.charAt(0), lastThree.charAt(1)) ?
|
Character.isSurrogatePair(lastThree.charAt(0), lastThree.charAt(1)) ?
|
||||||
Character.codePointAt(lastThree, 0) : lastThree.charAt(length - 3);
|
Character.codePointAt(lastThree, 0) : lastThree.charAt(length - 3);
|
||||||
if (canBeFollowedByDoubleSpacePeriod(firstCodePoint)) {
|
if (canBeFollowedByDoubleSpacePeriod(firstCodePoint)) {
|
||||||
handler.cancelDoubleSpacePeriodTimer();
|
cancelDoubleSpacePeriodCountdown();
|
||||||
mConnection.deleteSurroundingText(2, 0);
|
mConnection.deleteSurroundingText(2, 0);
|
||||||
final String textToInsert =
|
final String textToInsert = inputTransaction.mSettingsValues.mSpacingAndPunctuations
|
||||||
settingsValues.mSpacingAndPunctuations.mSentenceSeparatorAndSpace;
|
.mSentenceSeparatorAndSpace;
|
||||||
mConnection.commitText(textToInsert, 1);
|
mConnection.commitText(textToInsert, 1);
|
||||||
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
||||||
ResearchLogger.latinIME_maybeDoubleSpacePeriod(textToInsert,
|
ResearchLogger.latinIME_maybeDoubleSpacePeriod(textToInsert,
|
||||||
|
|
Loading…
Reference in New Issue