Merge "Move and rename computeProximityThreshold"

main
Tadashi G. Takaoka 2011-02-08 00:05:27 -08:00 committed by Android (Google) Code Review
commit 39c323eb12
5 changed files with 38 additions and 34 deletions

View File

@ -17,6 +17,7 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
public abstract class KeyDetector { public abstract class KeyDetector {
@ -108,4 +109,31 @@ public abstract class KeyDetector {
* @return The nearest key index * @return The nearest key index
*/ */
abstract public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys); abstract public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys);
/**
* Compute the most common key width in order to use it as proximity key detection threshold.
*
* @param keyboard The keyboard to compute the most common key width
* @return The most common key width in the keyboard
*/
public static int getMostCommonKeyWidth(Keyboard keyboard) {
if (keyboard == null) return 0;
final List<Key> keys = keyboard.getKeys();
if (keys == null || keys.size() == 0) return 0;
final HashMap<Integer, Integer> histogram = new HashMap<Integer, Integer>();
int maxCount = 0;
int mostCommonWidth = 0;
for (Key key : keys) {
final Integer width = key.mWidth + key.mGap;
Integer count = histogram.get(width);
if (count == null)
count = 0;
histogram.put(width, ++count);
if (count > maxCount) {
maxCount = count;
mostCommonWidth = width;
}
}
return mostCommonWidth;
}
} }

View File

@ -508,7 +508,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
requestLayout(); requestLayout();
mKeyboardChanged = true; mKeyboardChanged = true;
invalidateAllKeys(); invalidateAllKeys();
computeProximityThreshold(keyboard, mKeys); mKeyDetector.setProximityThreshold(KeyDetector.getMostCommonKeyWidth(keyboard));
mMiniKeyboardCache.clear(); mMiniKeyboardCache.clear();
} }
@ -600,30 +600,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
} }
} }
/**
* Compute the most common key width and use it as proximity key detection threshold.
* @param keyboard
* @param keys
*/
private void computeProximityThreshold(Keyboard keyboard, Key[] keys) {
if (keyboard == null || keys == null || keys.length == 0) return;
final HashMap<Integer, Integer> histogram = new HashMap<Integer, Integer>();
int maxCount = 0;
int mostCommonWidth = 0;
for (Key key : keys) {
final Integer width = key.mWidth + key.mGap;
Integer count = histogram.get(width);
if (count == null)
count = 0;
histogram.put(width, ++count);
if (count > maxCount) {
maxCount = count;
mostCommonWidth = width;
}
}
mKeyDetector.setProximityThreshold(mostCommonWidth);
}
@Override @Override
public void onDraw(Canvas canvas) { public void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);

View File

@ -2082,7 +2082,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void updateAutoTextEnabled() { private void updateAutoTextEnabled() {
if (mSuggest == null) return; if (mSuggest == null) return;
mSuggest.setAutoTextEnabled(mQuickFixes mSuggest.setQuickFixesEnabled(mQuickFixes
&& SubtypeSwitcher.getInstance().isSystemLanguageSameAsInputLanguage()); && SubtypeSwitcher.getInstance().isSystemLanguageSameAsInputLanguage());
} }

View File

@ -80,7 +80,7 @@ public class Suggest implements Dictionary.WordCallback {
private static final int PREF_MAX_BIGRAMS = 60; private static final int PREF_MAX_BIGRAMS = 60;
private boolean mAutoTextEnabled; private boolean mQuickFixesEnabled;
private double mAutoCorrectionThreshold; private double mAutoCorrectionThreshold;
private int[] mPriorities = new int[mPrefMaxSuggestions]; private int[] mPriorities = new int[mPrefMaxSuggestions];
@ -116,8 +116,8 @@ public class Suggest implements Dictionary.WordCallback {
} }
} }
public void setAutoTextEnabled(boolean enabled) { public void setQuickFixesEnabled(boolean enabled) {
mAutoTextEnabled = enabled; mQuickFixesEnabled = enabled;
} }
public int getCorrectionMode() { public int getCorrectionMode() {
@ -309,7 +309,7 @@ public class Suggest implements Dictionary.WordCallback {
if (typedWord != null) { if (typedWord != null) {
mSuggestions.add(0, typedWord.toString()); mSuggestions.add(0, typedWord.toString());
} }
if (mAutoTextEnabled) { if (mQuickFixesEnabled) {
int i = 0; int i = 0;
int max = 6; int max = 6;
// Don't autotext the suggestions from the dictionaries // Don't autotext the suggestions from the dictionaries
@ -416,12 +416,12 @@ public class Suggest implements Dictionary.WordCallback {
return mHasAutoCorrection; return mHasAutoCorrection;
} }
private boolean compareCaseInsensitive(final String mLowerOriginalWord, private static boolean compareCaseInsensitive(final String lowerOriginalWord,
final char[] word, final int offset, final int length) { final char[] word, final int offset, final int length) {
final int originalLength = mLowerOriginalWord.length(); final int originalLength = lowerOriginalWord.length();
if (originalLength == length && Character.isUpperCase(word[offset])) { if (originalLength == length && Character.isUpperCase(word[offset])) {
for (int i = 0; i < originalLength; i++) { for (int i = 0; i < originalLength; i++) {
if (mLowerOriginalWord.charAt(i) != Character.toLowerCase(word[offset+i])) { if (lowerOriginalWord.charAt(i) != Character.toLowerCase(word[offset+i])) {
return false; return false;
} }
} }

View File

@ -41,7 +41,7 @@ public class SuggestHelper {
public SuggestHelper(String tag, Context context, int resId) { public SuggestHelper(String tag, Context context, int resId) {
TAG = tag; TAG = tag;
mSuggest = new Suggest(context, resId); mSuggest = new Suggest(context, resId);
mSuggest.setAutoTextEnabled(false); mSuggest.setQuickFixesEnabled(false);
mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM); mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM);
} }