Refactor to utilize InputMethodSubtype
Change-Id: I76fbc8a395eb8dab996c02c86d7328f07865f8cfmain
parent
43ebd8a035
commit
cb389ef0d6
|
@ -25,6 +25,7 @@ import android.text.InputType;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import com.android.inputmethod.compat.EditorInfoCompatUtils;
|
import com.android.inputmethod.compat.EditorInfoCompatUtils;
|
||||||
import com.android.inputmethod.keyboard.KeyboardSet.Params.ElementParams;
|
import com.android.inputmethod.keyboard.KeyboardSet.Params.ElementParams;
|
||||||
|
@ -242,7 +243,10 @@ public class KeyboardSet {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setSubtype(Locale inputLocale, boolean asciiCapable) {
|
public Builder setSubtype(InputMethodSubtype subtype) {
|
||||||
|
final Locale inputLocale = SubtypeLocale.getSubtypeLocale(subtype);
|
||||||
|
final boolean asciiCapable = subtype.containsExtraValueKey(
|
||||||
|
LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE);
|
||||||
final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions(
|
final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions(
|
||||||
mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo);
|
mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo);
|
||||||
final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii(
|
final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii(
|
||||||
|
|
|
@ -137,10 +137,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
final KeyboardSet.Builder builder = new KeyboardSet.Builder(mThemeContext, editorInfo);
|
final KeyboardSet.Builder builder = new KeyboardSet.Builder(mThemeContext, editorInfo);
|
||||||
builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation,
|
builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation,
|
||||||
mThemeContext.getResources().getDisplayMetrics().widthPixels);
|
mThemeContext.getResources().getDisplayMetrics().widthPixels);
|
||||||
builder.setSubtype(
|
builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
|
||||||
mSubtypeSwitcher.getInputLocale(),
|
|
||||||
mSubtypeSwitcher.currentSubtypeContainsExtraValueKey(
|
|
||||||
LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE));
|
|
||||||
builder.setOptions(
|
builder.setOptions(
|
||||||
settingsValues.isVoiceKeyEnabled(editorInfo),
|
settingsValues.isVoiceKeyEnabled(editorInfo),
|
||||||
settingsValues.isVoiceKeyOnMain(),
|
settingsValues.isVoiceKeyOnMain(),
|
||||||
|
@ -384,7 +381,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
|
|
||||||
public void onNetworkStateChanged() {
|
public void onNetworkStateChanged() {
|
||||||
if (mKeyboardView != null) {
|
if (mKeyboardView != null) {
|
||||||
mKeyboardView.updateShortcutKey(SubtypeSwitcher.getInstance().isShortcutImeReady());
|
mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -713,9 +713,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
|
mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSubtypeSwitcher.isKeyboardMode()) {
|
switcher.loadKeyboard(editorInfo, mSettingsValues);
|
||||||
switcher.loadKeyboard(editorInfo, mSettingsValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mSuggestionsView != null)
|
if (mSuggestionsView != null)
|
||||||
mSuggestionsView.clear();
|
mSuggestionsView.clear();
|
||||||
|
|
|
@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -120,4 +121,14 @@ public class SubtypeLocale {
|
||||||
// - It also does not work with unicode surrogate code points.
|
// - It also does not work with unicode surrogate code points.
|
||||||
return s.toUpperCase(locale).charAt(0) + s.substring(1);
|
return s.toUpperCase(locale).charAt(0) + s.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getSubtypeLocaleString(InputMethodSubtype subtype) {
|
||||||
|
final String keyboardLocale = subtype.getExtraValueOf(
|
||||||
|
LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE);
|
||||||
|
return keyboardLocale != null ? keyboardLocale : subtype.getLocale();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Locale getSubtypeLocale(InputMethodSubtype subtype) {
|
||||||
|
return LocaleUtils.constructLocaleFromString(getSubtypeLocaleString(subtype));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -419,30 +419,23 @@ public class SubtypeSwitcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isKeyboardMode() {
|
// TODO: Remove this method
|
||||||
|
private boolean isKeyboardMode() {
|
||||||
return KEYBOARD_MODE.equals(getCurrentSubtypeMode());
|
return KEYBOARD_MODE.equals(getCurrentSubtypeMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
// TODO: Remove this method
|
||||||
// Other utility functions //
|
private String getCurrentSubtypeMode() {
|
||||||
/////////////////////////////
|
return mCurrentSubtype.getMode();
|
||||||
|
|
||||||
public String getCurrentSubtypeExtraValue() {
|
|
||||||
// If null, return what an empty ExtraValue would return : the empty string.
|
|
||||||
return mCurrentSubtype.getExtraValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this method
|
||||||
public boolean currentSubtypeContainsExtraValueKey(String key) {
|
public boolean currentSubtypeContainsExtraValueKey(String key) {
|
||||||
// If null, return what an empty ExtraValue would return : false.
|
// If null, return what an empty ExtraValue would return : false.
|
||||||
return mCurrentSubtype.containsExtraValueKey(key);
|
return mCurrentSubtype.containsExtraValueKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCurrentSubtypeExtraValueOf(String key) {
|
public InputMethodSubtype getCurrentSubtype() {
|
||||||
// If null, return what an empty ExtraValue would return : null.
|
return mCurrentSubtype;
|
||||||
return mCurrentSubtype.getExtraValueOf(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCurrentSubtypeMode() {
|
|
||||||
return mCurrentSubtype.getMode();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue