am 83372e75
: Merge "[CB09] Pass events through the combiner chain"
* commit '83372e75e4fc030e77de470e08cf7012436c759a': [CB09] Pass events through the combiner chain
This commit is contained in:
commit
b125f451c2
6 changed files with 57 additions and 6 deletions
|
@ -16,14 +16,22 @@
|
||||||
|
|
||||||
package com.android.inputmethod.event;
|
package com.android.inputmethod.event;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A generic interface for combiners.
|
* A generic interface for combiners. Combiners are objects that transform chains of input events
|
||||||
|
* into committable strings and manage feedback to show to the user on the combining state.
|
||||||
*/
|
*/
|
||||||
public interface Combiner {
|
public interface Combiner {
|
||||||
/**
|
/**
|
||||||
* Combine an event with the existing state and return the new event.
|
* Process an event, possibly combining it with the existing state and return the new event.
|
||||||
|
*
|
||||||
|
* If this event does not result in any new event getting passed down the chain, this method
|
||||||
|
* returns null. It may also modify the previous event list if appropriate.
|
||||||
|
*
|
||||||
|
* @param previousEvents the previous events in this composition.
|
||||||
* @param event the event to combine with the existing state.
|
* @param event the event to combine with the existing state.
|
||||||
* @return the resulting event.
|
* @return the resulting event.
|
||||||
*/
|
*/
|
||||||
Event combine(Event event);
|
Event processEvent(ArrayList<Event> previousEvents, Event event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,4 +51,19 @@ public class CombinerChain {
|
||||||
// The dead key combiner is always active, and always first
|
// The dead key combiner is always active, and always first
|
||||||
mCombiners.add(new DeadKeyCombiner());
|
mCombiners.add(new DeadKeyCombiner());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pass a new event through the whole chain.
|
||||||
|
public void processEvent(final ArrayList<Event> previousEvents, final Event newEvent) {
|
||||||
|
final ArrayList<Event> modifiablePreviousEvents = new ArrayList<Event>(previousEvents);
|
||||||
|
Event event = newEvent;
|
||||||
|
for (final Combiner combiner : mCombiners) {
|
||||||
|
// A combiner can never return more than one event; it can return several
|
||||||
|
// code points, but they should be encapsulated within one event.
|
||||||
|
event = combiner.processEvent(modifiablePreviousEvents, event);
|
||||||
|
if (null == event) {
|
||||||
|
// Combiners return null if they eat the event.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,17 @@ import android.view.KeyCharacterMap;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.Constants;
|
import com.android.inputmethod.latin.Constants;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A combiner that handles dead keys.
|
* A combiner that handles dead keys.
|
||||||
*/
|
*/
|
||||||
public class DeadKeyCombiner implements Combiner {
|
public class DeadKeyCombiner implements Combiner {
|
||||||
|
// TODO: make this a list of events instead
|
||||||
final StringBuilder mDeadSequence = new StringBuilder();
|
final StringBuilder mDeadSequence = new StringBuilder();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Event combine(final Event event) {
|
public Event processEvent(final ArrayList<Event> previousEvents, final Event event) {
|
||||||
if (null == event) return null; // Just in case some combiner is broken
|
if (null == event) return null; // Just in case some combiner is broken
|
||||||
if (TextUtils.isEmpty(mDeadSequence)) {
|
if (TextUtils.isEmpty(mDeadSequence)) {
|
||||||
if (event.isDead()) {
|
if (event.isDead()) {
|
||||||
|
|
|
@ -192,6 +192,7 @@ public final class WordComposer {
|
||||||
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);
|
||||||
mTypedWord.appendCodePoint(primaryCode);
|
mTypedWord.appendCodePoint(primaryCode);
|
||||||
mEvents.add(event);
|
mEvents.add(event);
|
||||||
refreshSize();
|
refreshSize();
|
||||||
|
|
|
@ -36,8 +36,6 @@ MAKEDICT_CORE_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/latin/makedi
|
||||||
# nearly-empty implementations, for parts that we don't use in Dicttool.
|
# nearly-empty implementations, for parts that we don't use in Dicttool.
|
||||||
LATINIME_SRCS_FOR_DICTTOOL := \
|
LATINIME_SRCS_FOR_DICTTOOL := \
|
||||||
event/Combiner.java \
|
event/Combiner.java \
|
||||||
event/CombinerChain.java \
|
|
||||||
event/DeadKeyCombiner.java \
|
|
||||||
event/Event.java \
|
event/Event.java \
|
||||||
latin/BinaryDictionary.java \
|
latin/BinaryDictionary.java \
|
||||||
latin/DicTraverseSession.java \
|
latin/DicTraverseSession.java \
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2014 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.inputmethod.event;
|
||||||
|
|
||||||
|
import com.android.inputmethod.latin.utils.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class CombinerChain {
|
||||||
|
public CombinerChain(final Combiner... combinerList) {}
|
||||||
|
public void processEvent(final ArrayList<Event> previousEvents, final Event newEvent) {}
|
||||||
|
}
|
Loading…
Reference in a new issue