aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/event/EventInterpreter.java46
-rw-r--r--java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java2
-rw-r--r--java/src/com/android/inputmethod/event/SoftwareKeyboardEventDecoder.java27
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java36
4 files changed, 93 insertions, 18 deletions
diff --git a/java/src/com/android/inputmethod/event/EventInterpreter.java b/java/src/com/android/inputmethod/event/EventInterpreter.java
index 443c269a2..739c6d227 100644
--- a/java/src/com/android/inputmethod/event/EventInterpreter.java
+++ b/java/src/com/android/inputmethod/event/EventInterpreter.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.event;
+import android.util.SparseArray;
import android.view.KeyEvent;
/**
@@ -32,18 +33,41 @@ public class EventInterpreter {
// TODO: Create an object type to represent input material + visual feedback + decoding state
// TODO: Create an interface to call back to Latin IME through the above object
- // TODO: replace this with an associative container to bind device id -> decoder
- HardwareEventDecoder mHardwareEventDecoder;
- SoftwareEventDecoder mSoftwareEventDecoder;
+ final EventDecoderSpec mDecoderSpec;
+ final SparseArray<HardwareEventDecoder> mHardwareEventDecoders;
+ final SoftwareEventDecoder mSoftwareEventDecoder;
+ /**
+ * Create a default interpreter.
+ *
+ * This creates a default interpreter that does nothing. A default interpreter should normally
+ * only be used for fallback purposes, when we really don't know what we want to do with input.
+ *
+ */
public EventInterpreter() {
this(null);
}
+ /**
+ * 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) {
- // TODO: create the decoding chain from a specification. The decoders should be
- // created lazily
- mHardwareEventDecoder = new HardwareKeyboardEventDecoder(0);
+ mDecoderSpec = null != specification ? specification : new EventDecoderSpec();
+ // For both, we expect to have only one decoder in almost all cases, hence the default
+ // capacity of 1.
+ mHardwareEventDecoders = new SparseArray<HardwareEventDecoder>(1);
+ mSoftwareEventDecoder = new SoftwareKeyboardEventDecoder();
}
// Helper method to decode a hardware key event into a generic event, and execute any
@@ -60,11 +84,17 @@ public class EventInterpreter {
}
private HardwareEventDecoder getHardwareKeyEventDecoder(final int deviceId) {
- // TODO: look up the decoder by device id. It should be created lazily
- return mHardwareEventDecoder;
+ final HardwareEventDecoder decoder = mHardwareEventDecoders.get(deviceId);
+ if (null != decoder) return decoder;
+ // TODO: create the decoder according to the specification
+ final HardwareEventDecoder newDecoder = new HardwareKeyboardEventDecoder(deviceId);
+ mHardwareEventDecoders.put(deviceId, newDecoder);
+ return newDecoder;
}
private SoftwareEventDecoder getSoftwareEventDecoder() {
+ // Within the context of Latin IME, since we never present several software interfaces
+ // at the time, we should never need multiple software event decoders at a time.
return mSoftwareEventDecoder;
}
diff --git a/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java b/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java
index 9aa6a273e..34ce1c3f4 100644
--- a/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java
+++ b/java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java
@@ -30,7 +30,7 @@ public class HardwareKeyboardEventDecoder implements HardwareEventDecoder {
}
@Override
- public Event decodeHardwareKey(KeyEvent keyEvent) {
+ public Event decodeHardwareKey(final KeyEvent keyEvent) {
return Event.obtainEvent();
}
}
diff --git a/java/src/com/android/inputmethod/event/SoftwareKeyboardEventDecoder.java b/java/src/com/android/inputmethod/event/SoftwareKeyboardEventDecoder.java
new file mode 100644
index 000000000..de91567c7
--- /dev/null
+++ b/java/src/com/android/inputmethod/event/SoftwareKeyboardEventDecoder.java
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+/**
+ * A decoder for events from software keyboard, like the ones displayed by Latin IME.
+ */
+public class SoftwareKeyboardEventDecoder implements SoftwareEventDecoder {
+ @Override
+ public Event decodeSoftwareEvent() {
+ return null;
+ }
+}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
index 3a57f673a..f8949b2ad 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
@@ -101,6 +101,16 @@ final class GesturePreviewTrail {
}
}
+ /**
+ * Calculate the alpha of a gesture trail.
+ * A gesture trail starts from fully opaque. After mFadeStartDelay has been passed, the alpha
+ * of a trail reduces in proportion to the elapsed time. Then after mFadeDuration has been
+ * passed, a trail becomes fully transparent.
+ *
+ * @param elapsedTime the elapsed time since a trail has been made.
+ * @param params gesture trail display parameters
+ * @return the width of a gesture trail
+ */
private static int getAlpha(final int elapsedTime, final Params params) {
if (elapsedTime < params.mFadeoutStartDelay) {
return Constants.Color.ALPHA_OPAQUE;
@@ -111,10 +121,19 @@ final class GesturePreviewTrail {
return Constants.Color.ALPHA_OPAQUE - decreasingAlpha;
}
+ /**
+ * Calculate the width of a gesture trail.
+ * A gesture trail starts from the width of mTrailStartWidth and reduces its width in proportion
+ * to the elapsed time. After mTrailEndWidth has been passed, the width becomes mTraiLEndWidth.
+ *
+ * @param elapsedTime the elapsed time since a trail has been made.
+ * @param params gesture trail display parameters
+ * @return the width of a gesture trail
+ */
private static float getWidth(final int elapsedTime, final Params params) {
- return Math.max((params.mTrailLingerDuration - elapsedTime)
- * (params.mTrailStartWidth - params.mTrailEndWidth)
- / params.mTrailLingerDuration, 0.0f);
+ final int deltaTime = params.mTrailLingerDuration - elapsedTime;
+ final float deltaWidth = params.mTrailStartWidth - params.mTrailEndWidth;
+ return (deltaTime * deltaWidth) / params.mTrailLingerDuration + params.mTrailEndWidth;
}
private final RoundedLine mRoundedLine = new RoundedLine();
@@ -154,7 +173,7 @@ final class GesturePreviewTrail {
final RoundedLine line = mRoundedLine;
int p1x = getXCoordValue(xCoords[startIndex]);
int p1y = yCoords[startIndex];
- int lastTime = sinceDown - eventTimes[startIndex];
+ final int lastTime = sinceDown - eventTimes[startIndex];
float maxWidth = getWidth(lastTime, params);
float r1 = maxWidth / 2.0f;
// Initialize bounds rectangle.
@@ -167,20 +186,19 @@ final class GesturePreviewTrail {
final float r2 = width / 2.0f;
// Draw trail line only when the current point isn't a down point.
if (!isDownEventXCoord(xCoords[i])) {
- final int alpha = getAlpha(elapsedTime, params);
- paint.setAlpha(alpha);
final Path path = line.makePath(p1x, p1y, r1, p2x, p2y, r2);
if (path != null) {
+ final int alpha = getAlpha(elapsedTime, params);
+ paint.setAlpha(alpha);
canvas.drawPath(path, paint);
+ // Take union for the bounds.
outBoundsRect.union(p2x, p2y);
+ maxWidth = Math.max(maxWidth, width);
}
- // Take union for the bounds.
- maxWidth = Math.max(maxWidth, width);
}
p1x = p2x;
p1y = p2y;
r1 = r2;
- lastTime = elapsedTime;
}
// Take care of trail line width.
final int inset = -((int)maxWidth + 1);