diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java index 85418a61d..6d25025c5 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java @@ -73,11 +73,10 @@ public class KeyDetector { return y + mCorrectionY; } - protected List getKeys() { + public Keyboard getKeyboard() { if (mKeyboard == null) throw new IllegalStateException("keyboard isn't set"); - // mKeyboard is guaranteed not to be null at setKeybaord() method if mKeys is not null - return mKeyboard.getKeys(); + return mKeyboard; } public void setProximityCorrectionEnabled(boolean enabled) { @@ -154,7 +153,7 @@ public class KeyDetector { } private void getNearbyKeyCodes(final int[] allCodes) { - final List keys = getKeys(); + final List keys = getKeyboard().getKeys(); final int[] indices = mIndices; // allCodes[0] should always have the key code even if it is a non-letter key. @@ -188,7 +187,7 @@ public class KeyDetector { * @return The nearest key index */ public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) { - final List keys = getKeys(); + final List keys = getKeyboard().getKeys(); final int touchX = getTouchX(x); final int touchY = getTouchY(y); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 275e9d1fe..7ad947c67 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -763,7 +763,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } mKeyboardView = (LatinKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view); - mKeyboardView.setOnKeyboardActionListener(mInputMethodService); + mKeyboardView.setKeyboardActionListener(mInputMethodService); // This always needs to be set since the accessibility state can // potentially change without the input view being re-created. diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java index 35ce0a3f0..cbd438d36 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java @@ -274,10 +274,10 @@ public class LatinKeyboardBaseView extends KeyboardView { mKeyTimerHandler.startIgnoringDoubleTap(); } - public void setOnKeyboardActionListener(KeyboardActionListener listener) { + public void setKeyboardActionListener(KeyboardActionListener listener) { mKeyboardActionListener = listener; for (PointerTracker tracker : mPointerTrackers) { - tracker.setOnKeyboardActionListener(listener); + tracker.setKeyboardActionListener(listener); } } @@ -285,7 +285,7 @@ public class LatinKeyboardBaseView extends KeyboardView { * Returns the {@link KeyboardActionListener} object. * @return the listener attached to this keyboard */ - protected KeyboardActionListener getOnKeyboardActionListener() { + protected KeyboardActionListener getKeyboardActionListener() { return mKeyboardActionListener; } @@ -310,10 +310,10 @@ public class LatinKeyboardBaseView extends KeyboardView { // Remove any pending messages, except dismissing preview mKeyTimerHandler.cancelKeyTimers(); super.setKeyboard(keyboard); - mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), - -getPaddingTop() + mVerticalCorrection); + mKeyDetector.setKeyboard( + keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); for (PointerTracker tracker : mPointerTrackers) { - tracker.setKeyboard(keyboard, mKeyDetector); + tracker.setKeyDetector(mKeyDetector); } mKeyDetector.setProximityThreshold(keyboard.getMostCommonKeyWidth()); mPopupPanelCache.clear(); @@ -399,7 +399,7 @@ public class LatinKeyboardBaseView extends KeyboardView { final PopupMiniKeyboardView miniKeyboardView = (PopupMiniKeyboardView)container.findViewById(R.id.mini_keyboard_view); - miniKeyboardView.setOnKeyboardActionListener(new KeyboardActionListener() { + miniKeyboardView.setKeyboardActionListener(new KeyboardActionListener() { @Override public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) { mKeyboardActionListener.onCodeInput(primaryCode, keyCodes, x, y); @@ -489,9 +489,9 @@ public class LatinKeyboardBaseView extends KeyboardView { new PointerTracker(i, getContext(), mKeyTimerHandler, mKeyDetector, this, mPointerQueue); if (keyboard != null) - tracker.setKeyboard(keyboard, mKeyDetector); + tracker.setKeyDetector(mKeyDetector); if (listener != null) - tracker.setOnKeyboardActionListener(listener); + tracker.setKeyboardActionListener(listener); pointers.add(tracker); } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 510bc16b4..39d607d95 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -106,7 +106,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { } private boolean invokeOnKey(int primaryCode) { - getOnKeyboardActionListener().onCodeInput(primaryCode, null, + getKeyboardActionListener().onCodeInput(primaryCode, null, KeyboardActionListener.NOT_A_TOUCH_COORDINATE, KeyboardActionListener.NOT_A_TOUCH_COORDINATE); return true; diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java index 69005db57..1ec0dda15 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java @@ -37,7 +37,7 @@ public class MiniKeyboardKeyDetector extends KeyDetector { @Override public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) { - final List keys = getKeys(); + final List keys = getKeyboard().getKeys(); final int touchX = getTouchX(x); final int touchY = getTouchY(y); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index ca90342b1..c00a66954 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -118,9 +118,9 @@ public class PointerTracker { mDrawingProxy = drawingProxy; mKeyTimerHandler = keyTimerHandler; mPointerTrackerQueue = queue; // This is null for non-distinct multi-touch device. - mKeyDetector = keyDetector; - mKeyboardSwitcher = KeyboardSwitcher.getInstance(); mKeyState = new PointerTrackerKeyState(keyDetector); + setKeyDetectorInner(keyDetector); + mKeyboardSwitcher = KeyboardSwitcher.getInstance(); final Resources res = context.getResources(); mConfigSlidingKeyInputEnabled = res.getBoolean(R.bool.config_sliding_key_input_enabled); mDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start); @@ -134,7 +134,7 @@ public class PointerTracker { mSubtypeSwitcher = SubtypeSwitcher.getInstance(); } - public void setOnKeyboardActionListener(KeyboardActionListener listener) { + public void setKeyboardActionListener(KeyboardActionListener listener) { mListener = listener; } @@ -195,15 +195,19 @@ public class PointerTracker { mListener.onCancelInput(); } - public void setKeyboard(Keyboard keyboard, KeyDetector keyDetector) { - if (keyboard == null || keyDetector == null) - throw new NullPointerException(); - mKeyboard = keyboard; - mKeys = keyboard.getKeys(); + public void setKeyDetectorInner(KeyDetector keyDetector) { mKeyDetector = keyDetector; + mKeyboard = keyDetector.getKeyboard(); + mKeys = mKeyboard.getKeys(); mKeyState.setKeyDetector(keyDetector); - final int keyQuarterWidth = keyboard.getKeyWidth() / 4; + final int keyQuarterWidth = mKeyboard.getKeyWidth() / 4; mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth; + } + + public void setKeyDetector(KeyDetector keyDetector) { + if (keyDetector == null) + throw new NullPointerException(); + setKeyDetectorInner(keyDetector); // Mark that keyboard layout has been changed. mKeyboardLayoutHasBeenChanged = true; } diff --git a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java index 6e2b60c30..5a12db248 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java @@ -39,8 +39,10 @@ public class PointerTrackerKeyState { private int mLastX; private int mLastY; - public PointerTrackerKeyState(KeyDetector keyDetecor) { - mKeyDetector = keyDetecor; + public PointerTrackerKeyState(KeyDetector keyDetector) { + if (keyDetector == null) + throw new NullPointerException(); + mKeyDetector = keyDetector; } public void setKeyDetector(KeyDetector keyDetector) {