From 576f8a5b72b550c5d610ccf9014e19db4a9cb8c9 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Tue, 28 Jan 2014 16:54:07 +0900 Subject: [PATCH] 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 --- .../keyboard/EmojiPalettesView.java | 20 ++++++++----------- .../keyboard/internal/KeyboardCodesSet.java | 3 +++ .../keyboard/internal/KeyboardState.java | 2 ++ .../android/inputmethod/latin/Constants.java | 4 +++- .../latin/inputlogic/InputLogic.java | 4 ++++ 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java index 36ebbb589..672759aee 100644 --- a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java +++ b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java @@ -487,24 +487,20 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange deleteKey.setTag(Constants.CODE_DELETE); deleteKey.setOnTouchListener(mDeleteKeyOnTouchListener); - // alphabetKey depends only on OnTouchListener as it does everything in key-press in - // ACTION_DOWN. + // alphabetKey, alphabetKey2, and spaceKey depend 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 + // 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); alphabetKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId); - alphabetKey.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL); + alphabetKey.setTag(Constants.CODE_ALPHA_FROM_EMOJI); alphabetKey.setOnTouchListener(this); - - // alphabetKey2 depends only on OnTouchListener as it does everything in key-press in - // ACTION_DOWN. + alphabetKey.setOnClickListener(this); final ImageView alphabetKey2 = (ImageView)findViewById(R.id.emoji_keyboard_alphabet2); alphabetKey2.setBackgroundResource(mEmojiFunctionalKeyBackgroundId); - alphabetKey2.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL); + alphabetKey2.setTag(Constants.CODE_ALPHA_FROM_EMOJI); alphabetKey2.setOnTouchListener(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. + alphabetKey2.setOnClickListener(this); final ImageView spaceKey = (ImageView)findViewById(R.id.emoji_keyboard_space); spaceKey.setBackgroundResource(mKeyBackgroundId); spaceKey.setTag(Constants.CODE_SPACE); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java index dc815e57d..78809d53b 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java @@ -54,6 +54,7 @@ public final class KeyboardCodesSet { "key_shift_enter", "key_language_switch", "key_emoji", + "key_alpha_from_emoji", "key_unspecified", "key_left_parenthesis", "key_right_parenthesis", @@ -91,6 +92,7 @@ public final class KeyboardCodesSet { Constants.CODE_SHIFT_ENTER, Constants.CODE_LANGUAGE_SWITCH, Constants.CODE_EMOJI, + Constants.CODE_ALPHA_FROM_EMOJI, Constants.CODE_UNSPECIFIED, CODE_LEFT_PARENTHESIS, CODE_RIGHT_PARENTHESIS, @@ -119,6 +121,7 @@ public final class KeyboardCodesSet { DEFAULT[13], DEFAULT[14], DEFAULT[15], + DEFAULT[16], CODE_RIGHT_PARENTHESIS, CODE_LEFT_PARENTHESIS, CODE_GREATER_THAN_SIGN, diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index 0c80ce206..ec0b5c95f 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -645,6 +645,8 @@ public final class KeyboardState { updateAlphabetShiftState(autoCaps, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); } else if (code == Constants.CODE_EMOJI) { setEmojiKeyboard(); + } else if (code == Constants.CODE_ALPHA_FROM_EMOJI) { + setAlphabetKeyboard(); } } diff --git a/java/src/com/android/inputmethod/latin/Constants.java b/java/src/com/android/inputmethod/latin/Constants.java index 0477133d7..0b396b1de 100644 --- a/java/src/com/android/inputmethod/latin/Constants.java +++ b/java/src/com/android/inputmethod/latin/Constants.java @@ -217,8 +217,9 @@ public final class Constants { public static final int CODE_EMOJI = -11; public static final int CODE_SHIFT_ENTER = -12; 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. - public static final int CODE_UNSPECIFIED = -14; + public static final int CODE_UNSPECIFIED = -15; public static boolean isLetterCode(final int code) { return code >= CODE_SPACE; @@ -241,6 +242,7 @@ public final class Constants { case CODE_UNSPECIFIED: return "unspec"; case CODE_TAB: return "tab"; case CODE_ENTER: return "enter"; + case CODE_ALPHA_FROM_EMOJI: return "alpha"; default: if (code < CODE_SPACE) return String.format("'\\u%02x'", code); if (code < 0x100) return String.format("'%c'", code); diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 43d75330d..16e032051 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -349,6 +349,10 @@ public final class InputLogic { didAutoCorrect = handleNonSpecialCharacter(settingsValues, Constants.CODE_ENTER, x, y, spaceState, keyboardSwitcher, handler); 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: didAutoCorrect = handleNonSpecialCharacter(settingsValues, code, x, y, spaceState, keyboardSwitcher, handler);