Move functions related to LanguageSwitcher to LatinIMESubtypeSwitcher
Change-Id: I5fa306cf311063ff96b6d45faaca2ffe84cddbf9main
parent
3a4d9b420f
commit
0ed7191b4d
|
@ -925,17 +925,14 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
public void showPreview(int keyIndex, PointerTracker tracker) {
|
public void showPreview(int keyIndex, PointerTracker tracker) {
|
||||||
int oldKeyIndex = mOldPreviewKeyIndex;
|
int oldKeyIndex = mOldPreviewKeyIndex;
|
||||||
mOldPreviewKeyIndex = keyIndex;
|
mOldPreviewKeyIndex = keyIndex;
|
||||||
final boolean isLanguageSwitchEnabled = (mKeyboard instanceof LatinKeyboard)
|
|
||||||
&& ((LatinKeyboard)mKeyboard).isLanguageSwitchEnabled();
|
|
||||||
// We should re-draw popup preview when 1) we need to hide the preview, 2) we will show
|
// We should re-draw popup preview when 1) we need to hide the preview, 2) we will show
|
||||||
// the space key preview and 3) pointer moves off the space key to other letter key, we
|
// the space key preview and 3) pointer moves off the space key to other letter key, we
|
||||||
// should hide the preview of the previous key.
|
// should hide the preview of the previous key.
|
||||||
final boolean hidePreviewOrShowSpaceKeyPreview = (tracker == null)
|
final boolean hidePreviewOrShowSpaceKeyPreview = (tracker == null)
|
||||||
|| 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
|
if (oldKeyIndex != keyIndex && (mShowPreview || (hidePreviewOrShowSpaceKeyPreview
|
||||||
&& (mShowPreview
|
&& SubtypeSwitcher.getInstance().isLanguageSwitchEnabled()))) {
|
||||||
|| (hidePreviewOrShowSpaceKeyPreview && isLanguageSwitchEnabled))) {
|
|
||||||
if (keyIndex == NOT_A_KEY) {
|
if (keyIndex == NOT_A_KEY) {
|
||||||
mHandler.cancelPopupPreview();
|
mHandler.cancelPopupPreview();
|
||||||
mHandler.dismissPreview(mDelayAfterPreview);
|
mHandler.dismissPreview(mDelayAfterPreview);
|
||||||
|
|
|
@ -71,9 +71,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
private static final int SYMBOLS_MODE_STATE_BEGIN = 1;
|
private static final int SYMBOLS_MODE_STATE_BEGIN = 1;
|
||||||
private static final int SYMBOLS_MODE_STATE_SYMBOL = 2;
|
private static final int SYMBOLS_MODE_STATE_SYMBOL = 2;
|
||||||
|
|
||||||
|
private SubtypeSwitcher mSubtypeSwitcher;
|
||||||
|
|
||||||
private LatinKeyboardView mInputView;
|
private LatinKeyboardView mInputView;
|
||||||
private final LatinIME mInputMethodService;
|
private LatinIME mInputMethodService;
|
||||||
private final LanguageSwitcher mLanguageSwitcher;
|
|
||||||
|
|
||||||
private ShiftKeyState mShiftState = new ShiftKeyState();
|
private ShiftKeyState mShiftState = new ShiftKeyState();
|
||||||
private ModifierKeyState mSymbolKeyState = new ModifierKeyState();
|
private ModifierKeyState mSymbolKeyState = new ModifierKeyState();
|
||||||
|
@ -107,17 +108,27 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
|
|
||||||
private int mLayoutId;
|
private int mLayoutId;
|
||||||
|
|
||||||
public KeyboardSwitcher(LatinIME ims, LanguageSwitcher languageSwitcher) {
|
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
||||||
mInputMethodService = ims;
|
|
||||||
mLanguageSwitcher = languageSwitcher;
|
public static KeyboardSwitcher getInstance() {
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private KeyboardSwitcher() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init(LatinIME ims) {
|
||||||
|
sInstance.mInputMethodService = ims;
|
||||||
|
sInstance.mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
||||||
|
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ims);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ims);
|
||||||
mLayoutId = Integer.valueOf(prefs.getString(PREF_KEYBOARD_LAYOUT, DEFAULT_LAYOUT_ID));
|
sInstance.mLayoutId = Integer.valueOf(
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.getString(PREF_KEYBOARD_LAYOUT, DEFAULT_LAYOUT_ID));
|
||||||
|
prefs.registerOnSharedPreferenceChangeListener(sInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeSymbolsKeyboardIds() {
|
private void makeSymbolsKeyboardIds() {
|
||||||
final Locale locale = mLanguageSwitcher.getInputLocale();
|
final Locale locale = mSubtypeSwitcher.getInputLocale();
|
||||||
final int orientation = mInputMethodService.getResources().getConfiguration().orientation;
|
final int orientation = mInputMethodService.getResources().getConfiguration().orientation;
|
||||||
final int mode = mMode;
|
final int mode = mMode;
|
||||||
final int colorScheme = getCharColorId();
|
final int colorScheme = getCharColorId();
|
||||||
|
@ -278,17 +289,15 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
LatinKeyboard keyboard = (ref == null) ? null : ref.get();
|
LatinKeyboard keyboard = (ref == null) ? null : ref.get();
|
||||||
if (keyboard == null) {
|
if (keyboard == null) {
|
||||||
final Resources res = mInputMethodService.getResources();
|
final Resources res = mInputMethodService.getResources();
|
||||||
final Configuration conf = res.getConfiguration();
|
final Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(
|
||||||
final Locale saveLocale = conf.locale;
|
mSubtypeSwitcher.getInputLocale());
|
||||||
conf.locale = mLanguageSwitcher.getInputLocale();
|
|
||||||
res.updateConfiguration(conf, null);
|
|
||||||
|
|
||||||
final int xml = id.getXmlId();
|
final int xml = id.getXmlId();
|
||||||
keyboard = new LatinKeyboard(mInputMethodService, id);
|
keyboard = new LatinKeyboard(mInputMethodService, id);
|
||||||
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(mLanguageSwitcher);
|
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));
|
||||||
|
|
||||||
|
@ -301,8 +310,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": "
|
Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": "
|
||||||
+ ((ref == null) ? "LOAD" : "GCed") + " id=" + id);
|
+ ((ref == null) ? "LOAD" : "GCed") + " id=" + id);
|
||||||
|
|
||||||
conf.locale = saveLocale;
|
mSubtypeSwitcher.changeSystemLocale(savedLocale);
|
||||||
res.updateConfiguration(conf, null);
|
|
||||||
} else if (DEBUG) {
|
} else if (DEBUG) {
|
||||||
Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": HIT id=" + id);
|
Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": HIT id=" + id);
|
||||||
}
|
}
|
||||||
|
@ -326,7 +334,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
enableShiftLock = mode == MODE_PHONE ? false : true;
|
enableShiftLock = mode == MODE_PHONE ? false : true;
|
||||||
}
|
}
|
||||||
final int orientation = mInputMethodService.getResources().getConfiguration().orientation;
|
final int orientation = mInputMethodService.getResources().getConfiguration().orientation;
|
||||||
final Locale locale = mLanguageSwitcher.getInputLocale();
|
final Locale locale = mSubtypeSwitcher.getInputLocale();
|
||||||
return new KeyboardId(locale, orientation, mode, xmlArray,
|
return new KeyboardId(locale, orientation, mode, xmlArray,
|
||||||
charColorId, mHasSettingsKey, hasVoiceKey, imeOptions, enableShiftLock);
|
charColorId, mHasSettingsKey, hasVoiceKey, imeOptions, enableShiftLock);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.LatinIMEUtil.RingCharBuffer;
|
import com.android.inputmethod.latin.LatinIMEUtil.RingCharBuffer;
|
||||||
import com.android.inputmethod.voice.FieldContext;
|
import com.android.inputmethod.voice.FieldContext;
|
||||||
import com.android.inputmethod.voice.SettingsUtil;
|
|
||||||
import com.android.inputmethod.voice.VoiceInput;
|
import com.android.inputmethod.voice.VoiceInput;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
@ -63,6 +62,7 @@ import android.view.inputmethod.ExtractedText;
|
||||||
import android.view.inputmethod.ExtractedTextRequest;
|
import android.view.inputmethod.ExtractedTextRequest;
|
||||||
import android.view.inputmethod.InputConnection;
|
import android.view.inputmethod.InputConnection;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
|
@ -70,7 +70,6 @@ import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -109,20 +108,6 @@ public class LatinIME extends InputMethodService
|
||||||
private static final String PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE =
|
private static final String PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE =
|
||||||
"has_used_voice_input_unsupported_locale";
|
"has_used_voice_input_unsupported_locale";
|
||||||
|
|
||||||
// A list of locales which are supported by default for voice input, unless we get a
|
|
||||||
// different list from Gservices.
|
|
||||||
public static final String DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES =
|
|
||||||
"en " +
|
|
||||||
"en_US " +
|
|
||||||
"en_GB " +
|
|
||||||
"en_AU " +
|
|
||||||
"en_CA " +
|
|
||||||
"en_IE " +
|
|
||||||
"en_IN " +
|
|
||||||
"en_NZ " +
|
|
||||||
"en_SG " +
|
|
||||||
"en_ZA ";
|
|
||||||
|
|
||||||
// The private IME option used to indicate that no microphone should be shown for a
|
// The private IME option used to indicate that no microphone should be shown for a
|
||||||
// given text field. For instance this is specified by the search dialog when the
|
// given text field. For instance this is specified by the search dialog when the
|
||||||
// dialog is already showing a voice search button.
|
// dialog is already showing a voice search button.
|
||||||
|
@ -174,6 +159,7 @@ public class LatinIME extends InputMethodService
|
||||||
private AlertDialog mVoiceWarningDialog;
|
private AlertDialog mVoiceWarningDialog;
|
||||||
|
|
||||||
private KeyboardSwitcher mKeyboardSwitcher;
|
private KeyboardSwitcher mKeyboardSwitcher;
|
||||||
|
private SubtypeSwitcher mSubtypeSwitcher;
|
||||||
|
|
||||||
private UserDictionary mUserDictionary;
|
private UserDictionary mUserDictionary;
|
||||||
private UserBigramDictionary mUserBigramDictionary;
|
private UserBigramDictionary mUserBigramDictionary;
|
||||||
|
@ -184,10 +170,6 @@ public class LatinIME extends InputMethodService
|
||||||
|
|
||||||
private Resources mResources;
|
private Resources mResources;
|
||||||
|
|
||||||
private String mInputLocale;
|
|
||||||
private String mSystemLocale;
|
|
||||||
private LanguageSwitcher mLanguageSwitcher;
|
|
||||||
|
|
||||||
private final StringBuilder mComposing = new StringBuilder();
|
private final StringBuilder mComposing = new StringBuilder();
|
||||||
private WordComposer mWord = new WordComposer();
|
private WordComposer mWord = new WordComposer();
|
||||||
private int mCommittedLength;
|
private int mCommittedLength;
|
||||||
|
@ -394,20 +376,15 @@ public class LatinIME extends InputMethodService
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
LatinImeLogger.init(this);
|
LatinImeLogger.init(this);
|
||||||
|
SubtypeSwitcher.init(this);
|
||||||
|
KeyboardSwitcher.init(this);
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
//setStatusIcon(R.drawable.ime_qwerty);
|
//setStatusIcon(R.drawable.ime_qwerty);
|
||||||
mResources = getResources();
|
mResources = getResources();
|
||||||
final Configuration conf = mResources.getConfiguration();
|
final Configuration conf = mResources.getConfiguration();
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
mLanguageSwitcher = new LanguageSwitcher(this);
|
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
||||||
mLanguageSwitcher.loadLocales(prefs);
|
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
||||||
mKeyboardSwitcher = new KeyboardSwitcher(this, mLanguageSwitcher);
|
|
||||||
mSystemLocale = conf.locale.toString();
|
|
||||||
mLanguageSwitcher.setSystemLocale(conf.locale);
|
|
||||||
String inputLanguage = mLanguageSwitcher.getInputLanguage();
|
|
||||||
if (inputLanguage == null) {
|
|
||||||
inputLanguage = conf.locale.toString();
|
|
||||||
}
|
|
||||||
mReCorrectionEnabled = prefs.getBoolean(PREF_RECORRECTION_ENABLED,
|
mReCorrectionEnabled = prefs.getBoolean(PREF_RECORRECTION_ENABLED,
|
||||||
getResources().getBoolean(R.bool.default_recorrection_enabled));
|
getResources().getBoolean(R.bool.default_recorrection_enabled));
|
||||||
|
|
||||||
|
@ -415,10 +392,10 @@ public class LatinIME extends InputMethodService
|
||||||
boolean tryGC = true;
|
boolean tryGC = true;
|
||||||
for (int i = 0; i < LatinIMEUtil.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
for (int i = 0; i < LatinIMEUtil.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
||||||
try {
|
try {
|
||||||
initSuggest(inputLanguage);
|
initSuggest();
|
||||||
tryGC = false;
|
tryGC = false;
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
tryGC = LatinIMEUtil.GCUtils.getInstance().tryGCOrWait(inputLanguage, e);
|
tryGC = LatinIMEUtil.GCUtils.getInstance().tryGCOrWait("InitSuggest", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,14 +460,12 @@ public class LatinIME extends InputMethodService
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSuggest(String locale) {
|
private void initSuggest() {
|
||||||
mInputLocale = locale;
|
updateAutoTextEnabled();
|
||||||
|
String locale = mSubtypeSwitcher.getInputLanguage();
|
||||||
|
|
||||||
Resources orig = getResources();
|
Resources orig = getResources();
|
||||||
Configuration conf = orig.getConfiguration();
|
Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(new Locale(locale));
|
||||||
Locale saveLocale = conf.locale;
|
|
||||||
conf.locale = new Locale(locale);
|
|
||||||
orig.updateConfiguration(conf, orig.getDisplayMetrics());
|
|
||||||
if (mSuggest != null) {
|
if (mSuggest != null) {
|
||||||
mSuggest.close();
|
mSuggest.close();
|
||||||
}
|
}
|
||||||
|
@ -500,21 +475,19 @@ public class LatinIME extends InputMethodService
|
||||||
int[] dictionaries = getDictionary(orig);
|
int[] dictionaries = getDictionary(orig);
|
||||||
mSuggest = new Suggest(this, dictionaries);
|
mSuggest = new Suggest(this, dictionaries);
|
||||||
loadAndSetAutoCompletionThreshold(sp);
|
loadAndSetAutoCompletionThreshold(sp);
|
||||||
updateAutoTextEnabled(saveLocale);
|
|
||||||
if (mUserDictionary != null) mUserDictionary.close();
|
if (mUserDictionary != null) mUserDictionary.close();
|
||||||
mUserDictionary = new UserDictionary(this, mInputLocale);
|
mUserDictionary = new UserDictionary(this, locale);
|
||||||
if (mContactsDictionary == null) {
|
if (mContactsDictionary == null) {
|
||||||
mContactsDictionary = new ContactsDictionary(this, Suggest.DIC_CONTACTS);
|
mContactsDictionary = new ContactsDictionary(this, Suggest.DIC_CONTACTS);
|
||||||
}
|
}
|
||||||
if (mAutoDictionary != null) {
|
if (mAutoDictionary != null) {
|
||||||
mAutoDictionary.close();
|
mAutoDictionary.close();
|
||||||
}
|
}
|
||||||
mAutoDictionary = new AutoDictionary(this, this, mInputLocale, Suggest.DIC_AUTO);
|
mAutoDictionary = new AutoDictionary(this, this, locale, Suggest.DIC_AUTO);
|
||||||
if (mUserBigramDictionary != null) {
|
if (mUserBigramDictionary != null) {
|
||||||
mUserBigramDictionary.close();
|
mUserBigramDictionary.close();
|
||||||
}
|
}
|
||||||
mUserBigramDictionary = new UserBigramDictionary(this, this, mInputLocale,
|
mUserBigramDictionary = new UserBigramDictionary(this, this, locale, Suggest.DIC_USER);
|
||||||
Suggest.DIC_USER);
|
|
||||||
mSuggest.setUserBigramDictionary(mUserBigramDictionary);
|
mSuggest.setUserBigramDictionary(mUserBigramDictionary);
|
||||||
mSuggest.setUserDictionary(mUserDictionary);
|
mSuggest.setUserDictionary(mUserDictionary);
|
||||||
mSuggest.setContactsDictionary(mContactsDictionary);
|
mSuggest.setContactsDictionary(mContactsDictionary);
|
||||||
|
@ -523,8 +496,7 @@ public class LatinIME extends InputMethodService
|
||||||
mWordSeparators = mResources.getString(R.string.word_separators);
|
mWordSeparators = mResources.getString(R.string.word_separators);
|
||||||
mSentenceSeparators = mResources.getString(R.string.sentence_separators);
|
mSentenceSeparators = mResources.getString(R.string.sentence_separators);
|
||||||
|
|
||||||
conf.locale = saveLocale;
|
mSubtypeSwitcher.changeSystemLocale(savedLocale);
|
||||||
orig.updateConfiguration(conf, orig.getDisplayMetrics());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -546,18 +518,9 @@ public class LatinIME extends InputMethodService
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration conf) {
|
public void onConfigurationChanged(Configuration conf) {
|
||||||
// If the system locale changes and is different from the saved
|
mSubtypeSwitcher.onConfigurationChanged(conf);
|
||||||
// locale (mSystemLocale), then reload the input locale list from the
|
updateAutoTextEnabled();
|
||||||
// latin ime settings (shared prefs) and reset the input locale
|
|
||||||
// to the first one.
|
|
||||||
final String systemLocale = conf.locale.toString();
|
|
||||||
if (!TextUtils.equals(systemLocale, mSystemLocale)) {
|
|
||||||
mSystemLocale = systemLocale;
|
|
||||||
mLanguageSwitcher.loadLocales(
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(this));
|
|
||||||
mLanguageSwitcher.setSystemLocale(conf.locale);
|
|
||||||
toggleLanguage(true, true);
|
|
||||||
}
|
|
||||||
// If orientation changed while predicting, commit the change
|
// If orientation changed while predicting, commit the change
|
||||||
if (conf.orientation != mOrientation) {
|
if (conf.orientation != mOrientation) {
|
||||||
InputConnection ic = getCurrentInputConnection();
|
InputConnection ic = getCurrentInputConnection();
|
||||||
|
@ -1637,11 +1600,7 @@ public class LatinIME extends InputMethodService
|
||||||
// Clear N-best suggestions
|
// Clear N-best suggestions
|
||||||
clearSuggestions();
|
clearSuggestions();
|
||||||
|
|
||||||
FieldContext context = new FieldContext(
|
FieldContext context = makeFieldContext();
|
||||||
getCurrentInputConnection(),
|
|
||||||
getCurrentInputEditorInfo(),
|
|
||||||
mLanguageSwitcher.getInputLanguage(),
|
|
||||||
mLanguageSwitcher.getEnabledLanguages());
|
|
||||||
mVoiceInput.startListening(context, swipe);
|
mVoiceInput.startListening(context, swipe);
|
||||||
switchToRecognitionStatusView();
|
switchToRecognitionStatusView();
|
||||||
}
|
}
|
||||||
|
@ -2218,30 +2177,21 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleLanguage(boolean reset, boolean next) {
|
private void toggleLanguage(boolean reset, boolean next) {
|
||||||
if (reset) {
|
mSubtypeSwitcher.toggleLanguage(reset, next);
|
||||||
mLanguageSwitcher.reset();
|
|
||||||
} else {
|
|
||||||
if (next) {
|
|
||||||
mLanguageSwitcher.next();
|
|
||||||
} else {
|
|
||||||
mLanguageSwitcher.prev();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||||
final int mode = switcher.getKeyboardMode();
|
final int mode = switcher.getKeyboardMode();
|
||||||
final EditorInfo attribute = getCurrentInputEditorInfo();
|
final EditorInfo attribute = getCurrentInputEditorInfo();
|
||||||
final int imeOptions = (attribute != null) ? attribute.imeOptions : 0;
|
final int imeOptions = (attribute != null) ? attribute.imeOptions : 0;
|
||||||
switcher.loadKeyboard(mode, imeOptions, mVoiceButtonEnabled,
|
switcher.loadKeyboard(mode, imeOptions, mVoiceButtonEnabled,
|
||||||
mVoiceButtonOnPrimary);
|
mVoiceButtonOnPrimary);
|
||||||
initSuggest(mLanguageSwitcher.getInputLanguage());
|
initSuggest();
|
||||||
mLanguageSwitcher.persist();
|
|
||||||
switcher.updateShiftState();
|
switcher.updateShiftState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||||
String key) {
|
String key) {
|
||||||
|
mSubtypeSwitcher.onSharedPreferenceChanged(sharedPreferences, key);
|
||||||
if (PREF_SELECTED_LANGUAGES.equals(key)) {
|
if (PREF_SELECTED_LANGUAGES.equals(key)) {
|
||||||
mLanguageSwitcher.loadLocales(sharedPreferences);
|
|
||||||
mRefreshKeyboardRequired = true;
|
mRefreshKeyboardRequired = true;
|
||||||
} else if (PREF_RECORRECTION_ENABLED.equals(key)) {
|
} else if (PREF_RECORRECTION_ENABLED.equals(key)) {
|
||||||
mReCorrectionEnabled = sharedPreferences.getBoolean(PREF_RECORRECTION_ENABLED,
|
mReCorrectionEnabled = sharedPreferences.getBoolean(PREF_RECORRECTION_ENABLED,
|
||||||
|
@ -2267,7 +2217,6 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
|
|
||||||
public void swipeUp() {
|
public void swipeUp() {
|
||||||
//launchSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPress(int primaryCode) {
|
public void onPress(int primaryCode) {
|
||||||
|
@ -2300,8 +2249,8 @@ public class LatinIME extends InputMethodService
|
||||||
return new FieldContext(
|
return new FieldContext(
|
||||||
getCurrentInputConnection(),
|
getCurrentInputConnection(),
|
||||||
getCurrentInputEditorInfo(),
|
getCurrentInputEditorInfo(),
|
||||||
mLanguageSwitcher.getInputLanguage(),
|
mSubtypeSwitcher.getInputLanguage(),
|
||||||
mLanguageSwitcher.getEnabledLanguages());
|
mSubtypeSwitcher.getEnabledLanguages());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean fieldCanDoVoice(FieldContext fieldContext) {
|
private boolean fieldCanDoVoice(FieldContext fieldContext) {
|
||||||
|
@ -2420,11 +2369,10 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAutoTextEnabled(Locale systemLocale) {
|
private void updateAutoTextEnabled() {
|
||||||
if (mSuggest == null) return;
|
if (mSuggest == null) return;
|
||||||
boolean different =
|
mSuggest.setAutoTextEnabled(mQuickFixes
|
||||||
!systemLocale.getLanguage().equalsIgnoreCase(mInputLocale.substring(0, 2));
|
&& SubtypeSwitcher.getInstance().isSystemLocaleSameAsInputLocale());
|
||||||
mSuggest.setAutoTextEnabled(!different && mQuickFixes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSuggestionVisibility(SharedPreferences prefs) {
|
private void updateSuggestionVisibility(SharedPreferences prefs) {
|
||||||
|
@ -2470,19 +2418,8 @@ public class LatinIME extends InputMethodService
|
||||||
mHasUsedVoiceInputUnsupportedLocale =
|
mHasUsedVoiceInputUnsupportedLocale =
|
||||||
sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false);
|
sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false);
|
||||||
|
|
||||||
// Get the current list of supported locales and check the current locale against that
|
mLocaleSupportedForVoiceInput = SubtypeSwitcher.getInstance().isVoiceSupported(
|
||||||
// list. We cache this value so as not to check it every time the user starts a voice
|
SubtypeSwitcher.getInstance().getInputLanguage());
|
||||||
// input. Because this method is called by onStartInputView, this should mean that as
|
|
||||||
// long as the locale doesn't change while the user is keeping the IME open, the
|
|
||||||
// value should never be stale.
|
|
||||||
String supportedLocalesString = SettingsUtil.getSettingsString(
|
|
||||||
getContentResolver(),
|
|
||||||
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
|
||||||
DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
|
||||||
ArrayList<String> voiceInputSupportedLocales =
|
|
||||||
newArrayList(supportedLocalesString.split("\\s+"));
|
|
||||||
|
|
||||||
mLocaleSupportedForVoiceInput = voiceInputSupportedLocales.contains(mInputLocale);
|
|
||||||
|
|
||||||
mAutoCorrectEnabled = isAutoCorrectEnabled(sp);
|
mAutoCorrectEnabled = isAutoCorrectEnabled(sp);
|
||||||
mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(sp);
|
mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(sp);
|
||||||
|
@ -2496,9 +2433,9 @@ public class LatinIME extends InputMethodService
|
||||||
mVoiceButtonOnPrimary = voiceMode.equals(getString(R.string.voice_mode_main));
|
mVoiceButtonOnPrimary = voiceMode.equals(getString(R.string.voice_mode_main));
|
||||||
}
|
}
|
||||||
updateCorrectionMode();
|
updateCorrectionMode();
|
||||||
updateAutoTextEnabled(mResources.getConfiguration().locale);
|
updateAutoTextEnabled();
|
||||||
updateSuggestionVisibility(sp);
|
updateSuggestionVisibility(sp);
|
||||||
mLanguageSwitcher.loadLocales(sp);
|
SubtypeSwitcher.getInstance().loadSettings(sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2599,13 +2536,6 @@ public class LatinIME extends InputMethodService
|
||||||
mOptionsDialog.show();
|
mOptionsDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <E> ArrayList<E> newArrayList(E... elements) {
|
|
||||||
int capacity = (elements.length * 110) / 100 + 5;
|
|
||||||
ArrayList<E> list = new ArrayList<E>(capacity);
|
|
||||||
Collections.addAll(list, elements);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
|
protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
|
||||||
super.dump(fd, fout, args);
|
super.dump(fd, fout, args);
|
||||||
|
@ -2647,4 +2577,9 @@ public class LatinIME extends InputMethodService
|
||||||
public void onAutoCompletionStateChanged(boolean isAutoCompletion) {
|
public void onAutoCompletionStateChanged(boolean isAutoCompletion) {
|
||||||
mKeyboardSwitcher.onAutoCompletionStateChanged(isAutoCompletion);
|
mKeyboardSwitcher.onAutoCompletionStateChanged(isAutoCompletion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
|
||||||
|
SubtypeSwitcher.getInstance().onCurrentInputMethodSubtypeChanged(subtype);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,13 +182,7 @@ public class LatinIMESettings extends PreferenceActivity
|
||||||
// Get the current list of supported locales and check the current locale against
|
// Get the current list of supported locales and check the current locale against
|
||||||
// that list, to decide whether to put a warning that voice input will not work in
|
// that list, to decide whether to put a warning that voice input will not work in
|
||||||
// the current language as part of the pop-up confirmation dialog.
|
// the current language as part of the pop-up confirmation dialog.
|
||||||
String supportedLocalesString = SettingsUtil.getSettingsString(
|
boolean localeSupported = SubtypeSwitcher.getInstance().isVoiceSupported(
|
||||||
getContentResolver(),
|
|
||||||
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
|
||||||
LatinIME.DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
|
||||||
ArrayList<String> voiceInputSupportedLocales =
|
|
||||||
LatinIME.newArrayList(supportedLocalesString.split("\\s+"));
|
|
||||||
boolean localeSupported = voiceInputSupportedLocales.contains(
|
|
||||||
Locale.getDefault().toString());
|
Locale.getDefault().toString());
|
||||||
|
|
||||||
if (localeSupported) {
|
if (localeSupported) {
|
||||||
|
|
|
@ -386,10 +386,6 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
return mSpaceKey;
|
return mSpaceKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLanguageSwitchEnabled() {
|
|
||||||
return mLocale != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
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.
|
||||||
|
|
|
@ -0,0 +1,216 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
|
import com.android.inputmethod.voice.SettingsUtil;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.inputmethodservice.InputMethodService;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class SubtypeSwitcher {
|
||||||
|
private static final boolean USE_LEGACY_LANGUAGE_SWITCHER = true;
|
||||||
|
private static final String TAG = "SubtypeSwitcher";
|
||||||
|
private static final SubtypeSwitcher sInstance = new SubtypeSwitcher();
|
||||||
|
private InputMethodService mService;
|
||||||
|
private Resources mResources;
|
||||||
|
private Locale mSystemLocale;
|
||||||
|
|
||||||
|
public static SubtypeSwitcher getInstance() {
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init(LatinIME service) {
|
||||||
|
sInstance.mService = service;
|
||||||
|
sInstance.mResources = service.getResources();
|
||||||
|
sInstance.mSystemLocale = sInstance.mResources.getConfiguration().locale;
|
||||||
|
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
||||||
|
sInstance.initLanguageSwitcher(service);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SubtypeSwitcher() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
// Language Switching functions //
|
||||||
|
//////////////////////////////////
|
||||||
|
|
||||||
|
private int getEnabledKeyboardLocaleCount() {
|
||||||
|
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
||||||
|
return mLanguageSwitcher.getLocaleCount();
|
||||||
|
}
|
||||||
|
// TODO: Implement for no legacy mode
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLanguageSwitchEnabled() {
|
||||||
|
// TODO: Takes care of two-char locale such as "en" in addition to "en_US"
|
||||||
|
return !(getEnabledKeyboardLocaleCount() == 1 && getSystemLocale().getLanguage(
|
||||||
|
).equalsIgnoreCase(getInputLocale().getLanguage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Locale getInputLocale() {
|
||||||
|
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
||||||
|
return mLanguageSwitcher.getInputLocale();
|
||||||
|
}
|
||||||
|
// TODO: Implement for no legacy mode
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInputLanguage() {
|
||||||
|
String inputLanguage = null;
|
||||||
|
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
||||||
|
inputLanguage = mLanguageSwitcher.getInputLanguage();
|
||||||
|
}
|
||||||
|
// Should return system locale if there is no Language available.
|
||||||
|
if (inputLanguage == null) {
|
||||||
|
inputLanguage = getSystemLocale().getLanguage();
|
||||||
|
}
|
||||||
|
return inputLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getEnabledLanguages() {
|
||||||
|
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
||||||
|
return mLanguageSwitcher.getEnabledLanguages();
|
||||||
|
}
|
||||||
|
// TODO: Implement for no legacy mode
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Locale getSystemLocale() {
|
||||||
|
return mSystemLocale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSystemLocaleSameAsInputLocale() {
|
||||||
|
// TODO: Takes care of two-char locale such as "en" in addition to "en_US"
|
||||||
|
return getSystemLocale().getLanguage().equalsIgnoreCase(
|
||||||
|
getInputLanguage().substring(0, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onConfigurationChanged(Configuration conf) {
|
||||||
|
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
||||||
|
// If the system locale changes and is different from the saved
|
||||||
|
// locale (mSystemLocale), then reload the input locale list from the
|
||||||
|
// latin ime settings (shared prefs) and reset the input locale
|
||||||
|
// to the first one.
|
||||||
|
final Locale systemLocale = conf.locale;
|
||||||
|
if (!TextUtils.equals(systemLocale.toString(), mSystemLocale.toString())) {
|
||||||
|
mSystemLocale = systemLocale;
|
||||||
|
mLanguageSwitcher.loadLocales(
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(mService));
|
||||||
|
mLanguageSwitcher.setSystemLocale(systemLocale);
|
||||||
|
toggleLanguage(true, true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
||||||
|
mLanguageSwitcher.loadLocales(sharedPreferences);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Locale changeSystemLocale(Locale newLocale) {
|
||||||
|
Configuration conf = mResources.getConfiguration();
|
||||||
|
Locale oldLocale = conf.locale;
|
||||||
|
conf.locale = newLocale;
|
||||||
|
mResources.updateConfiguration(conf, mResources.getDisplayMetrics());
|
||||||
|
return oldLocale;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
// Legacy Language Switch support //
|
||||||
|
////////////////////////////////////////////
|
||||||
|
private LanguageSwitcher mLanguageSwitcher;
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: This can be an array of String
|
||||||
|
// A list of locales which are supported by default for voice input, unless we get a
|
||||||
|
// different list from Gservices.
|
||||||
|
private static final String DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES =
|
||||||
|
"en " +
|
||||||
|
"en_US " +
|
||||||
|
"en_GB " +
|
||||||
|
"en_AU " +
|
||||||
|
"en_CA " +
|
||||||
|
"en_IE " +
|
||||||
|
"en_IN " +
|
||||||
|
"en_NZ " +
|
||||||
|
"en_SG " +
|
||||||
|
"en_ZA ";
|
||||||
|
|
||||||
|
public boolean isVoiceSupported(String locale) {
|
||||||
|
// Get the current list of supported locales and check the current locale against that
|
||||||
|
// list. We cache this value so as not to check it every time the user starts a voice
|
||||||
|
// input. Because this method is called by onStartInputView, this should mean that as
|
||||||
|
// long as the locale doesn't change while the user is keeping the IME open, the
|
||||||
|
// value should never be stale.
|
||||||
|
String supportedLocalesString = SettingsUtil.getSettingsString(
|
||||||
|
mService.getContentResolver(),
|
||||||
|
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
||||||
|
DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
||||||
|
List<String> voiceInputSupportedLocales = Arrays.asList(
|
||||||
|
supportedLocalesString.split("\\s+"));
|
||||||
|
return voiceInputSupportedLocales.contains(locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadSettings(SharedPreferences prefs) {
|
||||||
|
if (USE_LEGACY_LANGUAGE_SWITCHER) {
|
||||||
|
mLanguageSwitcher.loadLocales(prefs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleLanguage(boolean reset, boolean next) {
|
||||||
|
if (reset) {
|
||||||
|
mLanguageSwitcher.reset();
|
||||||
|
} else {
|
||||||
|
if (next) {
|
||||||
|
mLanguageSwitcher.next();
|
||||||
|
} else {
|
||||||
|
mLanguageSwitcher.prev();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mLanguageSwitcher.persist();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initLanguageSwitcher(LatinIME service) {
|
||||||
|
final Configuration conf = service.getResources().getConfiguration();
|
||||||
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(service);
|
||||||
|
mLanguageSwitcher = new LanguageSwitcher(service);
|
||||||
|
mLanguageSwitcher.loadLocales(prefs);
|
||||||
|
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