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