am bf2a3210: Merge "[HW6] Split processing and applying the event." into lmp-dev
* commit 'bf2a32100568a01d25edb56d3d9d46b5f5d2c0eb': [HW6] Split processing and applying the event.main
commit
99e13e485a
|
@ -81,11 +81,11 @@ public class CombinerChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass a new event through the whole chain.
|
* Process an event through the combining chain, and return a processed event to apply.
|
||||||
* @param previousEvents the list of previous events in this composition
|
* @param previousEvents the list of previous events in this composition
|
||||||
* @param newEvent the new event to process
|
* @param newEvent the new event to process
|
||||||
*/
|
*/
|
||||||
public void processEvent(final ArrayList<Event> previousEvents, final Event newEvent) {
|
public Event processEvent(final ArrayList<Event> previousEvents, final Event newEvent) {
|
||||||
final ArrayList<Event> modifiablePreviousEvents = new ArrayList<>(previousEvents);
|
final ArrayList<Event> modifiablePreviousEvents = new ArrayList<>(previousEvents);
|
||||||
Event event = newEvent;
|
Event event = newEvent;
|
||||||
for (final Combiner combiner : mCombiners) {
|
for (final Combiner combiner : mCombiners) {
|
||||||
|
@ -97,6 +97,14 @@ public class CombinerChain {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply a processed event.
|
||||||
|
* @param event the event to be applied
|
||||||
|
*/
|
||||||
|
public void applyProcessedEvent(final Event event) {
|
||||||
if (null != event) {
|
if (null != event) {
|
||||||
// TODO: figure out the generic way of doing this
|
// TODO: figure out the generic way of doing this
|
||||||
if (Constants.CODE_DELETE == event.mKeyCode) {
|
if (Constants.CODE_DELETE == event.mKeyCode) {
|
||||||
|
|
|
@ -175,20 +175,30 @@ public final class WordComposer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process an input event.
|
* Process an event and return an event, and return a processed event to apply.
|
||||||
|
* @param event the unprocessed event.
|
||||||
|
* @return the processed event.
|
||||||
|
*/
|
||||||
|
public Event processEvent(final Event event) {
|
||||||
|
final Event processedEvent = mCombinerChain.processEvent(mEvents, event);
|
||||||
|
mEvents.add(event);
|
||||||
|
return processedEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply a processed input event.
|
||||||
*
|
*
|
||||||
* All input events should be supported, including software/hardware events, characters as well
|
* All input events should be supported, including software/hardware events, characters as well
|
||||||
* as deletions, multiple inputs and gestures.
|
* as deletions, multiple inputs and gestures.
|
||||||
*
|
*
|
||||||
* @param event the event to process.
|
* @param event the event to apply.
|
||||||
*/
|
*/
|
||||||
public void processEvent(final Event event) {
|
public void applyProcessedEvent(final Event event) {
|
||||||
final int primaryCode = event.mCodePoint;
|
final int primaryCode = event.mCodePoint;
|
||||||
final int keyX = event.mX;
|
final int keyX = event.mX;
|
||||||
final int keyY = event.mY;
|
final int keyY = event.mY;
|
||||||
final int newIndex = size();
|
final int newIndex = size();
|
||||||
mCombinerChain.processEvent(mEvents, event);
|
mCombinerChain.applyProcessedEvent(event);
|
||||||
mEvents.add(event);
|
|
||||||
refreshTypedWordCache();
|
refreshTypedWordCache();
|
||||||
mCursorPositionWithinWord = mCodePointSize;
|
mCursorPositionWithinWord = mCodePointSize;
|
||||||
// We may have deleted the last one.
|
// We may have deleted the last one.
|
||||||
|
@ -281,7 +291,9 @@ public final class WordComposer {
|
||||||
final int codePoint = Character.codePointAt(word, i);
|
final int codePoint = Character.codePointAt(word, i);
|
||||||
// We don't want to override the batch input points that are held in mInputPointers
|
// We don't want to override the batch input points that are held in mInputPointers
|
||||||
// (See {@link #add(int,int,int)}).
|
// (See {@link #add(int,int,int)}).
|
||||||
processEvent(Event.createEventForCodePointFromUnknownSource(codePoint));
|
final Event processedEvent =
|
||||||
|
processEvent(Event.createEventForCodePointFromUnknownSource(codePoint));
|
||||||
|
applyProcessedEvent(processedEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,9 +307,11 @@ public final class WordComposer {
|
||||||
reset();
|
reset();
|
||||||
final int length = codePoints.length;
|
final int length = codePoints.length;
|
||||||
for (int i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
processEvent(Event.createEventForCodePointFromAlreadyTypedText(codePoints[i],
|
final Event processedEvent =
|
||||||
|
processEvent(Event.createEventForCodePointFromAlreadyTypedText(codePoints[i],
|
||||||
CoordinateUtils.xFromArray(coordinates, i),
|
CoordinateUtils.xFromArray(coordinates, i),
|
||||||
CoordinateUtils.yFromArray(coordinates, i)));
|
CoordinateUtils.yFromArray(coordinates, i)));
|
||||||
|
applyProcessedEvent(processedEvent);
|
||||||
}
|
}
|
||||||
mIsResumed = true;
|
mIsResumed = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -762,7 +762,8 @@ public final class InputLogic {
|
||||||
resetComposingState(false /* alsoResetLastComposedWord */);
|
resetComposingState(false /* alsoResetLastComposedWord */);
|
||||||
}
|
}
|
||||||
if (isComposingWord) {
|
if (isComposingWord) {
|
||||||
mWordComposer.processEvent(inputTransaction.mEvent);
|
final Event processedEvent = mWordComposer.processEvent(inputTransaction.mEvent);
|
||||||
|
mWordComposer.applyProcessedEvent(processedEvent);
|
||||||
// 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);
|
||||||
|
@ -933,7 +934,8 @@ public final class InputLogic {
|
||||||
mDictionaryFacilitator.removeWordFromPersonalizedDicts(rejectedSuggestion);
|
mDictionaryFacilitator.removeWordFromPersonalizedDicts(rejectedSuggestion);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mWordComposer.processEvent(inputTransaction.mEvent);
|
final Event processedEvent = mWordComposer.processEvent(inputTransaction.mEvent);
|
||||||
|
mWordComposer.applyProcessedEvent(processedEvent);
|
||||||
}
|
}
|
||||||
if (mWordComposer.isComposingWord()) {
|
if (mWordComposer.isComposingWord()) {
|
||||||
mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
|
mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
|
||||||
|
|
|
@ -31,8 +31,12 @@ public class CombinerChain {
|
||||||
mComposingWord = new StringBuilder(initialText);
|
mComposingWord = new StringBuilder(initialText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processEvent(final ArrayList<Event> previousEvents, final Event newEvent) {
|
public Event processEvent(final ArrayList<Event> previousEvents, final Event newEvent) {
|
||||||
mComposingWord.append(newEvent.getTextToCommit());
|
return newEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyProcessedEvent(final Event event) {
|
||||||
|
mComposingWord.append(event.getTextToCommit());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharSequence getComposingWordWithCombiningFeedback() {
|
public CharSequence getComposingWordWithCombiningFeedback() {
|
||||||
|
|
Loading…
Reference in New Issue