diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
3 files changed, 115 insertions, 56 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 5e701c1f0..b93b07ffb 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -21,6 +21,7 @@ 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; @@ -151,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; @@ -241,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(); @@ -252,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; } } @@ -297,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 @@ -319,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; @@ -401,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; @@ -1817,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/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java new file mode 100644 index 000000000..917521c40 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.latin; + +import android.content.Context; +import android.content.res.Resources; + +import java.util.Locale; + +public class SubtypeLocale { + private static String[] sExceptionKeys; + private static String[] sExceptionValues; + + private SubtypeLocale() { + // Intentional empty constructor for utility class. + } + + public static void init(Context context) { + final Resources res = context.getResources(); + sExceptionKeys = res.getStringArray(R.array.subtype_locale_exception_keys); + sExceptionValues = res.getStringArray(R.array.subtype_locale_exception_values); + } + + public static String getFullDisplayName(Locale locale) { + String localeCode = locale.toString(); + for (int index = 0; index < sExceptionKeys.length; index++) { + if (sExceptionKeys[index].equals(localeCode)) + return sExceptionValues[index]; + } + return locale.getDisplayName(locale); + } +} diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index e1852b2ad..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,11 +82,9 @@ 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); } private SubtypeSwitcher() { @@ -109,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. @@ -122,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(); } @@ -307,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; @@ -327,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. @@ -341,7 +345,7 @@ public class SubtypeSwitcher { } public String[] getEnabledLanguages() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return mLanguageSwitcher.getEnabledLanguages(); } else { return mEnabledLanguagesOfCurrentInputMethod.toArray( @@ -350,7 +354,7 @@ public class SubtypeSwitcher { } public Locale getSystemLocale() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return mLanguageSwitcher.getSystemLocale(); } else { return mSystemLocale; @@ -358,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 { @@ -366,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); } @@ -438,14 +425,14 @@ public class SubtypeSwitcher { } ////////////////////////////////////// - // SpaceBar Language Switch support // + // Spacebar Language Switch support // ////////////////////////////////////// private LanguageSwitcher mLanguageSwitcher; public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { if (returnsNameInThisLocale) { - return toTitleCase(locale.getDisplayName(locale)); + return toTitleCase(SubtypeLocale.getFullDisplayName(locale)); } else { return toTitleCase(locale.getDisplayName()); } @@ -466,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 @@ -479,7 +466,7 @@ public class SubtypeSwitcher { } public String getNextInputLanguageName() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return getDisplayLanguage(mLanguageSwitcher.getNextInputLocale()); } else { return ""; @@ -487,7 +474,7 @@ public class SubtypeSwitcher { } public String getPreviousInputLanguageName() { - if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (mConfigUseSpacebarLanguageSwitcher) { return getDisplayLanguage(mLanguageSwitcher.getPrevInputLocale()); } else { return ""; @@ -524,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 { |