diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 61 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/SubtypeSwitcher.java | 66 |
2 files changed, 67 insertions, 60 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index addc6c782..b93b07ffb 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -21,13 +21,11 @@ import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardView; +import com.android.inputmethod.keyboard.LatinKeyboard; import com.android.inputmethod.keyboard.LatinKeyboardView; import com.android.inputmethod.latin.Utils.RingCharBuffer; import com.android.inputmethod.voice.VoiceIMEConnector; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.Context; @@ -37,7 +35,6 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; -import android.content.res.XmlResourceParser; import android.inputmethodservice.InputMethodService; import android.media.AudioManager; import android.os.Debug; @@ -74,7 +71,6 @@ import android.widget.HorizontalScrollView; import android.widget.LinearLayout; import java.io.FileDescriptor; -import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; @@ -156,6 +152,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private boolean mAutoCap; private boolean mQuickFixes; private boolean mConfigSwipeDownDismissKeyboardEnabled; + private int mConfigDelayBeforeFadeoutLanguageOnSpacebar; + private int mConfigDurationOfFadeoutLanguageOnSpacebar; private int mCorrectionMode; private int mCommittedLength; @@ -246,9 +244,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private static final int MSG_UPDATE_OLD_SUGGESTIONS = 1; private static final int MSG_UPDATE_SHIFT_STATE = 2; private static final int MSG_VOICE_RESULTS = 3; + private static final int MSG_FADEOUT_LANGUAGE_ON_SPACEBAR = 4; + private static final int MSG_DISMISS_LANGUAGE_ON_SPACEBAR = 5; @Override public void handleMessage(Message msg) { + final KeyboardSwitcher switcher = mKeyboardSwitcher; + final LatinKeyboardView inputView = switcher.getInputView(); switch (msg.what) { case MSG_UPDATE_SUGGESTIONS: updateSuggestions(); @@ -257,12 +259,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen setOldSuggestions(); break; case MSG_UPDATE_SHIFT_STATE: - mKeyboardSwitcher.updateShiftState(); + switcher.updateShiftState(); break; case MSG_VOICE_RESULTS: mVoiceConnector.handleVoiceResults(preferCapitalization() - || (mKeyboardSwitcher.isAlphabetMode() - && mKeyboardSwitcher.isShiftedOrShiftLocked())); + || (switcher.isAlphabetMode() && switcher.isShiftedOrShiftLocked())); + break; + case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR: + if (inputView != null) + inputView.setSpacebarTextFadeFactor(0.5f, (LatinKeyboard)msg.obj); + sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj), + mConfigDurationOfFadeoutLanguageOnSpacebar); + break; + case MSG_DISMISS_LANGUAGE_ON_SPACEBAR: + if (inputView != null) + inputView.setSpacebarTextFadeFactor(0.0f, (LatinKeyboard)msg.obj); break; } } @@ -302,6 +313,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void updateVoiceResults() { sendMessage(obtainMessage(MSG_VOICE_RESULTS)); } + + public void startDisplayLanguageOnSpacebar() { + removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR); + removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR); + final LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); + if (inputView != null) { + final LatinKeyboard keyboard = inputView.getLatinKeyboard(); + // The language is never displayed when the delay is zero. + if (mConfigDelayBeforeFadeoutLanguageOnSpacebar != 0) + inputView.setSpacebarTextFadeFactor(1.0f, keyboard); + // The language is always displayed when the delay is negative. + if (mConfigDelayBeforeFadeoutLanguageOnSpacebar > 0) { + sendMessageDelayed(obtainMessage(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR, keyboard), + mConfigDelayBeforeFadeoutLanguageOnSpacebar); + } + } + } } @Override @@ -324,6 +352,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen res.getBoolean(R.bool.default_recorrection_enabled)); mConfigSwipeDownDismissKeyboardEnabled = res.getBoolean( R.bool.config_swipe_down_dismiss_keyboard_enabled); + mConfigDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger( + R.integer.config_delay_before_fadeout_language_on_spacebar); + mConfigDurationOfFadeoutLanguageOnSpacebar = res.getInteger( + R.integer.config_duration_of_fadeout_language_on_spacebar); Utils.GCUtils.getInstance().reset(); boolean tryGC = true; @@ -406,23 +438,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onConfigurationChanged(Configuration conf) { - mSubtypeSwitcher.onConfigurationChanged(conf); - if (mSubtypeSwitcher.isKeyboardMode()) - onKeyboardLanguageChanged(); - updateAutoTextEnabled(); - // If orientation changed while predicting, commit the change if (conf.orientation != mOrientation) { InputConnection ic = getCurrentInputConnection(); commitTyped(ic); if (ic != null) ic.finishComposingText(); // For voice input mOrientation = conf.orientation; - final int mode = mKeyboardSwitcher.getKeyboardMode(); - final EditorInfo attribute = getCurrentInputEditorInfo(); - final int imeOptions = (attribute != null) ? attribute.imeOptions : 0; - mKeyboardSwitcher.loadKeyboard(mode, imeOptions, - mVoiceConnector.isVoiceButtonEnabled(), - mVoiceConnector.isVoiceButtonOnPrimary()); } mConfigurationChanging = true; @@ -1822,7 +1843,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // "reset" and "next" are used only for USE_SPACEBAR_LANGUAGE_SWITCHER. private void toggleLanguage(boolean reset, boolean next) { - if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mSubtypeSwitcher.useSpacebarLanguageSwitcher()) { mSubtypeSwitcher.toggleLanguage(reset, next); } // Reload keyboard because the current language has been changed. diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index f75e2953e..f04f3efe7 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -41,10 +41,6 @@ import java.util.Locale; import java.util.Map; public class SubtypeSwitcher { - // TODO: This should be configurable by resource - // This flag indicates if we support language switching by swipe on space bar. - // We may or may not draw the current language on space bar regardless of this flag. - public static final boolean USE_SPACEBAR_LANGUAGE_SWITCHER = false; private static final boolean DBG = false; private static final String TAG = "SubtypeSwitcher"; @@ -63,6 +59,8 @@ public class SubtypeSwitcher { new ArrayList<InputMethodSubtype>(); private final ArrayList<String> mEnabledLanguagesOfCurrentInputMethod = new ArrayList<String>(); + private boolean mConfigUseSpacebarLanguageSwitcher; + /*-----------------------------------------------------------*/ // Variants which should be changed only by reload functions. private boolean mNeedsToDisplayLanguage; @@ -84,10 +82,6 @@ public class SubtypeSwitcher { public static void init(LatinIME service, SharedPreferences prefs) { sInstance.mPrefs = prefs; sInstance.resetParams(service); - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { - sInstance.initLanguageSwitcher(service); - } - sInstance.updateAllParameters(); SubtypeLocale.init(service); @@ -111,6 +105,10 @@ public class SubtypeSwitcher { mAllEnabledSubtypesOfCurrentInputMethod = null; // TODO: Voice input should be created here mVoiceInput = null; + mConfigUseSpacebarLanguageSwitcher = mResources.getBoolean( + R.bool.config_use_spacebar_language_switcher); + if (mConfigUseSpacebarLanguageSwitcher) + initLanguageSwitcher(service); } // Update all parameters stored in SubtypeSwitcher. @@ -124,8 +122,8 @@ public class SubtypeSwitcher { // Update parameters which are changed outside LatinIME. This parameters affect UI so they // should be updated every time onStartInputview. public void updateParametersOnStartInputView() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { - updateForSpaceBarLanguageSwitch(); + if (mConfigUseSpacebarLanguageSwitcher) { + updateForSpacebarLanguageSwitch(); } else { updateEnabledSubtypes(); } @@ -309,19 +307,23 @@ public class SubtypeSwitcher { ////////////////////////////////// public int getEnabledKeyboardLocaleCount() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return mLanguageSwitcher.getLocaleCount(); } else { return mEnabledKeyboardSubtypesOfCurrentInputMethod.size(); } } + public boolean useSpacebarLanguageSwitcher() { + return mConfigUseSpacebarLanguageSwitcher; + } + public boolean needsToDisplayLanguage() { return mNeedsToDisplayLanguage; } public Locale getInputLocale() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return mLanguageSwitcher.getInputLocale(); } else { return mInputLocale; @@ -329,7 +331,7 @@ public class SubtypeSwitcher { } public String getInputLocaleStr() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { String inputLanguage = null; inputLanguage = mLanguageSwitcher.getInputLanguage(); // Should return system locale if there is no Language available. @@ -343,7 +345,7 @@ public class SubtypeSwitcher { } public String[] getEnabledLanguages() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return mLanguageSwitcher.getEnabledLanguages(); } else { return mEnabledLanguagesOfCurrentInputMethod.toArray( @@ -352,7 +354,7 @@ public class SubtypeSwitcher { } public Locale getSystemLocale() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return mLanguageSwitcher.getSystemLocale(); } else { return mSystemLocale; @@ -360,7 +362,7 @@ public class SubtypeSwitcher { } public boolean isSystemLanguageSameAsInputLanguage() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return getSystemLocale().getLanguage().equalsIgnoreCase( getInputLocaleStr().substring(0, 2)); } else { @@ -368,25 +370,8 @@ public class SubtypeSwitcher { } } - public void onConfigurationChanged(Configuration conf) { - final Locale systemLocale = conf.locale; - // If system configuration was changed, update all parameters. - if (!TextUtils.equals(systemLocale.toString(), mSystemLocale.toString())) { - if (USE_SPACEBAR_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. - mLanguageSwitcher.loadLocales(mPrefs); - mLanguageSwitcher.setSystemLocale(systemLocale); - } else { - updateAllParameters(); - } - } - } - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { if (Settings.PREF_SELECTED_LANGUAGES.equals(key)) { mLanguageSwitcher.loadLocales(sharedPreferences); } @@ -434,12 +419,13 @@ public class SubtypeSwitcher { } private void triggerVoiceIME() { + if (!mService.isInputViewShown()) return; VoiceIMEConnector.getInstance().startListening(false, KeyboardSwitcher.getInstance().getInputView().getWindowToken(), false); } ////////////////////////////////////// - // SpaceBar Language Switch support // + // Spacebar Language Switch support // ////////////////////////////////////// private LanguageSwitcher mLanguageSwitcher; @@ -467,7 +453,7 @@ public class SubtypeSwitcher { return Character.toUpperCase(s.charAt(0)) + s.substring(1); } - private void updateForSpaceBarLanguageSwitch() { + private void updateForSpacebarLanguageSwitch() { // We need to update mNeedsToDisplayLanguage in onStartInputView because // getEnabledKeyboardLocaleCount could have been changed. mNeedsToDisplayLanguage = !(getEnabledKeyboardLocaleCount() <= 1 @@ -480,7 +466,7 @@ public class SubtypeSwitcher { } public String getNextInputLanguageName() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return getDisplayLanguage(mLanguageSwitcher.getNextInputLocale()); } else { return ""; @@ -488,7 +474,7 @@ public class SubtypeSwitcher { } public String getPreviousInputLanguageName() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return getDisplayLanguage(mLanguageSwitcher.getPrevInputLocale()); } else { return ""; @@ -525,13 +511,13 @@ public class SubtypeSwitcher { } public void loadSettings() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { mLanguageSwitcher.loadLocales(mPrefs); } } public void toggleLanguage(boolean reset, boolean next) { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { if (reset) { mLanguageSwitcher.reset(); } else { |