Move functions in LatinKeyboard related to LanguageSwitcher to SubtypeSwitcher
Change-Id: I777db896bd0287931ce7c810b080ccee1121d34emain
parent
0ed7191b4d
commit
3b776b7892
|
@ -932,7 +932,7 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
|| tracker.isSpaceKey(keyIndex) || tracker.isSpaceKey(oldKeyIndex);
|
|| tracker.isSpaceKey(keyIndex) || tracker.isSpaceKey(oldKeyIndex);
|
||||||
// If key changed and preview is on or the key is space (language switch is enabled)
|
// If key changed and preview is on or the key is space (language switch is enabled)
|
||||||
if (oldKeyIndex != keyIndex && (mShowPreview || (hidePreviewOrShowSpaceKeyPreview
|
if (oldKeyIndex != keyIndex && (mShowPreview || (hidePreviewOrShowSpaceKeyPreview
|
||||||
&& SubtypeSwitcher.getInstance().isLanguageSwitchEnabled()))) {
|
&& SubtypeSwitcher.getInstance().needsToDisplayLanguage()))) {
|
||||||
if (keyIndex == NOT_A_KEY) {
|
if (keyIndex == NOT_A_KEY) {
|
||||||
mHandler.cancelPopupPreview();
|
mHandler.cancelPopupPreview();
|
||||||
mHandler.dismissPreview(mDelayAfterPreview);
|
mHandler.dismissPreview(mDelayAfterPreview);
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class InputLanguageSelection extends PreferenceActivity {
|
||||||
for (int i = 0; i < mAvailableLanguages.size(); i++) {
|
for (int i = 0; i < mAvailableLanguages.size(); i++) {
|
||||||
CheckBoxPreference pref = new CheckBoxPreference(this);
|
CheckBoxPreference pref = new CheckBoxPreference(this);
|
||||||
Locale locale = mAvailableLanguages.get(i).locale;
|
Locale locale = mAvailableLanguages.get(i).locale;
|
||||||
pref.setTitle(LanguageSwitcher.toTitleCase(locale.getDisplayName(locale)));
|
pref.setTitle(SubtypeSwitcher.getLanguageName(locale));
|
||||||
boolean checked = isLocaleIn(locale, languageList);
|
boolean checked = isLocaleIn(locale, languageList);
|
||||||
pref.setChecked(checked);
|
pref.setChecked(checked);
|
||||||
if (hasDictionary(locale)) {
|
if (hasDictionary(locale)) {
|
||||||
|
@ -167,7 +167,7 @@ public class InputLanguageSelection extends PreferenceActivity {
|
||||||
|
|
||||||
if (finalSize == 0) {
|
if (finalSize == 0) {
|
||||||
preprocess[finalSize++] =
|
preprocess[finalSize++] =
|
||||||
new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName(l)), l);
|
new Loc(SubtypeSwitcher.getLanguageName(l), l);
|
||||||
} else {
|
} else {
|
||||||
// check previous entry:
|
// check previous entry:
|
||||||
// same lang and a country -> upgrade to full name and
|
// same lang and a country -> upgrade to full name and
|
||||||
|
@ -175,15 +175,15 @@ public class InputLanguageSelection extends PreferenceActivity {
|
||||||
// diff lang -> insert ours with lang-only name
|
// diff lang -> insert ours with lang-only name
|
||||||
if (preprocess[finalSize-1].locale.getLanguage().equals(
|
if (preprocess[finalSize-1].locale.getLanguage().equals(
|
||||||
language)) {
|
language)) {
|
||||||
preprocess[finalSize-1].label = LanguageSwitcher.toTitleCase(
|
preprocess[finalSize-1].label = SubtypeSwitcher.getLanguageName(
|
||||||
preprocess[finalSize-1].locale.getDisplayName());
|
preprocess[finalSize-1].locale);
|
||||||
preprocess[finalSize++] =
|
preprocess[finalSize++] =
|
||||||
new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName()), l);
|
new Loc(SubtypeSwitcher.getLanguageName(l), l);
|
||||||
} else {
|
} else {
|
||||||
String displayName;
|
String displayName;
|
||||||
if (s.equals("zz_ZZ")) {
|
if (s.equals("zz_ZZ")) {
|
||||||
} else {
|
} else {
|
||||||
displayName = LanguageSwitcher.toTitleCase(l.getDisplayName(l));
|
displayName = SubtypeSwitcher.getLanguageName(l);
|
||||||
preprocess[finalSize++] = new Loc(displayName, l);
|
preprocess[finalSize++] = new Loc(displayName, l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,7 +297,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
keyboard.setVoiceMode(
|
keyboard.setVoiceMode(
|
||||||
hasVoiceKey(xml == R.xml.kbd_symbols || xml == R.xml.kbd_symbols_black),
|
hasVoiceKey(xml == R.xml.kbd_symbols || xml == R.xml.kbd_symbols_black),
|
||||||
mVoiceButtonEnabled);
|
mVoiceButtonEnabled);
|
||||||
keyboard.setLanguageSwitcher(mSubtypeSwitcher.getLanguageSwitcher());
|
|
||||||
keyboard.setImeOptions(res, id.mMode, id.mImeOptions);
|
keyboard.setImeOptions(res, id.mMode, id.mImeOptions);
|
||||||
keyboard.setColorOfSymbolIcons(isBlackSym(id.mColorScheme));
|
keyboard.setColorOfSymbolIcons(isBlackSym(id.mColorScheme));
|
||||||
|
|
||||||
|
|
|
@ -192,12 +192,4 @@ public class LanguageSwitcher {
|
||||||
editor.putString(LatinIME.PREF_INPUT_LANGUAGE, getInputLanguage());
|
editor.putString(LatinIME.PREF_INPUT_LANGUAGE, getInputLanguage());
|
||||||
SharedPreferencesCompat.apply(editor);
|
SharedPreferencesCompat.apply(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String toTitleCase(String s) {
|
|
||||||
if (s.length() == 0) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,6 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
private int mSpaceKeyIndex = -1;
|
private int mSpaceKeyIndex = -1;
|
||||||
private int mSpaceDragStartX;
|
private int mSpaceDragStartX;
|
||||||
private int mSpaceDragLastDiff;
|
private int mSpaceDragLastDiff;
|
||||||
private Locale mLocale;
|
|
||||||
private LanguageSwitcher mLanguageSwitcher;
|
|
||||||
private final Resources mRes;
|
private final Resources mRes;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private int mMode; // TODO: remove this and use the corresponding mode in the parent class
|
private int mMode; // TODO: remove this and use the corresponding mode in the parent class
|
||||||
|
@ -389,7 +387,7 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
private void updateSpaceBarForLocale(boolean isAutoCompletion, boolean isBlack) {
|
private void updateSpaceBarForLocale(boolean isAutoCompletion, boolean isBlack) {
|
||||||
final Resources res = mRes;
|
final Resources res = mRes;
|
||||||
// If application locales are explicitly selected.
|
// If application locales are explicitly selected.
|
||||||
if (mLocale != null) {
|
if (SubtypeSwitcher.getInstance().needsToDisplayLanguage()) {
|
||||||
mSpaceKey.icon = new BitmapDrawable(res,
|
mSpaceKey.icon = new BitmapDrawable(res,
|
||||||
drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion, isBlack));
|
drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion, isBlack));
|
||||||
} else {
|
} else {
|
||||||
|
@ -421,7 +419,7 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
final Rect bounds = new Rect();
|
final Rect bounds = new Rect();
|
||||||
|
|
||||||
// Estimate appropriate language name text size to fit in maxTextWidth.
|
// Estimate appropriate language name text size to fit in maxTextWidth.
|
||||||
String language = LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale));
|
String language = SubtypeSwitcher.getLanguageName(locale);
|
||||||
int textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
int textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
||||||
// Assuming text width and text size are proportional to each other.
|
// Assuming text width and text size are proportional to each other.
|
||||||
float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
||||||
|
@ -437,7 +435,7 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
textSize = origTextSize;
|
textSize = origTextSize;
|
||||||
}
|
}
|
||||||
if (useShortName) {
|
if (useShortName) {
|
||||||
language = LanguageSwitcher.toTitleCase(locale.getLanguage());
|
language = SubtypeSwitcher.getShortLanguageName(locale);
|
||||||
textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
||||||
textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
||||||
}
|
}
|
||||||
|
@ -462,15 +460,16 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
final Resources res = mRes;
|
final Resources res = mRes;
|
||||||
canvas.drawColor(res.getColor(R.color.latinkeyboard_transparent), PorterDuff.Mode.CLEAR);
|
canvas.drawColor(res.getColor(R.color.latinkeyboard_transparent), PorterDuff.Mode.CLEAR);
|
||||||
|
|
||||||
|
SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance();
|
||||||
// If application locales are explicitly selected.
|
// If application locales are explicitly selected.
|
||||||
if (mLocale != null) {
|
if (subtypeSwitcher.needsToDisplayLanguage()) {
|
||||||
final Paint paint = new Paint();
|
final Paint paint = new Paint();
|
||||||
paint.setAlpha(opacity);
|
paint.setAlpha(opacity);
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
paint.setTextAlign(Align.CENTER);
|
paint.setTextAlign(Align.CENTER);
|
||||||
|
|
||||||
final boolean allowVariableTextSize = true;
|
final boolean allowVariableTextSize = true;
|
||||||
final String language = layoutSpaceBar(paint, mLanguageSwitcher.getInputLocale(),
|
final String language = layoutSpaceBar(paint, subtypeSwitcher.getInputLocale(),
|
||||||
mButtonArrowLeftIcon, mButtonArrowRightIcon, width, height,
|
mButtonArrowLeftIcon, mButtonArrowRightIcon, width, height,
|
||||||
getTextSizeFromTheme(android.R.style.TextAppearance_Small, 14),
|
getTextSizeFromTheme(android.R.style.TextAppearance_Small, 14),
|
||||||
allowVariableTextSize);
|
allowVariableTextSize);
|
||||||
|
@ -487,7 +486,8 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
canvas.drawText(language, width / 2, baseline - descent, paint);
|
canvas.drawText(language, width / 2, baseline - descent, paint);
|
||||||
|
|
||||||
// Put arrows that are already layed out on either side of the text
|
// Put arrows that are already layed out on either side of the text
|
||||||
if (mLanguageSwitcher.getLocaleCount() > 1) {
|
if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER
|
||||||
|
&& subtypeSwitcher.getEnabledKeyboardLocaleCount() > 1) {
|
||||||
mButtonArrowLeftIcon.draw(canvas);
|
mButtonArrowLeftIcon.draw(canvas);
|
||||||
mButtonArrowRightIcon.draw(canvas);
|
mButtonArrowRightIcon.draw(canvas);
|
||||||
}
|
}
|
||||||
|
@ -531,28 +531,13 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLanguageChangeDirection() {
|
public int getLanguageChangeDirection() {
|
||||||
if (mSpaceKey == null || mLanguageSwitcher.getLocaleCount() < 2
|
if (mSpaceKey == null || SubtypeSwitcher.getInstance().getEnabledKeyboardLocaleCount() <= 1
|
||||||
|| Math.abs(mSpaceDragLastDiff) < mSpaceKey.width * SPACEBAR_DRAG_THRESHOLD ) {
|
|| Math.abs(mSpaceDragLastDiff) < mSpaceKey.width * SPACEBAR_DRAG_THRESHOLD) {
|
||||||
return 0; // No change
|
return 0; // No change
|
||||||
}
|
}
|
||||||
return mSpaceDragLastDiff > 0 ? 1 : -1;
|
return mSpaceDragLastDiff > 0 ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLanguageSwitcher(LanguageSwitcher switcher) {
|
|
||||||
mLanguageSwitcher = switcher;
|
|
||||||
Locale locale = mLanguageSwitcher.getLocaleCount() > 0
|
|
||||||
? mLanguageSwitcher.getInputLocale()
|
|
||||||
: null;
|
|
||||||
// If the language count is 1 and is the same as the system language, don't show it.
|
|
||||||
if (locale != null
|
|
||||||
&& mLanguageSwitcher.getLocaleCount() == 1
|
|
||||||
&& mLanguageSwitcher.getSystemLocale().getLanguage()
|
|
||||||
.equalsIgnoreCase(locale.getLanguage())) {
|
|
||||||
locale = null;
|
|
||||||
}
|
|
||||||
mLocale = locale;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isCurrentlyInSpace() {
|
boolean isCurrentlyInSpace() {
|
||||||
return mCurrentlyInSpace;
|
return mCurrentlyInSpace;
|
||||||
}
|
}
|
||||||
|
@ -586,7 +571,8 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
if (code == KEYCODE_DELETE) x -= key.width / 6;
|
if (code == KEYCODE_DELETE) x -= key.width / 6;
|
||||||
} else if (code == LatinIME.KEYCODE_SPACE) {
|
} else if (code == LatinIME.KEYCODE_SPACE) {
|
||||||
y += LatinKeyboard.sSpacebarVerticalCorrection;
|
y += LatinKeyboard.sSpacebarVerticalCorrection;
|
||||||
if (mLanguageSwitcher.getLocaleCount() > 1) {
|
if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER
|
||||||
|
&& SubtypeSwitcher.getInstance().getEnabledKeyboardLocaleCount() > 1) {
|
||||||
if (mCurrentlyInSpace) {
|
if (mCurrentlyInSpace) {
|
||||||
int diff = x - mSpaceDragStartX;
|
int diff = x - mSpaceDragStartX;
|
||||||
if (Math.abs(diff - mSpaceDragLastDiff) > 0) {
|
if (Math.abs(diff - mSpaceDragLastDiff) > 0) {
|
||||||
|
@ -851,9 +837,6 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
invalidateSelf();
|
invalidateSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLanguageName(Locale locale) {
|
|
||||||
return LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
|
@ -867,10 +850,10 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
final Drawable rArrow = mRightDrawable;
|
final Drawable rArrow = mRightDrawable;
|
||||||
canvas.clipRect(0, 0, width, height);
|
canvas.clipRect(0, 0, width, height);
|
||||||
if (mCurrentLanguage == null) {
|
if (mCurrentLanguage == null) {
|
||||||
final LanguageSwitcher languageSwitcher = mLanguageSwitcher;
|
SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance();
|
||||||
mCurrentLanguage = getLanguageName(languageSwitcher.getInputLocale());
|
mCurrentLanguage = subtypeSwitcher.getInputLanguageName();
|
||||||
mNextLanguage = getLanguageName(languageSwitcher.getNextInputLocale());
|
mNextLanguage = subtypeSwitcher.getNextInputLanguageName();
|
||||||
mPrevLanguage = getLanguageName(languageSwitcher.getPrevInputLocale());
|
mPrevLanguage = subtypeSwitcher.getPreviousInputLanguageName();
|
||||||
}
|
}
|
||||||
// Draw language text with shadow
|
// Draw language text with shadow
|
||||||
final float baseline = mHeight * SPACEBAR_LANGUAGE_BASELINE - paint.descent();
|
final float baseline = mHeight * SPACEBAR_LANGUAGE_BASELINE - paint.descent();
|
||||||
|
|
|
@ -31,7 +31,9 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class SubtypeSwitcher {
|
public class SubtypeSwitcher {
|
||||||
private static final boolean USE_LEGACY_LANGUAGE_SWITCHER = true;
|
// This flag indicates if we support language switching by swipe on space bar.
|
||||||
|
// We may or may not draw the current language on space bar regardless of this flag.
|
||||||
|
public static final boolean USE_SPACEBAR_LANGUAGE_SWITCHER = true;
|
||||||
private static final String TAG = "SubtypeSwitcher";
|
private static final String TAG = "SubtypeSwitcher";
|
||||||
private static final SubtypeSwitcher sInstance = new SubtypeSwitcher();
|
private static final SubtypeSwitcher sInstance = new SubtypeSwitcher();
|
||||||
private InputMethodService mService;
|
private InputMethodService mService;
|
||||||
|
@ -46,7 +48,7 @@ public class SubtypeSwitcher {
|
||||||
sInstance.mService = service;
|
sInstance.mService = service;
|
||||||
sInstance.mResources = service.getResources();
|
sInstance.mResources = service.getResources();
|
||||||
sInstance.mSystemLocale = sInstance.mResources.getConfiguration().locale;
|
sInstance.mSystemLocale = sInstance.mResources.getConfiguration().locale;
|
||||||
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
sInstance.initLanguageSwitcher(service);
|
sInstance.initLanguageSwitcher(service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,22 +63,23 @@ public class SubtypeSwitcher {
|
||||||
// Language Switching functions //
|
// Language Switching functions //
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
|
||||||
private int getEnabledKeyboardLocaleCount() {
|
public int getEnabledKeyboardLocaleCount() {
|
||||||
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
return mLanguageSwitcher.getLocaleCount();
|
return mLanguageSwitcher.getLocaleCount();
|
||||||
}
|
}
|
||||||
// TODO: Implement for no legacy mode
|
// TODO: Implement for no legacy mode
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLanguageSwitchEnabled() {
|
// TODO: Cache the value
|
||||||
|
public boolean needsToDisplayLanguage() {
|
||||||
// TODO: Takes care of two-char locale such as "en" in addition to "en_US"
|
// TODO: Takes care of two-char locale such as "en" in addition to "en_US"
|
||||||
return !(getEnabledKeyboardLocaleCount() == 1 && getSystemLocale().getLanguage(
|
return !(getEnabledKeyboardLocaleCount() == 1 && getSystemLocale().getLanguage(
|
||||||
).equalsIgnoreCase(getInputLocale().getLanguage()));
|
).equalsIgnoreCase(getInputLocale().getLanguage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale getInputLocale() {
|
public Locale getInputLocale() {
|
||||||
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
return mLanguageSwitcher.getInputLocale();
|
return mLanguageSwitcher.getInputLocale();
|
||||||
}
|
}
|
||||||
// TODO: Implement for no legacy mode
|
// TODO: Implement for no legacy mode
|
||||||
|
@ -85,7 +88,7 @@ public class SubtypeSwitcher {
|
||||||
|
|
||||||
public String getInputLanguage() {
|
public String getInputLanguage() {
|
||||||
String inputLanguage = null;
|
String inputLanguage = null;
|
||||||
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
inputLanguage = mLanguageSwitcher.getInputLanguage();
|
inputLanguage = mLanguageSwitcher.getInputLanguage();
|
||||||
}
|
}
|
||||||
// Should return system locale if there is no Language available.
|
// Should return system locale if there is no Language available.
|
||||||
|
@ -96,7 +99,7 @@ public class SubtypeSwitcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getEnabledLanguages() {
|
public String[] getEnabledLanguages() {
|
||||||
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
return mLanguageSwitcher.getEnabledLanguages();
|
return mLanguageSwitcher.getEnabledLanguages();
|
||||||
}
|
}
|
||||||
// TODO: Implement for no legacy mode
|
// TODO: Implement for no legacy mode
|
||||||
|
@ -107,6 +110,7 @@ public class SubtypeSwitcher {
|
||||||
return mSystemLocale;
|
return mSystemLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Cache the value for faster processing.
|
||||||
public boolean isSystemLocaleSameAsInputLocale() {
|
public boolean isSystemLocaleSameAsInputLocale() {
|
||||||
// TODO: Takes care of two-char locale such as "en" in addition to "en_US"
|
// TODO: Takes care of two-char locale such as "en" in addition to "en_US"
|
||||||
return getSystemLocale().getLanguage().equalsIgnoreCase(
|
return getSystemLocale().getLanguage().equalsIgnoreCase(
|
||||||
|
@ -114,7 +118,7 @@ public class SubtypeSwitcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onConfigurationChanged(Configuration conf) {
|
public void onConfigurationChanged(Configuration conf) {
|
||||||
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
// If the system locale changes and is different from the saved
|
// If the system locale changes and is different from the saved
|
||||||
// locale (mSystemLocale), then reload the input locale list from the
|
// locale (mSystemLocale), then reload the input locale list from the
|
||||||
// latin ime settings (shared prefs) and reset the input locale
|
// latin ime settings (shared prefs) and reset the input locale
|
||||||
|
@ -132,7 +136,7 @@ public class SubtypeSwitcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
mLanguageSwitcher.loadLocales(sharedPreferences);
|
mLanguageSwitcher.loadLocales(sharedPreferences);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -151,6 +155,38 @@ public class SubtypeSwitcher {
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
private LanguageSwitcher mLanguageSwitcher;
|
private LanguageSwitcher mLanguageSwitcher;
|
||||||
|
|
||||||
|
public static String getLanguageName(Locale locale) {
|
||||||
|
return toTitleCase(locale.getDisplayLanguage(locale));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getShortLanguageName(Locale locale) {
|
||||||
|
return toTitleCase(locale.getLanguage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String toTitleCase(String s) {
|
||||||
|
if (s.length() == 0) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInputLanguageName() {
|
||||||
|
return getLanguageName(getInputLocale());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNextInputLanguageName() {
|
||||||
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
|
return getLanguageName(mLanguageSwitcher.getNextInputLocale());
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPreviousInputLanguageName() {
|
||||||
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
|
return getLanguageName(mLanguageSwitcher.getPrevInputLocale());
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: This can be an array of String
|
// TODO: This can be an array of String
|
||||||
// A list of locales which are supported by default for voice input, unless we get a
|
// A list of locales which are supported by default for voice input, unless we get a
|
||||||
|
@ -183,7 +219,7 @@ public class SubtypeSwitcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadSettings(SharedPreferences prefs) {
|
public void loadSettings(SharedPreferences prefs) {
|
||||||
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
mLanguageSwitcher.loadLocales(prefs);
|
mLanguageSwitcher.loadLocales(prefs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,9 +244,4 @@ public class SubtypeSwitcher {
|
||||||
mLanguageSwitcher.loadLocales(prefs);
|
mLanguageSwitcher.loadLocales(prefs);
|
||||||
mLanguageSwitcher.setSystemLocale(conf.locale);
|
mLanguageSwitcher.setSystemLocale(conf.locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove this function when the refactor for LanguageSwitcher will be finished
|
|
||||||
public LanguageSwitcher getLanguageSwitcher() {
|
|
||||||
return mLanguageSwitcher;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue