From 3b776b78924610da2874f3ac555ed5d91a550843 Mon Sep 17 00:00:00 2001 From: satok Date: Thu, 18 Nov 2010 07:58:14 +0900 Subject: Move functions in LatinKeyboard related to LanguageSwitcher to SubtypeSwitcher Change-Id: I777db896bd0287931ce7c810b080ccee1121d34e --- .../android/inputmethod/latin/InputLanguageSelection.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/InputLanguageSelection.java') diff --git a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java index e811a2cdd..4f4f7e3a7 100644 --- a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java @@ -74,7 +74,7 @@ public class InputLanguageSelection extends PreferenceActivity { for (int i = 0; i < mAvailableLanguages.size(); i++) { CheckBoxPreference pref = new CheckBoxPreference(this); Locale locale = mAvailableLanguages.get(i).locale; - pref.setTitle(LanguageSwitcher.toTitleCase(locale.getDisplayName(locale))); + pref.setTitle(SubtypeSwitcher.getLanguageName(locale)); boolean checked = isLocaleIn(locale, languageList); pref.setChecked(checked); if (hasDictionary(locale)) { @@ -167,7 +167,7 @@ public class InputLanguageSelection extends PreferenceActivity { if (finalSize == 0) { preprocess[finalSize++] = - new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName(l)), l); + new Loc(SubtypeSwitcher.getLanguageName(l), l); } else { // check previous entry: // same lang and a country -> upgrade to full name and @@ -175,15 +175,15 @@ public class InputLanguageSelection extends PreferenceActivity { // diff lang -> insert ours with lang-only name if (preprocess[finalSize-1].locale.getLanguage().equals( language)) { - preprocess[finalSize-1].label = LanguageSwitcher.toTitleCase( - preprocess[finalSize-1].locale.getDisplayName()); + preprocess[finalSize-1].label = SubtypeSwitcher.getLanguageName( + preprocess[finalSize-1].locale); preprocess[finalSize++] = - new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName()), l); + new Loc(SubtypeSwitcher.getLanguageName(l), l); } else { String displayName; if (s.equals("zz_ZZ")) { } else { - displayName = LanguageSwitcher.toTitleCase(l.getDisplayName(l)); + displayName = SubtypeSwitcher.getLanguageName(l); preprocess[finalSize++] = new Loc(displayName, l); } } -- cgit v1.2.3-83-g751a From 4ab730dbd34fad323063f2ffd31ce33de746668d Mon Sep 17 00:00:00 2001 From: satok Date: Thu, 18 Nov 2010 09:55:23 +0900 Subject: Add a functionarity to handle Subtype Change-Id: Ic6055ba218b64f4276e3db99a435f546c3990ee5 --- .../inputmethod/latin/InputLanguageSelection.java | 14 +- .../com/android/inputmethod/latin/LatinIME.java | 28 ++- .../inputmethod/latin/LatinIMESettings.java | 2 - .../android/inputmethod/latin/LatinKeyboard.java | 4 +- .../android/inputmethod/latin/SubtypeSwitcher.java | 259 ++++++++++++++++----- 5 files changed, 229 insertions(+), 78 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/InputLanguageSelection.java') diff --git a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java index 4f4f7e3a7..7f64bcb43 100644 --- a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java @@ -37,7 +37,7 @@ public class InputLanguageSelection extends PreferenceActivity { private String mSelectedLanguages; private ArrayList mAvailableLanguages = new ArrayList(); private static final String[] BLACKLIST_LANGUAGES = { - "ko", "ja", "zh", "el" + "ko", "ja", "zh", "el", "zz" }; private static class Loc implements Comparable { @@ -74,7 +74,7 @@ public class InputLanguageSelection extends PreferenceActivity { for (int i = 0; i < mAvailableLanguages.size(); i++) { CheckBoxPreference pref = new CheckBoxPreference(this); Locale locale = mAvailableLanguages.get(i).locale; - pref.setTitle(SubtypeSwitcher.getLanguageName(locale)); + pref.setTitle(SubtypeSwitcher.getFullDisplayName(locale, true)); boolean checked = isLocaleIn(locale, languageList); pref.setChecked(checked); if (hasDictionary(locale)) { @@ -167,7 +167,7 @@ public class InputLanguageSelection extends PreferenceActivity { if (finalSize == 0) { preprocess[finalSize++] = - new Loc(SubtypeSwitcher.getLanguageName(l), l); + new Loc(SubtypeSwitcher.getFullDisplayName(l, true), l); } else { // check previous entry: // same lang and a country -> upgrade to full name and @@ -175,15 +175,15 @@ public class InputLanguageSelection extends PreferenceActivity { // diff lang -> insert ours with lang-only name if (preprocess[finalSize-1].locale.getLanguage().equals( language)) { - preprocess[finalSize-1].label = SubtypeSwitcher.getLanguageName( - preprocess[finalSize-1].locale); + preprocess[finalSize-1].label = SubtypeSwitcher.getFullDisplayName( + preprocess[finalSize-1].locale, false); preprocess[finalSize++] = - new Loc(SubtypeSwitcher.getLanguageName(l), l); + new Loc(SubtypeSwitcher.getFullDisplayName(l, false), l); } else { String displayName; if (s.equals("zz_ZZ")) { } else { - displayName = SubtypeSwitcher.getLanguageName(l); + displayName = SubtypeSwitcher.getFullDisplayName(l, true); preprocess[finalSize++] = new Loc(displayName, l); } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 9a800ba38..295a03be3 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -462,7 +462,7 @@ public class LatinIME extends InputMethodService private void initSuggest() { updateAutoTextEnabled(); - String locale = mSubtypeSwitcher.getInputLanguage(); + String locale = mSubtypeSwitcher.getInputLocaleStr(); Resources orig = getResources(); Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(new Locale(locale)); @@ -519,6 +519,7 @@ public class LatinIME extends InputMethodService @Override public void onConfigurationChanged(Configuration conf) { mSubtypeSwitcher.onConfigurationChanged(conf); + onLanguageChanged(); updateAutoTextEnabled(); // If orientation changed while predicting, commit the change @@ -577,9 +578,11 @@ public class LatinIME extends InputMethodService return; } + SubtypeSwitcher.getInstance().updateParametersOnStartInputView(); + if (mRefreshKeyboardRequired) { mRefreshKeyboardRequired = false; - toggleLanguage(true, true); + onLanguageChanged(); } TextEntryState.newSession(this); @@ -2176,8 +2179,18 @@ public class LatinIME extends InputMethodService return mWord.isFirstCharCapitalized(); } + // Notify that Language has been changed and toggleLanguage will update KeyboaredID according + // to new Language. + private void onLanguageChanged() { + toggleLanguage(true, true); + } + + // "reset" and "next" are used only for USE_SPACEBAR_LANGUAGE_SWITCHER. private void toggleLanguage(boolean reset, boolean next) { - mSubtypeSwitcher.toggleLanguage(reset, next); + if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER) { + mSubtypeSwitcher.toggleLanguage(reset, next); + } + // Reload keyboard because the current language has been changed. KeyboardSwitcher switcher = mKeyboardSwitcher; final int mode = switcher.getKeyboardMode(); final EditorInfo attribute = getCurrentInputEditorInfo(); @@ -2249,7 +2262,7 @@ public class LatinIME extends InputMethodService return new FieldContext( getCurrentInputConnection(), getCurrentInputEditorInfo(), - mSubtypeSwitcher.getInputLanguage(), + mSubtypeSwitcher.getInputLocaleStr(), mSubtypeSwitcher.getEnabledLanguages()); } @@ -2372,7 +2385,7 @@ public class LatinIME extends InputMethodService private void updateAutoTextEnabled() { if (mSuggest == null) return; mSuggest.setAutoTextEnabled(mQuickFixes - && SubtypeSwitcher.getInstance().isSystemLocaleSameAsInputLocale()); + && SubtypeSwitcher.getInstance().isSystemLanguageSameAsInputLanguage()); } private void updateSuggestionVisibility(SharedPreferences prefs) { @@ -2419,7 +2432,7 @@ public class LatinIME extends InputMethodService sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false); mLocaleSupportedForVoiceInput = SubtypeSwitcher.getInstance().isVoiceSupported( - SubtypeSwitcher.getInstance().getInputLanguage()); + SubtypeSwitcher.getInstance().getInputLocaleStr()); mAutoCorrectEnabled = isAutoCorrectEnabled(sp); mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(sp); @@ -2580,6 +2593,7 @@ public class LatinIME extends InputMethodService @Override public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) { - SubtypeSwitcher.getInstance().onCurrentInputMethodSubtypeChanged(subtype); + SubtypeSwitcher.getInstance().updateSubtype(subtype); + onLanguageChanged(); } } diff --git a/java/src/com/android/inputmethod/latin/LatinIMESettings.java b/java/src/com/android/inputmethod/latin/LatinIMESettings.java index df2cd2717..960c54d7a 100644 --- a/java/src/com/android/inputmethod/latin/LatinIMESettings.java +++ b/java/src/com/android/inputmethod/latin/LatinIMESettings.java @@ -16,7 +16,6 @@ package com.android.inputmethod.latin; -import java.util.ArrayList; import java.util.Locale; import android.app.AlertDialog; @@ -34,7 +33,6 @@ import android.speech.SpeechRecognizer; import android.text.AutoText; import android.util.Log; -import com.android.inputmethod.voice.SettingsUtil; import com.android.inputmethod.voice.VoiceInputLogger; public class LatinIMESettings extends PreferenceActivity diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java index 9473eaf84..6520d08e6 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -419,7 +419,7 @@ public class LatinKeyboard extends BaseKeyboard { final Rect bounds = new Rect(); // Estimate appropriate language name text size to fit in maxTextWidth. - String language = SubtypeSwitcher.getLanguageName(locale); + String language = SubtypeSwitcher.getDisplayLanguage(locale); int textWidth = getTextWidth(paint, language, origTextSize, bounds); // Assuming text width and text size are proportional to each other. float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); @@ -435,7 +435,7 @@ public class LatinKeyboard extends BaseKeyboard { textSize = origTextSize; } if (useShortName) { - language = SubtypeSwitcher.getShortLanguageName(locale); + language = SubtypeSwitcher.getShortDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize, bounds); textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); } diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 768274ed7..fe629949c 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -18,14 +18,18 @@ package com.android.inputmethod.latin; import com.android.inputmethod.voice.SettingsUtil; +import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.inputmethodservice.InputMethodService; import android.preference.PreferenceManager; import android.text.TextUtils; +import android.util.Log; +import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -33,12 +37,34 @@ import java.util.Locale; public class SubtypeSwitcher { // 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 = true; + public static final boolean USE_SPACEBAR_LANGUAGE_SWITCHER = false; + private static final boolean DBG = false; private static final String TAG = "SubtypeSwitcher"; + + private static final char LOCALE_SEPARATER = '_'; + private static final String KEYBOARD_MODE = "keyboard"; + private static final String VOICE_MODE = "voice"; + private final TextUtils.SimpleStringSplitter mLocaleSplitter = + new TextUtils.SimpleStringSplitter(LOCALE_SEPARATER); + private static final SubtypeSwitcher sInstance = new SubtypeSwitcher(); - private InputMethodService mService; - private Resources mResources; + private /* final */ InputMethodService mService; + private /* final */ InputMethodManager mImm; + private /* final */ Resources mResources; + private final ArrayList mEnabledKeyboardSubtypesOfCurrentInputMethod = + new ArrayList(); + private final ArrayList mEnabledLanguagesOfCurrentInputMethod = new ArrayList(); + + /*-----------------------------------------------------------*/ + // Variants which should be changed only by reload functions. private Locale mSystemLocale; + private Locale mInputLocale; + private String mInputLocaleStr; + private String mMode; + private List mAllEnabledSubtypesOfCurrentInputMethod; + private boolean mNeedsToDisplayLanguage; + private boolean mIsSystemLanguageSameAsInputLanguage; + /*-----------------------------------------------------------*/ public static SubtypeSwitcher getInstance() { return sInstance; @@ -47,16 +73,97 @@ public class SubtypeSwitcher { public static void init(LatinIME service) { sInstance.mService = service; sInstance.mResources = service.getResources(); - sInstance.mSystemLocale = sInstance.mResources.getConfiguration().locale; + sInstance.mImm = (InputMethodManager) service.getSystemService( + Context.INPUT_METHOD_SERVICE); if (USE_SPACEBAR_LANGUAGE_SWITCHER) { sInstance.initLanguageSwitcher(service); } + + sInstance.updateAllParameters(); } private SubtypeSwitcher() { } - public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) { + // Update all parameters stored in SubtypeSwitcher. + // Only configuration changed event is allowed to call this because this is heavy. + private void updateAllParameters() { + mSystemLocale = mResources.getConfiguration().locale; + updateSubtype(mImm.getCurrentInputMethodSubtype()); + updateParametersOnStartInputView(); + } + + // 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(); + } else { + updateEnabledSubtypes(); + } + } + + // Reload enabledSubtypes from the framework. + private void updateEnabledSubtypes() { + boolean foundCurrentSubtypeBecameDisabled = true; + mAllEnabledSubtypesOfCurrentInputMethod = mImm.getEnabledInputMethodSubtypeList(null); + mEnabledLanguagesOfCurrentInputMethod.clear(); + mEnabledKeyboardSubtypesOfCurrentInputMethod.clear(); + for (InputMethodSubtype ims: mAllEnabledSubtypesOfCurrentInputMethod) { + final String locale = ims.getLocale(); + final String mode = ims.getMode(); + mLocaleSplitter.setString(locale); + if (mLocaleSplitter.hasNext()) { + mEnabledLanguagesOfCurrentInputMethod.add(mLocaleSplitter.next()); + } + if (locale.equals(mInputLocaleStr) && mode.equals(mMode)) { + foundCurrentSubtypeBecameDisabled = false; + } + if (KEYBOARD_MODE.equals(ims.getMode())) { + mEnabledKeyboardSubtypesOfCurrentInputMethod.add(ims); + } + } + mNeedsToDisplayLanguage = !(getEnabledKeyboardLocaleCount() <= 1 + && mIsSystemLanguageSameAsInputLanguage); + if (foundCurrentSubtypeBecameDisabled) { + updateSubtype(mImm.getCurrentInputMethodSubtype()); + } + } + + // Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function. + public void updateSubtype(InputMethodSubtype newSubtype) { + if (DBG) { + Log.w(TAG, "Update subtype to:" + newSubtype.getLocale() + "," + newSubtype.getMode()); + } + updateInputLocale(newSubtype.getLocale()); + mMode = newSubtype.getMode(); + } + + // Update the current input locale from Locale string. + private void updateInputLocale(String inputLocaleStr) { + // example: inputLocaleStr = "en_US" "en" "" + // "en_US" --> language: en & country: US + // "en" --> language: en + // "" --> the system locale + mLocaleSplitter.setString(inputLocaleStr); + if (mLocaleSplitter.hasNext()) { + String language = mLocaleSplitter.next(); + if (mLocaleSplitter.hasNext()) { + mInputLocale = new Locale(language, mLocaleSplitter.next()); + } else { + mInputLocale = new Locale(language); + } + mInputLocaleStr = inputLocaleStr; + } else { + mInputLocale = mSystemLocale; + String country = mSystemLocale.getCountry(); + mInputLocaleStr = mSystemLocale.getLanguage() + + (TextUtils.isEmpty(country) ? "" : "_" + mSystemLocale.getLanguage()); + } + mIsSystemLanguageSameAsInputLanguage = getSystemLocale().getLanguage().equalsIgnoreCase( + getInputLocale().getLanguage()); + mNeedsToDisplayLanguage = !(getEnabledKeyboardLocaleCount() <= 1 + && mIsSystemLanguageSameAsInputLanguage); } ////////////////////////////////// @@ -66,82 +173,94 @@ public class SubtypeSwitcher { public int getEnabledKeyboardLocaleCount() { if (USE_SPACEBAR_LANGUAGE_SWITCHER) { return mLanguageSwitcher.getLocaleCount(); + } else { + return mEnabledKeyboardSubtypesOfCurrentInputMethod.size(); } - // TODO: Implement for no legacy mode - return 0; } - // TODO: Cache the value public boolean needsToDisplayLanguage() { - // TODO: Takes care of two-char locale such as "en" in addition to "en_US" - return !(getEnabledKeyboardLocaleCount() <= 1 && getSystemLocale().getLanguage( - ).equalsIgnoreCase(getInputLocale().getLanguage())); + return mNeedsToDisplayLanguage; } public Locale getInputLocale() { if (USE_SPACEBAR_LANGUAGE_SWITCHER) { return mLanguageSwitcher.getInputLocale(); + } else { + return mInputLocale; } - // TODO: Implement for no legacy mode - return null; } - public String getInputLanguage() { - String inputLanguage = null; + public String getInputLocaleStr() { if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + String inputLanguage = null; inputLanguage = mLanguageSwitcher.getInputLanguage(); + // Should return system locale if there is no Language available. + if (inputLanguage == null) { + inputLanguage = getSystemLocale().getLanguage(); + } + return inputLanguage; + } else { + return mInputLocaleStr; } - // Should return system locale if there is no Language available. - if (inputLanguage == null) { - inputLanguage = getSystemLocale().getLanguage(); - } - return inputLanguage; } public String[] getEnabledLanguages() { if (USE_SPACEBAR_LANGUAGE_SWITCHER) { return mLanguageSwitcher.getEnabledLanguages(); + } else { + return mEnabledLanguagesOfCurrentInputMethod.toArray( + new String[mEnabledLanguagesOfCurrentInputMethod.size()]); } - // TODO: Implement for no legacy mode - return null; } public Locale getSystemLocale() { - return mSystemLocale; + if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + return mLanguageSwitcher.getSystemLocale(); + } else { + return mSystemLocale; + } } - // TODO: Cache the value for faster processing. - public boolean isSystemLocaleSameAsInputLocale() { - // TODO: Takes care of two-char locale such as "en" in addition to "en_US" - return getSystemLocale().getLanguage().equalsIgnoreCase( - getInputLanguage().substring(0, 2)); + public boolean isSystemLanguageSameAsInputLanguage() { + if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + return getSystemLocale().getLanguage().equalsIgnoreCase( + getInputLocaleStr().substring(0, 2)); + } else { + return mIsSystemLanguageSameAsInputLanguage; + } } public void onConfigurationChanged(Configuration conf) { - 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. - final Locale systemLocale = conf.locale; - if (!TextUtils.equals(systemLocale.toString(), mSystemLocale.toString())) { - mSystemLocale = systemLocale; - mLanguageSwitcher.loadLocales( - PreferenceManager.getDefaultSharedPreferences(mService)); + 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(PreferenceManager + .getDefaultSharedPreferences(mService)); mLanguageSwitcher.setSystemLocale(systemLocale); - toggleLanguage(true, true); + } else { + updateAllParameters(); } - return; } } public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (USE_SPACEBAR_LANGUAGE_SWITCHER) { - mLanguageSwitcher.loadLocales(sharedPreferences); - return; + if (LatinIME.PREF_SELECTED_LANGUAGES.equals(key)) { + mLanguageSwitcher.loadLocales(sharedPreferences); + } } } + /** + * Change system locale for this application + * @param newLocale + * @return oldLocale + */ public Locale changeSystemLocale(Locale newLocale) { Configuration conf = mResources.getConfiguration(); Locale oldLocale = conf.locale; @@ -150,16 +269,25 @@ public class SubtypeSwitcher { return oldLocale; } - //////////////////////////////////////////// - // Legacy Language Switch support // - //////////////////////////////////////////// + ////////////////////////////////////// + // SpaceBar Language Switch support // + ////////////////////////////////////// + private LanguageSwitcher mLanguageSwitcher; - public static String getLanguageName(Locale locale) { + public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { + if (returnsNameInThisLocale) { + return toTitleCase(locale.getDisplayName(locale)); + } else { + return toTitleCase(locale.getDisplayName()); + } + } + + public static String getDisplayLanguage(Locale locale) { return toTitleCase(locale.getDisplayLanguage(locale)); } - public static String getShortLanguageName(Locale locale) { + public static String getShortDisplayLanguage(Locale locale) { return toTitleCase(locale.getLanguage()); } @@ -170,25 +298,34 @@ public class SubtypeSwitcher { return Character.toUpperCase(s.charAt(0)) + s.substring(1); } + private void updateForSpaceBarLanguageSwitch() { + // We need to update mNeedsToDisplayLanguage in onStartInputView because + // getEnabledKeyboardLocaleCount could have been changed. + mNeedsToDisplayLanguage = !(getEnabledKeyboardLocaleCount() <= 1 + && getSystemLocale().getLanguage().equalsIgnoreCase( + getInputLocale().getLanguage())); + } + public String getInputLanguageName() { - return getLanguageName(getInputLocale()); + return getDisplayLanguage(getInputLocale()); } public String getNextInputLanguageName() { if (USE_SPACEBAR_LANGUAGE_SWITCHER) { - return getLanguageName(mLanguageSwitcher.getNextInputLocale()); + return getDisplayLanguage(mLanguageSwitcher.getNextInputLocale()); + } else { + return ""; } - return ""; } public String getPreviousInputLanguageName() { if (USE_SPACEBAR_LANGUAGE_SWITCHER) { - return getLanguageName(mLanguageSwitcher.getPrevInputLocale()); + return getDisplayLanguage(mLanguageSwitcher.getPrevInputLocale()); + } else { + return ""; } - return ""; } - // TODO: This can be an array of String // A list of locales which are supported by default for voice input, unless we get a // different list from Gservices. private static final String DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES = @@ -225,16 +362,18 @@ public class SubtypeSwitcher { } public void toggleLanguage(boolean reset, boolean next) { - if (reset) { - mLanguageSwitcher.reset(); - } else { - if (next) { - mLanguageSwitcher.next(); + if (USE_SPACEBAR_LANGUAGE_SWITCHER) { + if (reset) { + mLanguageSwitcher.reset(); } else { - mLanguageSwitcher.prev(); + if (next) { + mLanguageSwitcher.next(); + } else { + mLanguageSwitcher.prev(); + } } + mLanguageSwitcher.persist(); } - mLanguageSwitcher.persist(); } private void initLanguageSwitcher(LatinIME service) { -- cgit v1.2.3-83-g751a From 27d13713bbb291d25a910f97d88a81fdbabddc0e Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Fri, 26 Nov 2010 13:08:36 +0900 Subject: Preload SharedPreferences at start. bug: 3207554 Change-Id: I84072461aee9675cc67897de03f89e9c0036bc1f --- java/src/com/android/inputmethod/latin/Hints.java | 187 -------------------- .../inputmethod/latin/InputLanguageSelection.java | 8 +- .../inputmethod/latin/KeyboardSwitcher.java | 9 +- .../inputmethod/latin/LanguageSwitcher.java | 5 +- .../com/android/inputmethod/latin/LatinIME.java | 42 ++--- .../android/inputmethod/latin/LatinImeLogger.java | 2 +- .../android/inputmethod/latin/SubtypeSwitcher.java | 16 +- java/src/com/android/inputmethod/voice/Hints.java | 189 +++++++++++++++++++++ .../inputmethod/voice/VoiceIMEConnector.java | 9 +- 9 files changed, 234 insertions(+), 233 deletions(-) delete mode 100644 java/src/com/android/inputmethod/latin/Hints.java create mode 100644 java/src/com/android/inputmethod/voice/Hints.java (limited to 'java/src/com/android/inputmethod/latin/InputLanguageSelection.java') diff --git a/java/src/com/android/inputmethod/latin/Hints.java b/java/src/com/android/inputmethod/latin/Hints.java deleted file mode 100644 index c467365e7..000000000 --- a/java/src/com/android/inputmethod/latin/Hints.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * 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 com.android.inputmethod.voice.SettingsUtil; - -import android.content.ContentResolver; -import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; -import android.view.inputmethod.InputConnection; - -import java.util.Calendar; -import java.util.HashMap; -import java.util.Map; - -/** - * Logic to determine when to display hints on usage to the user. - */ -public class Hints { - public interface Display { - public void showHint(int viewResource); - } - - private static final String PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN = - "voice_hint_num_unique_days_shown"; - private static final String PREF_VOICE_HINT_LAST_TIME_SHOWN = - "voice_hint_last_time_shown"; - private static final String PREF_VOICE_INPUT_LAST_TIME_USED = - "voice_input_last_time_used"; - private static final String PREF_VOICE_PUNCTUATION_HINT_VIEW_COUNT = - "voice_punctuation_hint_view_count"; - private static final int DEFAULT_SWIPE_HINT_MAX_DAYS_TO_SHOW = 7; - private static final int DEFAULT_PUNCTUATION_HINT_MAX_DISPLAYS = 7; - - private Context mContext; - private Display mDisplay; - private boolean mVoiceResultContainedPunctuation; - private int mSwipeHintMaxDaysToShow; - private int mPunctuationHintMaxDisplays; - - // Only show punctuation hint if voice result did not contain punctuation. - static final Map SPEAKABLE_PUNCTUATION - = new HashMap(); - static { - SPEAKABLE_PUNCTUATION.put(",", "comma"); - SPEAKABLE_PUNCTUATION.put(".", "period"); - SPEAKABLE_PUNCTUATION.put("?", "question mark"); - } - - public Hints(Context context, Display display) { - mContext = context; - mDisplay = display; - - ContentResolver cr = mContext.getContentResolver(); - mSwipeHintMaxDaysToShow = SettingsUtil.getSettingsInt( - cr, - SettingsUtil.LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS, - DEFAULT_SWIPE_HINT_MAX_DAYS_TO_SHOW); - mPunctuationHintMaxDisplays = SettingsUtil.getSettingsInt( - cr, - SettingsUtil.LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS, - DEFAULT_PUNCTUATION_HINT_MAX_DISPLAYS); - } - - public boolean showSwipeHintIfNecessary(boolean fieldRecommended) { - if (fieldRecommended && shouldShowSwipeHint()) { - showHint(R.layout.voice_swipe_hint); - return true; - } - - return false; - } - - public boolean showPunctuationHintIfNecessary(InputConnection ic) { - if (!mVoiceResultContainedPunctuation - && ic != null - && getAndIncrementPref(PREF_VOICE_PUNCTUATION_HINT_VIEW_COUNT) - < mPunctuationHintMaxDisplays) { - CharSequence charBeforeCursor = ic.getTextBeforeCursor(1, 0); - if (SPEAKABLE_PUNCTUATION.containsKey(charBeforeCursor)) { - showHint(R.layout.voice_punctuation_hint); - return true; - } - } - - return false; - } - - public void registerVoiceResult(String text) { - // Update the current time as the last time voice input was used. - SharedPreferences.Editor editor = - PreferenceManager.getDefaultSharedPreferences(mContext).edit(); - editor.putLong(PREF_VOICE_INPUT_LAST_TIME_USED, System.currentTimeMillis()); - SharedPreferencesCompat.apply(editor); - - mVoiceResultContainedPunctuation = false; - for (CharSequence s : SPEAKABLE_PUNCTUATION.keySet()) { - if (text.indexOf(s.toString()) >= 0) { - mVoiceResultContainedPunctuation = true; - break; - } - } - } - - private boolean shouldShowSwipeHint() { - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); - - int numUniqueDaysShown = sp.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, 0); - - // If we've already shown the hint for enough days, we'll return false. - if (numUniqueDaysShown < mSwipeHintMaxDaysToShow) { - - long lastTimeVoiceWasUsed = sp.getLong(PREF_VOICE_INPUT_LAST_TIME_USED, 0); - - // If the user has used voice today, we'll return false. (We don't show the hint on - // any day that the user has already used voice.) - if (!isFromToday(lastTimeVoiceWasUsed)) { - return true; - } - } - - return false; - } - - /** - * Determines whether the provided time is from some time today (i.e., this day, month, - * and year). - */ - private boolean isFromToday(long timeInMillis) { - if (timeInMillis == 0) return false; - - Calendar today = Calendar.getInstance(); - today.setTimeInMillis(System.currentTimeMillis()); - - Calendar timestamp = Calendar.getInstance(); - timestamp.setTimeInMillis(timeInMillis); - - return (today.get(Calendar.YEAR) == timestamp.get(Calendar.YEAR) && - today.get(Calendar.DAY_OF_MONTH) == timestamp.get(Calendar.DAY_OF_MONTH) && - today.get(Calendar.MONTH) == timestamp.get(Calendar.MONTH)); - } - - private void showHint(int hintViewResource) { - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); - - int numUniqueDaysShown = sp.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, 0); - long lastTimeHintWasShown = sp.getLong(PREF_VOICE_HINT_LAST_TIME_SHOWN, 0); - - // If this is the first time the hint is being shown today, increase the saved values - // to represent that. We don't need to increase the last time the hint was shown unless - // it is a different day from the current value. - if (!isFromToday(lastTimeHintWasShown)) { - SharedPreferences.Editor editor = sp.edit(); - editor.putInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, numUniqueDaysShown + 1); - editor.putLong(PREF_VOICE_HINT_LAST_TIME_SHOWN, System.currentTimeMillis()); - SharedPreferencesCompat.apply(editor); - } - - if (mDisplay != null) { - mDisplay.showHint(hintViewResource); - } - } - - private int getAndIncrementPref(String pref) { - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); - int value = sp.getInt(pref, 0); - SharedPreferences.Editor editor = sp.edit(); - editor.putInt(pref, value + 1); - SharedPreferencesCompat.apply(editor); - return value; - } -} diff --git a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java index 7f64bcb43..2c9a162f7 100644 --- a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java @@ -34,6 +34,7 @@ import android.text.TextUtils; public class InputLanguageSelection extends PreferenceActivity { + private SharedPreferences mPrefs; private String mSelectedLanguages; private ArrayList mAvailableLanguages = new ArrayList(); private static final String[] BLACKLIST_LANGUAGES = { @@ -66,8 +67,8 @@ public class InputLanguageSelection extends PreferenceActivity { super.onCreate(icicle); addPreferencesFromResource(R.xml.language_prefs); // Get the settings preferences - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - mSelectedLanguages = sp.getString(LatinIME.PREF_SELECTED_LANGUAGES, ""); + mPrefs = PreferenceManager.getDefaultSharedPreferences(this); + mSelectedLanguages = mPrefs.getString(LatinIME.PREF_SELECTED_LANGUAGES, ""); String[] languageList = mSelectedLanguages.split(","); mAvailableLanguages = getUniqueLocales(); PreferenceGroup parent = getPreferenceScreen(); @@ -140,8 +141,7 @@ public class InputLanguageSelection extends PreferenceActivity { } } if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - Editor editor = sp.edit(); + Editor editor = mPrefs.edit(); editor.putString(LatinIME.PREF_SELECTED_LANGUAGES, checkedLanguages); SharedPreferencesCompat.apply(editor); } diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java index b08b97a81..3f7715329 100644 --- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -60,6 +60,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private static final int SYMBOLS_MODE_STATE_SYMBOL = 2; private SubtypeSwitcher mSubtypeSwitcher; + private SharedPreferences mPrefs; private LatinKeyboardView mInputView; private LatinIME mInputMethodService; @@ -105,11 +106,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private KeyboardSwitcher() { } - public static void init(LatinIME ims) { + public static void init(LatinIME ims, SharedPreferences prefs) { sInstance.mInputMethodService = ims; + sInstance.mPrefs = prefs; sInstance.mSubtypeSwitcher = SubtypeSwitcher.getInstance(); - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ims); sInstance.mLayoutId = Integer.valueOf( prefs.getString(PREF_KEYBOARD_LAYOUT, DEFAULT_LAYOUT_ID)); prefs.registerOnSharedPreferenceChangeListener(sInstance); @@ -282,9 +283,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mVoiceButtonOnPrimary = voiceButtonOnPrimary; mIsSymbols = isSymbols; // Update the settings key state because number of enabled IMEs could have been changed - mHasSettingsKey = getSettingsKeyMode( - PreferenceManager.getDefaultSharedPreferences(mInputMethodService), - mInputMethodService); + mHasSettingsKey = getSettingsKeyMode(mPrefs, mInputMethodService); makeSymbolsKeyboardIds(); KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols); diff --git a/java/src/com/android/inputmethod/latin/LanguageSwitcher.java b/java/src/com/android/inputmethod/latin/LanguageSwitcher.java index c2805f506..05d5164c4 100644 --- a/java/src/com/android/inputmethod/latin/LanguageSwitcher.java +++ b/java/src/com/android/inputmethod/latin/LanguageSwitcher.java @@ -186,9 +186,8 @@ public class LanguageSwitcher { mCurrentIndex = prevLocaleIndex(); } - public void persist() { - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mIme); - Editor editor = sp.edit(); + public void persist(SharedPreferences prefs) { + Editor editor = prefs.edit(); editor.putString(LatinIME.PREF_INPUT_LANGUAGE, getInputLanguage()); SharedPreferencesCompat.apply(editor); } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 8a0d1461a..3e12bf017 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -145,6 +145,7 @@ public class LatinIME extends InputMethodService private AutoDictionary mAutoDictionary; private Resources mResources; + private SharedPreferences mPrefs; private final StringBuilder mComposing = new StringBuilder(); private WordComposer mWord = new WordComposer(); @@ -332,15 +333,16 @@ public class LatinIME extends InputMethodService @Override public void onCreate() { - LatinImeLogger.init(this); - SubtypeSwitcher.init(this); - KeyboardSwitcher.init(this); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + mPrefs = prefs; + LatinImeLogger.init(this, prefs); + SubtypeSwitcher.init(this, prefs); + KeyboardSwitcher.init(this, prefs); super.onCreate(); //setStatusIcon(R.drawable.ime_qwerty); mResources = getResources(); mImm = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)); final Configuration conf = mResources.getConfiguration(); - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mKeyboardSwitcher = KeyboardSwitcher.getInstance(); mReCorrectionEnabled = prefs.getBoolean(PREF_RECORRECTION_ENABLED, @@ -363,7 +365,7 @@ public class LatinIME extends InputMethodService // register to receive ringer mode changes for silent mode IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION); registerReceiver(mReceiver, filter); - mVoiceConnector = VoiceIMEConnector.init(this, mHandler); + mVoiceConnector = VoiceIMEConnector.init(this, prefs, mHandler); prefs.registerOnSharedPreferenceChangeListener(this); } @@ -415,12 +417,12 @@ public class LatinIME extends InputMethodService if (mSuggest != null) { mSuggest.close(); } - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - mQuickFixes = sp.getBoolean(PREF_QUICK_FIXES, true); + final SharedPreferences prefs = mPrefs; + mQuickFixes = prefs.getBoolean(PREF_QUICK_FIXES, true); int[] dictionaries = getDictionary(orig); mSuggest = new Suggest(this, dictionaries); - loadAndSetAutoCompletionThreshold(sp); + loadAndSetAutoCompletionThreshold(prefs); if (mUserDictionary != null) mUserDictionary.close(); mUserDictionary = new UserDictionary(this, locale); if (mContactsDictionary == null) { @@ -2070,26 +2072,26 @@ public class LatinIME extends InputMethodService private void loadSettings(EditorInfo attribute) { // Get the settings preferences - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + final SharedPreferences prefs = mPrefs; Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); mVibrateOn = vibrator != null && vibrator.hasVibrator() - && sp.getBoolean(LatinIMESettings.PREF_VIBRATE_ON, false); - mSoundOn = sp.getBoolean(PREF_SOUND_ON, false); - mPopupOn = sp.getBoolean(PREF_POPUP_ON, + && prefs.getBoolean(LatinIMESettings.PREF_VIBRATE_ON, false); + mSoundOn = prefs.getBoolean(PREF_SOUND_ON, false); + mPopupOn = prefs.getBoolean(PREF_POPUP_ON, mResources.getBoolean(R.bool.default_popup_preview)); - mAutoCap = sp.getBoolean(PREF_AUTO_CAP, true); - mQuickFixes = sp.getBoolean(PREF_QUICK_FIXES, true); + mAutoCap = prefs.getBoolean(PREF_AUTO_CAP, true); + mQuickFixes = prefs.getBoolean(PREF_QUICK_FIXES, true); - mAutoCorrectEnabled = isAutoCorrectEnabled(sp); - mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(sp); - loadAndSetAutoCompletionThreshold(sp); + mAutoCorrectEnabled = isAutoCorrectEnabled(prefs); + mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(prefs); + loadAndSetAutoCompletionThreshold(prefs); - mVoiceConnector.loadSettings(attribute, sp); + mVoiceConnector.loadSettings(attribute, prefs); updateCorrectionMode(); updateAutoTextEnabled(); - updateSuggestionVisibility(sp); - SubtypeSwitcher.getInstance().loadSettings(sp); + updateSuggestionVisibility(prefs); + SubtypeSwitcher.getInstance().loadSettings(); } /** diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java index a3e368f2d..bb74a7a6f 100644 --- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java +++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java @@ -29,7 +29,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { } - public static void init(Context context) { + public static void init(Context context, SharedPreferences prefs) { } public static void commit() { diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 7cf055672..bb9c0eb90 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -50,6 +50,7 @@ public class SubtypeSwitcher { private static final SubtypeSwitcher sInstance = new SubtypeSwitcher(); private /* final */ LatinIME mService; + private /* final */ SharedPreferences mPrefs; private /* final */ InputMethodManager mImm; private /* final */ Resources mResources; private final ArrayList mEnabledKeyboardSubtypesOfCurrentInputMethod = @@ -72,7 +73,8 @@ public class SubtypeSwitcher { return sInstance; } - public static void init(LatinIME service) { + public static void init(LatinIME service, SharedPreferences prefs) { + sInstance.mPrefs = prefs; sInstance.resetParams(service); if (USE_SPACEBAR_LANGUAGE_SWITCHER) { sInstance.initLanguageSwitcher(service); @@ -304,8 +306,7 @@ public class SubtypeSwitcher { // 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(PreferenceManager - .getDefaultSharedPreferences(mService)); + mLanguageSwitcher.loadLocales(mPrefs); mLanguageSwitcher.setSystemLocale(systemLocale); } else { updateAllParameters(); @@ -450,9 +451,9 @@ public class SubtypeSwitcher { return voiceInputSupportedLocales.contains(locale); } - public void loadSettings(SharedPreferences prefs) { + public void loadSettings() { if (USE_SPACEBAR_LANGUAGE_SWITCHER) { - mLanguageSwitcher.loadLocales(prefs); + mLanguageSwitcher.loadLocales(mPrefs); } } @@ -467,15 +468,14 @@ public class SubtypeSwitcher { mLanguageSwitcher.prev(); } } - mLanguageSwitcher.persist(); + mLanguageSwitcher.persist(mPrefs); } } private void initLanguageSwitcher(LatinIME service) { final Configuration conf = service.getResources().getConfiguration(); - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(service); mLanguageSwitcher = new LanguageSwitcher(service); - mLanguageSwitcher.loadLocales(prefs); + mLanguageSwitcher.loadLocales(mPrefs); mLanguageSwitcher.setSystemLocale(conf.locale); } } diff --git a/java/src/com/android/inputmethod/voice/Hints.java b/java/src/com/android/inputmethod/voice/Hints.java new file mode 100644 index 000000000..3707dc366 --- /dev/null +++ b/java/src/com/android/inputmethod/voice/Hints.java @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2009 Google Inc. + * + * 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.voice; + +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.SharedPreferencesCompat; + +import android.content.ContentResolver; +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.view.inputmethod.InputConnection; + +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; + +/** + * Logic to determine when to display hints on usage to the user. + */ +public class Hints { + public interface Display { + public void showHint(int viewResource); + } + + private static final String PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN = + "voice_hint_num_unique_days_shown"; + private static final String PREF_VOICE_HINT_LAST_TIME_SHOWN = + "voice_hint_last_time_shown"; + private static final String PREF_VOICE_INPUT_LAST_TIME_USED = + "voice_input_last_time_used"; + private static final String PREF_VOICE_PUNCTUATION_HINT_VIEW_COUNT = + "voice_punctuation_hint_view_count"; + private static final int DEFAULT_SWIPE_HINT_MAX_DAYS_TO_SHOW = 7; + private static final int DEFAULT_PUNCTUATION_HINT_MAX_DISPLAYS = 7; + + private final Context mContext; + private final SharedPreferences mPrefs; + private final Display mDisplay; + private boolean mVoiceResultContainedPunctuation; + private int mSwipeHintMaxDaysToShow; + private int mPunctuationHintMaxDisplays; + + // Only show punctuation hint if voice result did not contain punctuation. + static final Map SPEAKABLE_PUNCTUATION + = new HashMap(); + static { + SPEAKABLE_PUNCTUATION.put(",", "comma"); + SPEAKABLE_PUNCTUATION.put(".", "period"); + SPEAKABLE_PUNCTUATION.put("?", "question mark"); + } + + public Hints(Context context, SharedPreferences prefs, Display display) { + mContext = context; + mPrefs = prefs; + mDisplay = display; + + ContentResolver cr = mContext.getContentResolver(); + mSwipeHintMaxDaysToShow = SettingsUtil.getSettingsInt( + cr, + SettingsUtil.LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS, + DEFAULT_SWIPE_HINT_MAX_DAYS_TO_SHOW); + mPunctuationHintMaxDisplays = SettingsUtil.getSettingsInt( + cr, + SettingsUtil.LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS, + DEFAULT_PUNCTUATION_HINT_MAX_DISPLAYS); + } + + public boolean showSwipeHintIfNecessary(boolean fieldRecommended) { + if (fieldRecommended && shouldShowSwipeHint()) { + showHint(R.layout.voice_swipe_hint); + return true; + } + + return false; + } + + public boolean showPunctuationHintIfNecessary(InputConnection ic) { + if (!mVoiceResultContainedPunctuation + && ic != null + && getAndIncrementPref(PREF_VOICE_PUNCTUATION_HINT_VIEW_COUNT) + < mPunctuationHintMaxDisplays) { + CharSequence charBeforeCursor = ic.getTextBeforeCursor(1, 0); + if (SPEAKABLE_PUNCTUATION.containsKey(charBeforeCursor)) { + showHint(R.layout.voice_punctuation_hint); + return true; + } + } + + return false; + } + + public void registerVoiceResult(String text) { + // Update the current time as the last time voice input was used. + SharedPreferences.Editor editor = mPrefs.edit(); + editor.putLong(PREF_VOICE_INPUT_LAST_TIME_USED, System.currentTimeMillis()); + SharedPreferencesCompat.apply(editor); + + mVoiceResultContainedPunctuation = false; + for (CharSequence s : SPEAKABLE_PUNCTUATION.keySet()) { + if (text.indexOf(s.toString()) >= 0) { + mVoiceResultContainedPunctuation = true; + break; + } + } + } + + private boolean shouldShowSwipeHint() { + final SharedPreferences prefs = mPrefs; + + int numUniqueDaysShown = prefs.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, 0); + + // If we've already shown the hint for enough days, we'll return false. + if (numUniqueDaysShown < mSwipeHintMaxDaysToShow) { + + long lastTimeVoiceWasUsed = prefs.getLong(PREF_VOICE_INPUT_LAST_TIME_USED, 0); + + // If the user has used voice today, we'll return false. (We don't show the hint on + // any day that the user has already used voice.) + if (!isFromToday(lastTimeVoiceWasUsed)) { + return true; + } + } + + return false; + } + + /** + * Determines whether the provided time is from some time today (i.e., this day, month, + * and year). + */ + private boolean isFromToday(long timeInMillis) { + if (timeInMillis == 0) return false; + + Calendar today = Calendar.getInstance(); + today.setTimeInMillis(System.currentTimeMillis()); + + Calendar timestamp = Calendar.getInstance(); + timestamp.setTimeInMillis(timeInMillis); + + return (today.get(Calendar.YEAR) == timestamp.get(Calendar.YEAR) && + today.get(Calendar.DAY_OF_MONTH) == timestamp.get(Calendar.DAY_OF_MONTH) && + today.get(Calendar.MONTH) == timestamp.get(Calendar.MONTH)); + } + + private void showHint(int hintViewResource) { + final SharedPreferences prefs = mPrefs; + + int numUniqueDaysShown = prefs.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, 0); + long lastTimeHintWasShown = prefs.getLong(PREF_VOICE_HINT_LAST_TIME_SHOWN, 0); + + // If this is the first time the hint is being shown today, increase the saved values + // to represent that. We don't need to increase the last time the hint was shown unless + // it is a different day from the current value. + if (!isFromToday(lastTimeHintWasShown)) { + SharedPreferences.Editor editor = prefs.edit(); + editor.putInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, numUniqueDaysShown + 1); + editor.putLong(PREF_VOICE_HINT_LAST_TIME_SHOWN, System.currentTimeMillis()); + SharedPreferencesCompat.apply(editor); + } + + if (mDisplay != null) { + mDisplay.showHint(hintViewResource); + } + } + + private int getAndIncrementPref(String pref) { + final SharedPreferences prefs = mPrefs; + int value = prefs.getInt(pref, 0); + SharedPreferences.Editor editor = prefs.edit(); + editor.putInt(pref, value + 1); + SharedPreferencesCompat.apply(editor); + return value; + } +} diff --git a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java index 359760d3c..498ef728c 100644 --- a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java +++ b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java @@ -17,7 +17,6 @@ package com.android.inputmethod.voice; import com.android.inputmethod.latin.EditingUtil; -import com.android.inputmethod.latin.Hints; import com.android.inputmethod.latin.KeyboardSwitcher; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.R; @@ -91,8 +90,8 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { private final Map> mWordToSuggestions = new HashMap>(); - public static VoiceIMEConnector init(LatinIME context, UIHandler h) { - sInstance.initInternal(context, h); + public static VoiceIMEConnector init(LatinIME context, SharedPreferences prefs, UIHandler h) { + sInstance.initInternal(context, prefs, h); return sInstance; } @@ -100,14 +99,14 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { return sInstance; } - private void initInternal(LatinIME context, UIHandler h) { + private void initInternal(LatinIME context, SharedPreferences prefs, UIHandler h) { mContext = context; mHandler = h; mImm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); if (VOICE_INSTALLED) { mVoiceInput = new VoiceInput(context, this); - mHints = new Hints(context, new Hints.Display() { + mHints = new Hints(context, prefs, new Hints.Display() { public void showHint(int viewResource) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE); -- cgit v1.2.3-83-g751a From fa086c90760bc2bedf0b74eacb0fed3bf7ebc2b7 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 29 Nov 2010 17:57:48 +0900 Subject: Cleanup unused Java import This change also fixes wrong file mode. Change-Id: Ifcf4c9444ddcdc62d2e4b394891d6eee135c1e8f --- java/AndroidManifest.xml | 0 java/res/drawable-hdpi/working.png | Bin java/res/raw/main.dict | Bin java/res/raw/type3.ogg | Bin .../src/com/android/inputmethod/latin/AutoDictionary.java | 8 ++++---- .../com/android/inputmethod/latin/BinaryDictionary.java | 8 ++++---- java/src/com/android/inputmethod/latin/CandidateView.java | 0 .../android/inputmethod/latin/ExpandableDictionary.java | 4 ++-- .../android/inputmethod/latin/InputLanguageSelection.java | 10 +++++----- .../com/android/inputmethod/latin/KeyboardSwitcher.java | 1 - .../com/android/inputmethod/latin/LanguageSwitcher.java | 1 - java/src/com/android/inputmethod/latin/LatinIME.java | 1 - .../com/android/inputmethod/latin/LatinIMESettings.java | 6 +++--- java/src/com/android/inputmethod/latin/LatinIMEUtil.java | 5 +---- .../src/com/android/inputmethod/latin/LatinImeLogger.java | 1 + .../com/android/inputmethod/latin/SubtypeSwitcher.java | 1 - java/src/com/android/inputmethod/latin/Suggest.java | 10 +++++----- .../android/inputmethod/latin/UserBigramDictionary.java | 8 ++++---- java/src/com/android/inputmethod/voice/Hints.java | 1 - .../com/android/inputmethod/voice/RecognitionView.java | 14 +++++++------- java/src/com/android/inputmethod/voice/SettingsUtil.java | 3 --- .../com/android/inputmethod/voice/VoiceIMEConnector.java | 2 +- java/src/com/android/inputmethod/voice/VoiceInput.java | 4 ++-- java/src/com/android/inputmethod/voice/Whitelist.java | 1 + 24 files changed, 40 insertions(+), 49 deletions(-) mode change 100755 => 100644 java/AndroidManifest.xml mode change 100755 => 100644 java/res/drawable-hdpi/working.png mode change 100755 => 100644 java/res/raw/main.dict mode change 100755 => 100644 java/res/raw/type3.ogg mode change 100755 => 100644 java/src/com/android/inputmethod/latin/CandidateView.java mode change 100755 => 100644 java/src/com/android/inputmethod/latin/Suggest.java (limited to 'java/src/com/android/inputmethod/latin/InputLanguageSelection.java') diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml old mode 100755 new mode 100644 diff --git a/java/res/drawable-hdpi/working.png b/java/res/drawable-hdpi/working.png old mode 100755 new mode 100644 diff --git a/java/res/raw/main.dict b/java/res/raw/main.dict old mode 100755 new mode 100644 diff --git a/java/res/raw/type3.ogg b/java/res/raw/type3.ogg old mode 100755 new mode 100644 diff --git a/java/src/com/android/inputmethod/latin/AutoDictionary.java b/java/src/com/android/inputmethod/latin/AutoDictionary.java index 4fbb5b012..a3bf25642 100644 --- a/java/src/com/android/inputmethod/latin/AutoDictionary.java +++ b/java/src/com/android/inputmethod/latin/AutoDictionary.java @@ -16,10 +16,6 @@ package com.android.inputmethod.latin; -import java.util.HashMap; -import java.util.Set; -import java.util.Map.Entry; - import android.content.ContentValues; import android.content.Context; import android.database.Cursor; @@ -30,6 +26,10 @@ import android.os.AsyncTask; import android.provider.BaseColumns; import android.util.Log; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Set; + /** * Stores new words temporarily until they are promoted to the user dictionary * for longevity. Words in the auto dictionary are used to determine if it's ok diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index d0e143dd0..4e02f84d9 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -16,16 +16,16 @@ package com.android.inputmethod.latin; -import java.io.InputStream; +import android.content.Context; +import android.util.Log; + import java.io.IOException; +import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.Channels; import java.util.Arrays; -import android.content.Context; -import android.util.Log; - /** * Implements a static, compacted, binary dictionary of standard words. */ diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java old mode 100755 new mode 100644 diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index e954c0818..2a7767ddd 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -16,11 +16,11 @@ package com.android.inputmethod.latin; -import java.util.LinkedList; - import android.content.Context; import android.os.AsyncTask; +import java.util.LinkedList; + /** * Base class for an in-memory dictionary that can grow dynamically and can * be searched for suggestions and valid words. diff --git a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java index 2c9a162f7..fc517aeb7 100644 --- a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java @@ -16,11 +16,6 @@ package com.android.inputmethod.latin; -import java.text.Collator; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Locale; - import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.res.Configuration; @@ -32,6 +27,11 @@ import android.preference.PreferenceGroup; import android.preference.PreferenceManager; import android.text.TextUtils; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Locale; + public class InputLanguageSelection extends PreferenceActivity { private SharedPreferences mPrefs; diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 3f7715329..af1575f06 100644 --- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -19,7 +19,6 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; -import android.preference.PreferenceManager; import android.util.Log; import android.view.InflateException; import android.view.inputmethod.EditorInfo; diff --git a/java/src/com/android/inputmethod/latin/LanguageSwitcher.java b/java/src/com/android/inputmethod/latin/LanguageSwitcher.java index 05d5164c4..fc725bf1b 100644 --- a/java/src/com/android/inputmethod/latin/LanguageSwitcher.java +++ b/java/src/com/android/inputmethod/latin/LanguageSwitcher.java @@ -18,7 +18,6 @@ package com.android.inputmethod.latin; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; -import android.preference.PreferenceManager; import android.text.TextUtils; import java.util.ArrayList; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 3e12bf017..cc8dfebe2 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -35,7 +35,6 @@ import android.inputmethodservice.InputMethodService; import android.media.AudioManager; import android.os.Debug; import android.os.Handler; -import android.os.IBinder; import android.os.Message; import android.os.SystemClock; import android.os.Vibrator; diff --git a/java/src/com/android/inputmethod/latin/LatinIMESettings.java b/java/src/com/android/inputmethod/latin/LatinIMESettings.java index 8da9c223d..669192f59 100644 --- a/java/src/com/android/inputmethod/latin/LatinIMESettings.java +++ b/java/src/com/android/inputmethod/latin/LatinIMESettings.java @@ -16,7 +16,8 @@ package com.android.inputmethod.latin; -import java.util.Locale; +import com.android.inputmethod.voice.VoiceIMEConnector; +import com.android.inputmethod.voice.VoiceInputLogger; import android.app.AlertDialog; import android.app.Dialog; @@ -33,8 +34,7 @@ import android.speech.SpeechRecognizer; import android.text.AutoText; import android.util.Log; -import com.android.inputmethod.voice.VoiceIMEConnector; -import com.android.inputmethod.voice.VoiceInputLogger; +import java.util.Locale; public class LatinIMESettings extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener, diff --git a/java/src/com/android/inputmethod/latin/LatinIMEUtil.java b/java/src/com/android/inputmethod/latin/LatinIMEUtil.java index 4db1ec5c8..a58f630cd 100644 --- a/java/src/com/android/inputmethod/latin/LatinIMEUtil.java +++ b/java/src/com/android/inputmethod/latin/LatinIMEUtil.java @@ -16,17 +16,14 @@ package com.android.inputmethod.latin; -import android.view.inputmethod.InputMethodManager; - -import android.content.Context; import android.inputmethodservice.InputMethodService; import android.os.AsyncTask; import android.os.Handler; import android.os.HandlerThread; import android.os.Process; import android.text.format.DateUtils; -import android.text.format.Time; import android.util.Log; +import android.view.inputmethod.InputMethodManager; import java.io.BufferedReader; import java.io.File; diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java index bb74a7a6f..b64e3ddb2 100644 --- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java +++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java @@ -20,6 +20,7 @@ import com.android.inputmethod.latin.Dictionary.DataType; import android.content.Context; import android.content.SharedPreferences; + import java.util.List; public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChangeListener { diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index bb9c0eb90..4600f77d1 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -24,7 +24,6 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; -import android.preference.PreferenceManager; import android.text.TextUtils; import android.util.Log; import android.view.inputmethod.InputMethodManager; diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java old mode 100755 new mode 100644 index 29c3eea5f..ca2ffe13a --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -16,17 +16,17 @@ package com.android.inputmethod.latin; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - import android.content.Context; import android.text.AutoText; import android.text.TextUtils; import android.util.Log; import android.view.View; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + /** * This class loads a dictionary and provides a list of suggestions for a given sequence of * characters. This includes corrections and completions. diff --git a/java/src/com/android/inputmethod/latin/UserBigramDictionary.java b/java/src/com/android/inputmethod/latin/UserBigramDictionary.java index 67d9c0bcf..6d2f6b611 100644 --- a/java/src/com/android/inputmethod/latin/UserBigramDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserBigramDictionary.java @@ -16,10 +16,6 @@ package com.android.inputmethod.latin; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; - import android.content.ContentValues; import android.content.Context; import android.database.Cursor; @@ -30,6 +26,10 @@ import android.os.AsyncTask; import android.provider.BaseColumns; import android.util.Log; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; + /** * Stores all the pairs user types in databases. Prune the database if the size * gets too big. Unlike AutoDictionary, it even stores the pairs that are already diff --git a/java/src/com/android/inputmethod/voice/Hints.java b/java/src/com/android/inputmethod/voice/Hints.java index 3707dc366..d11d3b042 100644 --- a/java/src/com/android/inputmethod/voice/Hints.java +++ b/java/src/com/android/inputmethod/voice/Hints.java @@ -22,7 +22,6 @@ import com.android.inputmethod.latin.SharedPreferencesCompat; import android.content.ContentResolver; import android.content.Context; import android.content.SharedPreferences; -import android.preference.PreferenceManager; import android.view.inputmethod.InputConnection; import java.util.Calendar; diff --git a/java/src/com/android/inputmethod/voice/RecognitionView.java b/java/src/com/android/inputmethod/voice/RecognitionView.java index 7cec0b04a..1d1297713 100644 --- a/java/src/com/android/inputmethod/voice/RecognitionView.java +++ b/java/src/com/android/inputmethod/voice/RecognitionView.java @@ -16,12 +16,7 @@ package com.android.inputmethod.voice; -import java.io.ByteArrayOutputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.ShortBuffer; -import java.util.ArrayList; -import java.util.List; +import com.android.inputmethod.latin.R; import android.content.ContentResolver; import android.content.Context; @@ -43,7 +38,12 @@ import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; -import com.android.inputmethod.latin.R; +import java.io.ByteArrayOutputStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.ShortBuffer; +import java.util.ArrayList; +import java.util.List; /** * The user interface for the "Speak now" and "working" states. diff --git a/java/src/com/android/inputmethod/voice/SettingsUtil.java b/java/src/com/android/inputmethod/voice/SettingsUtil.java index abf52047f..4d746e120 100644 --- a/java/src/com/android/inputmethod/voice/SettingsUtil.java +++ b/java/src/com/android/inputmethod/voice/SettingsUtil.java @@ -17,10 +17,7 @@ package com.android.inputmethod.voice; import android.content.ContentResolver; -import android.database.Cursor; -import android.net.Uri; import android.provider.Settings; -import android.util.Log; /** * Utility for retrieving settings from Settings.Secure. diff --git a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java index 498ef728c..fd9559dae 100644 --- a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java +++ b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java @@ -19,10 +19,10 @@ package com.android.inputmethod.voice; import com.android.inputmethod.latin.EditingUtil; import com.android.inputmethod.latin.KeyboardSwitcher; import com.android.inputmethod.latin.LatinIME; +import com.android.inputmethod.latin.LatinIME.UIHandler; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SharedPreferencesCompat; import com.android.inputmethod.latin.SubtypeSwitcher; -import com.android.inputmethod.latin.LatinIME.UIHandler; import android.app.AlertDialog; import android.content.Context; diff --git a/java/src/com/android/inputmethod/voice/VoiceInput.java b/java/src/com/android/inputmethod/voice/VoiceInput.java index 4c54dd3c5..6d45ef97c 100644 --- a/java/src/com/android/inputmethod/voice/VoiceInput.java +++ b/java/src/com/android/inputmethod/voice/VoiceInput.java @@ -28,12 +28,12 @@ import android.os.Handler; import android.os.Message; import android.os.Parcelable; import android.speech.RecognitionListener; -import android.speech.SpeechRecognizer; import android.speech.RecognizerIntent; +import android.speech.SpeechRecognizer; import android.util.Log; -import android.view.inputmethod.InputConnection; import android.view.View; import android.view.View.OnClickListener; +import android.view.inputmethod.InputConnection; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/java/src/com/android/inputmethod/voice/Whitelist.java b/java/src/com/android/inputmethod/voice/Whitelist.java index 167b688ca..f4c24de0c 100644 --- a/java/src/com/android/inputmethod/voice/Whitelist.java +++ b/java/src/com/android/inputmethod/voice/Whitelist.java @@ -17,6 +17,7 @@ package com.android.inputmethod.voice; import android.os.Bundle; + import java.util.ArrayList; import java.util.List; -- cgit v1.2.3-83-g751a From 5a309f57155fb95667c2ccdda730eaf175de8876 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 2 Dec 2010 18:46:21 +0900 Subject: Move some inner static class to top class in new package This change introduces new package com.android.inputmethod.keyboard which hosts keyboard related classes. Also adds missing @Override and @SuppressWarning("unused") annotation Change-Id: I0317f5cfa317e13f3c77815f48ffc69b5d1ade05 --- .../res/layout-xlarge/keyboard_popup_honeycomb.xml | 4 +- java/res/layout/input_basic.xml | 2 +- java/res/layout/input_basic_highcontrast.xml | 2 +- java/res/layout/input_gingerbread.xml | 2 +- java/res/layout/input_honeycomb.xml | 2 +- java/res/layout/input_stone_bold.xml | 2 +- java/res/layout/input_stone_normal.xml | 2 +- java/res/layout/input_stone_popup.xml | 4 +- java/res/layout/keyboard_popup.xml | 4 +- java/res/layout/keyboard_popup_honeycomb.xml | 4 +- java/res/values/attrs.xml | 20 +- java/res/values/styles.xml | 2 +- java/src/com/android/inputmethod/keyboard/Key.java | 305 ++++ .../android/inputmethod/keyboard/KeyDetector.java | 112 ++ .../android/inputmethod/keyboard/KeyStyles.java | 246 +++ .../com/android/inputmethod/keyboard/Keyboard.java | 386 +++++ .../keyboard/KeyboardActionListener.java | 99 ++ .../android/inputmethod/keyboard/KeyboardId.java | 148 ++ .../inputmethod/keyboard/KeyboardParser.java | 569 +++++++ .../android/inputmethod/keyboard/KeyboardView.java | 1469 ++++++++++++++++++ .../com/android/inputmethod/keyboard/LatinKey.java | 90 ++ .../inputmethod/keyboard/LatinKeyboard.java | 543 +++++++ .../keyboard/LatinKeyboardShiftState.java | 107 ++ .../inputmethod/keyboard/LatinKeyboardView.java | 369 +++++ .../keyboard/MiniKeyboardKeyDetector.java | 58 + .../inputmethod/keyboard/PointerTracker.java | 546 +++++++ .../inputmethod/keyboard/PointerTrackerQueue.java | 67 + .../inputmethod/keyboard/ProximityKeyDetector.java | 75 + java/src/com/android/inputmethod/keyboard/Row.java | 73 + .../keyboard/SlidingLocaleDrawable.java | 163 ++ .../android/inputmethod/keyboard/SwipeTracker.java | 157 ++ .../android/inputmethod/latin/BaseKeyboard.java | 717 --------- .../inputmethod/latin/BaseKeyboardParser.java | 571 ------- .../inputmethod/latin/BaseKeyboardView.java | 1585 -------------------- .../inputmethod/latin/InputLanguageSelection.java | 1 + .../com/android/inputmethod/latin/KeyDetector.java | 112 -- .../com/android/inputmethod/latin/KeyStyles.java | 238 --- .../inputmethod/latin/KeyboardSwitcher.java | 147 +- .../com/android/inputmethod/latin/LatinIME.java | 116 +- .../inputmethod/latin/LatinIMEDebugSettings.java | 1 + .../inputmethod/latin/LatinIMESettings.java | 3 + .../android/inputmethod/latin/LatinIMEUtil.java | 3 + .../android/inputmethod/latin/LatinImeLogger.java | 4 +- .../android/inputmethod/latin/LatinKeyboard.java | 720 --------- .../inputmethod/latin/LatinKeyboardShiftState.java | 89 -- .../inputmethod/latin/LatinKeyboardView.java | 376 ----- .../inputmethod/latin/MiniKeyboardKeyDetector.java | 60 - .../android/inputmethod/latin/PointerTracker.java | 546 ------- .../inputmethod/latin/ProximityKeyDetector.java | 77 - .../android/inputmethod/latin/SubtypeSwitcher.java | 5 +- .../src/com/android/inputmethod/latin/Suggest.java | 1 + .../android/inputmethod/latin/SwipeTracker.java | 157 -- .../android/inputmethod/latin/TextEntryState.java | 2 +- .../com/android/inputmethod/latin/Tutorial.java | 4 + .../android/inputmethod/latin/UserDictionary.java | 1 + .../android/inputmethod/voice/FieldContext.java | 2 + .../android/inputmethod/voice/RecognitionView.java | 8 + .../inputmethod/voice/VoiceIMEConnector.java | 3 +- .../com/android/inputmethod/voice/VoiceInput.java | 11 + .../inputmethod/voice/VoiceInputLogger.java | 1 + .../inputmethod/latin/EventRingBufferTests.java | 2 +- 61 files changed, 5734 insertions(+), 5461 deletions(-) create mode 100644 java/src/com/android/inputmethod/keyboard/Key.java create mode 100644 java/src/com/android/inputmethod/keyboard/KeyDetector.java create mode 100644 java/src/com/android/inputmethod/keyboard/KeyStyles.java create mode 100644 java/src/com/android/inputmethod/keyboard/Keyboard.java create mode 100644 java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java create mode 100644 java/src/com/android/inputmethod/keyboard/KeyboardId.java create mode 100644 java/src/com/android/inputmethod/keyboard/KeyboardParser.java create mode 100644 java/src/com/android/inputmethod/keyboard/KeyboardView.java create mode 100644 java/src/com/android/inputmethod/keyboard/LatinKey.java create mode 100644 java/src/com/android/inputmethod/keyboard/LatinKeyboard.java create mode 100644 java/src/com/android/inputmethod/keyboard/LatinKeyboardShiftState.java create mode 100644 java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java create mode 100644 java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java create mode 100644 java/src/com/android/inputmethod/keyboard/PointerTracker.java create mode 100644 java/src/com/android/inputmethod/keyboard/PointerTrackerQueue.java create mode 100644 java/src/com/android/inputmethod/keyboard/ProximityKeyDetector.java create mode 100644 java/src/com/android/inputmethod/keyboard/Row.java create mode 100644 java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java create mode 100644 java/src/com/android/inputmethod/keyboard/SwipeTracker.java delete mode 100644 java/src/com/android/inputmethod/latin/BaseKeyboard.java delete mode 100644 java/src/com/android/inputmethod/latin/BaseKeyboardParser.java delete mode 100644 java/src/com/android/inputmethod/latin/BaseKeyboardView.java delete mode 100644 java/src/com/android/inputmethod/latin/KeyDetector.java delete mode 100644 java/src/com/android/inputmethod/latin/KeyStyles.java delete mode 100644 java/src/com/android/inputmethod/latin/LatinKeyboard.java delete mode 100644 java/src/com/android/inputmethod/latin/LatinKeyboardShiftState.java delete mode 100644 java/src/com/android/inputmethod/latin/LatinKeyboardView.java delete mode 100644 java/src/com/android/inputmethod/latin/MiniKeyboardKeyDetector.java delete mode 100644 java/src/com/android/inputmethod/latin/PointerTracker.java delete mode 100644 java/src/com/android/inputmethod/latin/ProximityKeyDetector.java delete mode 100644 java/src/com/android/inputmethod/latin/SwipeTracker.java (limited to 'java/src/com/android/inputmethod/latin/InputLanguageSelection.java') diff --git a/java/res/layout-xlarge/keyboard_popup_honeycomb.xml b/java/res/layout-xlarge/keyboard_popup_honeycomb.xml index 5a91dbeb0..0b8229ca5 100644 --- a/java/res/layout-xlarge/keyboard_popup_honeycomb.xml +++ b/java/res/layout-xlarge/keyboard_popup_honeycomb.xml @@ -26,9 +26,9 @@ android:paddingLeft="40dip" android:paddingRight="40dip" > - - - - - - - - - - - + @@ -68,14 +68,14 @@ - + - + @@ -86,7 +86,7 @@ - + @@ -114,7 +114,7 @@ - + @@ -135,7 +135,7 @@ - + @@ -145,12 +145,12 @@ - + - - + + @@ -175,7 +175,7 @@ - + diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 02d21b43b..130714fd3 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -15,7 +15,7 @@ --> -