Fix inconsistent behavior with the back-to-the-main-keyboard key

With this patch, the back-to-the-main-keyboard in the Emoji
palette will be registered as a key-release action instead of
a key-press action, like switch-to-the-emoji-palette in the
main layout. This provides mroe consistent UX when the layout is
switched from the main layout to the Emoji palette then
switched back to the main layout.

BUG: 12464067
Change-Id: Ia0d0185db43234dfcfb7cee2677f3d199fe6ed96
This commit is contained in:
Yohei Yukawa 2014-01-28 16:54:07 +09:00
parent 437fa64af3
commit 576f8a5b72
5 changed files with 20 additions and 13 deletions

View File

@ -487,24 +487,20 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
deleteKey.setTag(Constants.CODE_DELETE); deleteKey.setTag(Constants.CODE_DELETE);
deleteKey.setOnTouchListener(mDeleteKeyOnTouchListener); deleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);
// alphabetKey depends only on OnTouchListener as it does everything in key-press in // alphabetKey, alphabetKey2, and spaceKey depend on {@link View.OnClickListener} as well as
// ACTION_DOWN. // {@link View.OnTouchListener}. {@link View.OnTouchListener} is used as the trigger of
// key-press, while {@link View.OnClickListener} is used as the trigger of key-release which
// does not occur if the event is canceled by moving off the finger from the view.
final ImageView alphabetKey = (ImageView)findViewById(R.id.emoji_keyboard_alphabet); final ImageView alphabetKey = (ImageView)findViewById(R.id.emoji_keyboard_alphabet);
alphabetKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId); alphabetKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
alphabetKey.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL); alphabetKey.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
alphabetKey.setOnTouchListener(this); alphabetKey.setOnTouchListener(this);
alphabetKey.setOnClickListener(this);
// alphabetKey2 depends only on OnTouchListener as it does everything in key-press in
// ACTION_DOWN.
final ImageView alphabetKey2 = (ImageView)findViewById(R.id.emoji_keyboard_alphabet2); final ImageView alphabetKey2 = (ImageView)findViewById(R.id.emoji_keyboard_alphabet2);
alphabetKey2.setBackgroundResource(mEmojiFunctionalKeyBackgroundId); alphabetKey2.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
alphabetKey2.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL); alphabetKey2.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
alphabetKey2.setOnTouchListener(this); alphabetKey2.setOnTouchListener(this);
alphabetKey2.setOnClickListener(this);
// spaceKey depends on {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
// {@link View.OnTouchListener} is used as the trigger of key-press while
// {@link View.OnClickListener} is used as the trigger of key-release which may not occur
// if the event is canceled by moving off the finger from the view.
final ImageView spaceKey = (ImageView)findViewById(R.id.emoji_keyboard_space); final ImageView spaceKey = (ImageView)findViewById(R.id.emoji_keyboard_space);
spaceKey.setBackgroundResource(mKeyBackgroundId); spaceKey.setBackgroundResource(mKeyBackgroundId);
spaceKey.setTag(Constants.CODE_SPACE); spaceKey.setTag(Constants.CODE_SPACE);

View File

@ -54,6 +54,7 @@ public final class KeyboardCodesSet {
"key_shift_enter", "key_shift_enter",
"key_language_switch", "key_language_switch",
"key_emoji", "key_emoji",
"key_alpha_from_emoji",
"key_unspecified", "key_unspecified",
"key_left_parenthesis", "key_left_parenthesis",
"key_right_parenthesis", "key_right_parenthesis",
@ -91,6 +92,7 @@ public final class KeyboardCodesSet {
Constants.CODE_SHIFT_ENTER, Constants.CODE_SHIFT_ENTER,
Constants.CODE_LANGUAGE_SWITCH, Constants.CODE_LANGUAGE_SWITCH,
Constants.CODE_EMOJI, Constants.CODE_EMOJI,
Constants.CODE_ALPHA_FROM_EMOJI,
Constants.CODE_UNSPECIFIED, Constants.CODE_UNSPECIFIED,
CODE_LEFT_PARENTHESIS, CODE_LEFT_PARENTHESIS,
CODE_RIGHT_PARENTHESIS, CODE_RIGHT_PARENTHESIS,
@ -119,6 +121,7 @@ public final class KeyboardCodesSet {
DEFAULT[13], DEFAULT[13],
DEFAULT[14], DEFAULT[14],
DEFAULT[15], DEFAULT[15],
DEFAULT[16],
CODE_RIGHT_PARENTHESIS, CODE_RIGHT_PARENTHESIS,
CODE_LEFT_PARENTHESIS, CODE_LEFT_PARENTHESIS,
CODE_GREATER_THAN_SIGN, CODE_GREATER_THAN_SIGN,

View File

@ -645,6 +645,8 @@ public final class KeyboardState {
updateAlphabetShiftState(autoCaps, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); updateAlphabetShiftState(autoCaps, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
} else if (code == Constants.CODE_EMOJI) { } else if (code == Constants.CODE_EMOJI) {
setEmojiKeyboard(); setEmojiKeyboard();
} else if (code == Constants.CODE_ALPHA_FROM_EMOJI) {
setAlphabetKeyboard();
} }
} }

View File

@ -217,8 +217,9 @@ public final class Constants {
public static final int CODE_EMOJI = -11; public static final int CODE_EMOJI = -11;
public static final int CODE_SHIFT_ENTER = -12; public static final int CODE_SHIFT_ENTER = -12;
public static final int CODE_SYMBOL_SHIFT = -13; public static final int CODE_SYMBOL_SHIFT = -13;
public static final int CODE_ALPHA_FROM_EMOJI = -14;
// Code value representing the code is not specified. // Code value representing the code is not specified.
public static final int CODE_UNSPECIFIED = -14; public static final int CODE_UNSPECIFIED = -15;
public static boolean isLetterCode(final int code) { public static boolean isLetterCode(final int code) {
return code >= CODE_SPACE; return code >= CODE_SPACE;
@ -241,6 +242,7 @@ public final class Constants {
case CODE_UNSPECIFIED: return "unspec"; case CODE_UNSPECIFIED: return "unspec";
case CODE_TAB: return "tab"; case CODE_TAB: return "tab";
case CODE_ENTER: return "enter"; case CODE_ENTER: return "enter";
case CODE_ALPHA_FROM_EMOJI: return "alpha";
default: default:
if (code < CODE_SPACE) return String.format("'\\u%02x'", code); if (code < CODE_SPACE) return String.format("'\\u%02x'", code);
if (code < 0x100) return String.format("'%c'", code); if (code < 0x100) return String.format("'%c'", code);

View File

@ -349,6 +349,10 @@ public final class InputLogic {
didAutoCorrect = handleNonSpecialCharacter(settingsValues, Constants.CODE_ENTER, didAutoCorrect = handleNonSpecialCharacter(settingsValues, Constants.CODE_ENTER,
x, y, spaceState, keyboardSwitcher, handler); x, y, spaceState, keyboardSwitcher, handler);
break; break;
case Constants.CODE_ALPHA_FROM_EMOJI:
// Note: Switching back from Emoji keyboard to the main keyboard is being handled in
// {@link KeyboardState#onCodeInput(int,int)}.
break;
default: default:
didAutoCorrect = handleNonSpecialCharacter(settingsValues, didAutoCorrect = handleNonSpecialCharacter(settingsValues,
code, x, y, spaceState, keyboardSwitcher, handler); code, x, y, spaceState, keyboardSwitcher, handler);