diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index d0a2f864c3b73f8585983e42172c22f12435b93d..2e4988fb0a9fb47d4bbfcd3a1958e51a61fc1dd9 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -113,14 +113,6 @@ public class KeyboardId { false, F2KEY_MODE_NONE, false, false, false); } - public KeyboardId cloneWithNewGeometry(int orientation, int width) { - if (mWidth == width) - return this; - return new KeyboardId(mXmlName, mXmlId, mLocale, orientation, width, mMode, mAttribute, - mHasSettingsKey, mF2KeyMode, mClobberSettingsKey, mShortcutKeyEnabled, - mHasShortcutKey); - } - public int getXmlId() { return mXmlId; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 10f110e0b9a5c5d0550e67fa175adabef36ca118..8bf82807a3309a3afd9613307786f4827d310040 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -20,7 +20,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; -import android.inputmethodservice.InputMethodService; +import android.util.DisplayMetrics; import android.util.Log; import android.view.ContextThemeWrapper; import android.view.InflateException; @@ -39,7 +39,6 @@ import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.Utils; import java.lang.ref.SoftReference; -import java.util.Arrays; import java.util.HashMap; import java.util.Locale; @@ -78,9 +77,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private KeyboardId mCurrentId; private final HashMap<KeyboardId, SoftReference<LatinKeyboard>> mKeyboardCache = new HashMap<KeyboardId, SoftReference<LatinKeyboard>>(); - // TODO: Remove this cache object when {@link DisplayMetrics} has actual window width excluding - // system navigation bar. - private WindowWidthCache mWindowWidthCache; private KeyboardLayoutState mSavedKeyboardState = new KeyboardLayoutState(); @@ -105,77 +101,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private static final KeyboardSwitcher sInstance = new KeyboardSwitcher(); - private static class WindowWidthCache { - private final InputMethodService mService; - private final Resources mResources; - private final boolean mIsRegistered[] = new boolean[Configuration.ORIENTATION_SQUARE + 1]; - private final int mWidth[] = new int[Configuration.ORIENTATION_SQUARE + 1]; - - public WindowWidthCache(InputMethodService service) { - mService = service; - mResources = service.getResources(); - - Arrays.fill(mIsRegistered, false); - Arrays.fill(mWidth, 0); - } - - private int getCurrentWindowWidth() { - return mService.getWindow().getWindow().getDecorView().getWidth(); - } - - public int getWidth(Configuration conf) { - final int orientation = conf.orientation; - try { - final int width = mWidth[orientation]; - if (mIsRegistered[orientation] || width > 0) { - // Return registered or cached window width for this orientation. - return width; - } - // Fall through - } catch (IndexOutOfBoundsException e) { - Log.w(TAG, "unknwon orientation value " + orientation); - // Fall through - } - - // Return screen width as default window width. - return mResources.getDisplayMetrics().widthPixels; - } - - public int getWidthOnSizeChanged(Configuration conf) { - final int orientation = conf.orientation; - try { - if (mIsRegistered[orientation]) { - // Return registered window width for this orientation. - return mWidth[orientation]; - } - - // Cache the current window width without registering. - final int width = getCurrentWindowWidth(); - mWidth[orientation] = width; - return width; - } catch (IndexOutOfBoundsException e) { - Log.w(TAG, "unknwon orientation value " + orientation); - return 0; - } - } - - public void registerWidth() { - final int orientation = mResources.getConfiguration().orientation; - try { - if (!mIsRegistered[orientation]) { - final int width = getCurrentWindowWidth(); - if (width > 0) { - // Register current window width. - mWidth[orientation] = width; - mIsRegistered[orientation] = true; - } - } - } catch (IndexOutOfBoundsException e) { - Log.w(TAG, "unknwon orientation value " + orientation); - } - } - } - public class KeyboardLayoutState { private boolean mIsValid; private boolean mIsAlphabetMode; @@ -247,7 +172,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mResources = ims.getResources(); mPrefs = prefs; mSubtypeSwitcher = SubtypeSwitcher.getInstance(); - mWindowWidthCache = new WindowWidthCache(ims); setContextThemeWrapper(ims, getKeyboardThemeIndex(ims, prefs)); prefs.registerOnSharedPreferenceChangeListener(this); } @@ -298,26 +222,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mIsAutoCorrectionActive = false; } - public void registerWindowWidth() { - mWindowWidthCache.registerWidth(); - } - - @SuppressWarnings("unused") - public void onSizeChanged(int w, int h, int oldw, int oldh) { - // TODO: This hack should be removed when display metric returns a proper width. - // Until then, the behavior of KeyboardSwitcher is suboptimal on a device that has a - // vertical system navigation bar in landscape screen orientation, for instance. - final Configuration conf = mResources.getConfiguration(); - final int width = mWindowWidthCache.getWidthOnSizeChanged(conf); - // If the window width hasn't fixed yet or keyboard doesn't exist, nothing to do with. - if (width == 0 || mCurrentId == null) - return; - // Reload keyboard with new width. - final KeyboardId newId = mCurrentId.cloneWithNewGeometry(conf.orientation, width); - mInputMethodService.mHandler.postRestoreKeyboardLayout(); - setKeyboard(getKeyboard(newId)); - } - private void setKeyboard(final Keyboard keyboard) { final Keyboard oldKeyboard = mKeyboardView.getKeyboard(); mKeyboardView.setKeyboard(keyboard); @@ -416,10 +320,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final int f2KeyMode = getF2KeyMode(settingsKeyEnabled, noSettingsKey); final boolean hasShortcutKey = voiceKeyEnabled && (isSymbols != voiceKeyOnMain); final Configuration conf = mResources.getConfiguration(); + final DisplayMetrics dm = mResources.getDisplayMetrics(); return new KeyboardId( mResources.getResourceEntryName(xmlId), xmlId, mSubtypeSwitcher.getInputLocale(), - conf.orientation, mWindowWidthCache.getWidth(conf), mode, editorInfo, + conf.orientation, dm.widthPixels, mode, editorInfo, hasSettingsKey, f2KeyMode, noSettingsKey, voiceKeyEnabled, hasShortcutKey); } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java index 12aadcb5c419e2c90fe5003e0029d9c4d0df6bb7..e0c6bbbb2b79c377586a1cb0946101934cdf5206 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java @@ -266,12 +266,6 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke return mKeyTimerHandler; } - @Override - protected void onSizeChanged(int w, int h, int oldw, int oldh) { - // TODO: Should notify InputMethodService instead? - KeyboardSwitcher.getInstance().onSizeChanged(w, h, oldw, oldh); - } - /** * Attaches a keyboard to this view. The keyboard can be switched at any time and the * view will re-layout itself to accommodate the keyboard. diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index a932f03ac5d860faaf28de6aed56affdcfabb777..afbdd36a995ab5826e384699bae9327bd48bbefa 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -2027,7 +2027,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void onPress(int primaryCode, boolean withSliding) { final KeyboardSwitcher switcher = mKeyboardSwitcher; - switcher.registerWindowWidth(); if (switcher.isVibrateAndSoundFeedbackRequired()) { vibrate(); playKeyClick(primaryCode);