[IL125] Remove arg to onPickSuggestionManually
Bug: 8636060 Change-Id: I55332c22897e97148621cbd367acf5175b5b3d04
This commit is contained in:
parent
0dabae720a
commit
46e17983c6
3 changed files with 84 additions and 30 deletions
|
@ -17,6 +17,7 @@
|
||||||
package com.android.inputmethod.event;
|
package com.android.inputmethod.event;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.Constants;
|
import com.android.inputmethod.latin.Constants;
|
||||||
|
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing a generic input event as handled by Latin IME.
|
* Class representing a generic input event as handled by Latin IME.
|
||||||
|
@ -49,6 +50,8 @@ public class Event {
|
||||||
final public static int EVENT_MODE_KEY = 3;
|
final public static int EVENT_MODE_KEY = 3;
|
||||||
// An event corresponding to a gesture.
|
// An event corresponding to a gesture.
|
||||||
final public static int EVENT_GESTURE = 4;
|
final public static int EVENT_GESTURE = 4;
|
||||||
|
// An event corresponding to the manual pick of a suggestion.
|
||||||
|
final public static int EVENT_SUGGESTION_PICKED = 5;
|
||||||
|
|
||||||
// 0 is a valid code point, so we use -1 here.
|
// 0 is a valid code point, so we use -1 here.
|
||||||
final public static int NOT_A_CODE_POINT = -1;
|
final public static int NOT_A_CODE_POINT = -1;
|
||||||
|
@ -85,31 +88,50 @@ public class Event {
|
||||||
// Some flags that can't go into the key code. It's a bit field of FLAG_*
|
// Some flags that can't go into the key code. It's a bit field of FLAG_*
|
||||||
final private int mFlags;
|
final private int mFlags;
|
||||||
|
|
||||||
|
// If this is of type EVENT_SUGGESTION_PICKED, this must not be null (and must be null in
|
||||||
|
// other cases).
|
||||||
|
final public SuggestedWordInfo mSuggestedWordInfo;
|
||||||
|
|
||||||
// The next event, if any. Null if there is no next event yet.
|
// The next event, if any. Null if there is no next event yet.
|
||||||
final public Event mNextEvent;
|
final public Event mNextEvent;
|
||||||
|
|
||||||
// This method is private - to create a new event, use one of the create* utility methods.
|
// This method is private - to create a new event, use one of the create* utility methods.
|
||||||
private Event(final int type, final int codePoint, final int keyCode, final int x, final int y,
|
private Event(final int type, final int codePoint, final int keyCode, final int x, final int y,
|
||||||
final int flags, final Event next) {
|
final SuggestedWordInfo suggestedWordInfo, final int flags, final Event next) {
|
||||||
mType = type;
|
mType = type;
|
||||||
mCodePoint = codePoint;
|
mCodePoint = codePoint;
|
||||||
mKeyCode = keyCode;
|
mKeyCode = keyCode;
|
||||||
mX = x;
|
mX = x;
|
||||||
mY = y;
|
mY = y;
|
||||||
|
mSuggestedWordInfo = suggestedWordInfo;
|
||||||
mFlags = flags;
|
mFlags = flags;
|
||||||
mNextEvent = next;
|
mNextEvent = next;
|
||||||
|
// Sanity checks
|
||||||
|
// mSuggestedWordInfo is non-null if and only if the type is SUGGESTION_PICKED
|
||||||
|
if (EVENT_SUGGESTION_PICKED == mType) {
|
||||||
|
if (null == mSuggestedWordInfo) {
|
||||||
|
throw new RuntimeException("Wrong event: SUGGESTION_PICKED event must have a "
|
||||||
|
+ "non-null SuggestedWordInfo");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (null != mSuggestedWordInfo) {
|
||||||
|
throw new RuntimeException("Wrong event: only SUGGESTION_PICKED events may have " +
|
||||||
|
"a non-null SuggestedWordInfo");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Event createSoftwareKeypressEvent(final int codePoint, final int keyCode,
|
public static Event createSoftwareKeypressEvent(final int codePoint, final int keyCode,
|
||||||
final int x, final int y) {
|
final int x, final int y) {
|
||||||
return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode, x, y, FLAG_NONE, null);
|
return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode, x, y,
|
||||||
|
null /* suggestedWordInfo */, FLAG_NONE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Event createHardwareKeypressEvent(final int codePoint, final int keyCode,
|
public static Event createHardwareKeypressEvent(final int codePoint, final int keyCode,
|
||||||
final Event next) {
|
final Event next) {
|
||||||
return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode,
|
return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode,
|
||||||
Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE,
|
Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE,
|
||||||
FLAG_NONE, next);
|
null /* suggestedWordInfo */, FLAG_NONE, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This creates an input event for a dead character. @see {@link #FLAG_DEAD}
|
// This creates an input event for a dead character. @see {@link #FLAG_DEAD}
|
||||||
|
@ -117,7 +139,7 @@ public class Event {
|
||||||
// TODO: add an argument or something if we ever create a software layout with dead keys.
|
// TODO: add an argument or something if we ever create a software layout with dead keys.
|
||||||
return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode,
|
return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode,
|
||||||
Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE,
|
Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE,
|
||||||
FLAG_DEAD, next);
|
null /* suggestedWordInfo */, FLAG_DEAD, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,7 +152,8 @@ public class Event {
|
||||||
public static Event createEventForCodePointFromUnknownSource(final int codePoint) {
|
public static Event createEventForCodePointFromUnknownSource(final int codePoint) {
|
||||||
// TODO: should we have a different type of event for this? After all, it's not a key press.
|
// TODO: should we have a different type of event for this? After all, it's not a key press.
|
||||||
return new Event(EVENT_INPUT_KEYPRESS, codePoint, NOT_A_KEY_CODE,
|
return new Event(EVENT_INPUT_KEYPRESS, codePoint, NOT_A_KEY_CODE,
|
||||||
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, FLAG_NONE, null /* next */);
|
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE,
|
||||||
|
null /* suggestedWordInfo */, FLAG_NONE, null /* next */);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,13 +167,24 @@ public class Event {
|
||||||
public static Event createEventForCodePointFromAlreadyTypedText(final int codePoint,
|
public static Event createEventForCodePointFromAlreadyTypedText(final int codePoint,
|
||||||
final int x, final int y) {
|
final int x, final int y) {
|
||||||
// TODO: should we have a different type of event for this? After all, it's not a key press.
|
// TODO: should we have a different type of event for this? After all, it's not a key press.
|
||||||
return new Event(EVENT_INPUT_KEYPRESS, codePoint, NOT_A_KEY_CODE, x, y, FLAG_NONE,
|
return new Event(EVENT_INPUT_KEYPRESS, codePoint, NOT_A_KEY_CODE, x, y,
|
||||||
null /* next */);
|
null /* suggestedWordInfo */, FLAG_NONE, null /* next */);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an input event representing the manual pick of a suggestion.
|
||||||
|
* @return an event for this suggestion pick.
|
||||||
|
*/
|
||||||
|
public static Event createSuggestionPickedEvent(final SuggestedWordInfo suggestedWordInfo) {
|
||||||
|
return new Event(EVENT_SUGGESTION_PICKED, NOT_A_CODE_POINT, NOT_A_KEY_CODE,
|
||||||
|
Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE,
|
||||||
|
suggestedWordInfo, FLAG_NONE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Event createNotHandledEvent() {
|
public static Event createNotHandledEvent() {
|
||||||
return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT, NOT_A_KEY_CODE,
|
return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT, NOT_A_KEY_CODE,
|
||||||
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, FLAG_NONE, null);
|
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE,
|
||||||
|
null /* suggestedWordInfo */, FLAG_NONE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns whether this event is for a dead character. @see {@link #FLAG_DEAD}
|
// Returns whether this event is for a dead character. @see {@link #FLAG_DEAD}
|
||||||
|
|
|
@ -1276,15 +1276,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
final InputTransaction completeInputTransaction =
|
final InputTransaction completeInputTransaction =
|
||||||
mInputLogic.onCodeInput(mSettings.getCurrent(), event,
|
mInputLogic.onCodeInput(mSettings.getCurrent(), event,
|
||||||
mKeyboardSwitcher.getKeyboardShiftMode(), mHandler);
|
mKeyboardSwitcher.getKeyboardShiftMode(), mHandler);
|
||||||
switch (completeInputTransaction.getRequiredShiftUpdate()) {
|
updateShiftModeAfterInputTransaction(completeInputTransaction.getRequiredShiftUpdate());
|
||||||
case InputTransaction.SHIFT_UPDATE_LATER:
|
|
||||||
mHandler.postUpdateShiftState();
|
|
||||||
break;
|
|
||||||
case InputTransaction.SHIFT_UPDATE_NOW:
|
|
||||||
mKeyboardSwitcher.updateShiftState();
|
|
||||||
break;
|
|
||||||
default: // SHIFT_NO_UPDATE
|
|
||||||
}
|
|
||||||
mKeyboardSwitcher.onCodeInput(codePoint);
|
mKeyboardSwitcher.onCodeInput(codePoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1500,8 +1492,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
// interface
|
// interface
|
||||||
@Override
|
@Override
|
||||||
public void pickSuggestionManually(final int index, final SuggestedWordInfo suggestionInfo) {
|
public void pickSuggestionManually(final int index, final SuggestedWordInfo suggestionInfo) {
|
||||||
mInputLogic.onPickSuggestionManually(mSettings.getCurrent(), index, suggestionInfo,
|
final InputTransaction completeInputTransaction = mInputLogic.onPickSuggestionManually(
|
||||||
mHandler, mKeyboardSwitcher);
|
mSettings.getCurrent(), index, suggestionInfo,
|
||||||
|
mKeyboardSwitcher.getKeyboardShiftMode(), mHandler);
|
||||||
|
updateShiftModeAfterInputTransaction(completeInputTransaction.getRequiredShiftUpdate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1539,6 +1533,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateShiftModeAfterInputTransaction(final int requiredShiftUpdate) {
|
||||||
|
switch (requiredShiftUpdate) {
|
||||||
|
case InputTransaction.SHIFT_UPDATE_LATER:
|
||||||
|
mHandler.postUpdateShiftState();
|
||||||
|
break;
|
||||||
|
case InputTransaction.SHIFT_UPDATE_NOW:
|
||||||
|
mKeyboardSwitcher.updateShiftState();
|
||||||
|
break;
|
||||||
|
default: // SHIFT_NO_UPDATE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void hapticAndAudioFeedback(final int code, final int repeatCount) {
|
private void hapticAndAudioFeedback(final int code, final int repeatCount) {
|
||||||
final MainKeyboardView keyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
final MainKeyboardView keyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
||||||
if (keyboardView != null && keyboardView.isInDraggingFinger()) {
|
if (keyboardView != null && keyboardView.isInDraggingFinger()) {
|
||||||
|
|
|
@ -196,13 +196,16 @@ public final class InputLogic {
|
||||||
* @param settingsValues the current values of the settings.
|
* @param settingsValues the current values of the settings.
|
||||||
* @param index the index of the suggestion.
|
* @param index the index of the suggestion.
|
||||||
* @param suggestionInfo the suggestion info.
|
* @param suggestionInfo the suggestion info.
|
||||||
|
* @param keyboardShiftState the shift state of the keyboard, as returned by
|
||||||
|
* {@link com.android.inputmethod.keyboard.KeyboardSwitcher#getKeyboardShiftMode()}
|
||||||
|
* @return the complete transaction object
|
||||||
*/
|
*/
|
||||||
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
|
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
|
||||||
// interface
|
// interface
|
||||||
public void onPickSuggestionManually(final SettingsValues settingsValues,
|
public InputTransaction onPickSuggestionManually(final SettingsValues settingsValues,
|
||||||
final int index, final SuggestedWordInfo suggestionInfo,
|
final int index, final SuggestedWordInfo suggestionInfo, final int keyboardShiftState,
|
||||||
// TODO: remove these two arguments
|
// TODO: remove this argument
|
||||||
final LatinIME.UIHandler handler, final KeyboardSwitcher keyboardSwitcher) {
|
final LatinIME.UIHandler handler) {
|
||||||
final SuggestedWords suggestedWords = mSuggestedWords;
|
final SuggestedWords suggestedWords = mSuggestedWords;
|
||||||
final String suggestion = suggestionInfo.mWord;
|
final String suggestion = suggestionInfo.mWord;
|
||||||
// If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
|
// If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
|
||||||
|
@ -212,16 +215,26 @@ public final class InputLogic {
|
||||||
LatinImeLogger.logOnManualSuggestion("", suggestion, index, suggestedWords);
|
LatinImeLogger.logOnManualSuggestion("", suggestion, index, suggestedWords);
|
||||||
// Rely on onCodeInput to do the complicated swapping/stripping logic consistently.
|
// Rely on onCodeInput to do the complicated swapping/stripping logic consistently.
|
||||||
final int primaryCode = suggestion.charAt(0);
|
final int primaryCode = suggestion.charAt(0);
|
||||||
final Event event = Event.createSoftwareKeypressEvent(primaryCode, Event.NOT_A_KEY_CODE,
|
// TODO: we should be using createSuggestionPickedEvent here, but for legacy reasons,
|
||||||
Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE);
|
// onCodeInput is expected a software keypress event for a suggested punctuation
|
||||||
onCodeInput(settingsValues, event, keyboardSwitcher.getKeyboardShiftMode(), handler);
|
// because the current code is descended from a time where this information used not
|
||||||
|
// to be available. Fix this.
|
||||||
|
final Event event = Event.createSoftwareKeypressEvent(primaryCode,
|
||||||
|
Event.NOT_A_KEY_CODE /* keyCode*/,
|
||||||
|
Constants.SUGGESTION_STRIP_COORDINATE /* x */,
|
||||||
|
Constants.SUGGESTION_STRIP_COORDINATE /* y */);
|
||||||
|
final InputTransaction completeTransaction = onCodeInput(settingsValues, event,
|
||||||
|
keyboardShiftState, handler);
|
||||||
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
||||||
ResearchLogger.latinIME_punctuationSuggestion(index, suggestion,
|
ResearchLogger.latinIME_punctuationSuggestion(index, suggestion,
|
||||||
false /* isBatchMode */, suggestedWords.mIsPrediction);
|
false /* isBatchMode */, suggestedWords.mIsPrediction);
|
||||||
}
|
}
|
||||||
return;
|
return completeTransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Event event = Event.createSuggestionPickedEvent(suggestionInfo);
|
||||||
|
final InputTransaction inputTransaction = new InputTransaction(settingsValues,
|
||||||
|
event, SystemClock.uptimeMillis(), mSpaceState, keyboardShiftState);
|
||||||
mConnection.beginBatchEdit();
|
mConnection.beginBatchEdit();
|
||||||
if (SpaceState.PHANTOM == mSpaceState && suggestion.length() > 0
|
if (SpaceState.PHANTOM == mSpaceState && suggestion.length() > 0
|
||||||
// In the batch input mode, a manually picked suggested word should just replace
|
// In the batch input mode, a manually picked suggested word should just replace
|
||||||
|
@ -241,11 +254,11 @@ public final class InputLogic {
|
||||||
if (SuggestedWordInfo.KIND_APP_DEFINED == suggestionInfo.mKind) {
|
if (SuggestedWordInfo.KIND_APP_DEFINED == suggestionInfo.mKind) {
|
||||||
mSuggestedWords = SuggestedWords.EMPTY;
|
mSuggestedWords = SuggestedWords.EMPTY;
|
||||||
mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
|
mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
|
||||||
keyboardSwitcher.updateShiftState();
|
inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
|
||||||
resetComposingState(true /* alsoResetLastComposedWord */);
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
||||||
mConnection.commitCompletion(suggestionInfo.mApplicationSpecifiedCompletionInfo);
|
mConnection.commitCompletion(suggestionInfo.mApplicationSpecifiedCompletionInfo);
|
||||||
mConnection.endBatchEdit();
|
mConnection.endBatchEdit();
|
||||||
return;
|
return inputTransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to log before we commit, because the word composer will store away the user
|
// We need to log before we commit, because the word composer will store away the user
|
||||||
|
@ -264,7 +277,7 @@ public final class InputLogic {
|
||||||
mLastComposedWord.deactivate();
|
mLastComposedWord.deactivate();
|
||||||
// Space state must be updated before calling updateShiftState
|
// Space state must be updated before calling updateShiftState
|
||||||
mSpaceState = SpaceState.PHANTOM;
|
mSpaceState = SpaceState.PHANTOM;
|
||||||
keyboardSwitcher.updateShiftState();
|
inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
|
||||||
|
|
||||||
// We should show the "Touch again to save" hint if the user pressed the first entry
|
// We should show the "Touch again to save" hint if the user pressed the first entry
|
||||||
// AND it's in none of our current dictionaries (main, user or otherwise).
|
// AND it's in none of our current dictionaries (main, user or otherwise).
|
||||||
|
@ -290,6 +303,7 @@ public final class InputLogic {
|
||||||
// If we're not showing the "Touch again to save", then update the suggestion strip.
|
// If we're not showing the "Touch again to save", then update the suggestion strip.
|
||||||
handler.postUpdateSuggestionStrip();
|
handler.postUpdateSuggestionStrip();
|
||||||
}
|
}
|
||||||
|
return inputTransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue