am e30c4e0b: Stabilize gesture recognition algorithm that looks for the nearest key.

* commit 'e30c4e0bb1522f45b3bb37b54c35ee1f6a21dd4b':
  Stabilize gesture recognition algorithm that looks for the nearest key.
main
Ken Wakasa 2012-09-11 05:19:10 -07:00 committed by Android Git Automerger
commit 5d46fb59d4
2 changed files with 12 additions and 5 deletions

View File

@ -52,7 +52,7 @@ import java.util.Locale;
/** /**
* Class for describing the position and characteristics of a single key in the keyboard. * 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(); 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; if (this == o) return true;
return o.mX == mX return o.mX == mX
&& o.mY == mY && o.mY == mY
@ -427,6 +427,13 @@ public class Key {
&& o.mLabelFlags == mLabelFlags; && o.mLabelFlags == mLabelFlags;
} }
@Override
public int compareTo(Key o) {
if (equalsInternal(o)) return 0;
if (mHashCode > o.mHashCode) return 1;
return -1;
}
@Override @Override
public int hashCode() { public int hashCode() {
return mHashCode; return mHashCode;
@ -434,7 +441,7 @@ public class Key {
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
return o instanceof Key && equals((Key)o); return o instanceof Key && equalsInternal((Key)o);
} }
@Override @Override

View File

@ -24,7 +24,7 @@ import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.TreeSet;
public class KeyboardParams { public class KeyboardParams {
public KeyboardId mId; public KeyboardId mId;
@ -58,7 +58,7 @@ public class KeyboardParams {
public int GRID_WIDTH; public int GRID_WIDTH;
public int GRID_HEIGHT; 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> mShiftKeys = CollectionUtils.newArrayList();
public final ArrayList<Key> mAltCodeKeysWhileTyping = CollectionUtils.newArrayList(); public final ArrayList<Key> mAltCodeKeysWhileTyping = CollectionUtils.newArrayList();
public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet(); public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet();