aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/compat/ArraysCompatUtils.java50
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboard.java18
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java2
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java14
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java14
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java3
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/SpellChecker.java5
8 files changed, 85 insertions, 23 deletions
diff --git a/java/src/com/android/inputmethod/compat/ArraysCompatUtils.java b/java/src/com/android/inputmethod/compat/ArraysCompatUtils.java
new file mode 100644
index 000000000..f6afbcfe2
--- /dev/null
+++ b/java/src/com/android/inputmethod/compat/ArraysCompatUtils.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.compat;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+public class ArraysCompatUtils {
+ private static final Method METHOD_Arrays_binarySearch = CompatUtils
+ .getMethod(Arrays.class, "binarySearch", int[].class, int.class, int.class, int.class);
+
+ public static int binarySearch(int[] array, int startIndex, int endIndex, int value) {
+ if (METHOD_Arrays_binarySearch != null) {
+ final Object index = CompatUtils.invoke(null, 0, METHOD_Arrays_binarySearch,
+ array, startIndex, endIndex, value);
+ return (Integer)index;
+ } else {
+ return compatBinarySearch(array, startIndex, endIndex, value);
+ }
+ }
+
+ /* package */ static int compatBinarySearch(int[] array, int startIndex, int endIndex,
+ int value) {
+ if (startIndex > endIndex) throw new IllegalArgumentException();
+ if (startIndex < 0 || endIndex > array.length) throw new ArrayIndexOutOfBoundsException();
+
+ final int work[] = new int[endIndex - startIndex];
+ System.arraycopy(array, startIndex, work, 0, work.length);
+ final int index = Arrays.binarySearch(work, value);
+ if (index >= 0) {
+ return index + startIndex;
+ } else {
+ return ~(~index + startIndex);
+ }
+ }
+}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 8657768ee..1218a5abd 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -186,7 +186,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
public void onSizeChanged() {
final int width = mInputMethodService.getWindow().getWindow().getDecorView().getWidth();
- if (width == 0)
+ if (width == 0 || mCurrentId == null)
return;
mKeyboardWidth = width;
// Set keyboard with new width.
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index 473006deb..020fb56ca 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
@@ -136,12 +136,16 @@ public class LatinKeyboard extends Keyboard {
// The threshold is "key width" x 1.25
mSpacebarLanguageSwitchThreshold = (getMostCommonKeyWidth() * 5) / 4;
- final int spaceKeyWidth = Math.max(mSpaceKey.mWidth,
- (int)(getMinWidth() * SPACEBAR_POPUP_MIN_RATIO));
- final int spaceKeyheight = mSpacePreviewIcon.getIntrinsicHeight();
- mSlidingLocaleIcon = new SlidingLocaleDrawable(
- context, mSpacePreviewIcon, spaceKeyWidth, spaceKeyheight);
- mSlidingLocaleIcon.setBounds(0, 0, spaceKeyWidth, spaceKeyheight);
+ if (mSpaceKey != null) {
+ final int slidingIconWidth = Math.max(mSpaceKey.mWidth,
+ (int)(getMinWidth() * SPACEBAR_POPUP_MIN_RATIO));
+ final int spaceKeyheight = mSpacePreviewIcon.getIntrinsicHeight();
+ mSlidingLocaleIcon = new SlidingLocaleDrawable(
+ context, mSpacePreviewIcon, slidingIconWidth, spaceKeyheight);
+ mSlidingLocaleIcon.setBounds(0, 0, slidingIconWidth, spaceKeyheight);
+ } else {
+ mSlidingLocaleIcon = null;
+ }
}
public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) {
@@ -350,6 +354,8 @@ public class LatinKeyboard extends Keyboard {
if (mSpacebarSlidingLanguageSwitchDiff == diff)
return;
mSpacebarSlidingLanguageSwitchDiff = diff;
+ if (mSlidingLocaleIcon == null)
+ return;
mSlidingLocaleIcon.setDiff(diff);
if (Math.abs(diff) == Integer.MAX_VALUE) {
mSpaceKey.setPreviewIcon(mSpacePreviewIcon);
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index 185f1f8f7..901df6ab7 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -120,7 +120,7 @@ public class LatinKeyboardView extends KeyboardView {
&& keyboard.isShiftedOrShiftLocked()
&& !TextUtils.isEmpty(label) && label.length() < 3
&& Character.isLowerCase(label.charAt(0))) {
- return label.toString().toUpperCase();
+ return label.toString().toUpperCase(keyboard.mId.mLocale);
}
return label;
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index dd97db34e..1645b1678 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1274,7 +1274,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
clearSuggestions();
}
}
- KeyboardSwitcher switcher = mKeyboardSwitcher;
+ final KeyboardSwitcher switcher = mKeyboardSwitcher;
if (switcher.isShiftedOrShiftLocked()) {
if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT
|| keyCodes[0] > Character.MAX_CODE_POINT) {
@@ -1282,13 +1282,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
code = keyCodes[0];
if (switcher.isAlphabetMode() && Character.isLowerCase(code)) {
- int upperCaseCode = Character.toUpperCase(code);
- if (upperCaseCode != code) {
- code = upperCaseCode;
+ // In some locales, such as Turkish, Character.toUpperCase() may return a wrong
+ // character because it doesn't take care of locale.
+ final String upperCaseString = new String(new int[] {code}, 0, 1)
+ .toUpperCase(mSubtypeSwitcher.getInputLocale());
+ if (upperCaseString.codePointCount(0, upperCaseString.length()) == 1) {
+ code = upperCaseString.codePointAt(0);
} else {
// Some keys, such as [eszett], have upper case as multi-characters.
- String upperCase = new String(new int[] {code}, 0, 1).toUpperCase();
- onTextInput(upperCase);
+ onTextInput(upperCaseString);
return;
}
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 8b51af880..6ca12c0c5 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -577,30 +577,30 @@ public class SubtypeSwitcher {
public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) {
if (returnsNameInThisLocale) {
- return toTitleCase(SubtypeLocale.getFullDisplayName(locale));
+ return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale);
} else {
- return toTitleCase(locale.getDisplayName());
+ return toTitleCase(locale.getDisplayName(), locale);
}
}
public static String getDisplayLanguage(Locale locale) {
- return toTitleCase(SubtypeLocale.getFullDisplayName(locale));
+ return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale);
}
public static String getMiddleDisplayLanguage(Locale locale) {
return toTitleCase((Utils.constructLocaleFromString(
- locale.getLanguage()).getDisplayLanguage(locale)));
+ locale.getLanguage()).getDisplayLanguage(locale)), locale);
}
public static String getShortDisplayLanguage(Locale locale) {
- return toTitleCase(locale.getLanguage());
+ return toTitleCase(locale.getLanguage(), locale);
}
- private static String toTitleCase(String s) {
+ private static String toTitleCase(String s, Locale locale) {
if (s.length() == 0) {
return s;
}
- return Character.toUpperCase(s.charAt(0)) + s.substring(1);
+ return s.toUpperCase(locale).charAt(0) + s.substring(1);
}
public String getInputLanguageName() {
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index d01e3e9c2..eb5ed5a65 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -250,6 +250,7 @@ public class Suggest implements Dictionary.WordCallback {
poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1)
: new StringBuilder(getApproxMaxWordLength());
sb.setLength(0);
+ // TODO: Must pay attention to locale when changing case.
if (all) {
sb.append(word.toString().toUpperCase());
} else if (first) {
@@ -315,6 +316,7 @@ public class Suggest implements Dictionary.WordCallback {
} else {
// Word entered: return only bigrams that match the first char of the typed word
final char currentChar = typedWord.charAt(0);
+ // TODO: Must pay attention to locale when changing case.
final char currentCharUpper = Character.toUpperCase(currentChar);
int count = 0;
final int bigramSuggestionSize = mBigramSuggestions.size();
@@ -518,6 +520,7 @@ public class Suggest implements Dictionary.WordCallback {
StringBuilder sb = poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1)
: new StringBuilder(getApproxMaxWordLength());
sb.setLength(0);
+ // TODO: Must pay attention to locale when changing case.
if (mIsAllUpperCase) {
sb.append(new String(word, offset, length).toUpperCase());
} else if (mIsFirstCharCapitalized) {
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/SpellChecker.java b/java/src/com/android/inputmethod/latin/spellcheck/SpellChecker.java
index e3407a269..63c6d69d7 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/SpellChecker.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/SpellChecker.java
@@ -19,6 +19,7 @@ package com.android.inputmethod.latin.spellcheck;
import android.content.Context;
import android.content.res.Resources;
+import com.android.inputmethod.compat.ArraysCompatUtils;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.Dictionary.DataType;
import com.android.inputmethod.latin.Dictionary.WordCallback;
@@ -26,7 +27,6 @@ import com.android.inputmethod.latin.DictionaryFactory;
import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.WordComposer;
-import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
@@ -64,13 +64,14 @@ public class SpellChecker {
private int[] mScores = new int[DEFAULT_SUGGESTION_LENGTH];
private int mLength = 0;
+ @Override
synchronized public boolean addWord(char[] word, int wordOffset, int wordLength, int score,
int dicTypeId, DataType dataType) {
if (mLength >= mScores.length) {
final int newLength = mScores.length * 2;
mScores = new int[newLength];
}
- final int positionIndex = Arrays.binarySearch(mScores, 0, mLength, score);
+ final int positionIndex = ArraysCompatUtils.binarySearch(mScores, 0, mLength, score);
// binarySearch returns the index if the element exists, and -<insertion index> - 1
// if it doesn't. See documentation for binarySearch.
final int insertionIndex = positionIndex >= 0 ? positionIndex : -positionIndex - 1;