From 0c72ea1c925c6f022e4cdcb126843b72bd8bb09f Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 20 Apr 2011 20:25:26 +0900 Subject: Remove a useless import. Change-Id: I911e3e928a45bbca352a87e6b0616a2ba9bd9e9c --- java/src/com/android/inputmethod/latin/AutoDictionary.java | 1 - 1 file changed, 1 deletion(-) (limited to 'java/src/com/android/inputmethod') diff --git a/java/src/com/android/inputmethod/latin/AutoDictionary.java b/java/src/com/android/inputmethod/latin/AutoDictionary.java index a00b0915c..307b81d43 100644 --- a/java/src/com/android/inputmethod/latin/AutoDictionary.java +++ b/java/src/com/android/inputmethod/latin/AutoDictionary.java @@ -27,7 +27,6 @@ import android.provider.BaseColumns; import android.util.Log; import java.util.HashMap; -import java.util.Map; import java.util.Map.Entry; import java.util.Set; -- cgit v1.2.3-83-g751a From e6cb8fc234940700ae97af787e62962a98d332e5 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 21 Apr 2011 12:22:00 +0900 Subject: Display spacebar language switcher even when key preview is off Bug: 4313884 Change-Id: I9d4a474302dadbfc610324799f8768b803705e52 --- .../com/android/inputmethod/keyboard/KeyboardView.java | 8 +++++++- .../android/inputmethod/keyboard/PointerTracker.java | 17 ++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'java/src/com/android/inputmethod') diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index eb09a455b..95ecb3bc9 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -889,8 +889,11 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { @Override public void showKeyPreview(int keyIndex, PointerTracker tracker) { - if (mShowKeyPreview || mKeyboard.needSpacebarPreview(keyIndex)) { + if (mShowKeyPreview) { mHandler.showKeyPreview(mDelayBeforePreview, keyIndex, tracker); + } else if (mKeyboard.needSpacebarPreview(keyIndex)) { + // Show key preview (in this case, slide language switcher) without any delay. + showKey(keyIndex, tracker); } } @@ -899,6 +902,9 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { if (mShowKeyPreview) { mHandler.cancelShowKeyPreview(tracker); mHandler.dismissKeyPreview(mDelayAfterPreview, tracker); + } else if (mKeyboard.needSpacebarPreview(KeyDetector.NOT_A_KEY)) { + // Dismiss key preview (in this case, slide language switcher) without any delay. + mPreviewText.setVisibility(View.INVISIBLE); } } diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 64f2f9644..249f6648b 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -392,7 +392,7 @@ public class PointerTracker { startLongPressTimer(keyIndex); showKeyPreview(keyIndex); setPressedKeyGraphics(keyIndex); - } else if (!isMinorMoveBounce(x, y, keyIndex)) { + } else if (isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) { // The pointer has been slid in to the new key from the previous key, we must call // onRelease() first to notify that the previous key has been released, then call // onPress() to notify that the new key is being pressed. @@ -430,9 +430,12 @@ public class PointerTracker { } return; } + } else if (mKeyboard.needSpacebarPreview(keyIndex)) { + // Display spacebar slide language switcher. + showKeyPreview(keyIndex); } } else { - if (oldKey != null && !isMinorMoveBounce(x, y, keyIndex)) { + if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) { // The pointer has been slid out from the previous key, we must call onRelease() to // notify that the previous key has been released. setReleasedKeyGraphics(oldKeyIndex); @@ -483,7 +486,7 @@ public class PointerTracker { mIsInSlidingKeyInput = false; final PointerTrackerKeyState keyState = mKeyState; final int keyX, keyY; - if (!isMinorMoveBounce(x, y, keyState.onMoveKey(x, y))) { + if (isMajorEnoughMoveToBeOnNewKey(x, y, keyState.onMoveKey(x, y))) { keyX = x; keyY = y; } else { @@ -544,16 +547,16 @@ public class PointerTracker { return mKeyState.getDownTime(); } - private boolean isMinorMoveBounce(int x, int y, int newKey) { + private boolean isMajorEnoughMoveToBeOnNewKey(int x, int y, int newKey) { if (mKeys == null || mKeyHysteresisDistanceSquared < 0) throw new IllegalStateException("keyboard and/or hysteresis not set"); int curKey = mKeyState.getKeyIndex(); if (newKey == curKey) { - return true; + return false; } else if (isValidKeyIndex(curKey)) { - return mKeys.get(curKey).squaredDistanceToEdge(x, y) < mKeyHysteresisDistanceSquared; + return mKeys.get(curKey).squaredDistanceToEdge(x, y) >= mKeyHysteresisDistanceSquared; } else { - return false; + return true; } } -- cgit v1.2.3-83-g751a From 46ca84584810dfe606e709b3fe283cbde8aba5f5 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 21 Apr 2011 14:51:53 +0900 Subject: Compute content and visible insets even in voice mode Bug: 4317779 Change-Id: If54d15466db9d0362b4470a2ba4618377bdffc2a --- java/src/com/android/inputmethod/latin/LatinIME.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'java/src/com/android/inputmethod') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 13ef4ffe8..a680b9825 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -901,15 +901,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar public void onComputeInsets(InputMethodService.Insets outInsets) { super.onComputeInsets(outInsets); final KeyboardView inputView = mKeyboardSwitcher.getInputView(); + if (inputView == null) + return; + final int containerHeight = mCandidateViewContainer.getHeight(); + int touchY = containerHeight; // Need to set touchable region only if input view is being shown - if (inputView != null && mKeyboardSwitcher.isInputViewShown()) { - final int containerHeight = mCandidateViewContainer.getHeight(); - int touchY = containerHeight; + if (mKeyboardSwitcher.isInputViewShown()) { if (mCandidateViewContainer.getVisibility() == View.VISIBLE) { touchY -= mCandidateStripHeight; } - outInsets.contentTopInsets = touchY; - outInsets.visibleTopInsets = touchY; final int touchWidth = inputView.getWidth(); final int touchHeight = inputView.getHeight() + containerHeight // Extend touchable region below the keyboard. @@ -920,6 +920,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } setTouchableRegionCompat(outInsets, 0, touchY, touchWidth, touchHeight); } + outInsets.contentTopInsets = touchY; + outInsets.visibleTopInsets = touchY; } @Override -- cgit v1.2.3-83-g751a From 15a0ba6d74feed57124938336f951ae14aa47ad9 Mon Sep 17 00:00:00 2001 From: satok Date: Thu, 21 Apr 2011 15:35:07 +0900 Subject: Check the availability of layouts for showing the input languages in the settings Bug: 4316889 Change-Id: I746b3ff79c2a6cd4925fca1817d5b209623b5108 --- java/AndroidManifest.xml | 2 +- java/res/values/attrs.xml | 2 + java/res/xml-ar/kbd_qwerty.xml | 1 + java/res/xml-cs/kbd_qwerty.xml | 1 + java/res/xml-da/kbd_qwerty.xml | 1 + java/res/xml-de/kbd_qwerty.xml | 1 + java/res/xml-fi/kbd_qwerty.xml | 1 + java/res/xml-fr-rCA/kbd_qwerty.xml | 1 + java/res/xml-fr-rCH/kbd_qwerty.xml | 1 + java/res/xml-fr/kbd_qwerty.xml | 1 + java/res/xml-hu/kbd_qwerty.xml | 1 + java/res/xml-iw/kbd_qwerty.xml | 1 + java/res/xml-nb/kbd_qwerty.xml | 1 + java/res/xml-ru/kbd_qwerty.xml | 1 + java/res/xml-sr/kbd_qwerty.xml | 1 + java/res/xml-sv/kbd_qwerty.xml | 1 + java/res/xml-xlarge/kbd_qwerty.xml | 33 --- java/res/xml/kbd_qwerty.xml | 1 + java/res/xml/prefs.xml | 7 + .../languageswitcher/InputLanguageSelection.java | 248 +++++++++++++++++++++ .../inputmethod/keyboard/KeyboardParser.java | 22 ++ .../inputmethod/latin/InputLanguageSelection.java | 217 ------------------ .../com/android/inputmethod/latin/Settings.java | 6 + .../src/com/android/inputmethod/latin/Suggest.java | 2 +- 24 files changed, 302 insertions(+), 252 deletions(-) delete mode 100644 java/res/xml-xlarge/kbd_qwerty.xml create mode 100644 java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java delete mode 100644 java/src/com/android/inputmethod/latin/InputLanguageSelection.java (limited to 'java/src/com/android/inputmethod') diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml index e0eecfc7d..2fbf4c2be 100644 --- a/java/AndroidManifest.xml +++ b/java/AndroidManifest.xml @@ -33,7 +33,7 @@ - diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 9b38139f0..e88b007a9 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -91,6 +91,8 @@ + + diff --git a/java/res/xml-ar/kbd_qwerty.xml b/java/res/xml-ar/kbd_qwerty.xml index 4c6a4f50a..5faf60336 100644 --- a/java/res/xml-ar/kbd_qwerty.xml +++ b/java/res/xml-ar/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="ar" > diff --git a/java/res/xml-cs/kbd_qwerty.xml b/java/res/xml-cs/kbd_qwerty.xml index 010bdb3f7..0e6e40d7c 100644 --- a/java/res/xml-cs/kbd_qwerty.xml +++ b/java/res/xml-cs/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="cs" > diff --git a/java/res/xml-da/kbd_qwerty.xml b/java/res/xml-da/kbd_qwerty.xml index 441b7cb17..d9847ae83 100644 --- a/java/res/xml-da/kbd_qwerty.xml +++ b/java/res/xml-da/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="da" > diff --git a/java/res/xml-de/kbd_qwerty.xml b/java/res/xml-de/kbd_qwerty.xml index a23e4fbf0..6b5c22391 100644 --- a/java/res/xml-de/kbd_qwerty.xml +++ b/java/res/xml-de/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="de" > diff --git a/java/res/xml-fi/kbd_qwerty.xml b/java/res/xml-fi/kbd_qwerty.xml index b0a7b3eb0..ea08d670b 100644 --- a/java/res/xml-fi/kbd_qwerty.xml +++ b/java/res/xml-fi/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="fi" > diff --git a/java/res/xml-fr-rCA/kbd_qwerty.xml b/java/res/xml-fr-rCA/kbd_qwerty.xml index 92d92f0e6..f9c29698b 100644 --- a/java/res/xml-fr-rCA/kbd_qwerty.xml +++ b/java/res/xml-fr-rCA/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="fr_CA" > diff --git a/java/res/xml-fr-rCH/kbd_qwerty.xml b/java/res/xml-fr-rCH/kbd_qwerty.xml index a23e4fbf0..e47cfd9b4 100644 --- a/java/res/xml-fr-rCH/kbd_qwerty.xml +++ b/java/res/xml-fr-rCH/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="fr_CH" > diff --git a/java/res/xml-fr/kbd_qwerty.xml b/java/res/xml-fr/kbd_qwerty.xml index 2d0b42baf..e4b73bf21 100644 --- a/java/res/xml-fr/kbd_qwerty.xml +++ b/java/res/xml-fr/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="fr" > diff --git a/java/res/xml-hu/kbd_qwerty.xml b/java/res/xml-hu/kbd_qwerty.xml index 010bdb3f7..db729cf02 100644 --- a/java/res/xml-hu/kbd_qwerty.xml +++ b/java/res/xml-hu/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="hu" > diff --git a/java/res/xml-iw/kbd_qwerty.xml b/java/res/xml-iw/kbd_qwerty.xml index 72826d461..4cd565b88 100644 --- a/java/res/xml-iw/kbd_qwerty.xml +++ b/java/res/xml-iw/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="iw" > diff --git a/java/res/xml-nb/kbd_qwerty.xml b/java/res/xml-nb/kbd_qwerty.xml index 441b7cb17..7b20ca28d 100644 --- a/java/res/xml-nb/kbd_qwerty.xml +++ b/java/res/xml-nb/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="nb" > diff --git a/java/res/xml-ru/kbd_qwerty.xml b/java/res/xml-ru/kbd_qwerty.xml index 0eb311501..065cf3afc 100644 --- a/java/res/xml-ru/kbd_qwerty.xml +++ b/java/res/xml-ru/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="ru" > diff --git a/java/res/xml-sr/kbd_qwerty.xml b/java/res/xml-sr/kbd_qwerty.xml index 3995e4e27..9782cd5eb 100644 --- a/java/res/xml-sr/kbd_qwerty.xml +++ b/java/res/xml-sr/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="sr" > diff --git a/java/res/xml-sv/kbd_qwerty.xml b/java/res/xml-sv/kbd_qwerty.xml index 72bdc339e..3ff1679a2 100644 --- a/java/res/xml-sv/kbd_qwerty.xml +++ b/java/res/xml-sv/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="sv" > diff --git a/java/res/xml-xlarge/kbd_qwerty.xml b/java/res/xml-xlarge/kbd_qwerty.xml deleted file mode 100644 index 1c8d51ffe..000000000 --- a/java/res/xml-xlarge/kbd_qwerty.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - diff --git a/java/res/xml/kbd_qwerty.xml b/java/res/xml/kbd_qwerty.xml index 92d92f0e6..6bf6b781d 100644 --- a/java/res/xml/kbd_qwerty.xml +++ b/java/res/xml/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="en" > diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index cbfc3c39d..fb7b0ea40 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -64,6 +64,13 @@ android:key="subtype_settings" android:title="@string/language_selection_title" android:summary="@string/language_selection_summary" /> + + + mAvailableLanguages = new ArrayList(); + + private static class Loc implements Comparable { + private static Collator sCollator = Collator.getInstance(); + + private String mLabel; + public final Locale mLocale; + + public Loc(String label, Locale locale) { + this.mLabel = label; + this.mLocale = locale; + } + + public void setLabel(String label) { + this.mLabel = label; + } + + @Override + public String toString() { + return this.mLabel; + } + + @Override + public int compareTo(Object o) { + return sCollator.compare(this.mLabel, ((Loc) o).mLabel); + } + } + + @Override + protected void onCreate(Bundle icicle) { + super.onCreate(icicle); + addPreferencesFromResource(R.xml.language_prefs); + // Get the settings preferences + mPrefs = PreferenceManager.getDefaultSharedPreferences(this); + mSelectedLanguages = mPrefs.getString(Settings.PREF_SELECTED_LANGUAGES, ""); + String[] languageList = mSelectedLanguages.split(","); + mAvailableLanguages = getUniqueLocales(); + PreferenceGroup parent = getPreferenceScreen(); + for (int i = 0; i < mAvailableLanguages.size(); i++) { + Locale locale = mAvailableLanguages.get(i).mLocale; + if (!hasDictionary(locale) && !hasLayout(locale)) { + continue; + } + CheckBoxPreference pref = new CheckBoxPreference(this); + pref.setTitle(SubtypeSwitcher.getFullDisplayName(locale, true)); + boolean checked = isLocaleIn(locale, languageList); + pref.setChecked(checked); + if (hasDictionary(locale)) { + pref.setSummary(R.string.has_dictionary); + } + parent.addPreference(pref); + } + } + + private boolean isLocaleIn(Locale locale, String[] list) { + String lang = get5Code(locale); + for (int i = 0; i < list.length; i++) { + if (lang.equalsIgnoreCase(list[i])) return true; + } + return false; + } + + private boolean hasDictionary(Locale locale) { + final Resources res = getResources(); + final Configuration conf = res.getConfiguration(); + final Locale saveLocale = conf.locale; + boolean haveDictionary = false; + conf.locale = locale; + res.updateConfiguration(conf, res.getDisplayMetrics()); + + BinaryDictionary bd = BinaryDictionary.initDictionaryFromManager(this, Suggest.DIC_MAIN, + locale, Utils.getMainDictionaryResourceId(res)); + + // Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of + // 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words. + if (bd.getSize() > Suggest.LARGE_DICTIONARY_THRESHOLD / 4) { + haveDictionary = true; + } + bd.close(); + conf.locale = saveLocale; + res.updateConfiguration(conf, res.getDisplayMetrics()); + return haveDictionary; + } + + private boolean hasLayout(Locale locale) { + if (locale == null) return false; + final Resources res = getResources(); + final Configuration conf = res.getConfiguration(); + final Locale saveLocale = conf.locale; + conf.locale = locale; + res.updateConfiguration(conf, res.getDisplayMetrics()); + + try { + final String countryCode = locale.getLanguage(); + final String layoutCountryCode = KeyboardParser.parseKeyboardLocale( + this, R.xml.kbd_qwerty); + if (!TextUtils.isEmpty(countryCode) && !TextUtils.isEmpty(layoutCountryCode)) { + return countryCode.subSequence(0, 2).equals(layoutCountryCode.substring(0, 2)); + } + return false; + } catch (XmlPullParserException e) { + return false; + } catch (IOException e) { + return false; + } finally { + conf.locale = saveLocale; + res.updateConfiguration(conf, res.getDisplayMetrics()); + } + } + + private String get5Code(Locale locale) { + String country = locale.getCountry(); + return locale.getLanguage() + + (TextUtils.isEmpty(country) ? "" : "_" + country); + } + + @Override + protected void onResume() { + super.onResume(); + } + + @Override + protected void onPause() { + super.onPause(); + // Save the selected languages + String checkedLanguages = ""; + PreferenceGroup parent = getPreferenceScreen(); + int count = parent.getPreferenceCount(); + for (int i = 0; i < count; i++) { + CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i); + if (pref.isChecked()) { + Locale locale = mAvailableLanguages.get(i).mLocale; + checkedLanguages += get5Code(locale) + ","; + } + } + if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null + Editor editor = mPrefs.edit(); + editor.putString(Settings.PREF_SELECTED_LANGUAGES, checkedLanguages); + SharedPreferencesCompat.apply(editor); + } + + public ArrayList getUniqueLocales() { + String[] locales = getAssets().getLocales(); + Arrays.sort(locales); + ArrayList uniqueLocales = new ArrayList(); + + final int origSize = locales.length; + Loc[] preprocess = new Loc[origSize]; + int finalSize = 0; + for (int i = 0 ; i < origSize; i++ ) { + String s = locales[i]; + int len = s.length(); + String language = ""; + String country = ""; + if (len == 5) { + language = s.substring(0, 2); + country = s.substring(3, 5); + } else if (len < 5) { + language = s; + } + Locale l = new Locale(language, country); + + // Exclude languages that are not relevant to LatinIME + if (TextUtils.isEmpty(language)) { + continue; + } + + if (finalSize == 0) { + preprocess[finalSize++] = + new Loc(SubtypeSwitcher.getFullDisplayName(l, true), l); + } else { + // check previous entry: + // same lang and a country -> upgrade to full name and + // insert ours with full name + // diff lang -> insert ours with lang-only name + if (preprocess[finalSize-1].mLocale.getLanguage().equals( + language)) { + preprocess[finalSize-1].setLabel(SubtypeSwitcher.getFullDisplayName( + preprocess[finalSize-1].mLocale, false)); + preprocess[finalSize++] = + new Loc(SubtypeSwitcher.getFullDisplayName(l, false), l); + } else { + String displayName; + if (s.equals("zz_ZZ")) { + // ignore this locale + } else { + displayName = SubtypeSwitcher.getFullDisplayName(l, true); + preprocess[finalSize++] = new Loc(displayName, l); + } + } + } + } + for (int i = 0; i < finalSize ; i++) { + uniqueLocales.add(preprocess[i]); + } + return uniqueLocales; + } +} diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java index 9c556c309..69ae7886a 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java @@ -22,6 +22,7 @@ import com.android.inputmethod.latin.R; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; @@ -163,6 +164,27 @@ public class KeyboardParser { } } + public static String parseKeyboardLocale( + Context context, int resId) throws XmlPullParserException, IOException { + final Resources res = context.getResources(); + final XmlResourceParser parser = res.getXml(resId); + if (parser == null) return ""; + int event; + while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { + if (event == XmlPullParser.START_TAG) { + final String tag = parser.getName(); + if (TAG_KEYBOARD.equals(tag)) { + final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard); + return keyboardAttr.getString(R.styleable.Keyboard_keyboardLocale); + } else { + throw new IllegalStartTag(parser, TAG_KEYBOARD); + } + } + } + return ""; + } + private void parseKeyboardAttributes(XmlResourceParser parser) { final Keyboard keyboard = mKeyboard; final TypedArray keyboardAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), diff --git a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java deleted file mode 100644 index 40ab28c98..000000000 --- a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (C) 2008-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 android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; -import android.content.res.Configuration; -import android.content.res.Resources; -import android.os.Bundle; -import android.preference.CheckBoxPreference; -import android.preference.PreferenceActivity; -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; - private String mSelectedLanguages; - private ArrayList mAvailableLanguages = new ArrayList(); - private static final String[] BLACKLIST_LANGUAGES = { - "ko", "ja", "zh", "el", "zz" - }; - - private static class Loc implements Comparable { - private static Collator sCollator = Collator.getInstance(); - - private String mLabel; - public final Locale mLocale; - - public Loc(String label, Locale locale) { - this.mLabel = label; - this.mLocale = locale; - } - - public void setLabel(String label) { - this.mLabel = label; - } - - @Override - public String toString() { - return this.mLabel; - } - - @Override - public int compareTo(Object o) { - return sCollator.compare(this.mLabel, ((Loc) o).mLabel); - } - } - - @Override - protected void onCreate(Bundle icicle) { - super.onCreate(icicle); - addPreferencesFromResource(R.xml.language_prefs); - // Get the settings preferences - mPrefs = PreferenceManager.getDefaultSharedPreferences(this); - mSelectedLanguages = mPrefs.getString(Settings.PREF_SELECTED_LANGUAGES, ""); - String[] languageList = mSelectedLanguages.split(","); - mAvailableLanguages = getUniqueLocales(); - PreferenceGroup parent = getPreferenceScreen(); - for (int i = 0; i < mAvailableLanguages.size(); i++) { - CheckBoxPreference pref = new CheckBoxPreference(this); - Locale locale = mAvailableLanguages.get(i).mLocale; - pref.setTitle(SubtypeSwitcher.getFullDisplayName(locale, true)); - boolean checked = isLocaleIn(locale, languageList); - pref.setChecked(checked); - if (hasDictionary(locale)) { - pref.setSummary(R.string.has_dictionary); - } - parent.addPreference(pref); - } - } - - private boolean isLocaleIn(Locale locale, String[] list) { - String lang = get5Code(locale); - for (int i = 0; i < list.length; i++) { - if (lang.equalsIgnoreCase(list[i])) return true; - } - return false; - } - - private boolean hasDictionary(Locale locale) { - final Resources res = getResources(); - final Configuration conf = res.getConfiguration(); - final Locale saveLocale = conf.locale; - boolean haveDictionary = false; - conf.locale = locale; - res.updateConfiguration(conf, res.getDisplayMetrics()); - - BinaryDictionary bd = BinaryDictionary.initDictionaryFromManager(this, Suggest.DIC_MAIN, - locale, Utils.getMainDictionaryResourceId(res)); - - // Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of - // 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words. - if (bd.getSize() > Suggest.LARGE_DICTIONARY_THRESHOLD / 4) { - haveDictionary = true; - } - bd.close(); - conf.locale = saveLocale; - res.updateConfiguration(conf, res.getDisplayMetrics()); - return haveDictionary; - } - - private String get5Code(Locale locale) { - String country = locale.getCountry(); - return locale.getLanguage() - + (TextUtils.isEmpty(country) ? "" : "_" + country); - } - - @Override - protected void onResume() { - super.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - // Save the selected languages - String checkedLanguages = ""; - PreferenceGroup parent = getPreferenceScreen(); - int count = parent.getPreferenceCount(); - for (int i = 0; i < count; i++) { - CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i); - if (pref.isChecked()) { - Locale locale = mAvailableLanguages.get(i).mLocale; - checkedLanguages += get5Code(locale) + ","; - } - } - if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null - Editor editor = mPrefs.edit(); - editor.putString(Settings.PREF_SELECTED_LANGUAGES, checkedLanguages); - SharedPreferencesCompat.apply(editor); - } - - public ArrayList getUniqueLocales() { - String[] locales = getAssets().getLocales(); - Arrays.sort(locales); - ArrayList uniqueLocales = new ArrayList(); - - final int origSize = locales.length; - Loc[] preprocess = new Loc[origSize]; - int finalSize = 0; - for (int i = 0 ; i < origSize; i++ ) { - String s = locales[i]; - int len = s.length(); - String language = ""; - String country = ""; - if (len == 5) { - language = s.substring(0, 2); - country = s.substring(3, 5); - } else if (len < 5) { - language = s; - } - Locale l = new Locale(language, country); - - // Exclude languages that are not relevant to LatinIME - if (arrayContains(BLACKLIST_LANGUAGES, language) || TextUtils.isEmpty(language)) { - continue; - } - - if (finalSize == 0) { - preprocess[finalSize++] = - new Loc(SubtypeSwitcher.getFullDisplayName(l, true), l); - } else { - // check previous entry: - // same lang and a country -> upgrade to full name and - // insert ours with full name - // diff lang -> insert ours with lang-only name - if (preprocess[finalSize-1].mLocale.getLanguage().equals( - language)) { - preprocess[finalSize-1].setLabel(SubtypeSwitcher.getFullDisplayName( - preprocess[finalSize-1].mLocale, false)); - preprocess[finalSize++] = - new Loc(SubtypeSwitcher.getFullDisplayName(l, false), l); - } else { - String displayName; - if (s.equals("zz_ZZ")) { - // ignore this locale - } else { - displayName = SubtypeSwitcher.getFullDisplayName(l, true); - preprocess[finalSize++] = new Loc(displayName, l); - } - } - } - } - for (int i = 0; i < finalSize ; i++) { - uniqueLocales.add(preprocess[i]); - } - return uniqueLocales; - } - - private boolean arrayContains(String[] array, String value) { - for (int i = 0; i < array.length; i++) { - if (array[i].equalsIgnoreCase(value)) return true; - } - return false; - } -} diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 8f7278e3a..1725ee7aa 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin; import com.android.inputmethod.compat.CompatUtils; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.compat.VibratorCompatWrapper; @@ -67,6 +68,7 @@ public class Settings extends PreferenceActivity public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold"; public static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion"; public static final String PREF_DEBUG_SETTINGS = "debug_settings"; + public static final String PREF_LANGUAGE_SELECTION = "language_selection"; public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; @@ -183,6 +185,10 @@ public class Settings extends PreferenceActivity if (!showUsabilityModeStudyOption) { getPreferenceScreen().removePreference(findPreference(PREF_USABILITY_STUDY_MODE)); } + + if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) { + generalSettings.removePreference(findPreference(PREF_LANGUAGE_SELECTION)); + } } @Override diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index cd7f71c2a..f37206223 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -75,7 +75,7 @@ public class Suggest implements Dictionary.WordCallback { public static final String DICT_KEY_USER_BIGRAM = "user_bigram"; public static final String DICT_KEY_WHITELIST ="whitelist"; - static final int LARGE_DICTIONARY_THRESHOLD = 200 * 1000; + public static final int LARGE_DICTIONARY_THRESHOLD = 200 * 1000; private static final boolean DBG = LatinImeLogger.sDBG; -- cgit v1.2.3-83-g751a From 9ee51db95bdfec4a99bbbc5c78af00b06b426979 Mon Sep 17 00:00:00 2001 From: satok Date: Thu, 21 Apr 2011 18:05:27 +0900 Subject: Optimize InputLanguageSelection Change-Id: I49117a1e5f7766fcfa0140ff602ff1e19ba1e3d2 --- .../languageswitcher/InputLanguageSelection.java | 55 +++++++++------------- 1 file changed, 23 insertions(+), 32 deletions(-) (limited to 'java/src/com/android/inputmethod') diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java index 9ad64f876..6c6960cc4 100644 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java @@ -37,6 +37,7 @@ import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; import android.text.TextUtils; +import android.util.Pair; import java.io.IOException; import java.text.Collator; @@ -88,14 +89,17 @@ public class InputLanguageSelection extends PreferenceActivity { PreferenceGroup parent = getPreferenceScreen(); for (int i = 0; i < mAvailableLanguages.size(); i++) { Locale locale = mAvailableLanguages.get(i).mLocale; - if (!hasDictionary(locale) && !hasLayout(locale)) { + final Pair hasDictionaryOrLayout = hasDictionaryOrLayout(locale); + final boolean hasDictionary = hasDictionaryOrLayout.first; + final boolean hasLayout = hasDictionaryOrLayout.second; + if (!hasDictionary && !hasLayout) { continue; } CheckBoxPreference pref = new CheckBoxPreference(this); pref.setTitle(SubtypeSwitcher.getFullDisplayName(locale, true)); boolean checked = isLocaleIn(locale, languageList); pref.setChecked(checked); - if (hasDictionary(locale)) { + if (hasDictionary) { pref.setSummary(R.string.has_dictionary); } parent.addPreference(pref); @@ -110,52 +114,39 @@ public class InputLanguageSelection extends PreferenceActivity { return false; } - private boolean hasDictionary(Locale locale) { + private Pair hasDictionaryOrLayout(Locale locale) { + if (locale == null) return new Pair(false, false); final Resources res = getResources(); final Configuration conf = res.getConfiguration(); final Locale saveLocale = conf.locale; - boolean haveDictionary = false; conf.locale = locale; res.updateConfiguration(conf, res.getDisplayMetrics()); + boolean hasDictionary = false; + boolean hasLayout = false; - BinaryDictionary bd = BinaryDictionary.initDictionaryFromManager(this, Suggest.DIC_MAIN, - locale, Utils.getMainDictionaryResourceId(res)); - - // Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of - // 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words. - if (bd.getSize() > Suggest.LARGE_DICTIONARY_THRESHOLD / 4) { - haveDictionary = true; - } - bd.close(); - conf.locale = saveLocale; - res.updateConfiguration(conf, res.getDisplayMetrics()); - return haveDictionary; - } + try { + BinaryDictionary bd = BinaryDictionary.initDictionaryFromManager(this, Suggest.DIC_MAIN, + locale, Utils.getMainDictionaryResourceId(res)); - private boolean hasLayout(Locale locale) { - if (locale == null) return false; - final Resources res = getResources(); - final Configuration conf = res.getConfiguration(); - final Locale saveLocale = conf.locale; - conf.locale = locale; - res.updateConfiguration(conf, res.getDisplayMetrics()); + // Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of + // 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words. + if (bd.getSize() > Suggest.LARGE_DICTIONARY_THRESHOLD / 4) { + hasDictionary = true; + } + bd.close(); - try { final String countryCode = locale.getLanguage(); final String layoutCountryCode = KeyboardParser.parseKeyboardLocale( this, R.xml.kbd_qwerty); if (!TextUtils.isEmpty(countryCode) && !TextUtils.isEmpty(layoutCountryCode)) { - return countryCode.subSequence(0, 2).equals(layoutCountryCode.substring(0, 2)); + hasLayout = countryCode.subSequence(0, 2).equals(layoutCountryCode.substring(0, 2)); } - return false; } catch (XmlPullParserException e) { - return false; } catch (IOException e) { - return false; - } finally { - conf.locale = saveLocale; - res.updateConfiguration(conf, res.getDisplayMetrics()); } + conf.locale = saveLocale; + res.updateConfiguration(conf, res.getDisplayMetrics()); + return new Pair(hasDictionary, hasLayout); } private String get5Code(Locale locale) { -- cgit v1.2.3-83-g751a From ba9aefcc188b7f8ac99ba6cfef42a032b7d693a4 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 21 Apr 2011 18:24:41 +0900 Subject: Disable key preview of space, return and delete This change also re-orders punctuation mini keyboard. Change-Id: I987ef14fe5956d13439a0a76de367feed825314c --- java/res/values/donottranslate-altchars.xml | 4 ++-- java/src/com/android/inputmethod/keyboard/Key.java | 4 ---- .../android/inputmethod/keyboard/KeyDetector.java | 2 +- .../inputmethod/keyboard/PointerTracker.java | 25 +++++++++++++++------- 4 files changed, 20 insertions(+), 15 deletions(-) (limited to 'java/src/com/android/inputmethod') diff --git a/java/res/values/donottranslate-altchars.xml b/java/res/values/donottranslate-altchars.xml index 883ccb71d..e77957578 100644 --- a/java/res/values/donottranslate-altchars.xml +++ b/java/res/values/donottranslate-altchars.xml @@ -48,8 +48,8 @@ ¢,£,$,¥,₱ ¢,$,€,¥,₱ ":-)|:-) ,:-(|:-( ,;-)|;-) ,:-P|:-P ,=-O|=-O ,:-*|:-* ,:O|:O ,B-)|B-) ,:-$|:-$ ,:-!|:-! ,:-[|:-[ ,O:-)|O:-) ,:-\\\\\\\\|:-\\\\\\\\ ,:\'(|:\'( ,:-D|:-D " - "\?,!,\\,,:,-,\',\",(,),/,;,+,&,\@" - ".,\?,!,\\,,:,-,\',\",(,),/,;,+,&,\@" + "\\,,\?,!,:,-,\',\",(,),/,;,+,&,\@" + ".,\\,,\?,!,:,-,\',\",(,),/,;,+,&,\@" ".com" ".net,.org,.gov,.edu" diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 1b7e8ef21..fb70b3579 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -338,10 +338,6 @@ public class Key { mPressed = false; } - public boolean isInside(int x, int y) { - return mKeyboard.isInside(this, x, y); - } - /** * Detects if a point falls on this key. * @param x the x-coordinate of the point diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java index 95ec93181..2eeae96b2 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java @@ -174,7 +174,7 @@ public class KeyDetector { int primaryIndex = NOT_A_KEY; for (final int index : mKeyboard.getNearestKeys(touchX, touchY)) { final Key key = keys.get(index); - final boolean isInside = key.isInside(touchX, touchY); + final boolean isInside = mKeyboard.isInside(key, touchX, touchY); final int distance = key.squaredDistanceToEdge(touchX, touchY); if (isInside || (mProximityCorrectOn && distance < mProximityThresholdSquare)) { final int insertedPosition = sortNearbyKeys(index, distance); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 249f6648b..1b1aa492c 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -560,15 +560,24 @@ public class PointerTracker { } } - private void showKeyPreview(int keyIndex) { + // The modifier key, such as shift key, should not show its key preview. If accessibility is + // turned on, the modifier key should show its key preview. + private boolean isKeyPreviewNotRequired(int keyIndex) { final Key key = getKey(keyIndex); - if (key != null && !key.mEnabled) - return; - // The modifier key, such as shift key, should not be shown as preview when multi-touch is - // supported. On the other hand, if multi-touch is not supported, the modifier key should - // be shown as preview. If accessibility is turned on, the modifier key should be shown as - // preview. - if (mHasDistinctMultitouch && isModifier() && !mIsAccessibilityEnabled) + if (!key.mEnabled) + return true; + if (mIsAccessibilityEnabled) + return false; + // Such as spacebar sliding language switch. + if (mKeyboard.needSpacebarPreview(keyIndex)) + return false; + final int code = key.mCode; + return isModifierCode(code) || code == Keyboard.CODE_DELETE + || code == Keyboard.CODE_ENTER || code == Keyboard.CODE_SPACE; + } + + private void showKeyPreview(int keyIndex) { + if (isKeyPreviewNotRequired(keyIndex)) return; mProxy.showKeyPreview(keyIndex, this); } -- cgit v1.2.3-83-g751a