Let KeyDetector hold Keyboard

Bug: 4768084
Change-Id: Ia28d6971fc59086dd4e6fedc9fd1b50f13b59854
main
Tadashi G. Takaoka 2011-07-07 22:31:29 -07:00
parent 1c9817f0e6
commit 5a7a696aff
7 changed files with 33 additions and 28 deletions

View File

@ -73,11 +73,10 @@ public class KeyDetector {
return y + mCorrectionY;
}
protected List<Key> 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<Key> keys = getKeys();
final List<Key> 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<Key> keys = getKeys();
final List<Key> keys = getKeyboard().getKeys();
final int touchX = getTouchX(x);
final int touchY = getTouchY(y);

View File

@ -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.

View File

@ -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);
}

View File

@ -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;

View File

@ -37,7 +37,7 @@ public class MiniKeyboardKeyDetector extends KeyDetector {
@Override
public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) {
final List<Key> keys = getKeys();
final List<Key> keys = getKeyboard().getKeys();
final int touchX = getTouchX(x);
final int touchY = getTouchY(y);

View File

@ -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;
}

View File

@ -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) {