diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/KeyboardSwitcher.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/KeyboardSwitcher.java | 64 |
1 files changed, 56 insertions, 8 deletions
diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 1a196448f..5a271f264 100644 --- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -21,11 +21,12 @@ import java.util.Locale; import java.util.Map; import android.content.Context; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; -import android.inputmethodservice.InputMethodService; +import android.preference.PreferenceManager; -public class KeyboardSwitcher { +public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceChangeListener { public static final int MODE_TEXT = 1; public static final int MODE_SYMBOLS = 2; @@ -45,6 +46,13 @@ public class KeyboardSwitcher { public static final int KEYBOARDMODE_IM = R.id.mode_im; public static final int KEYBOARDMODE_WEB = R.id.mode_webentry; + public static final String DEFAULT_LAYOUT_ID = "3"; + public static final String PREF_KEYBOARD_LAYOUT = "keyboard_layout"; + private static final int[] LAYOUTS = new int [] { + R.layout.input, R.layout.input2, R.layout.input3, R.layout.input4, R.layout.input5, + R.layout.input6 + }; + private static final int SYMBOLS_MODE_STATE_NONE = 0; private static final int SYMBOLS_MODE_STATE_BEGIN = 1; private static final int SYMBOLS_MODE_STATE_SYMBOL = 2; @@ -57,9 +65,8 @@ public class KeyboardSwitcher { KEYBOARDMODE_IM, KEYBOARDMODE_WEB}; - //LatinIME mContext; Context mContext; - InputMethodService mInputMethodService; + LatinIME mInputMethodService; private KeyboardId mSymbolsId; private KeyboardId mSymbolsShiftedId; @@ -79,14 +86,20 @@ public class KeyboardSwitcher { private int mLastDisplayWidth; private LanguageSwitcher mLanguageSwitcher; private Locale mInputLocale; - private boolean mEnableMultipleLanguages; - KeyboardSwitcher(Context context, InputMethodService ims) { + private int mLayoutId; + + KeyboardSwitcher(Context context, LatinIME ims) { mContext = context; mKeyboards = new HashMap<KeyboardId, LatinKeyboard>(); mSymbolsId = new KeyboardId(R.xml.kbd_symbols, false); mSymbolsShiftedId = new KeyboardId(R.xml.kbd_symbols_shift, false); mInputMethodService = ims; + + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ims); + int mLayoutId = Integer.valueOf(prefs.getString(PREF_KEYBOARD_LAYOUT, DEFAULT_LAYOUT_ID)); + prefs.registerOnSharedPreferenceChangeListener(this); + changeLatinKeyboardView(mLayoutId, false); } /** @@ -98,13 +111,12 @@ public class KeyboardSwitcher { void setLanguageSwitcher(LanguageSwitcher languageSwitcher) { mLanguageSwitcher = languageSwitcher; mInputLocale = mLanguageSwitcher.getInputLocale(); - mEnableMultipleLanguages = mLanguageSwitcher.getLocaleCount() > 1; } void setInputView(LatinKeyboardView inputView) { mInputView = inputView; } - + void makeKeyboards(boolean forceCreate) { if (forceCreate) mKeyboards.clear(); // Configuration change is coming after the keyboard gets recreated. So don't rely on that. @@ -140,6 +152,7 @@ public class KeyboardSwitcher { this(xml, 0, false, hasVoice); } + @Override public boolean equals(Object other) { return other instanceof KeyboardId && equals((KeyboardId) other); } @@ -150,6 +163,7 @@ public class KeyboardSwitcher { && other.mEnableShiftLock == this.mEnableShiftLock; } + @Override public int hashCode() { return (mXml + 1) * (mKeyboardMode + 1) * (mEnableShiftLock ? 2 : 1) * (mHasVoice ? 4 : 8); @@ -348,4 +362,38 @@ public class KeyboardSwitcher { } return false; } + + public LatinKeyboardView getInputView() { + return mInputView; + } + + public void recreateInputView() { + changeLatinKeyboardView(mLayoutId, true); + } + + private void changeLatinKeyboardView(int newLayout, boolean forceReset) { + if (mLayoutId != newLayout || mInputView == null || forceReset) { + if (LAYOUTS.length <= newLayout) { + newLayout = Integer.valueOf(DEFAULT_LAYOUT_ID); + } + mInputView = (LatinKeyboardView) mInputMethodService.getLayoutInflater().inflate( + LAYOUTS[newLayout], null); + mInputView.setOnKeyboardActionListener(mInputMethodService); + mLayoutId = newLayout; + } + mInputMethodService.mHandler.post(new Runnable() { + public void run() { + if (mInputView != null) { + mInputMethodService.setInputView(mInputView); + } + mInputMethodService.updateInputViewShown(); + }}); + } + + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (PREF_KEYBOARD_LAYOUT.equals(key)) { + changeLatinKeyboardView( + Integer.valueOf(sharedPreferences.getString(key, DEFAULT_LAYOUT_ID)), false); + } + } } |