aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java116
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java49
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java3
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java14
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java3
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java3
-rw-r--r--java/src/com/android/inputmethod/latin/AutoCorrection.java6
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java4
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java5
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsValues.java10
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java9
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java22
12 files changed, 189 insertions, 55 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java
index 955cb4c42..67e21b10c 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java
@@ -18,13 +18,18 @@ package com.android.inputmethod.accessibility;
import android.graphics.Rect;
import android.inputmethodservice.InputMethodService;
+import android.os.Bundle;
+import android.os.SystemClock;
import android.support.v4.view.ViewCompat;
+import android.support.v4.view.accessibility.AccessibilityEventCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.support.v4.view.accessibility.AccessibilityNodeProviderCompat;
import android.support.v4.view.accessibility.AccessibilityRecordCompat;
import android.util.Log;
import android.util.SparseArray;
+import android.view.MotionEvent;
import android.view.View;
+import android.view.ViewParent;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.accessibility.AccessibilityEvent;
import android.view.inputmethod.EditorInfo;
@@ -45,6 +50,7 @@ import com.android.inputmethod.keyboard.KeyboardView;
*/
public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat {
private static final String TAG = AccessibilityEntityProvider.class.getSimpleName();
+ private static final int UNDEFINED = Integer.MIN_VALUE;
private final KeyboardView mKeyboardView;
private final InputMethodService mInputMethodService;
@@ -60,6 +66,9 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
/** The parent view's cached on-screen location. */
private final int[] mParentLocation = new int[2];
+ /** The virtual view identifier for the focused node. */
+ private int mAccessibilityFocusedView = UNDEFINED;
+
public AccessibilityEntityProvider(KeyboardView keyboardView, InputMethodService inputMethod) {
mKeyboardView = keyboardView;
mInputMethodService = inputMethod;
@@ -124,7 +133,9 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(int virtualViewId) {
AccessibilityNodeInfoCompat info = null;
- if (virtualViewId == View.NO_ID) {
+ if (virtualViewId == UNDEFINED) {
+ return null;
+ } else if (virtualViewId == View.NO_ID) {
// We are requested to create an AccessibilityNodeInfo describing
// this View, i.e. the root of the virtual sub-tree.
info = AccessibilityNodeInfoCompat.obtain(mKeyboardView);
@@ -166,12 +177,115 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
info.setSource(mKeyboardView, virtualViewId);
info.setBoundsInScreen(boundsInScreen);
info.setEnabled(true);
+ info.setClickable(true);
+ info.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
+
+ if (mAccessibilityFocusedView == virtualViewId) {
+ info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
+ } else {
+ info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
+ }
}
return info;
}
/**
+ * Simulates a key press by injecting touch events into the keyboard view.
+ * This avoids the complexity of trackers and listeners within the keyboard.
+ *
+ * @param key The key to press.
+ */
+ void simulateKeyPress(Key key) {
+ final int x = key.mX + (key.mWidth / 2);
+ final int y = key.mY + (key.mHeight / 2);
+ final long downTime = SystemClock.uptimeMillis();
+ final MotionEvent downEvent = MotionEvent.obtain(
+ downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0);
+ final MotionEvent upEvent = MotionEvent.obtain(
+ downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, x, y, 0);
+
+ mKeyboardView.onTouchEvent(downEvent);
+ mKeyboardView.onTouchEvent(upEvent);
+ }
+
+ @Override
+ public boolean performAction(int virtualViewId, int action, Bundle arguments) {
+ final Key key = mVirtualViewIdToKey.get(virtualViewId);
+
+ if (key == null) {
+ return false;
+ }
+
+ return performActionForKey(key, action, arguments);
+ }
+
+ /**
+ * Performs the specified accessibility action for the given key.
+ *
+ * @param key The on which to perform the action.
+ * @param action The action to perform.
+ * @param arguments The action's arguments.
+ * @return The result of performing the action, or false if the action is
+ * not supported.
+ */
+ boolean performActionForKey(Key key, int action, Bundle arguments) {
+ final int virtualViewId = generateVirtualViewIdForKey(key);
+
+ switch (action) {
+ case AccessibilityNodeInfoCompat.ACTION_CLICK:
+ simulateKeyPress(key);
+ return true;
+ case AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS:
+ if (mAccessibilityFocusedView == virtualViewId) {
+ return false;
+ }
+ mAccessibilityFocusedView = virtualViewId;
+ sendAccessibilityEventForKey(
+ key, AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
+ return true;
+ case AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
+ if (mAccessibilityFocusedView != virtualViewId) {
+ return false;
+ }
+ mAccessibilityFocusedView = UNDEFINED;
+ sendAccessibilityEventForKey(
+ key, AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public AccessibilityNodeInfoCompat findAccessibilityFocus(int virtualViewId) {
+ return createAccessibilityNodeInfo(mAccessibilityFocusedView);
+ }
+
+ @Override
+ public AccessibilityNodeInfoCompat accessibilityFocusSearch(int direction, int virtualViewId) {
+ // Focus search is not currently supported for IMEs.
+ return null;
+ }
+
+ /**
+ * Sends an accessibility event for the given {@link Key}.
+ *
+ * @param key The key that's sending the event.
+ * @param eventType The type of event to send.
+ */
+ void sendAccessibilityEventForKey(Key key, int eventType) {
+ final AccessibilityEvent event = createAccessibilityEvent(key, eventType);
+ final ViewParent parent = mKeyboardView.getParent();
+
+ if (parent == null) {
+ return;
+ }
+
+ parent.requestSendAccessibilityEvent(mKeyboardView, event);
+ }
+
+ /**
* Returns the context-specific description for a {@link Key}.
*
* @param key The key to describe.
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
index 34817ba4e..1b0e488bc 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
@@ -21,10 +21,10 @@ import android.inputmethodservice.InputMethodService;
import android.support.v4.view.AccessibilityDelegateCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityEventCompat;
+import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
-import android.view.accessibility.AccessibilityEvent;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
@@ -91,13 +91,7 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
*/
@Override
public AccessibilityEntityProvider getAccessibilityNodeProvider(View host) {
- // Instantiate the provide only when requested. Since the system
- // will call this method multiple times it is a good practice to
- // cache the provider instance.
- if (mAccessibilityNodeProvider == null) {
- mAccessibilityNodeProvider = new AccessibilityEntityProvider(mView, mInputMethod);
- }
- return mAccessibilityNodeProvider;
+ return getAccessibilityNodeProvider();
}
/**
@@ -120,7 +114,7 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
// Make sure we're not getting an EXIT event because the user slid
// off the keyboard area, then force a key press.
if (pointInView(x, y)) {
- tracker.onRegisterKey(key);
+ getAccessibilityNodeProvider().simulateKeyPress(key);
}
//$FALL-THROUGH$
case MotionEvent.ACTION_HOVER_ENTER:
@@ -137,6 +131,19 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
}
/**
+ * @return A lazily-instantiated node provider for this view proxy.
+ */
+ private AccessibilityEntityProvider getAccessibilityNodeProvider() {
+ // Instantiate the provide only when requested. Since the system
+ // will call this method multiple times it is a good practice to
+ // cache the provider instance.
+ if (mAccessibilityNodeProvider == null) {
+ mAccessibilityNodeProvider = new AccessibilityEntityProvider(mView, mInputMethod);
+ }
+ return mAccessibilityNodeProvider;
+ }
+
+ /**
* Utility method to determine whether the given point, in local
* coordinates, is inside the view, where the area of the view is contracted
* by the edge slop factor.
@@ -191,12 +198,18 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
return false;
}
+ final AccessibilityEntityProvider provider = getAccessibilityNodeProvider();
+
switch (event.getAction()) {
case MotionEvent.ACTION_HOVER_ENTER:
- sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
+ provider.sendAccessibilityEventForKey(
+ key, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
+ provider.performActionForKey(
+ key, AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS, null);
break;
case MotionEvent.ACTION_HOVER_EXIT:
- sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT);
+ provider.sendAccessibilityEventForKey(
+ key, AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT);
break;
}
@@ -204,20 +217,6 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
}
/**
- * Populates and sends an {@link AccessibilityEvent} for the specified key.
- *
- * @param key The key to send an event for.
- * @param eventType The type of event to send.
- */
- private void sendAccessibilityEventForKey(Key key, int eventType) {
- final AccessibilityEntityProvider nodeProvider = getAccessibilityNodeProvider(null);
- final AccessibilityEvent event = nodeProvider.createAccessibilityEvent(key, eventType);
-
- // Propagates the event up the view hierarchy.
- mView.getParent().requestSendAccessibilityEvent(mView, event);
- }
-
- /**
* Notifies the user of changes in the keyboard shift state.
*/
public void notifyShiftState() {
diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
index 3d861c231..f4e4105e3 100644
--- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
+++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
@@ -111,6 +111,9 @@ public class KeyCodeDescriptionMapper {
if (mKeyLabelMap.containsKey(label)) {
return context.getString(mKeyLabelMap.get(label));
}
+
+ // Otherwise, return the label.
+ return key.mLabel;
}
// Just attempt to speak the description.
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index bd3b0e114..0be4cf3a7 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -197,6 +197,20 @@ public class Keyboard {
return null;
}
+ public boolean hasKey(Key aKey) {
+ if (mKeyCache.containsKey(aKey)) {
+ return true;
+ }
+
+ for (final Key key : mKeys) {
+ if (key == aKey) {
+ mKeyCache.put(key.mCode, key);
+ return true;
+ }
+ }
+ return false;
+ }
+
public static boolean isLetterCode(int code) {
return code >= MINIMUM_LETTER_CODE;
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index c0d5b6772..cc0a1fb10 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -487,6 +487,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} else {
// Draw invalidated keys.
for (final Key key : mInvalidatedKeys) {
+ if (!mKeyboard.hasKey(key)) {
+ continue;
+ }
final int x = key.mX + getPaddingLeft();
final int y = key.mY + getPaddingTop();
mInvalidatedKeysRect.set(x, y, x + key.mWidth, y + key.mHeight);
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index 90394ce5e..5ea28abe2 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.keyboard;
import android.graphics.Rect;
import android.text.TextUtils;
+import android.util.FloatMath;
import com.android.inputmethod.keyboard.Keyboard.Params.TouchPositionCorrection;
import com.android.inputmethod.latin.JniUtils;
@@ -147,7 +148,7 @@ public class ProximityInfo {
final float radius = touchPositionCorrection.mRadii[row];
sweetSpotCenterXs[i] = hitBoxCenterX + x * hitBoxWidth;
sweetSpotCenterYs[i] = hitBoxCenterY + y * hitBoxHeight;
- sweetSpotRadii[i] = radius * (float) Math.sqrt(
+ sweetSpotRadii[i] = radius * FloatMath.sqrt(
hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
}
}
diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java
index 38444a10c..da1936aef 100644
--- a/java/src/com/android/inputmethod/latin/AutoCorrection.java
+++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java
@@ -35,7 +35,7 @@ public class AutoCorrection {
public static CharSequence computeAutoCorrectionWord(
HashMap<String, Dictionary> dictionaries,
WordComposer wordComposer, ArrayList<SuggestedWordInfo> suggestions,
- CharSequence consideredWord, double autoCorrectionThreshold,
+ CharSequence consideredWord, float autoCorrectionThreshold,
CharSequence whitelistedWord) {
if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
return whitelistedWord;
@@ -100,14 +100,14 @@ public class AutoCorrection {
private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer,
ArrayList<SuggestedWordInfo> suggestions,
- CharSequence consideredWord, double autoCorrectionThreshold) {
+ CharSequence consideredWord, float autoCorrectionThreshold) {
if (wordComposer.size() > 1 && suggestions.size() > 0) {
final SuggestedWordInfo autoCorrectionSuggestion = suggestions.get(0);
//final int autoCorrectionSuggestionScore = sortedScores[0];
final int autoCorrectionSuggestionScore = autoCorrectionSuggestion.mScore;
// TODO: when the normalized score of the first suggestion is nearly equals to
// the normalized score of the second suggestion, behave less aggressive.
- final double normalizedScore = BinaryDictionary.calcNormalizedScore(
+ final float normalizedScore = BinaryDictionary.calcNormalizedScore(
consideredWord.toString(), autoCorrectionSuggestion.mWord.toString(),
autoCorrectionSuggestionScore);
if (DBG) {
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index cc20f4294..e18aee6ff 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -92,7 +92,7 @@ public class BinaryDictionary extends Dictionary {
private native int getBigramsNative(long dict, int[] prevWord, int prevWordLength,
int[] inputCodes, int inputCodesLength, char[] outputChars, int[] scores,
int maxWordLength, int maxBigrams);
- private static native double calcNormalizedScoreNative(
+ private static native float calcNormalizedScoreNative(
char[] before, int beforeLength, char[] after, int afterLength, int score);
private static native int editDistanceNative(
char[] before, int beforeLength, char[] after, int afterLength);
@@ -189,7 +189,7 @@ public class BinaryDictionary extends Dictionary {
prevWordCodePointArray, mUseFullEditDistance, outputChars, scores);
}
- public static double calcNormalizedScore(String before, String after, int score) {
+ public static float calcNormalizedScore(String before, String after, int score) {
return calcNormalizedScoreNative(before.toCharArray(), before.length(),
after.toCharArray(), after.length(), score);
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b59e939b7..261755f53 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1298,8 +1298,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
break;
}
switcher.onCodeInput(primaryCode);
- // Reset after any single keystroke
- if (!didAutoCorrect)
+ // Reset after any single keystroke, except shift and symbol-shift
+ if (!didAutoCorrect && primaryCode != Keyboard.CODE_SHIFT
+ && primaryCode != Keyboard.CODE_SWITCH_ALPHA_SYMBOL)
mLastComposedWord.deactivate();
mEnteredText = null;
}
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index 55b896f5a..932920a60 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -77,7 +77,7 @@ public class SettingsValues {
public final float mFxVolume;
public final int mKeyPreviewPopupDismissDelay;
public final boolean mAutoCorrectEnabled;
- public final double mAutoCorrectionThreshold;
+ public final float mAutoCorrectionThreshold;
private final boolean mVoiceKeyEnabled;
private final boolean mVoiceKeyOnMain;
@@ -255,21 +255,21 @@ public class SettingsValues {
R.bool.config_default_next_word_prediction));
}
- private static double getAutoCorrectionThreshold(final Resources resources,
+ private static float getAutoCorrectionThreshold(final Resources resources,
final String currentAutoCorrectionSetting) {
final String[] autoCorrectionThresholdValues = resources.getStringArray(
R.array.auto_correction_threshold_values);
// When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off.
- double autoCorrectionThreshold = Double.MAX_VALUE;
+ float autoCorrectionThreshold = Float.MAX_VALUE;
try {
final int arrayIndex = Integer.valueOf(currentAutoCorrectionSetting);
if (arrayIndex >= 0 && arrayIndex < autoCorrectionThresholdValues.length) {
- autoCorrectionThreshold = Double.parseDouble(
+ autoCorrectionThreshold = Float.parseFloat(
autoCorrectionThresholdValues[arrayIndex]);
}
} catch (NumberFormatException e) {
// Whenever the threshold settings are correct, never come here.
- autoCorrectionThreshold = Double.MAX_VALUE;
+ autoCorrectionThreshold = Float.MAX_VALUE;
Log.w(TAG, "Cannot load auto correction threshold setting."
+ " currentAutoCorrectionSetting: " + currentAutoCorrectionSetting
+ ", autoCorrectionThresholdValues: "
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 7832cb522..9e478fab4 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -77,7 +77,7 @@ public class Suggest implements Dictionary.WordCallback {
private static final int PREF_MAX_BIGRAMS = 60;
- private double mAutoCorrectionThreshold;
+ private float mAutoCorrectionThreshold;
private ArrayList<SuggestedWordInfo> mSuggestions = new ArrayList<SuggestedWordInfo>();
private ArrayList<SuggestedWordInfo> mBigramSuggestions = new ArrayList<SuggestedWordInfo>();
@@ -185,7 +185,7 @@ public class Suggest implements Dictionary.WordCallback {
userHistoryDictionary);
}
- public void setAutoCorrectionThreshold(double threshold) {
+ public void setAutoCorrectionThreshold(float threshold) {
mAutoCorrectionThreshold = threshold;
}
@@ -408,8 +408,6 @@ public class Suggest implements Dictionary.WordCallback {
final String typedWord, final ArrayList<SuggestedWordInfo> suggestions) {
final SuggestedWordInfo typedWordInfo = suggestions.get(0);
typedWordInfo.setDebugString("+");
- double normalizedScore = BinaryDictionary.calcNormalizedScore(
- typedWord, typedWordInfo.toString(), typedWordInfo.mScore);
final int suggestionsSize = suggestions.size();
final ArrayList<SuggestedWordInfo> suggestionsList =
new ArrayList<SuggestedWordInfo>(suggestionsSize);
@@ -418,10 +416,11 @@ public class Suggest implements Dictionary.WordCallback {
// than i because we added the typed word to mSuggestions without touching mScores.
for (int i = 0; i < suggestionsSize - 1; ++i) {
final SuggestedWordInfo cur = suggestions.get(i + 1);
+ final float normalizedScore = BinaryDictionary.calcNormalizedScore(
+ typedWord, cur.toString(), cur.mScore);
final String scoreInfoString;
if (normalizedScore > 0) {
scoreInfoString = String.format("%d (%4.2f)", cur.mScore, normalizedScore);
- normalizedScore = 0.0;
} else {
scoreInfoString = Integer.toString(cur.mScore);
}
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 0c9f9fb27..d7c8e3850 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -79,9 +79,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService
private Dictionary mContactsDictionary;
// The threshold for a candidate to be offered as a suggestion.
- private double mSuggestionThreshold;
+ private float mSuggestionThreshold;
// The threshold for a suggestion to be considered "recommended".
- private double mRecommendedThreshold;
+ private float mRecommendedThreshold;
// Whether to use the contacts dictionary
private boolean mUseContactsDictionary;
private final Object mUseContactsLock = new Object();
@@ -113,9 +113,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService
@Override public void onCreate() {
super.onCreate();
mSuggestionThreshold =
- Double.parseDouble(getString(R.string.spellchecker_suggestion_threshold_value));
+ Float.parseFloat(getString(R.string.spellchecker_suggestion_threshold_value));
mRecommendedThreshold =
- Double.parseDouble(getString(R.string.spellchecker_recommended_threshold_value));
+ Float.parseFloat(getString(R.string.spellchecker_recommended_threshold_value));
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(prefs, PREF_USE_CONTACTS_KEY);
@@ -207,8 +207,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService
private final ArrayList<CharSequence> mSuggestions;
private final int[] mScores;
private final String mOriginalText;
- private final double mSuggestionThreshold;
- private final double mRecommendedThreshold;
+ private final float mSuggestionThreshold;
+ private final float mRecommendedThreshold;
private final int mMaxLength;
private int mLength = 0;
@@ -217,8 +217,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService
private String mBestSuggestion = null;
private int mBestScore = Integer.MIN_VALUE; // As small as possible
- SuggestionsGatherer(final String originalText, final double suggestionThreshold,
- final double recommendedThreshold, final int maxLength) {
+ SuggestionsGatherer(final String originalText, final float suggestionThreshold,
+ final float recommendedThreshold, final int maxLength) {
mOriginalText = originalText;
mSuggestionThreshold = suggestionThreshold;
mRecommendedThreshold = recommendedThreshold;
@@ -261,7 +261,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
// Compute the normalized score and skip this word if it's normalized score does not
// make the threshold.
final String wordString = new String(word, wordOffset, wordLength);
- final double normalizedScore =
+ final float normalizedScore =
BinaryDictionary.calcNormalizedScore(mOriginalText, wordString, score);
if (normalizedScore < mSuggestionThreshold) {
if (DBG) Log.i(TAG, wordString + " does not make the score threshold");
@@ -295,7 +295,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
hasRecommendedSuggestions = false;
} else {
gatheredSuggestions = EMPTY_STRING_ARRAY;
- final double normalizedScore = BinaryDictionary.calcNormalizedScore(
+ final float normalizedScore = BinaryDictionary.calcNormalizedScore(
mOriginalText, mBestSuggestion, mBestScore);
hasRecommendedSuggestions = (normalizedScore > mRecommendedThreshold);
}
@@ -329,7 +329,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
final int bestScore = mScores[mLength - 1];
final CharSequence bestSuggestion = mSuggestions.get(0);
- final double normalizedScore =
+ final float normalizedScore =
BinaryDictionary.calcNormalizedScore(
mOriginalText, bestSuggestion.toString(), bestScore);
hasRecommendedSuggestions = (normalizedScore > mRecommendedThreshold);