From 7a3d3ae17f7a8ca0b44e9c92328a7de7cbc80f92 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 13 Apr 2011 14:12:24 +0900 Subject: Fast key preview Previously the key preview was implemented by PopupWindow. The key preview popup window would be dismissed and shown each time the key was released and pressed. It turned out that it was taking several milliseconds. This change implements the key preview by a simple TextView which will be layout-ed at absolute coordinates within the screen FrameLayout. And dismissing and showing the key preview is implemented by the TextView's visibility. This implementation needs careful coordination of candidates.xml layout and LatinIME.onComputeInsets to control suggestion strip visibility. Bug: 4179964 Change-Id: Id6347cb35b91eb14ab20dd2f312e58b54b6625a7 --- .../compat/InputMethodServiceCompatWrapper.java | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java') diff --git a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java index e02aac704..1ea7236f9 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java @@ -19,20 +19,9 @@ package com.android.inputmethod.compat; import com.android.inputmethod.latin.SubtypeSwitcher; import android.inputmethodservice.InputMethodService; -import android.view.View; import android.view.inputmethod.InputMethodSubtype; -import android.widget.HorizontalScrollView; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; public class InputMethodServiceCompatWrapper extends InputMethodService { - private static final Method METHOD_HorizontalScrollView_setOverScrollMode = - CompatUtils.getMethod(HorizontalScrollView.class, "setOverScrollMode", int.class); - private static final Field FIELD_View_OVER_SCROLL_NEVER = - CompatUtils.getField(View.class, "OVER_SCROLL_NEVER"); - private static final Integer View_OVER_SCROLL_NEVER = - (Integer)CompatUtils.getFieldValue(null, null, FIELD_View_OVER_SCROLL_NEVER); // CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED needs to be false if the API level is 10 // or previous. Note that InputMethodSubtype was added in the API level 11. // For the API level 11 or later, LatinIME should override onCurrentInputMethodSubtypeChanged(). @@ -66,13 +55,6 @@ public class InputMethodServiceCompatWrapper extends InputMethodService { } } - protected static void setOverScrollModeNever(HorizontalScrollView scrollView) { - if (View_OVER_SCROLL_NEVER != null) { - CompatUtils.invoke(scrollView, null, METHOD_HorizontalScrollView_setOverScrollMode, - View_OVER_SCROLL_NEVER); - } - } - ////////////////////////////////////// // Functions using API v11 or later // ////////////////////////////////////// -- cgit v1.2.3-83-g751a From 6d9021527a38ba1e94225020389621a0d7227aa1 Mon Sep 17 00:00:00 2001 From: satok Date: Thu, 14 Apr 2011 11:42:08 +0900 Subject: Fix for language bar switching Change-Id: Id3974642b62b012968c537eff7c1a7ee37e2def2 --- .../compat/InputMethodManagerCompatWrapper.java | 7 ++----- .../compat/InputMethodServiceCompatWrapper.java | 4 ++++ .../deprecated/LanguageSwitcherProxy.java | 18 +++++++++++++--- .../languageswitcher/LanguageSwitcher.java | 24 +++++++++++++++------- .../com/android/inputmethod/latin/LatinIME.java | 2 +- 5 files changed, 39 insertions(+), 16 deletions(-) (limited to 'java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java') diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java index e7eaba2d8..2b7e25591 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java @@ -107,7 +107,8 @@ public class InputMethodManagerCompatWrapper { public List getEnabledInputMethodSubtypeList( InputMethodInfoCompatWrapper imi, boolean allowsImplicitlySelectedSubtypes) { if (!SUBTYPE_SUPPORTED) { - String[] languages = mLanguageSwitcherProxy.getEnabledLanguages(); + String[] languages = mLanguageSwitcherProxy.getEnabledLanguages( + allowsImplicitlySelectedSubtypes); List subtypeList = new ArrayList(); for (String lang: languages) { @@ -195,10 +196,6 @@ public class InputMethodManagerCompatWrapper { public void setInputMethodAndSubtype( IBinder token, String id, InputMethodSubtypeCompatWrapper subtype) { - if (!SUBTYPE_SUPPORTED) { - mLanguageSwitcherProxy.setLocale(subtype.getLocale()); - return; - } CompatUtils.invoke(mImm, null, METHOD_setInputMethodAndSubtype, token, id, subtype.getOriginalObject()); } diff --git a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java index 1ea7236f9..399dcf2dd 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java @@ -16,6 +16,7 @@ package com.android.inputmethod.compat; +import com.android.inputmethod.deprecated.LanguageSwitcherProxy; import com.android.inputmethod.latin.SubtypeSwitcher; import android.inputmethodservice.InputMethodService; @@ -51,6 +52,9 @@ public class InputMethodServiceCompatWrapper extends InputMethodService { subtype = mImm.getCurrentInputMethodSubtype(); } if (subtype != null) { + if (!InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) { + LanguageSwitcherProxy.getInstance().setLocale(subtype.getLocale()); + } SubtypeSwitcher.getInstance().updateSubtype(subtype); } } diff --git a/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java b/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java index 5d165cda9..73f0b7a2d 100644 --- a/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java +++ b/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java @@ -19,6 +19,7 @@ package com.android.inputmethod.deprecated; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.deprecated.languageswitcher.LanguageSwitcher; import com.android.inputmethod.latin.LatinIME; +import com.android.inputmethod.latin.Settings; import android.content.SharedPreferences; import android.content.res.Configuration; @@ -26,7 +27,7 @@ import android.content.res.Configuration; import java.util.Locale; // This class is used only when the IME doesn't use method.xml for language switching. -public class LanguageSwitcherProxy { +public class LanguageSwitcherProxy implements SharedPreferences.OnSharedPreferenceChangeListener { private static final LanguageSwitcherProxy sInstance = new LanguageSwitcherProxy(); private LanguageSwitcher mLanguageSwitcher; private SharedPreferences mPrefs; @@ -42,6 +43,7 @@ public class LanguageSwitcherProxy { sInstance.mLanguageSwitcher = new LanguageSwitcher(service); sInstance.mLanguageSwitcher.loadLocales(prefs, conf.locale); sInstance.mPrefs = prefs; + prefs.registerOnSharedPreferenceChangeListener(sInstance); } public static void onConfigurationChanged(Configuration conf) { @@ -58,8 +60,8 @@ public class LanguageSwitcherProxy { return mLanguageSwitcher.getLocaleCount(); } - public String[] getEnabledLanguages() { - return mLanguageSwitcher.getEnabledLanguages(); + public String[] getEnabledLanguages(boolean allowImplicitlySelectedLanguages) { + return mLanguageSwitcher.getEnabledLanguages(allowImplicitlySelectedLanguages); } public Locale getInputLocale() { @@ -70,4 +72,14 @@ public class LanguageSwitcherProxy { mLanguageSwitcher.setLocale(localeStr); mLanguageSwitcher.persist(mPrefs); } + + @Override + public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + // PREF_SELECTED_LANGUAGES: enabled input subtypes + // PREF_INPUT_LANGUAGE: current input subtype + if (key.equals(Settings.PREF_SELECTED_LANGUAGES) + || key.equals(Settings.PREF_INPUT_LANGUAGE)) { + mLanguageSwitcher.loadLocales(prefs, null); + } + } } diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java index 639b7cdd0..e4b2e035c 100644 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java +++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java @@ -18,6 +18,7 @@ package com.android.inputmethod.deprecated.languageswitcher; import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; import com.android.inputmethod.latin.LatinIME; +import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.Settings; import com.android.inputmethod.latin.SharedPreferencesCompat; @@ -25,6 +26,7 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.res.Configuration; import android.text.TextUtils; +import android.util.Log; import java.util.ArrayList; import java.util.Locale; @@ -34,12 +36,14 @@ import java.util.Locale; * input language that the user has selected. */ public class LanguageSwitcher { + private static final String TAG = LanguageSwitcher.class.getSimpleName(); private static final String KEYBOARD_MODE = "keyboard"; + private static final String[] EMPTY_STIRNG_ARRAY = new String[0]; private final ArrayList mLocales = new ArrayList(); private final LatinIME mIme; - private String[] mSelectedLanguageArray; + private String[] mSelectedLanguageArray = EMPTY_STIRNG_ARRAY; private String mSelectedLanguages; private int mCurrentIndex = 0; private String mDefaultInputLanguage; @@ -69,12 +73,16 @@ public class LanguageSwitcher { * @return whether there was any change */ public boolean loadLocales(SharedPreferences sp, Locale systemLocale) { + if (LatinImeLogger.sDBG) { + Log.d(TAG, "load locales"); + } if (systemLocale != null) { setSystemLocale(systemLocale); } String selectedLanguages = sp.getString(Settings.PREF_SELECTED_LANGUAGES, null); String currentLanguage = sp.getString(Settings.PREF_INPUT_LANGUAGE, null); - if (selectedLanguages == null || selectedLanguages.length() < 1) { + if (TextUtils.isEmpty(selectedLanguages)) { + mSelectedLanguageArray = EMPTY_STIRNG_ARRAY; loadDefaults(); if (mLocales.size() == 0) { return false; @@ -104,6 +112,9 @@ public class LanguageSwitcher { } private void loadDefaults() { + if (LatinImeLogger.sDBG) { + Log.d(TAG, "load default locales:"); + } mDefaultInputLocale = mIme.getResources().getConfiguration().locale; String country = mDefaultInputLocale.getCountry(); mDefaultInputLanguage = mDefaultInputLocale.getLanguage() + @@ -132,7 +143,10 @@ public class LanguageSwitcher { /** * Returns the list of enabled language codes. */ - public String[] getEnabledLanguages() { + public String[] getEnabledLanguages(boolean allowImplicitlySelectedLanguages) { + if (mSelectedLanguageArray.length == 0 && allowImplicitlySelectedLanguages) { + return new String[] { mDefaultInputLanguage }; + } return mSelectedLanguageArray; } @@ -218,9 +232,5 @@ public class LanguageSwitcher { Editor editor = prefs.edit(); editor.putString(Settings.PREF_INPUT_LANGUAGE, getInputLanguage()); SharedPreferencesCompat.apply(editor); - // When the current language is changed, the event for this change should be handled - // internally as a subtype switching. - mIme.notifyOnCurrentInputMethodSubtypeChanged(new InputMethodSubtypeCompatWrapper( - 0, 0, getInputLocale().toString(), KEYBOARD_MODE, "")); } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index d87de09c6..6f5d2fe4f 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -375,10 +375,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); mPrefs = prefs; LatinImeLogger.init(this, prefs); + LanguageSwitcherProxy.init(this, prefs); SubtypeSwitcher.init(this, prefs); KeyboardSwitcher.init(this, prefs); AccessibilityUtils.init(this, prefs); - LanguageSwitcherProxy.init(this, prefs); super.onCreate(); -- cgit v1.2.3-83-g751a