Skip to content
Snippets Groups Projects
Commit d81479a3 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Implement KeyboardLocale InputMethodSubtype extra key

The locale is specified by KeyboardLocale extra key in method.xml,
LatinIME will use the specified locale for keyboard layout.

Bug: 5238658
Change-Id: I8e6cb66c73a7ac1bf611d9910b42fa9cff38eba0
parent b91b3a3e
No related branches found
No related tags found
No related merge requests found
...@@ -332,11 +332,11 @@ ...@@ -332,11 +332,11 @@
<!-- Title of the item to change the keyboard theme [CHAR LIMIT=20]--> <!-- Title of the item to change the keyboard theme [CHAR LIMIT=20]-->
<string name="keyboard_layout">Keyboard theme</string> <string name="keyboard_layout">Keyboard theme</string>
<!-- Description for German QWERTY keyboard subtype [CHAR LIMIT=35] --> <!-- Description for German QWERTY keyboard subtype [CHAR LIMIT=22] -->
<string name="subtype_de_qwerty">German QWERTY</string> <string name="subtype_de_qwerty">German QWERTY</string>
<!-- Description for English (United Kingdom) keyboard subtype [CHAR LIMIT=35] --> <!-- Description for English (United Kingdom) keyboard subtype [CHAR LIMIT=22] -->
<string name="subtype_en_GB">English (UK)</string> <string name="subtype_en_GB">English (UK)</string>
<!-- Description for English (United States) keyboard subtype [CHAR LIMIT=35] --> <!-- Description for English (United States) keyboard subtype [CHAR LIMIT=22] -->
<string name="subtype_en_US">English (US)</string> <string name="subtype_en_US">English (US)</string>
<!-- Title of an option for usability study mode --> <!-- Title of an option for usability study mode -->
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<!-- The attributes in this XML file provide configuration information --> <!-- The attributes in this XML file provide configuration information -->
<!-- for the Input Method Manager. --> <!-- for the Input Method Manager. -->
<!-- Keyboard: en_US, en_GB, ar, cs, da, de, de_ZZ, es, es_US, fi, fr, fr_CA, fr_CH, hr, hu, it, iw, nb, nl, pl, pt, ru, sr, sv, tr --> <!-- Keyboard: en_US, en_GB, ar, cs, da, de, de(QWERTY), es, es_US, fi, fr, fr_CA, fr_CH, hr, hu, it, iw, nb, nl, pl, pt, ru, sr, sv, tr -->
<!-- TODO: use <lang>_keyboard icon instead of a common keyboard icon. --> <!-- TODO: use <lang>_keyboard icon instead of a common keyboard icon. -->
<!-- If IME doesn't have an applicable subtype, the first subtype will be used as a default <!-- If IME doesn't have an applicable subtype, the first subtype will be used as a default
subtype.--> subtype.-->
...@@ -64,9 +64,9 @@ ...@@ -64,9 +64,9 @@
/> />
<subtype android:icon="@drawable/ic_subtype_keyboard" <subtype android:icon="@drawable/ic_subtype_keyboard"
android:label="@string/subtype_de_qwerty" android:label="@string/subtype_de_qwerty"
android:imeSubtypeLocale="de_ZZ" android:imeSubtypeLocale="de"
android:imeSubtypeMode="keyboard" android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable" android:imeSubtypeExtraValue="AsciiCapable,KeyboardLocale=de_ZZ"
/> />
<subtype android:icon="@drawable/ic_subtype_keyboard" <subtype android:icon="@drawable/ic_subtype_keyboard"
android:label="@string/subtype_generic" android:label="@string/subtype_generic"
......
...@@ -73,16 +73,17 @@ public class InputMethodServiceCompatWrapper extends InputMethodService { ...@@ -73,16 +73,17 @@ public class InputMethodServiceCompatWrapper extends InputMethodService {
// This call is required to let LatinIME itself know a subtype changed // This call is required to let LatinIME itself know a subtype changed
// event when the API level is 10 or previous. // event when the API level is 10 or previous.
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void notifyOnCurrentInputMethodSubtypeChanged(InputMethodSubtypeCompatWrapper subtype) { public void notifyOnCurrentInputMethodSubtypeChanged(
InputMethodSubtypeCompatWrapper newSubtype) {
// Do nothing when the API level is 11 or later // Do nothing when the API level is 11 or later
// and FORCE_ENABLE_VOICE_EVEN_WITH_NO_VOICE_SUBTYPES is not true // and FORCE_ENABLE_VOICE_EVEN_WITH_NO_VOICE_SUBTYPES is not true
if (CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED && !InputMethodManagerCompatWrapper. if (CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED && !InputMethodManagerCompatWrapper.
FORCE_ENABLE_VOICE_EVEN_WITH_NO_VOICE_SUBTYPES) { FORCE_ENABLE_VOICE_EVEN_WITH_NO_VOICE_SUBTYPES) {
return; return;
} }
if (subtype == null) { final InputMethodSubtypeCompatWrapper subtype = (newSubtype == null)
subtype = mImm.getCurrentInputMethodSubtype(); ? mImm.getCurrentInputMethodSubtype()
} : newSubtype;
if (subtype != null) { if (subtype != null) {
if (!InputMethodManagerCompatWrapper.FORCE_ENABLE_VOICE_EVEN_WITH_NO_VOICE_SUBTYPES if (!InputMethodManagerCompatWrapper.FORCE_ENABLE_VOICE_EVEN_WITH_NO_VOICE_SUBTYPES
&& !subtype.isDummy()) return; && !subtype.isDummy()) return;
......
...@@ -118,6 +118,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar ...@@ -118,6 +118,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
*/ */
public static final String SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE = "AsciiCapable"; public static final String SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE = "AsciiCapable";
/**
* The subtype extra value used to indicate that the subtype keyboard layout should be loaded
* from the specified locale.
*/
public static final String SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE = "KeyboardLocale";
private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100; private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100;
// How many continuous deletes at which to start deleting at a higher speed. // How many continuous deletes at which to start deleting at a higher speed.
......
...@@ -138,7 +138,7 @@ public class SubtypeSwitcher { ...@@ -138,7 +138,7 @@ public class SubtypeSwitcher {
mEnabledLanguagesOfCurrentInputMethod.clear(); mEnabledLanguagesOfCurrentInputMethod.clear();
mEnabledKeyboardSubtypesOfCurrentInputMethod.clear(); mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
for (InputMethodSubtypeCompatWrapper ims : mAllEnabledSubtypesOfCurrentInputMethod) { for (InputMethodSubtypeCompatWrapper ims : mAllEnabledSubtypesOfCurrentInputMethod) {
final String locale = ims.getLocale(); final String locale = getSubtypeLocale(ims);
final String mode = ims.getMode(); final String mode = ims.getMode();
mLocaleSplitter.setString(locale); mLocaleSplitter.setString(locale);
if (mLocaleSplitter.hasNext()) { if (mLocaleSplitter.hasNext()) {
...@@ -167,7 +167,7 @@ public class SubtypeSwitcher { ...@@ -167,7 +167,7 @@ public class SubtypeSwitcher {
Log.d(TAG, "Update shortcut IME from : " Log.d(TAG, "Update shortcut IME from : "
+ (mShortcutInputMethodInfo == null + (mShortcutInputMethodInfo == null
? "<null>" : mShortcutInputMethodInfo.getId()) + ", " ? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
+ (mShortcutSubtype == null ? "<null>" : (mShortcutSubtype.getLocale() + (mShortcutSubtype == null ? "<null>" : (getSubtypeLocale(mShortcutSubtype)
+ ", " + mShortcutSubtype.getMode()))); + ", " + mShortcutSubtype.getMode())));
} }
// TODO: Update an icon for shortcut IME // TODO: Update an icon for shortcut IME
...@@ -189,11 +189,17 @@ public class SubtypeSwitcher { ...@@ -189,11 +189,17 @@ public class SubtypeSwitcher {
Log.d(TAG, "Update shortcut IME to : " Log.d(TAG, "Update shortcut IME to : "
+ (mShortcutInputMethodInfo == null + (mShortcutInputMethodInfo == null
? "<null>" : mShortcutInputMethodInfo.getId()) + ", " ? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
+ (mShortcutSubtype == null ? "<null>" : (mShortcutSubtype.getLocale() + (mShortcutSubtype == null ? "<null>" : (getSubtypeLocale(mShortcutSubtype)
+ ", " + mShortcutSubtype.getMode()))); + ", " + mShortcutSubtype.getMode())));
} }
} }
private static String getSubtypeLocale(InputMethodSubtypeCompatWrapper subtype) {
final String keyboardLocale = subtype.getExtraValueOf(
LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE);
return keyboardLocale != null ? keyboardLocale : subtype.getLocale();
}
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function. // Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
public void updateSubtype(InputMethodSubtypeCompatWrapper newSubtype) { public void updateSubtype(InputMethodSubtypeCompatWrapper newSubtype) {
final String newLocale; final String newLocale;
...@@ -206,7 +212,7 @@ public class SubtypeSwitcher { ...@@ -206,7 +212,7 @@ public class SubtypeSwitcher {
newLocale = "en_US"; newLocale = "en_US";
newMode = KEYBOARD_MODE; newMode = KEYBOARD_MODE;
} else { } else {
newLocale = newSubtype.getLocale(); newLocale = getSubtypeLocale(newSubtype);
newMode = newSubtype.getMode(); newMode = newSubtype.getMode();
} }
if (DBG) { if (DBG) {
...@@ -332,7 +338,7 @@ public class SubtypeSwitcher { ...@@ -332,7 +338,7 @@ public class SubtypeSwitcher {
final String imiPackageName = imi.getPackageName(); final String imiPackageName = imi.getPackageName();
if (DBG) { if (DBG) {
Log.d(TAG, "Update icons of IME: " + imiPackageName + "," Log.d(TAG, "Update icons of IME: " + imiPackageName + ","
+ subtype.getLocale() + "," + subtype.getMode()); + getSubtypeLocale(subtype) + "," + subtype.getMode());
} }
if (subtype != null) { if (subtype != null) {
return pm.getDrawable(imiPackageName, subtype.getIconResId(), return pm.getDrawable(imiPackageName, subtype.getIconResId(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment