Cleanup KeyboardActionListener interface
Change-Id: I851eaea479f1590fd404a7a37a9a35d1bdcd378cmain
parent
cb2469ae17
commit
8aa3f5a3ad
|
@ -40,10 +40,10 @@ public interface KeyboardActionListener {
|
||||||
void onRelease(int primaryCode);
|
void onRelease(int primaryCode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a key press to the listener.
|
* Send a key code to the listener.
|
||||||
*
|
*
|
||||||
* @param primaryCode
|
* @param primaryCode
|
||||||
* this is the key that was pressed
|
* this is the code of the key that was pressed
|
||||||
* @param keyCodes
|
* @param keyCodes
|
||||||
* the codes for all the possible alternative keys with
|
* the codes for all the possible alternative keys with
|
||||||
* the primary code being the first. If the primary key
|
* the primary code being the first. If the primary key
|
||||||
|
@ -60,7 +60,7 @@ public interface KeyboardActionListener {
|
||||||
* y-coordinate pixel of touched event. If onKey is not called by onTouchEvent,
|
* y-coordinate pixel of touched event. If onKey is not called by onTouchEvent,
|
||||||
* the value should be NOT_A_TOUCH_COORDINATE.
|
* the value should be NOT_A_TOUCH_COORDINATE.
|
||||||
*/
|
*/
|
||||||
void onKey(int primaryCode, int[] keyCodes, int x, int y);
|
void onCodeInput(int primaryCode, int[] keyCodes, int x, int y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a sequence of characters to the listener.
|
* Sends a sequence of characters to the listener.
|
||||||
|
@ -68,32 +68,15 @@ public interface KeyboardActionListener {
|
||||||
* @param text
|
* @param text
|
||||||
* the sequence of characters to be displayed.
|
* the sequence of characters to be displayed.
|
||||||
*/
|
*/
|
||||||
void onText(CharSequence text);
|
void onTextInput(CharSequence text);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when user released a finger outside any key.
|
* Called when user released a finger outside any key.
|
||||||
*/
|
*/
|
||||||
void onCancel();
|
void onCancelInput();
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the user quickly moves the finger from right to
|
|
||||||
* left.
|
|
||||||
*/
|
|
||||||
void swipeLeft();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the user quickly moves the finger from left to
|
|
||||||
* right.
|
|
||||||
*/
|
|
||||||
void swipeRight();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the user quickly moves the finger from up to down.
|
* Called when the user quickly moves the finger from up to down.
|
||||||
*/
|
*/
|
||||||
void swipeDown();
|
void onSwipeDown();
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the user quickly moves the finger from down to up.
|
|
||||||
*/
|
|
||||||
void swipeUp();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -409,31 +409,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
float velocityY) {
|
float velocityY) {
|
||||||
final float absX = Math.abs(velocityX);
|
final float absX = Math.abs(velocityX);
|
||||||
final float absY = Math.abs(velocityY);
|
final float absY = Math.abs(velocityY);
|
||||||
float deltaX = me2.getX() - me1.getX();
|
|
||||||
float deltaY = me2.getY() - me1.getY();
|
float deltaY = me2.getY() - me1.getY();
|
||||||
int travelX = getWidth() / 2; // Half the keyboard width
|
|
||||||
int travelY = getHeight() / 2; // Half the keyboard height
|
int travelY = getHeight() / 2; // Half the keyboard height
|
||||||
mSwipeTracker.computeCurrentVelocity(1000);
|
mSwipeTracker.computeCurrentVelocity(1000);
|
||||||
final float endingVelocityX = mSwipeTracker.getXVelocity();
|
|
||||||
final float endingVelocityY = mSwipeTracker.getYVelocity();
|
final float endingVelocityY = mSwipeTracker.getYVelocity();
|
||||||
if (velocityX > mSwipeThreshold && absY < absX && deltaX > travelX) {
|
if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
|
||||||
if (mDisambiguateSwipe && endingVelocityX >= velocityX / 4) {
|
|
||||||
swipeRight();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else if (velocityX < -mSwipeThreshold && absY < absX && deltaX < -travelX) {
|
|
||||||
if (mDisambiguateSwipe && endingVelocityX <= velocityX / 4) {
|
|
||||||
swipeLeft();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else if (velocityY < -mSwipeThreshold && absX < absY && deltaY < -travelY) {
|
|
||||||
if (mDisambiguateSwipe && endingVelocityY <= velocityY / 4) {
|
|
||||||
swipeUp();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
|
|
||||||
if (mDisambiguateSwipe && endingVelocityY >= velocityY / 4) {
|
if (mDisambiguateSwipe && endingVelocityY >= velocityY / 4) {
|
||||||
swipeDown();
|
onSwipeDown();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1089,14 +1071,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
private void onLongPressShiftKey(PointerTracker tracker) {
|
private void onLongPressShiftKey(PointerTracker tracker) {
|
||||||
tracker.setAlreadyProcessed();
|
tracker.setAlreadyProcessed();
|
||||||
mPointerQueue.remove(tracker);
|
mPointerQueue.remove(tracker);
|
||||||
mKeyboardActionListener.onKey(Keyboard.CODE_CAPSLOCK, null, 0, 0);
|
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) {
|
private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) {
|
||||||
// When shift key is double tapped, the first tap is correctly processed as usual tap. And
|
// When shift key is double tapped, the first tap is correctly processed as usual tap. And
|
||||||
// the second tap is treated as this double tap event, so that we need not mark tracker
|
// the second tap is treated as this double tap event, so that we need not mark tracker
|
||||||
// calling setAlreadyProcessed() nor remove the tracker from mPointerQueueueue.
|
// calling setAlreadyProcessed() nor remove the tracker from mPointerQueueueue.
|
||||||
mKeyboardActionListener.onKey(Keyboard.CODE_CAPSLOCK, null, 0, 0);
|
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private View inflateMiniKeyboardContainer(Key popupKey) {
|
private View inflateMiniKeyboardContainer(Key popupKey) {
|
||||||
|
@ -1111,36 +1093,24 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
(KeyboardView)container.findViewById(R.id.KeyboardView);
|
(KeyboardView)container.findViewById(R.id.KeyboardView);
|
||||||
miniKeyboard.setOnKeyboardActionListener(new KeyboardActionListener() {
|
miniKeyboard.setOnKeyboardActionListener(new KeyboardActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onKey(int primaryCode, int[] keyCodes, int x, int y) {
|
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
||||||
mKeyboardActionListener.onKey(primaryCode, keyCodes, x, y);
|
mKeyboardActionListener.onCodeInput(primaryCode, keyCodes, x, y);
|
||||||
dismissPopupKeyboard();
|
dismissPopupKeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onText(CharSequence text) {
|
public void onTextInput(CharSequence text) {
|
||||||
mKeyboardActionListener.onText(text);
|
mKeyboardActionListener.onTextInput(text);
|
||||||
dismissPopupKeyboard();
|
dismissPopupKeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel() {
|
public void onCancelInput() {
|
||||||
dismissPopupKeyboard();
|
dismissPopupKeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void swipeLeft() {
|
public void onSwipeDown() {
|
||||||
// Nothing to do.
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void swipeRight() {
|
|
||||||
// Nothing to do.
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void swipeUp() {
|
|
||||||
// Nothing to do.
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void swipeDown() {
|
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -1461,20 +1431,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
mPointerQueue.remove(tracker);
|
mPointerQueue.remove(tracker);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void swipeRight() {
|
protected void onSwipeDown() {
|
||||||
mKeyboardActionListener.swipeRight();
|
mKeyboardActionListener.onSwipeDown();
|
||||||
}
|
|
||||||
|
|
||||||
protected void swipeLeft() {
|
|
||||||
mKeyboardActionListener.swipeLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void swipeUp() {
|
|
||||||
mKeyboardActionListener.swipeUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void swipeDown() {
|
|
||||||
mKeyboardActionListener.swipeDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closing() {
|
public void closing() {
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class LatinKeyboardView extends KeyboardView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean invokeOnKey(int primaryCode) {
|
private boolean invokeOnKey(int primaryCode) {
|
||||||
getOnKeyboardActionListener().onKey(primaryCode, null,
|
getOnKeyboardActionListener().onCodeInput(primaryCode, null,
|
||||||
KeyboardView.NOT_A_TOUCH_COORDINATE,
|
KeyboardView.NOT_A_TOUCH_COORDINATE,
|
||||||
KeyboardView.NOT_A_TOUCH_COORDINATE);
|
KeyboardView.NOT_A_TOUCH_COORDINATE);
|
||||||
return true;
|
return true;
|
||||||
|
@ -205,7 +205,7 @@ public class LatinKeyboardView extends KeyboardView {
|
||||||
if (me.getAction() == MotionEvent.ACTION_UP) {
|
if (me.getAction() == MotionEvent.ACTION_UP) {
|
||||||
int languageDirection = keyboard.getLanguageChangeDirection();
|
int languageDirection = keyboard.getLanguageChangeDirection();
|
||||||
if (languageDirection != 0) {
|
if (languageDirection != 0) {
|
||||||
getOnKeyboardActionListener().onKey(
|
getOnKeyboardActionListener().onCodeInput(
|
||||||
languageDirection == 1
|
languageDirection == 1
|
||||||
? Keyboard.CODE_NEXT_LANGUAGE : Keyboard.CODE_PREV_LANGUAGE,
|
? Keyboard.CODE_NEXT_LANGUAGE : Keyboard.CODE_PREV_LANGUAGE,
|
||||||
null, mLastX, mLastY);
|
null, mLastX, mLastY);
|
||||||
|
|
|
@ -92,19 +92,13 @@ public class PointerTracker {
|
||||||
@Override
|
@Override
|
||||||
public void onRelease(int primaryCode) {}
|
public void onRelease(int primaryCode) {}
|
||||||
@Override
|
@Override
|
||||||
public void onKey(int primaryCode, int[] keyCodes, int x, int y) {}
|
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {}
|
||||||
@Override
|
@Override
|
||||||
public void onText(CharSequence text) {}
|
public void onTextInput(CharSequence text) {}
|
||||||
@Override
|
@Override
|
||||||
public void onCancel() {}
|
public void onCancelInput() {}
|
||||||
@Override
|
@Override
|
||||||
public void swipeLeft() {}
|
public void onSwipeDown() {}
|
||||||
@Override
|
|
||||||
public void swipeRight() {}
|
|
||||||
@Override
|
|
||||||
public void swipeDown() {}
|
|
||||||
@Override
|
|
||||||
public void swipeUp() {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public PointerTracker(int id, UIHandler handler, KeyDetector keyDetector, UIProxy proxy,
|
public PointerTracker(int id, UIHandler handler, KeyDetector keyDetector, UIProxy proxy,
|
||||||
|
@ -136,17 +130,17 @@ public class PointerTracker {
|
||||||
mListener.onPress(primaryCode);
|
mListener.onPress(primaryCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callListenerOnKey(int primaryCode, int[] keyCodes, int x, int y) {
|
private void callListenerOnCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
||||||
if (DEBUG_LISTENER)
|
if (DEBUG_LISTENER)
|
||||||
Log.d(TAG, "onKey : " + keyCodePrintable(primaryCode)
|
Log.d(TAG, "onCodeInput: " + keyCodePrintable(primaryCode)
|
||||||
+ " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y);
|
+ " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y);
|
||||||
mListener.onKey(primaryCode, keyCodes, x, y);
|
mListener.onCodeInput(primaryCode, keyCodes, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callListenerOnText(CharSequence text) {
|
private void callListenerOnTextInput(CharSequence text) {
|
||||||
if (DEBUG_LISTENER)
|
if (DEBUG_LISTENER)
|
||||||
Log.d(TAG, "onText : text=" + text);
|
Log.d(TAG, "onTextInput: text=" + text);
|
||||||
mListener.onText(text);
|
mListener.onTextInput(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callListenerOnRelease(int primaryCode) {
|
private void callListenerOnRelease(int primaryCode) {
|
||||||
|
@ -155,10 +149,10 @@ public class PointerTracker {
|
||||||
mListener.onRelease(primaryCode);
|
mListener.onRelease(primaryCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callListenerOnCancel() {
|
private void callListenerOnCancelInput() {
|
||||||
if (DEBUG_LISTENER)
|
if (DEBUG_LISTENER)
|
||||||
Log.d(TAG, "onCancel");
|
Log.d(TAG, "onCancelInput");
|
||||||
mListener.onCancel();
|
mListener.onCancelInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyboard(Keyboard keyboard, Key[] keys, float keyHysteresisDistance) {
|
public void setKeyboard(Keyboard keyboard, Key[] keys, float keyHysteresisDistance) {
|
||||||
|
@ -446,11 +440,11 @@ public class PointerTracker {
|
||||||
private void detectAndSendKey(int index, int x, int y, long eventTime) {
|
private void detectAndSendKey(int index, int x, int y, long eventTime) {
|
||||||
final Key key = getKey(index);
|
final Key key = getKey(index);
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
callListenerOnCancel();
|
callListenerOnCancelInput();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (key.mOutputText != null) {
|
if (key.mOutputText != null) {
|
||||||
callListenerOnText(key.mOutputText);
|
callListenerOnTextInput(key.mOutputText);
|
||||||
callListenerOnRelease(key.mCodes[0]);
|
callListenerOnRelease(key.mCodes[0]);
|
||||||
} else {
|
} else {
|
||||||
int code = key.mCodes[0];
|
int code = key.mCodes[0];
|
||||||
|
@ -459,7 +453,7 @@ public class PointerTracker {
|
||||||
// Multi-tap
|
// Multi-tap
|
||||||
if (mInMultiTap) {
|
if (mInMultiTap) {
|
||||||
if (mTapCount != -1) {
|
if (mTapCount != -1) {
|
||||||
callListenerOnKey(Keyboard.CODE_DELETE, KEY_DELETE, x, y);
|
callListenerOnCodeInput(Keyboard.CODE_DELETE, KEY_DELETE, x, y);
|
||||||
} else {
|
} else {
|
||||||
mTapCount = 0;
|
mTapCount = 0;
|
||||||
}
|
}
|
||||||
|
@ -480,7 +474,7 @@ public class PointerTracker {
|
||||||
codes[1] = codes[0];
|
codes[1] = codes[0];
|
||||||
codes[0] = code;
|
codes[0] = code;
|
||||||
}
|
}
|
||||||
callListenerOnKey(code, codes, x, y);
|
callListenerOnCodeInput(code, codes, x, y);
|
||||||
callListenerOnRelease(code);
|
callListenerOnRelease(code);
|
||||||
}
|
}
|
||||||
mLastSentIndex = index;
|
mLastSentIndex = index;
|
||||||
|
|
|
@ -1047,7 +1047,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
// Implementation of KeyboardViewListener
|
// Implementation of KeyboardViewListener
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onKey(int primaryCode, int[] keyCodes, int x, int y) {
|
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
||||||
long when = SystemClock.uptimeMillis();
|
long when = SystemClock.uptimeMillis();
|
||||||
if (primaryCode != Keyboard.CODE_DELETE || when > mLastKeyTime + QUICK_PRESS) {
|
if (primaryCode != Keyboard.CODE_DELETE || when > mLastKeyTime + QUICK_PRESS) {
|
||||||
mDeleteCount = 0;
|
mDeleteCount = 0;
|
||||||
|
@ -1117,7 +1117,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onText(CharSequence text) {
|
public void onTextInput(CharSequence text) {
|
||||||
mVoiceConnector.commitVoiceInput();
|
mVoiceConnector.commitVoiceInput();
|
||||||
InputConnection ic = getCurrentInputConnection();
|
InputConnection ic = getCurrentInputConnection();
|
||||||
if (ic == null) return;
|
if (ic == null) return;
|
||||||
|
@ -1135,7 +1135,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel() {
|
public void onCancelInput() {
|
||||||
// User released a finger outside any key
|
// User released a finger outside any key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1257,7 +1257,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
} else {
|
} else {
|
||||||
// Some keys, such as [eszett], have upper case as multi-characters.
|
// Some keys, such as [eszett], have upper case as multi-characters.
|
||||||
String upperCase = new String(new int[] {code}, 0, 1).toUpperCase();
|
String upperCase = new String(new int[] {code}, 0, 1).toUpperCase();
|
||||||
onText(upperCase);
|
onTextInput(upperCase);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1570,7 +1570,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
LatinImeLogger.logOnManualSuggestion(
|
LatinImeLogger.logOnManualSuggestion(
|
||||||
"", suggestion.toString(), index, suggestions.mWords);
|
"", suggestion.toString(), index, suggestions.mWords);
|
||||||
final char primaryCode = suggestion.charAt(0);
|
final char primaryCode = suggestion.charAt(0);
|
||||||
onKey(primaryCode, new int[]{primaryCode}, KeyboardView.NOT_A_TOUCH_COORDINATE,
|
onCodeInput(primaryCode, new int[]{primaryCode}, KeyboardView.NOT_A_TOUCH_COORDINATE,
|
||||||
KeyboardView.NOT_A_TOUCH_COORDINATE);
|
KeyboardView.NOT_A_TOUCH_COORDINATE);
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
|
@ -1866,25 +1866,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void swipeRight() {
|
public void onSwipeDown() {
|
||||||
// Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void swipeLeft() {
|
|
||||||
// Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void swipeDown() {
|
|
||||||
handleClose();
|
handleClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void swipeUp() {
|
|
||||||
// Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPress(int primaryCode) {
|
public void onPress(int primaryCode) {
|
||||||
if (mKeyboardSwitcher.isVibrateAndSoundFeedbackRequired()) {
|
if (mKeyboardSwitcher.isVibrateAndSoundFeedbackRequired()) {
|
||||||
|
|
Loading…
Reference in New Issue