diff options
-rw-r--r-- | java/res/values/config.xml | 2 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java | 25 | ||||
-rw-r--r-- | native/jni/src/hash_map_compat.h | 34 |
3 files changed, 50 insertions, 11 deletions
diff --git a/java/res/values/config.xml b/java/res/values/config.xml index 8477df054..8e2d43e4e 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -51,7 +51,7 @@ <integer name="config_key_preview_linger_timeout">70</integer> <integer name="config_gesture_floating_preview_text_linger_timeout">200</integer> <integer name="config_gesture_preview_trail_fadeout_start_delay">100</integer> - <integer name="config_gesture_preview_trail_fadeout_duration">1000</integer> + <integer name="config_gesture_preview_trail_fadeout_duration">800</integer> <integer name="config_gesture_preview_trail_update_interval">20</integer> <!-- Configuration for MainKeyboardView diff --git a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java index 747627b7d..e814d8009 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java @@ -32,6 +32,7 @@ class GesturePreviewTrail { private final ResizableIntArray mEventTimes = new ResizableIntArray(DEFAULT_CAPACITY); private int mCurrentStrokeId = -1; private long mCurrentDownTime; + private int mTrailStartIndex; // Use this value as imaginary zero because x-coordinates may be zero. private static final int DOWN_EVENT_MARKER = -128; @@ -80,7 +81,7 @@ class GesturePreviewTrail { if (isNewStroke) { final int elapsedTime = (int)(downTime - mCurrentDownTime); final int[] eventTimes = mEventTimes.getPrimitiveArray(); - for (int i = 0; i < trailSize; i++) { + for (int i = mTrailStartIndex; i < trailSize; i++) { eventTimes[i] -= elapsedTime; } @@ -122,13 +123,14 @@ class GesturePreviewTrail { final int lingeringDuration = mPreviewParams.mFadeoutStartDelay + mPreviewParams.mFadeoutDuration; int startIndex; - for (startIndex = 0; startIndex < trailSize; startIndex++) { + for (startIndex = mTrailStartIndex; startIndex < trailSize; startIndex++) { final int elapsedTime = sinceDown - eventTimes[startIndex]; // Skip too old trail points. if (elapsedTime < lingeringDuration) { break; } } + mTrailStartIndex = startIndex; if (startIndex < trailSize) { int lastX = getXCoordValue(xCoords[startIndex]); @@ -147,15 +149,18 @@ class GesturePreviewTrail { } } - // TODO: Implement ring buffer to avoid moving points. - // Discard faded out points. final int newSize = trailSize - startIndex; - System.arraycopy(eventTimes, startIndex, eventTimes, 0, newSize); - System.arraycopy(xCoords, startIndex, xCoords, 0, newSize); - System.arraycopy(yCoords, startIndex, yCoords, 0, newSize); - mEventTimes.setLength(newSize); - mXCoordinates.setLength(newSize); - mYCoordinates.setLength(newSize); + if (newSize < startIndex) { + mTrailStartIndex = 0; + if (newSize > 0) { + System.arraycopy(eventTimes, startIndex, eventTimes, 0, newSize); + System.arraycopy(xCoords, startIndex, xCoords, 0, newSize); + System.arraycopy(yCoords, startIndex, yCoords, 0, newSize); + } + mEventTimes.setLength(newSize); + mXCoordinates.setLength(newSize); + mYCoordinates.setLength(newSize); + } return newSize > 0; } } diff --git a/native/jni/src/hash_map_compat.h b/native/jni/src/hash_map_compat.h new file mode 100644 index 000000000..116359a73 --- /dev/null +++ b/native/jni/src/hash_map_compat.h @@ -0,0 +1,34 @@ +/* + * 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. + */ + +#ifndef LATINIME_HASH_MAP_COMPAT_H +#define LATINIME_HASH_MAP_COMPAT_H + +// TODO: Use std::unordered_map that has been standardized in C++11 + +#ifdef __APPLE__ +#include <ext/hash_map> +#else // __APPLE__ +#include <hash_map> +#endif // __APPLE__ + +#ifdef __SGI_STL_PORT +#define hash_map_compat stlport::hash_map +#else // __SGI_STL_PORT +#define hash_map_compat __gnu_cxx::hash_map +#endif // __SGI_STL_PORT + +#endif // LATINIME_HASH_MAP_COMPAT_H |