From 7ede642df417c0f732573f639970b138f0bee18c Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 14 Mar 2014 22:50:20 +0900 Subject: [PATCH] [CB08] Create a combiner chain in the word composer. Bug: 13406701 Change-Id: I3b9f75de9283f76366d1bef7e14a8f22f2186669 --- .../inputmethod/event/CombinerChain.java | 54 +++++++++++++++++ .../inputmethod/event/EventDecoderSpec.java | 26 --------- .../inputmethod/event/EventInterpreter.java | 58 ------------------- .../inputmethod/latin/WordComposer.java | 5 ++ .../latin/inputlogic/InputLogic.java | 1 - tools/dicttool/Android.mk | 3 + 6 files changed, 62 insertions(+), 85 deletions(-) create mode 100644 java/src/com/android/inputmethod/event/CombinerChain.java delete mode 100644 java/src/com/android/inputmethod/event/EventDecoderSpec.java delete mode 100644 java/src/com/android/inputmethod/event/EventInterpreter.java diff --git a/java/src/com/android/inputmethod/event/CombinerChain.java b/java/src/com/android/inputmethod/event/CombinerChain.java new file mode 100644 index 000000000..1deaed68f --- /dev/null +++ b/java/src/com/android/inputmethod/event/CombinerChain.java @@ -0,0 +1,54 @@ +/* + * 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; + +/** + * This class implements the logic chain between receiving events and generating code points. + * + * Event sources are multiple. It may be a hardware keyboard, a D-PAD, a software keyboard, + * or any exotic input source. + * This class will orchestrate the composing chain that starts with an event as its input. Each + * composer will be given turns one after the other. + * The output is composed of two sequences of code points: the first, representing the already + * finished combining part, will be shown normally as the composing string, while the second is + * feedback on the composing state and will typically be shown with different styling such as + * a colored background. + */ +public class CombinerChain { + // TODO: Create an object type to represent input material + visual feedback + decoding state + + private final ArrayList mCombiners; + + /** + * Create an combiner chain. + * + * The combiner chain takes events as inputs and outputs code points and combining state. + * For example, if the input language is Japanese, the combining chain will typically perform + * kana conversion. + * + * @param combinerList A list of combiners to be applied in order. + */ + public CombinerChain(final Combiner... combinerList) { + mCombiners = CollectionUtils.newArrayList(); + // The dead key combiner is always active, and always first + mCombiners.add(new DeadKeyCombiner()); + } +} diff --git a/java/src/com/android/inputmethod/event/EventDecoderSpec.java b/java/src/com/android/inputmethod/event/EventDecoderSpec.java deleted file mode 100644 index 303b4b4c9..000000000 --- a/java/src/com/android/inputmethod/event/EventDecoderSpec.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2012 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; - -/** - * Class describing a decoder chain. This will depend on the language and the input medium (soft - * or hard keyboard for example). - */ -public class EventDecoderSpec { - public EventDecoderSpec() { - } -} diff --git a/java/src/com/android/inputmethod/event/EventInterpreter.java b/java/src/com/android/inputmethod/event/EventInterpreter.java deleted file mode 100644 index bcf10fc58..000000000 --- a/java/src/com/android/inputmethod/event/EventInterpreter.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2012 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; - -/** - * This class implements the logic between receiving events and generating code points. - * - * Event sources are multiple. It may be a hardware keyboard, a D-PAD, a software keyboard, - * or any exotic input source. - * This class will orchestrate the decoding chain that starts with an event and ends up with - * a stream of code points + decoding state. - */ -public class EventInterpreter { - // TODO: Implement an object pool for events, as we'll create a lot of them - // TODO: Create a combiner - // TODO: Create an object type to represent input material + visual feedback + decoding state - - private final EventDecoderSpec mDecoderSpec; - private final ArrayList mCombiners; - - /** - * Create an event interpreter according to a specification. - * - * The specification contains information about what to do with events. Typically, it will - * contain information about the type of keyboards - for example, if hardware keyboard(s) is/are - * attached, their type will be included here so that the decoder knows what to do with each - * keypress (a 10-key keyboard is not handled like a qwerty-ish keyboard). - * It also contains information for combining characters. For example, if the input language - * is Japanese, the specification will typically request kana conversion. - * Also note that the specification can be null. This means that we need to create a default - * interpreter that does no specific combining, and assumes the most common cases. - * - * @param specification the specification for event interpretation. null for default. - */ - public EventInterpreter(final EventDecoderSpec specification) { - mDecoderSpec = null != specification ? specification : new EventDecoderSpec(); - mCombiners = CollectionUtils.newArrayList(); - mCombiners.add(new DeadKeyCombiner()); - } -} diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 2ac11aa29..9e5d9205d 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -16,6 +16,7 @@ package com.android.inputmethod.latin; +import com.android.inputmethod.event.CombinerChain; import com.android.inputmethod.event.Event; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; @@ -40,6 +41,8 @@ public final class WordComposer { public static final int CAPS_MODE_AUTO_SHIFTED = 0x5; public static final int CAPS_MODE_AUTO_SHIFT_LOCKED = 0x7; + private CombinerChain mCombinerChain; + // An array of code points representing the characters typed so far. // The array is limited to MAX_WORD_LENGTH code points, but mTypedWord extends past that // and mCodePointSize can go past that. If mCodePointSize is greater than MAX_WORD_LENGTH, @@ -87,6 +90,7 @@ public final class WordComposer { private boolean mIsFirstCharCapitalized; public WordComposer() { + mCombinerChain = new CombinerChain(); mPrimaryKeyCodes = new int[MAX_WORD_LENGTH]; mEvents = CollectionUtils.newArrayList(); mTypedWord = new StringBuilder(MAX_WORD_LENGTH); @@ -101,6 +105,7 @@ public final class WordComposer { } public WordComposer(final WordComposer source) { + mCombinerChain = source.mCombinerChain; mPrimaryKeyCodes = Arrays.copyOf(source.mPrimaryKeyCodes, source.mPrimaryKeyCodes.length); mEvents = new ArrayList(source.mEvents); mTypedWord = new StringBuilder(source.mTypedWord); diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 1eff42762..3c7e67693 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -28,7 +28,6 @@ import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.SuggestionSpanUtils; import com.android.inputmethod.event.Event; -import com.android.inputmethod.event.EventInterpreter; import com.android.inputmethod.event.InputTransaction; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.Constants; diff --git a/tools/dicttool/Android.mk b/tools/dicttool/Android.mk index 948c03b4f..91f8af709 100644 --- a/tools/dicttool/Android.mk +++ b/tools/dicttool/Android.mk @@ -35,6 +35,9 @@ MAKEDICT_CORE_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/latin/makedi # a significant part of the dependencies are mocked in the compat/ directory, with empty or # nearly-empty implementations, for parts that we don't use in Dicttool. LATINIME_SRCS_FOR_DICTTOOL := \ + event/Combiner.java \ + event/CombinerChain.java \ + event/DeadKeyCombiner.java \ event/Event.java \ latin/BinaryDictionary.java \ latin/DicTraverseSession.java \