From e354a85ef44e13999aaefd735cef7f659090f6e8 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Wed, 20 Oct 2010 00:18:50 +0900 Subject: [PATCH] Manual merge of the following Gingerbread changes logically I8b38e280 Ia3929bb0 If925b546 I1062763d I901e36aa bug: 3100311 Change-Id: Ic7e01277ec816e77d34732599b2b9552668b81c2 --- java/res/drawable-hdpi/hint_popup.9.png | Bin 0 -> 226 bytes java/res/drawable-mdpi/hint_popup.9.png | Bin 0 -> 202 bytes java/res/xml/kbd_popup_narrow_template.xml | 10 +- java/res/xml/kbd_qwerty_black_row4.xml | 20 ++- java/res/xml/kbd_qwerty_row4.xml | 20 ++- java/res/xml/kbd_symbols.xml | 111 ++++++------ java/res/xml/kbd_symbols_black.xml | 100 +++++------ .../res/xml/kbd_symbols_black_row4_common.xml | 46 +++++ ...ls_black_row4_common_with_settings_key.xml | 50 ++++++ java/res/xml/kbd_symbols_black_row4_im.xml | 47 +++++ ...ymbols_black_row4_im_with_settings_key.xml | 51 ++++++ java/res/xml/kbd_symbols_row4_common.xml | 51 ++++++ ..._symbols_row4_common_with_settings_key.xml | 56 ++++++ java/res/xml/kbd_symbols_row4_im.xml | 52 ++++++ .../kbd_symbols_row4_im_with_settings_key.xml | 57 +++++++ java/res/xml/kbd_symbols_shift.xml | 109 ++++++------ java/res/xml/kbd_symbols_shift_black.xml | 98 ++++++----- .../kbd_symbols_shift_black_row4_common.xml | 44 +++++ ...ft_black_row4_common_with_settings_key.xml | 48 ++++++ .../xml/kbd_symbols_shift_black_row4_im.xml | 45 +++++ ..._shift_black_row4_im_with_settings_key.xml | 49 ++++++ .../res/xml/kbd_symbols_shift_row4_common.xml | 49 ++++++ ...ls_shift_row4_common_with_settings_key.xml | 54 ++++++ java/res/xml/kbd_symbols_shift_row4_im.xml | 50 ++++++ ...ymbols_shift_row4_im_with_settings_key.xml | 55 ++++++ java/res/xml/popup_at.xml | 39 +++++ java/res/xml/popup_slash.xml | 39 +++++ .../inputmethod/latin/KeyboardSwitcher.java | 161 ++++++++++-------- .../android/inputmethod/latin/LatinIME.java | 4 +- .../inputmethod/latin/LatinKeyboard.java | 71 ++++++-- .../latin/LatinKeyboardBaseView.java | 54 +++--- 31 files changed, 1301 insertions(+), 339 deletions(-) create mode 100644 java/res/drawable-hdpi/hint_popup.9.png create mode 100644 java/res/drawable-mdpi/hint_popup.9.png create mode 100644 java/res/xml/kbd_symbols_black_row4_common.xml create mode 100644 java/res/xml/kbd_symbols_black_row4_common_with_settings_key.xml create mode 100644 java/res/xml/kbd_symbols_black_row4_im.xml create mode 100644 java/res/xml/kbd_symbols_black_row4_im_with_settings_key.xml create mode 100644 java/res/xml/kbd_symbols_row4_common.xml create mode 100644 java/res/xml/kbd_symbols_row4_common_with_settings_key.xml create mode 100644 java/res/xml/kbd_symbols_row4_im.xml create mode 100644 java/res/xml/kbd_symbols_row4_im_with_settings_key.xml create mode 100644 java/res/xml/kbd_symbols_shift_black_row4_common.xml create mode 100644 java/res/xml/kbd_symbols_shift_black_row4_common_with_settings_key.xml create mode 100644 java/res/xml/kbd_symbols_shift_black_row4_im.xml create mode 100644 java/res/xml/kbd_symbols_shift_black_row4_im_with_settings_key.xml create mode 100644 java/res/xml/kbd_symbols_shift_row4_common.xml create mode 100644 java/res/xml/kbd_symbols_shift_row4_common_with_settings_key.xml create mode 100644 java/res/xml/kbd_symbols_shift_row4_im.xml create mode 100644 java/res/xml/kbd_symbols_shift_row4_im_with_settings_key.xml create mode 100644 java/res/xml/popup_at.xml create mode 100644 java/res/xml/popup_slash.xml diff --git a/java/res/drawable-hdpi/hint_popup.9.png b/java/res/drawable-hdpi/hint_popup.9.png new file mode 100644 index 0000000000000000000000000000000000000000..b5ec003e655b5cd6de5ca98e10bbf849aed0fe37 GIT binary patch literal 226 zcmeAS@N?(olHy`uVBq!ia0vp^MnG)I!3HEtepD0zDajJoh?3y^w370~qErUQl>DSr z1<%~X^wgl##FWaylc_d9MJ=8#jv*Dd-rO|gI-tPA8W3D{L~e8W7NuA#k(fma@AV&v z$TJ2CZM`;WX2%QGsJR|%C-cq}6@Y>Xd*(!!EZ)0e`wI?Ca3ag&<>o(k68H5rfPl)= zs_WGS|G6zssTs~=V`Tgpm#@ul`RQy0iv+`r-B%uJewT0nx`)Bj)z4*}Q$iB}N`Fe% literal 0 HcmV?d00001 diff --git a/java/res/drawable-mdpi/hint_popup.9.png b/java/res/drawable-mdpi/hint_popup.9.png new file mode 100644 index 0000000000000000000000000000000000000000..444cc26ee69c1e754a95d8c977e7169fab1e9321 GIT binary patch literal 202 zcmeAS@N?(olHy`uVBq!ia0vp^NDSr z1<%~X^wgl##FWaylc_d9MLC`>jv*Dd-rR8HI-tPg61cp=<$e9skb_IN1&Ff!Vs2Xf zAwW6M)g_A8)6_RZ^Els$z8#Z185lo_-DJFYYW`YACKe6>1&0O(Mx*8}br%=qmsS*A zviZ*!^s8dl?{yrZ&R1)!l$Wpndy)T%?g56ES7dENwbS1L?Pc(E^>bP0l+XkK - diff --git a/java/res/xml/kbd_qwerty_black_row4.xml b/java/res/xml/kbd_qwerty_black_row4.xml index 1718603fd..330ddda42 100644 --- a/java/res/xml/kbd_qwerty_black_row4.xml +++ b/java/res/xml/kbd_qwerty_black_row4.xml @@ -40,6 +40,7 @@ latin:keyWidth="40%p" /> + latin:codes="@integer/key_f1" /> + latin:codes="@integer/key_f1" /> @@ -153,6 +158,7 @@ latin:keyWidth="20%p" /> + latin:codes="@integer/key_f1" /> + latin:codes="@integer/key_f1" /> @@ -312,6 +323,7 @@ latin:iconPreview="@drawable/sym_keyboard_feedback_tab" /> - - - - - + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_black.xml b/java/res/xml/kbd_symbols_black.xml index b6a069c25..9e401a1cd 100644 --- a/java/res/xml/kbd_symbols_black.xml +++ b/java/res/xml/kbd_symbols_black.xml @@ -142,59 +142,63 @@ latin:keyEdgeFlags="right" /> - - - - - + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_black_row4_common.xml b/java/res/xml/kbd_symbols_black_row4_common.xml new file mode 100644 index 000000000..7433eca7f --- /dev/null +++ b/java/res/xml/kbd_symbols_black_row4_common.xml @@ -0,0 +1,46 @@ + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_black_row4_common_with_settings_key.xml b/java/res/xml/kbd_symbols_black_row4_common_with_settings_key.xml new file mode 100644 index 000000000..bbb169919 --- /dev/null +++ b/java/res/xml/kbd_symbols_black_row4_common_with_settings_key.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_black_row4_im.xml b/java/res/xml/kbd_symbols_black_row4_im.xml new file mode 100644 index 000000000..a1546b7b5 --- /dev/null +++ b/java/res/xml/kbd_symbols_black_row4_im.xml @@ -0,0 +1,47 @@ + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_black_row4_im_with_settings_key.xml b/java/res/xml/kbd_symbols_black_row4_im_with_settings_key.xml new file mode 100644 index 000000000..4cab461e7 --- /dev/null +++ b/java/res/xml/kbd_symbols_black_row4_im_with_settings_key.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_row4_common.xml b/java/res/xml/kbd_symbols_row4_common.xml new file mode 100644 index 000000000..ef7cdcaff --- /dev/null +++ b/java/res/xml/kbd_symbols_row4_common.xml @@ -0,0 +1,51 @@ + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_row4_common_with_settings_key.xml b/java/res/xml/kbd_symbols_row4_common_with_settings_key.xml new file mode 100644 index 000000000..54b85429c --- /dev/null +++ b/java/res/xml/kbd_symbols_row4_common_with_settings_key.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_row4_im.xml b/java/res/xml/kbd_symbols_row4_im.xml new file mode 100644 index 000000000..c7d679bc4 --- /dev/null +++ b/java/res/xml/kbd_symbols_row4_im.xml @@ -0,0 +1,52 @@ + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_row4_im_with_settings_key.xml b/java/res/xml/kbd_symbols_row4_im_with_settings_key.xml new file mode 100644 index 000000000..7cc209b6b --- /dev/null +++ b/java/res/xml/kbd_symbols_row4_im_with_settings_key.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_shift.xml b/java/res/xml/kbd_symbols_shift.xml index d83706b5c..b8f8faeb2 100644 --- a/java/res/xml/kbd_symbols_shift.xml +++ b/java/res/xml/kbd_symbols_shift.xml @@ -122,68 +122,63 @@ latin:keyEdgeFlags="right" /> - - - - - + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_shift_black.xml b/java/res/xml/kbd_symbols_shift_black.xml index e5f8abf6e..34684a65b 100644 --- a/java/res/xml/kbd_symbols_shift_black.xml +++ b/java/res/xml/kbd_symbols_shift_black.xml @@ -121,57 +121,63 @@ latin:keyEdgeFlags="right" /> - - - - - + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_shift_black_row4_common.xml b/java/res/xml/kbd_symbols_shift_black_row4_common.xml new file mode 100644 index 000000000..beb5b3d67 --- /dev/null +++ b/java/res/xml/kbd_symbols_shift_black_row4_common.xml @@ -0,0 +1,44 @@ + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_shift_black_row4_common_with_settings_key.xml b/java/res/xml/kbd_symbols_shift_black_row4_common_with_settings_key.xml new file mode 100644 index 000000000..97f882a5a --- /dev/null +++ b/java/res/xml/kbd_symbols_shift_black_row4_common_with_settings_key.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_shift_black_row4_im.xml b/java/res/xml/kbd_symbols_shift_black_row4_im.xml new file mode 100644 index 000000000..c0263c215 --- /dev/null +++ b/java/res/xml/kbd_symbols_shift_black_row4_im.xml @@ -0,0 +1,45 @@ + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_shift_black_row4_im_with_settings_key.xml b/java/res/xml/kbd_symbols_shift_black_row4_im_with_settings_key.xml new file mode 100644 index 000000000..14d6a0b51 --- /dev/null +++ b/java/res/xml/kbd_symbols_shift_black_row4_im_with_settings_key.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_shift_row4_common.xml b/java/res/xml/kbd_symbols_shift_row4_common.xml new file mode 100644 index 000000000..4d5199e88 --- /dev/null +++ b/java/res/xml/kbd_symbols_shift_row4_common.xml @@ -0,0 +1,49 @@ + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_shift_row4_common_with_settings_key.xml b/java/res/xml/kbd_symbols_shift_row4_common_with_settings_key.xml new file mode 100644 index 000000000..df570ea1b --- /dev/null +++ b/java/res/xml/kbd_symbols_shift_row4_common_with_settings_key.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_shift_row4_im.xml b/java/res/xml/kbd_symbols_shift_row4_im.xml new file mode 100644 index 000000000..69c609254 --- /dev/null +++ b/java/res/xml/kbd_symbols_shift_row4_im.xml @@ -0,0 +1,50 @@ + + + + + + + + + + diff --git a/java/res/xml/kbd_symbols_shift_row4_im_with_settings_key.xml b/java/res/xml/kbd_symbols_shift_row4_im_with_settings_key.xml new file mode 100644 index 000000000..aad6e400b --- /dev/null +++ b/java/res/xml/kbd_symbols_shift_row4_im_with_settings_key.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + diff --git a/java/res/xml/popup_at.xml b/java/res/xml/popup_at.xml new file mode 100644 index 000000000..4b19d4fd4 --- /dev/null +++ b/java/res/xml/popup_at.xml @@ -0,0 +1,39 @@ + + + + + + + + + diff --git a/java/res/xml/popup_slash.xml b/java/res/xml/popup_slash.xml new file mode 100644 index 000000000..1ace909ef --- /dev/null +++ b/java/res/xml/popup_slash.xml @@ -0,0 +1,39 @@ + + + + + + + + + diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 86dbf1f60..ec422174d 100644 --- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -29,14 +29,14 @@ import java.util.Locale; public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceChangeListener { - public static final int MODE_NONE = 0; - public static final int MODE_TEXT = 1; - public static final int MODE_SYMBOLS = 2; - public static final int MODE_PHONE = 3; - public static final int MODE_URL = 4; - public static final int MODE_EMAIL = 5; - public static final int MODE_IM = 6; - public static final int MODE_WEB = 7; + public static final int MODE_TEXT = 0; + public static final int MODE_URL = 1; + public static final int MODE_EMAIL = 2; + public static final int MODE_IM = 3; + public static final int MODE_WEB = 4; + public static final int MODE_PHONE = 5; + + public static final int MODE_NONE = -1; // Main keyboard layouts without the settings key public static final int KEYBOARDMODE_NORMAL = R.id.mode_normal; @@ -44,6 +44,13 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public static final int KEYBOARDMODE_EMAIL = R.id.mode_email; public static final int KEYBOARDMODE_IM = R.id.mode_im; public static final int KEYBOARDMODE_WEB = R.id.mode_webentry; + public static final int[] QWERTY_MODES = { + KEYBOARDMODE_NORMAL, + KEYBOARDMODE_URL, + KEYBOARDMODE_EMAIL, + KEYBOARDMODE_IM, + KEYBOARDMODE_WEB, + 0 /* for MODE_PHONE */ }; // Main keyboard layouts with the settings key public static final int KEYBOARDMODE_NORMAL_WITH_SETTINGS_KEY = R.id.mode_normal_with_settings_key; @@ -55,12 +62,45 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha R.id.mode_im_with_settings_key; public static final int KEYBOARDMODE_WEB_WITH_SETTINGS_KEY = R.id.mode_webentry_with_settings_key; + public static final int[] QWERTY_WITH_SETTINGS_KEY_MODES = { + KEYBOARDMODE_NORMAL_WITH_SETTINGS_KEY, + KEYBOARDMODE_URL_WITH_SETTINGS_KEY, + KEYBOARDMODE_EMAIL_WITH_SETTINGS_KEY, + KEYBOARDMODE_IM_WITH_SETTINGS_KEY, + KEYBOARDMODE_WEB_WITH_SETTINGS_KEY, + 0 /* for MODE_PHONE */ }; - // Symbols keyboard layout without the settings key - public static final int KEYBOARDMODE_SYMBOLS = R.id.mode_symbols; - // Symbols keyboard layout with the settings key - public static final int KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY = - R.id.mode_symbols_with_settings_key; + // Symbols keyboard layouts without the settings key + public static final int KEYBOARDMODE_SYMBOLS_NORMAL = R.id.mode_symbols_normal; + public static final int KEYBOARDMODE_SYMBOLS_URL = R.id.mode_symbols_url; + public static final int KEYBOARDMODE_SYMBOLS_EMAIL = R.id.mode_symbols_email; + public static final int KEYBOARDMODE_SYMBOLS_IM = R.id.mode_symbols_im; + public static final int KEYBOARDMODE_SYMBOLS_WEB = R.id.mode_symbols_webentry; + public static final int[] SYMBOLS_MODES = { + KEYBOARDMODE_SYMBOLS_NORMAL, + KEYBOARDMODE_SYMBOLS_URL, + KEYBOARDMODE_SYMBOLS_EMAIL, + KEYBOARDMODE_SYMBOLS_IM, + KEYBOARDMODE_SYMBOLS_WEB, + 0 /* for MODE_PHONE */ }; + // Symbols keyboard layouts with the settings key + public static final int KEYBOARDMODE_SYMBOLS_NORMAL_WITH_SETTINGS_KEY = + R.id.mode_symbols_normal_with_settings_key; + public static final int KEYBOARDMODE_SYMBOLS_URL_WITH_SETTINGS_KEY = + R.id.mode_symbols_url_with_settings_key; + public static final int KEYBOARDMODE_SYMBOLS_EMAIL_WITH_SETTINGS_KEY = + R.id.mode_symbols_email_with_settings_key; + public static final int KEYBOARDMODE_SYMBOLS_IM_WITH_SETTINGS_KEY = + R.id.mode_symbols_im_with_settings_key; + public static final int KEYBOARDMODE_SYMBOLS_WEB_WITH_SETTINGS_KEY = + R.id.mode_symbols_webentry_with_settings_key; + public static final int[] SYMBOLS_WITH_SETTINGS_KEY_MODES = { + KEYBOARDMODE_SYMBOLS_NORMAL_WITH_SETTINGS_KEY, + KEYBOARDMODE_SYMBOLS_URL_WITH_SETTINGS_KEY, + KEYBOARDMODE_SYMBOLS_EMAIL_WITH_SETTINGS_KEY, + KEYBOARDMODE_SYMBOLS_IM_WITH_SETTINGS_KEY, + KEYBOARDMODE_SYMBOLS_WEB_WITH_SETTINGS_KEY, + 0 /* for MODE_PHONE */ }; public static final String DEFAULT_LAYOUT_ID = "4"; public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20100902"; @@ -115,7 +155,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private boolean mIsAutoCompletionActive; private boolean mHasVoice; private boolean mVoiceOnPrimary; - private boolean mPreferSymbols; private int mSymbolsModeState = SYMBOLS_MODE_STATE_NONE; // Indicates whether or not we have the settings key @@ -158,21 +197,26 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } private KeyboardId makeSymbolsId(boolean hasVoice) { + final int mode = mMode == MODE_NONE ? MODE_TEXT : mMode; return new KeyboardId(KBD_SYMBOLS[getCharColorId()], mHasSettingsKey ? - KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS, + SYMBOLS_WITH_SETTINGS_KEY_MODES[mode] : SYMBOLS_MODES[mode], false, hasVoice); } private KeyboardId makeSymbolsShiftedId(boolean hasVoice) { + final int mode = mMode == MODE_NONE ? MODE_TEXT : mMode; return new KeyboardId(KBD_SYMBOLS_SHIFT[getCharColorId()], mHasSettingsKey ? - KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS, + SYMBOLS_WITH_SETTINGS_KEY_MODES[mode] : SYMBOLS_MODES[mode], false, hasVoice); } - public void makeKeyboards(boolean forceCreate) { + private void makeSymbolsKeyboardIds() { mSymbolsId = makeSymbolsId(mHasVoice && !mVoiceOnPrimary); mSymbolsShiftedId = makeSymbolsShiftedId(mHasVoice && !mVoiceOnPrimary); + } + public void makeKeyboards(boolean forceCreate) { + makeSymbolsKeyboardIds(); if (forceCreate) mKeyboards.clear(); // Configuration change is coming after the keyboard gets recreated. So don't rely on that. // If keyboards have already been made, check if we have a screen width change and @@ -207,10 +251,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha }); } - public KeyboardId(int xml, boolean hasVoice) { - this(xml, 0, false, hasVoice); - } - @Override public boolean equals(Object other) { return other instanceof KeyboardId && equals((KeyboardId) other); @@ -244,14 +284,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void setKeyboardMode(int mode, int imeOptions, boolean enableVoice) { mSymbolsModeState = SYMBOLS_MODE_STATE_NONE; - mPreferSymbols = mode == MODE_SYMBOLS; - if (mode == MODE_SYMBOLS) { - mode = MODE_TEXT; - } try { - setKeyboardMode(mode, imeOptions, enableVoice, mPreferSymbols); + setKeyboardMode(mode, imeOptions, enableVoice, false); } catch (RuntimeException e) { - LatinImeLogger.logOnException(mode + "," + imeOptions + "," + mPreferSymbols, e); + LatinImeLogger.logOnException(mode + "," + imeOptions, e); } } @@ -259,8 +295,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (mInputView == null) return; mMode = mode; mImeOptions = imeOptions; + makeSymbolsKeyboardIds(); if (enableVoice != mHasVoice) { - setVoiceMode(mHasVoice, mVoiceOnPrimary); + // TODO clean up this unnecessary recursive call. + setVoiceMode(enableVoice, mVoiceOnPrimary); } mIsSymbols = isSymbols; @@ -277,7 +315,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mInputView.setKeyboard(keyboard); keyboard.setShifted(false); keyboard.setShiftLocked(keyboard.isShiftLocked()); - keyboard.setImeOptions(mInputMethodService.getResources(), mMode, imeOptions); + keyboard.setImeOptions(mInputMethodService.getResources(), mode, imeOptions); keyboard.setColorOfSymbolIcons(mIsAutoCompletionActive, isBlackSym()); // Update the settings key state because number of enabled IMEs could have been changed updateSettingsKeyState(PreferenceManager.getDefaultSharedPreferences(mInputMethodService)); @@ -309,48 +347,31 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } private KeyboardId getKeyboardId(int mode, int imeOptions, boolean isSymbols) { - boolean hasVoice = hasVoiceButton(isSymbols); - int charColorId = getCharColorId(); - // TODO: generalize for any KeyboardId - int keyboardRowsResId = KBD_QWERTY[charColorId]; + final boolean hasVoice = hasVoiceButton(isSymbols); + final int charColorId = getCharColorId(); + final int keyboardRowsResId; + final boolean enableShiftLock; + final int keyboardMode; + + if (mode == MODE_NONE) { + LatinImeLogger.logOnWarning( + "getKeyboardId:" + mode + "," + imeOptions + "," + isSymbols); + mode = MODE_TEXT; + } if (isSymbols) { - if (mode == MODE_PHONE) { - return new KeyboardId(KBD_PHONE_SYMBOLS[charColorId], hasVoice); - } else { - return new KeyboardId(KBD_SYMBOLS[charColorId], mHasSettingsKey ? - KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS, - false, hasVoice); - } + keyboardRowsResId = mode == MODE_PHONE + ? KBD_PHONE_SYMBOLS[charColorId] : KBD_SYMBOLS[charColorId]; + enableShiftLock = false; + keyboardMode = mHasSettingsKey + ? SYMBOLS_WITH_SETTINGS_KEY_MODES[mode] : SYMBOLS_MODES[mode]; + } else { // QWERTY + keyboardRowsResId = mode == MODE_PHONE + ? KBD_PHONE[charColorId] : KBD_QWERTY[charColorId]; + enableShiftLock = mode == MODE_PHONE ? false : true; + keyboardMode = mHasSettingsKey + ? QWERTY_WITH_SETTINGS_KEY_MODES[mode] : QWERTY_MODES[mode]; } - switch (mode) { - case MODE_NONE: - LatinImeLogger.logOnWarning( - "getKeyboardId:" + mode + "," + imeOptions + "," + isSymbols); - /* fall through */ - case MODE_TEXT: - return new KeyboardId(keyboardRowsResId, mHasSettingsKey ? - KEYBOARDMODE_NORMAL_WITH_SETTINGS_KEY : KEYBOARDMODE_NORMAL, - true, hasVoice); - case MODE_SYMBOLS: - return new KeyboardId(KBD_SYMBOLS[charColorId], mHasSettingsKey ? - KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS, - false, hasVoice); - case MODE_PHONE: - return new KeyboardId(KBD_PHONE[charColorId], hasVoice); - case MODE_URL: - return new KeyboardId(keyboardRowsResId, mHasSettingsKey ? - KEYBOARDMODE_URL_WITH_SETTINGS_KEY : KEYBOARDMODE_URL, true, hasVoice); - case MODE_EMAIL: - return new KeyboardId(keyboardRowsResId, mHasSettingsKey ? - KEYBOARDMODE_EMAIL_WITH_SETTINGS_KEY : KEYBOARDMODE_EMAIL, true, hasVoice); - case MODE_IM: - return new KeyboardId(keyboardRowsResId, mHasSettingsKey ? - KEYBOARDMODE_IM_WITH_SETTINGS_KEY : KEYBOARDMODE_IM, true, hasVoice); - case MODE_WEB: - return new KeyboardId(keyboardRowsResId, mHasSettingsKey ? - KEYBOARDMODE_WEB_WITH_SETTINGS_KEY : KEYBOARDMODE_WEB, true, hasVoice); - } - return null; + return new KeyboardId(keyboardRowsResId, keyboardMode, enableShiftLock, hasVoice); } public int getKeyboardMode() { @@ -411,7 +432,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public void toggleSymbols() { setKeyboardMode(mMode, mImeOptions, mHasVoice, !mIsSymbols); - if (mIsSymbols && !mPreferSymbols) { + if (mIsSymbols) { mSymbolsModeState = SYMBOLS_MODE_STATE_BEGIN; } else { mSymbolsModeState = SYMBOLS_MODE_STATE_NONE; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index edda9e866..bb29e6367 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -2333,8 +2333,8 @@ public class LatinIME extends InputMethodService private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo attribute) { return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) - && !(attribute != null && attribute.privateImeOptions != null - && attribute.privateImeOptions.equals(IME_OPTION_NO_MICROPHONE)) + && !(attribute != null + && IME_OPTION_NO_MICROPHONE.equals(attribute.privateImeOptions)) && SpeechRecognizer.isRecognitionAvailable(this); } diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java index 3ca85c5d0..fcbada191 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -60,6 +60,7 @@ public class LatinKeyboard extends BaseKeyboard { private final Drawable mButtonArrowRightIcon; private Key mEnterKey; private Key mF1Key; + private final Drawable mHintIcon; private Key mSpaceKey; private Key m123Key; private int mSpaceKeyIndex = -1; @@ -69,6 +70,7 @@ public class LatinKeyboard extends BaseKeyboard { private LanguageSwitcher mLanguageSwitcher; private final Resources mRes; private final Context mContext; + private int mMode; // TODO: remove this and use the corresponding mode in the parent class // Whether this keyboard has voice icon on it private boolean mHasVoiceButton; // Whether voice icon is enabled at all @@ -119,6 +121,7 @@ public class LatinKeyboard extends BaseKeyboard { super(context, xmlLayoutResId, mode); final Resources res = context.getResources(); mContext = context; + mMode = mode; mRes = res; mShiftLockIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked); mShiftLockPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_shift_locked); @@ -133,6 +136,7 @@ public class LatinKeyboard extends BaseKeyboard { mButtonArrowRightIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_right); m123MicIcon = res.getDrawable(R.drawable.sym_keyboard_123_mic); m123MicPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_123_mic); + mHintIcon = res.getDrawable(R.drawable.hint_popup); setDefaultBounds(m123MicPreviewIcon); sSpacebarVerticalCorrection = res.getDimensionPixelOffset( R.dimen.spacebar_vertical_correction); @@ -180,10 +184,12 @@ public class LatinKeyboard extends BaseKeyboard { key.text = null; key.iconPreview = null; key.icon = null; + key.hintIcon = null; key.label = label; } public void setImeOptions(Resources res, int mode, int options) { + mMode = mode; if (mEnterKey == null) return; switch (options & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION)) { @@ -292,7 +298,7 @@ public class LatinKeyboard extends BaseKeyboard { mMicIcon = mRes.getDrawable(R.drawable.sym_keyboard_mic); m123MicIcon = mRes.getDrawable(R.drawable.sym_keyboard_123_mic); } - updateF1Key(); + updateDynamicKeys(); if (mSpaceKey != null) { updateSpaceBarForLocale(isAutoCompletion, isBlack); } @@ -301,11 +307,16 @@ public class LatinKeyboard extends BaseKeyboard { public void setVoiceMode(boolean hasVoiceButton, boolean hasVoice) { mHasVoiceButton = hasVoiceButton; mVoiceEnabled = hasVoice; + updateDynamicKeys(); + } + + private void updateDynamicKeys() { + update123Key(); updateF1Key(); } - private void updateF1Key() { - if (mF1Key == null) return; + private void update123Key() { + // Update KEYCODE_MODE_CHANGE key only on alphabet mode, not on symbol mode. if (m123Key != null && mIsAlphaKeyboard) { if (mVoiceEnabled && !mHasVoiceButton) { m123Key.icon = m123MicIcon; @@ -317,22 +328,52 @@ public class LatinKeyboard extends BaseKeyboard { m123Key.label = m123Label; } } + } - if (mHasVoiceButton && mVoiceEnabled) { - mF1Key.codes = new int[] { LatinKeyboardView.KEYCODE_VOICE }; - mF1Key.label = null; - mF1Key.icon = mMicIcon; - mF1Key.iconPreview = mMicPreviewIcon; - mF1Key.popupResId = R.xml.popup_mic; - } else { - mF1Key.label = ","; - mF1Key.codes = new int[] { ',' }; - mF1Key.icon = null; - mF1Key.iconPreview = null; - mF1Key.popupResId = R.xml.popup_comma; + private void updateF1Key() { + // Update KEYCODE_F1 key. Please note that some keyboard layouts have no F1 key. + if (mF1Key == null) + return; + + if (mIsAlphaKeyboard) { + if (mMode == KeyboardSwitcher.MODE_URL) { + setNonMicF1Key(mF1Key, "/", R.xml.popup_slash); + } else if (mMode == KeyboardSwitcher.MODE_EMAIL) { + setNonMicF1Key(mF1Key, "@", R.xml.popup_at); + } else { + if (mVoiceEnabled && mHasVoiceButton) { + setMicF1Key(mF1Key); + } else { + setNonMicF1Key(mF1Key, ",", R.xml.popup_comma); + } + } + } else { // Symbols keyboard + if (mVoiceEnabled && mHasVoiceButton) { + setMicF1Key(mF1Key); + } else { + setNonMicF1Key(mF1Key, ",", R.xml.popup_comma); + } } } + private void setMicF1Key(Key key) { + key.label = null; + key.codes = new int[] { LatinKeyboardView.KEYCODE_VOICE }; + key.popupResId = R.xml.popup_mic; + key.icon = mMicIcon; + key.hintIcon = mHintIcon; + key.iconPreview = mMicPreviewIcon; + } + + private void setNonMicF1Key(Key key, String label, int popupResId) { + key.label = label; + key.codes = new int[] { label.charAt(0) }; + key.popupResId = popupResId; + key.icon = null; + key.hintIcon = mHintIcon; + key.iconPreview = null; + } + /** * @return a key which should be invalidated. */ diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index b02780bf6..4e264e853 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -57,6 +57,8 @@ import java.util.WeakHashMap; * A view that renders a virtual {@link LatinKeyboard}. It handles rendering of keys and * detecting key presses and touch movements. * + * TODO: References to LatinKeyboard in this class should be replaced with ones to its base class. + * * @attr ref R.styleable#LatinKeyboardBaseView_keyBackground * @attr ref R.styleable#LatinKeyboardBaseView_keyPreviewLayout * @attr ref R.styleable#LatinKeyboardBaseView_keyPreviewOffset @@ -160,7 +162,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx // Miscellaneous constants /* package */ static final int NOT_A_KEY = -1; private static final int[] LONG_PRESSABLE_STATE_SET = { android.R.attr.state_long_pressable }; - private static final int NUMBER_HINT_VERTICAL_ADJUSTMENT_PIXEL = -1; + private static final int HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL = -1; // XML attribute private int mKeyTextSize; @@ -861,32 +863,20 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx // Turn off drop shadow paint.setShadowLayer(0, 0, 0, 0); } - Drawable icon = null; - if (key.label == null && key.icon != null) - icon = key.icon; - if (icon == null && key.hintIcon != null && drawHintIcon) - icon = key.hintIcon; - if (icon != null) { - // Special handing for the upper-right number hint icons - final int drawableWidth; - final int drawableHeight; - final int drawableX; - final int drawableY; - if (icon == key.hintIcon) { - drawableWidth = key.width; - drawableHeight = key.height; - drawableX = 0; - drawableY = NUMBER_HINT_VERTICAL_ADJUSTMENT_PIXEL; - } else { - drawableWidth = key.icon.getIntrinsicWidth(); - drawableHeight = key.icon.getIntrinsicHeight(); - drawableX = (key.width + padding.left - padding.right - drawableWidth) / 2; - drawableY = (key.height + padding.top - padding.bottom - drawableHeight) / 2; - } - canvas.translate(drawableX, drawableY); - icon.setBounds(0, 0, drawableWidth, drawableHeight); - icon.draw(canvas); - canvas.translate(-drawableX, -drawableY); + if (key.label == null && key.icon != null) { + int drawableWidth = key.icon.getIntrinsicWidth(); + int drawableHeight = key.icon.getIntrinsicHeight(); + int drawableX = (key.width + padding.left - padding.right - drawableWidth) / 2; + int drawableY = (key.height + padding.top - padding.bottom - drawableHeight) / 2; + drawIcon(canvas, key.icon, drawableX, drawableY, drawableWidth, drawableHeight); + + } + if (key.hintIcon != null && drawHintIcon) { + int drawableWidth = key.width; + int drawableHeight = key.height; + int drawableX = 0; + int drawableY = HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL; + drawIcon(canvas, key.hintIcon, drawableX, drawableY, drawableWidth, drawableHeight); } canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop); } @@ -920,6 +910,13 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx mDirtyRect.setEmpty(); } + private void drawIcon(Canvas canvas, Drawable icon, int x, int y, int width, int height) { + canvas.translate(x, y); + icon.setBounds(0, 0, width, height); + icon.draw(canvas); + canvas.translate(-x, -y); + } + public void setForeground(boolean foreground) { mInForeground = foreground; } @@ -962,8 +959,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx // WindowManager.BadTokenException. if (key == null || !mInForeground) return; - // Should not draw number hint icons - if (key.icon != null && key.label == null) { + if (key.icon != null) { mPreviewText.setCompoundDrawables(null, null, null, key.iconPreview != null ? key.iconPreview : key.icon); mPreviewText.setText(null);