Merge "Move and rename computeProximityThreshold"
This commit is contained in:
commit
39c323eb12
5 changed files with 38 additions and 34 deletions
|
@ -17,6 +17,7 @@
|
|||
package com.android.inputmethod.keyboard;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class KeyDetector {
|
||||
|
@ -108,4 +109,31 @@ public abstract class KeyDetector {
|
|||
* @return The nearest key index
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -508,7 +508,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
|||
requestLayout();
|
||||
mKeyboardChanged = true;
|
||||
invalidateAllKeys();
|
||||
computeProximityThreshold(keyboard, mKeys);
|
||||
mKeyDetector.setProximityThreshold(KeyDetector.getMostCommonKeyWidth(keyboard));
|
||||
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
|
||||
public void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
|
|
@ -2082,7 +2082,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
|
||||
private void updateAutoTextEnabled() {
|
||||
if (mSuggest == null) return;
|
||||
mSuggest.setAutoTextEnabled(mQuickFixes
|
||||
mSuggest.setQuickFixesEnabled(mQuickFixes
|
||||
&& SubtypeSwitcher.getInstance().isSystemLanguageSameAsInputLanguage());
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ public class Suggest implements Dictionary.WordCallback {
|
|||
|
||||
private static final int PREF_MAX_BIGRAMS = 60;
|
||||
|
||||
private boolean mAutoTextEnabled;
|
||||
private boolean mQuickFixesEnabled;
|
||||
|
||||
private double mAutoCorrectionThreshold;
|
||||
private int[] mPriorities = new int[mPrefMaxSuggestions];
|
||||
|
@ -116,8 +116,8 @@ public class Suggest implements Dictionary.WordCallback {
|
|||
}
|
||||
}
|
||||
|
||||
public void setAutoTextEnabled(boolean enabled) {
|
||||
mAutoTextEnabled = enabled;
|
||||
public void setQuickFixesEnabled(boolean enabled) {
|
||||
mQuickFixesEnabled = enabled;
|
||||
}
|
||||
|
||||
public int getCorrectionMode() {
|
||||
|
@ -309,7 +309,7 @@ public class Suggest implements Dictionary.WordCallback {
|
|||
if (typedWord != null) {
|
||||
mSuggestions.add(0, typedWord.toString());
|
||||
}
|
||||
if (mAutoTextEnabled) {
|
||||
if (mQuickFixesEnabled) {
|
||||
int i = 0;
|
||||
int max = 6;
|
||||
// Don't autotext the suggestions from the dictionaries
|
||||
|
@ -416,12 +416,12 @@ public class Suggest implements Dictionary.WordCallback {
|
|||
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 int originalLength = mLowerOriginalWord.length();
|
||||
final int originalLength = lowerOriginalWord.length();
|
||||
if (originalLength == length && Character.isUpperCase(word[offset])) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class SuggestHelper {
|
|||
public SuggestHelper(String tag, Context context, int resId) {
|
||||
TAG = tag;
|
||||
mSuggest = new Suggest(context, resId);
|
||||
mSuggest.setAutoTextEnabled(false);
|
||||
mSuggest.setQuickFixesEnabled(false);
|
||||
mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue