diff options
author | 2010-09-02 12:54:02 -0700 | |
---|---|---|
committer | 2010-09-02 12:54:02 -0700 | |
commit | a18e956f7aec76b4bebaecd3ce022520026fba48 (patch) | |
tree | 33d7842d29b392dd5a64ddd76d1c7ced1be3e296 /java/src | |
parent | ac64a5c3edf9a99889bc9f800139df95abb200b9 (diff) | |
parent | 23eb4711020f73ebb89a761a0c4ab917a94cfabe (diff) | |
download | latinime-a18e956f7aec76b4bebaecd3ce022520026fba48.tar.gz latinime-a18e956f7aec76b4bebaecd3ce022520026fba48.tar.xz latinime-a18e956f7aec76b4bebaecd3ce022520026fba48.zip |
am 23eb4711: am 6bfb234f: Refactor KeyDetector to share more methods
Merge commit '23eb4711020f73ebb89a761a0c4ab917a94cfabe'
* commit '23eb4711020f73ebb89a761a0c4ab917a94cfabe':
Refactor KeyDetector to share more methods
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/latin/KeyDetector.java | 18 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/ProximityKeyDetector.java | 11 |
2 files changed, 19 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/latin/KeyDetector.java b/java/src/com/android/inputmethod/latin/KeyDetector.java index 5583e3275..e443f272b 100644 --- a/java/src/com/android/inputmethod/latin/KeyDetector.java +++ b/java/src/com/android/inputmethod/latin/KeyDetector.java @@ -19,11 +19,12 @@ package com.android.inputmethod.latin; import android.inputmethodservice.Keyboard; import android.inputmethodservice.Keyboard.Key; +import java.util.Arrays; import java.util.List; abstract class KeyDetector { protected Keyboard mKeyboard; - protected Key[] mKeys; + private Key[] mKeys; protected int mCorrectionX; protected int mCorrectionY; @@ -50,6 +51,13 @@ abstract class KeyDetector { return y + mCorrectionY; } + protected Key[] getKeys() { + if (mKeys == null) + throw new IllegalStateException("keyboard isn't set"); + // mKeyboard is guaranteed not null at setKeybaord() method + return mKeys; + } + public void setProximityCorrectionEnabled(boolean enabled) { mProximityCorrectOn = enabled; } @@ -62,7 +70,13 @@ abstract class KeyDetector { mProximityThresholdSquare = threshold * threshold; } - abstract public int[] newCodeArray(); + public int[] newCodeArray() { + int[] codes = new int[getMaxNearbyKeys()]; + Arrays.fill(codes, LatinKeyboardBaseView.NOT_A_KEY); + return codes; + } + + abstract protected int getMaxNearbyKeys(); abstract public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys); }
\ No newline at end of file diff --git a/java/src/com/android/inputmethod/latin/ProximityKeyDetector.java b/java/src/com/android/inputmethod/latin/ProximityKeyDetector.java index 408e4e147..d17bedb56 100644 --- a/java/src/com/android/inputmethod/latin/ProximityKeyDetector.java +++ b/java/src/com/android/inputmethod/latin/ProximityKeyDetector.java @@ -27,20 +27,15 @@ class ProximityKeyDetector extends KeyDetector { private int[] mDistances = new int[MAX_NEARBY_KEYS]; @Override - public int[] newCodeArray() { - int[] codes = new int[MAX_NEARBY_KEYS]; - Arrays.fill(codes, LatinKeyboardBaseView.NOT_A_KEY); - return codes; + protected int getMaxNearbyKeys() { + return MAX_NEARBY_KEYS; } @Override public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys) { + final Key[] keys = getKeys(); final int touchX = getTouchX(x); final int touchY = getTouchY(y); - final Key[] keys = mKeys; - if (keys == null) - throw new IllegalStateException("keyboard isn't set"); - // mKeyboard is guaranteed not null at setKeybaord() method int primaryIndex = LatinKeyboardBaseView.NOT_A_KEY; int closestKey = LatinKeyboardBaseView.NOT_A_KEY; int closestKeyDist = mProximityThresholdSquare + 1; |