aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorKen Wakasa <kwakasa@google.com>2012-09-11 19:15:00 +0900
committerKen Wakasa <kwakasa@google.com>2012-09-11 20:00:21 +0900
commite30c4e0bb1522f45b3bb37b54c35ee1f6a21dd4b (patch)
treea011fcea63d949c64f1f399c81cbce7b449a21ac /java/src
parentb0c693d005761dc2d2c2e323cc0456bac9a33297 (diff)
downloadlatinime-e30c4e0bb1522f45b3bb37b54c35ee1f6a21dd4b.tar.gz
latinime-e30c4e0bb1522f45b3bb37b54c35ee1f6a21dd4b.tar.xz
latinime-e30c4e0bb1522f45b3bb37b54c35ee1f6a21dd4b.zip
Stabilize gesture recognition algorithm that looks for the nearest key.
It relies on the order of the key array. Change-Id: I58fa71a7b330e59cd774fc208e5b6bc1a3decd2e
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java13
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java4
2 files changed, 12 insertions, 5 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 03c216474..cb120a33e 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -52,7 +52,7 @@ import java.util.Locale;
/**
* Class for describing the position and characteristics of a single key in the keyboard.
*/
-public class Key {
+public class Key implements Comparable<Key> {
private static final String TAG = Key.class.getSimpleName();
/**
@@ -410,7 +410,7 @@ public class Key {
});
}
- private boolean equals(final Key o) {
+ private boolean equalsInternal(final Key o) {
if (this == o) return true;
return o.mX == mX
&& o.mY == mY
@@ -428,13 +428,20 @@ public class Key {
}
@Override
+ public int compareTo(Key o) {
+ if (equalsInternal(o)) return 0;
+ if (mHashCode > o.mHashCode) return 1;
+ return -1;
+ }
+
+ @Override
public int hashCode() {
return mHashCode;
}
@Override
public boolean equals(final Object o) {
- return o instanceof Key && equals((Key)o);
+ return o instanceof Key && equalsInternal((Key)o);
}
@Override
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
index ab5d31d42..e6fe50e02 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
@@ -24,7 +24,7 @@ import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.latin.CollectionUtils;
import java.util.ArrayList;
-import java.util.HashSet;
+import java.util.TreeSet;
public class KeyboardParams {
public KeyboardId mId;
@@ -58,7 +58,7 @@ public class KeyboardParams {
public int GRID_WIDTH;
public int GRID_HEIGHT;
- public final HashSet<Key> mKeys = CollectionUtils.newHashSet();
+ public final TreeSet<Key> mKeys = CollectionUtils.newTreeSet(); // ordered set
public final ArrayList<Key> mShiftKeys = CollectionUtils.newArrayList();
public final ArrayList<Key> mAltCodeKeysWhileTyping = CollectionUtils.newArrayList();
public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet();