From 12e582c79c4e8028bb03971377633440aa95cefb Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Wed, 30 Sep 2009 21:15:47 -0700 Subject: [PATCH] Fix 2146178: On-screen keyboard is wider than screen Sometimes the keyboard is getting confused about it's width when switching between hard keyboard open and close state and portrait-forced home. Force creation of keyboard layouts after a configuration change to fix the inconsistent state. Don't force create when just switching between input fields, too expensive. Also fixes the problem of keyboard not changing layout after a locale change, unless there's an orientation change. --- .../inputmethod/latin/KeyboardSwitcher.java | 5 +++-- src/com/android/inputmethod/latin/LatinIME.java | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 2da703632..c82587b71 100644 --- a/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -70,14 +70,15 @@ public class KeyboardSwitcher { mInputView = inputView; } - void makeKeyboards() { + void makeKeyboards(boolean forceCreate) { + if (forceCreate) mKeyboards.clear(); // Configuration change is coming after the keyboard gets recreated. So don't rely on that. // If keyboards have already been made, check if we have a screen width change and // create the keyboard layouts again at the correct orientation int displayWidth = mContext.getMaxWidth(); if (displayWidth == mLastDisplayWidth) return; mLastDisplayWidth = displayWidth; - mKeyboards.clear(); + if (!forceCreate) mKeyboards.clear(); mSymbolsId = new KeyboardId(R.xml.kbd_symbols); mSymbolsShiftedId = new KeyboardId(R.xml.kbd_symbols_shift); } diff --git a/src/com/android/inputmethod/latin/LatinIME.java b/src/com/android/inputmethod/latin/LatinIME.java index 6ee9bd127..8c9102d8c 100644 --- a/src/com/android/inputmethod/latin/LatinIME.java +++ b/src/com/android/inputmethod/latin/LatinIME.java @@ -210,16 +210,16 @@ public class LatinIME extends InputMethodService public void onConfigurationChanged(Configuration conf) { if (!TextUtils.equals(conf.locale.toString(), mLocale)) { initSuggest(conf.locale.toString()); - if (mKeyboardSwitcher == null) { - mKeyboardSwitcher = new KeyboardSwitcher(this); - } - mKeyboardSwitcher.makeKeyboards(); } // If orientation changed while predicting, commit the change if (conf.orientation != mOrientation) { commitTyped(getCurrentInputConnection()); mOrientation = conf.orientation; } + if (mKeyboardSwitcher == null) { + mKeyboardSwitcher = new KeyboardSwitcher(this); + } + mKeyboardSwitcher.makeKeyboards(true); super.onConfigurationChanged(conf); } @@ -228,7 +228,7 @@ public class LatinIME extends InputMethodService mInputView = (LatinKeyboardView) getLayoutInflater().inflate( R.layout.input, null); mKeyboardSwitcher.setInputView(mInputView); - mKeyboardSwitcher.makeKeyboards(); + mKeyboardSwitcher.makeKeyboards(true); mInputView.setOnKeyboardActionListener(this); mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_TEXT, 0); return mInputView; @@ -236,7 +236,7 @@ public class LatinIME extends InputMethodService @Override public View onCreateCandidatesView() { - mKeyboardSwitcher.makeKeyboards(); + mKeyboardSwitcher.makeKeyboards(true); mCandidateViewContainer = (CandidateViewContainer) getLayoutInflater().inflate( R.layout.candidates, null); mCandidateViewContainer.initViews(); @@ -253,7 +253,7 @@ public class LatinIME extends InputMethodService return; } - mKeyboardSwitcher.makeKeyboards(); + mKeyboardSwitcher.makeKeyboards(false); TextEntryState.newSession(this);