Fix that long pressing shift on symbol keyboard registers caps lock code
Bug: 5088376 Change-Id: I586a9fb685f3443aa22fd877df52b36247c4f858
This commit is contained in:
parent
60ccbe16ee
commit
851c3267d4
2 changed files with 32 additions and 30 deletions
|
@ -77,6 +77,8 @@ public class Keyboard {
|
||||||
public static final int CODE_CLOSING_SQUARE_BRACKET = ']';
|
public static final int CODE_CLOSING_SQUARE_BRACKET = ']';
|
||||||
public static final int CODE_CLOSING_CURLY_BRACKET = '}';
|
public static final int CODE_CLOSING_CURLY_BRACKET = '}';
|
||||||
public static final int CODE_CLOSING_ANGLE_BRACKET = '>';
|
public static final int CODE_CLOSING_ANGLE_BRACKET = '>';
|
||||||
|
public static final int CODE_DIGIT0 = '0';
|
||||||
|
public static final int CODE_PLUS = '+';
|
||||||
|
|
||||||
|
|
||||||
/** Special keys code. These should be aligned with values/keycodes.xml */
|
/** Special keys code. These should be aligned with values/keycodes.xml */
|
||||||
|
|
|
@ -53,55 +53,55 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) {
|
public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) {
|
||||||
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
final Keyboard keyboard = getKeyboard();
|
||||||
if (latinKeyboard != null
|
if (keyboard instanceof LatinKeyboard) {
|
||||||
&& (latinKeyboard.isPhoneKeyboard() || latinKeyboard.isNumberKeyboard())) {
|
final LatinKeyboard latinKeyboard = (LatinKeyboard)keyboard;
|
||||||
// Phone and number keyboard never shows popup preview (except language switch).
|
if (latinKeyboard.isPhoneKeyboard() || latinKeyboard.isNumberKeyboard()) {
|
||||||
|
// Phone and number keyboard never shows popup preview.
|
||||||
super.setKeyPreviewPopupEnabled(false, delay);
|
super.setKeyPreviewPopupEnabled(false, delay);
|
||||||
} else {
|
return;
|
||||||
super.setKeyPreviewPopupEnabled(previewEnabled, delay);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
super.setKeyPreviewPopupEnabled(previewEnabled, delay);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setKeyboard(Keyboard newKeyboard) {
|
public void setKeyboard(Keyboard newKeyboard) {
|
||||||
super.setKeyboard(newKeyboard);
|
super.setKeyboard(newKeyboard);
|
||||||
// One-seventh of the keyboard width seems like a reasonable threshold
|
// One-seventh of the keyboard width seems like a reasonable threshold
|
||||||
mJumpThresholdSquare = newKeyboard.getMinWidth() / 7;
|
final int jumpThreshold = newKeyboard.getMinWidth() / 7;
|
||||||
mJumpThresholdSquare *= mJumpThresholdSquare;
|
mJumpThresholdSquare = jumpThreshold * jumpThreshold;
|
||||||
}
|
|
||||||
|
|
||||||
private LatinKeyboard getLatinKeyboard() {
|
|
||||||
Keyboard keyboard = getKeyboard();
|
|
||||||
if (keyboard instanceof LatinKeyboard) {
|
|
||||||
return (LatinKeyboard)keyboard;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) {
|
public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) {
|
||||||
final LatinKeyboard currentKeyboard = getLatinKeyboard();
|
final Keyboard keyboard = getKeyboard();
|
||||||
// We should not set text fade factor to the keyboard which does not display the language on
|
// We should not set text fade factor to the keyboard which does not display the language on
|
||||||
// its spacebar.
|
// its spacebar.
|
||||||
if (currentKeyboard != null && currentKeyboard == oldKeyboard)
|
if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) {
|
||||||
currentKeyboard.setSpacebarTextFadeFactor(fadeFactor, this);
|
((LatinKeyboard)keyboard).setSpacebarTextFadeFactor(fadeFactor, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onLongPress(Key key, PointerTracker tracker) {
|
protected boolean onLongPress(Key key, PointerTracker tracker) {
|
||||||
int primaryCode = key.mCode;
|
final int primaryCode = key.mCode;
|
||||||
|
final Keyboard keyboard = getKeyboard();
|
||||||
|
if (keyboard instanceof LatinKeyboard) {
|
||||||
|
final LatinKeyboard latinKeyboard = (LatinKeyboard) keyboard;
|
||||||
|
if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.isPhoneKeyboard()) {
|
||||||
|
tracker.onLongPressed();
|
||||||
|
// Long pressing on 0 in phone number keypad gives you a '+'.
|
||||||
|
return invokeOnKey(Keyboard.CODE_PLUS);
|
||||||
|
}
|
||||||
|
if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.isAlphaKeyboard()) {
|
||||||
|
tracker.onLongPressed();
|
||||||
|
return invokeOnKey(Keyboard.CODE_CAPSLOCK);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) {
|
if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) {
|
||||||
tracker.onLongPressed();
|
tracker.onLongPressed();
|
||||||
// Both long pressing settings key and space key invoke IME switcher dialog.
|
// Both long pressing settings key and space key invoke IME switcher dialog.
|
||||||
return invokeOnKey(Keyboard.CODE_SETTINGS_LONGPRESS);
|
return invokeOnKey(Keyboard.CODE_SETTINGS_LONGPRESS);
|
||||||
} else if (primaryCode == '0' && getLatinKeyboard().isPhoneKeyboard()) {
|
|
||||||
tracker.onLongPressed();
|
|
||||||
// Long pressing on 0 in phone number keypad gives you a '+'.
|
|
||||||
return invokeOnKey('+');
|
|
||||||
} else if (primaryCode == Keyboard.CODE_SHIFT) {
|
|
||||||
tracker.onLongPressed();
|
|
||||||
return invokeOnKey(Keyboard.CODE_CAPSLOCK);
|
|
||||||
} else {
|
} else {
|
||||||
return super.onLongPress(key, tracker);
|
return super.onLongPress(key, tracker);
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent me) {
|
public boolean onTouchEvent(MotionEvent me) {
|
||||||
if (getLatinKeyboard() == null) return true;
|
if (getKeyboard() == null) return true;
|
||||||
|
|
||||||
// If there was a sudden jump, return without processing the actual motion event.
|
// If there was a sudden jump, return without processing the actual motion event.
|
||||||
if (handleSuddenJump(me)) {
|
if (handleSuddenJump(me)) {
|
||||||
|
|
Loading…
Reference in a new issue