aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java33
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestedWords.java21
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestionsView.java6
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java14
4 files changed, 49 insertions, 25 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 3c878d0a8..4292025a3 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -160,6 +160,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private Settings.Values mSettingsValues;
+ private View mExtractArea;
private View mKeyPreviewBackingView;
private View mSuggestionsContainer;
private SuggestionsView mSuggestionsView;
@@ -642,6 +643,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public void setInputView(View view) {
super.setInputView(view);
+ mExtractArea = getWindow().getWindow().getDecorView()
+ .findViewById(android.R.id.extractArea);
mKeyPreviewBackingView = view.findViewById(R.id.key_preview_backing);
mSuggestionsContainer = view.findViewById(R.id.suggestions_container);
mSuggestionsView = (SuggestionsView) view.findViewById(R.id.suggestions_view);
@@ -1005,11 +1008,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
if (inputView == null || mSuggestionsContainer == null)
return;
+ // In fullscreen mode, the height of the extract area managed by InputMethodService should
+ // be considered.
+ // See {@link android.inputmethodservice.InputMethodService#onComputeInsets}.
+ final int extractHeight = isFullscreenMode() ? mExtractArea.getHeight() : 0;
final int backingHeight = (mKeyPreviewBackingView.getVisibility() == View.GONE) ? 0
: mKeyPreviewBackingView.getHeight();
final int suggestionsHeight = (mSuggestionsContainer.getVisibility() == View.GONE) ? 0
: mSuggestionsContainer.getHeight();
- final int extraHeight = backingHeight + suggestionsHeight;
+ final int extraHeight = extractHeight + backingHeight + suggestionsHeight;
int touchY = extraHeight;
// Need to set touchable region only if input view is being shown
if (mKeyboardSwitcher.isInputViewShown()) {
@@ -1032,17 +1039,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public boolean onEvaluateFullscreenMode() {
- if (!super.onEvaluateFullscreenMode()) return false;
-
- final EditorInfo ei = getCurrentInputEditorInfo();
- if (ei != null) {
- final int imeOptions = ei.imeOptions;
- if ((imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0) {
- return false;
- }
- }
-
- return mResources.getBoolean(R.bool.config_use_fullscreen_mode);
+ return super.onEvaluateFullscreenMode()
+ && mResources.getBoolean(R.bool.config_use_fullscreen_mode);
}
@Override
@@ -1050,9 +1048,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
super.updateFullscreenMode();
if (mKeyPreviewBackingView == null) return;
- // In fullscreen mode, no need to have extra space to show the key preview.
+ // In extract mode, no need to have extra space to show the key preview.
// If not, we should have extra space above the keyboard to show the key preview.
- mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE);
+ mKeyPreviewBackingView.setVisibility(isExtractViewShown() ? View.GONE : View.VISIBLE);
}
@Override
@@ -1722,9 +1720,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
public void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) {
+ final boolean shouldBlockAutoCorrectionBySafetyNet =
+ Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest);
+ if (shouldBlockAutoCorrectionBySafetyNet) {
+ suggestedWords.setShouldBlockAutoCorrection();
+ }
setSuggestions(suggestedWords);
if (suggestedWords.size() > 0) {
- if (Utils.shouldBlockedBySafetyNetForAutoCorrection(suggestedWords, mSuggest)) {
+ if (shouldBlockAutoCorrectionBySafetyNet) {
mBestWord = typedWord;
} else if (suggestedWords.hasAutoCorrectionWord()) {
mBestWord = suggestedWords.getWord(1);
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index 005db36bd..ed6359cfa 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -29,12 +29,13 @@ public class SuggestedWords {
public final List<CharSequence> mWords;
public final boolean mTypedWordValid;
- public final boolean mHasMinimalSuggestion;
+ public final boolean mHasAutoCorrectionCandidate;
public final boolean mIsPunctuationSuggestions;
private final List<SuggestedWordInfo> mSuggestedWordInfoList;
+ private boolean mShouldBlockAutoCorrection;
private SuggestedWords(List<CharSequence> words, boolean typedWordValid,
- boolean hasMinimalSuggestion, boolean isPunctuationSuggestions,
+ boolean hasAutoCorrectionCandidate, boolean isPunctuationSuggestions,
List<SuggestedWordInfo> suggestedWordInfoList) {
if (words != null) {
mWords = words;
@@ -42,9 +43,10 @@ public class SuggestedWords {
mWords = Collections.emptyList();
}
mTypedWordValid = typedWordValid;
- mHasMinimalSuggestion = hasMinimalSuggestion;
+ mHasAutoCorrectionCandidate = hasAutoCorrectionCandidate;
mIsPunctuationSuggestions = isPunctuationSuggestions;
mSuggestedWordInfoList = suggestedWordInfoList;
+ mShouldBlockAutoCorrection = false;
}
public int size() {
@@ -60,17 +62,25 @@ public class SuggestedWords {
}
public boolean hasAutoCorrectionWord() {
- return mHasMinimalSuggestion && size() > 1 && !mTypedWordValid;
+ return mHasAutoCorrectionCandidate && size() > 1 && !mTypedWordValid;
}
public boolean hasWordAboveAutoCorrectionScoreThreshold() {
- return mHasMinimalSuggestion && ((size() > 1 && !mTypedWordValid) || mTypedWordValid);
+ return mHasAutoCorrectionCandidate && ((size() > 1 && !mTypedWordValid) || mTypedWordValid);
}
public boolean isPunctuationSuggestions() {
return mIsPunctuationSuggestions;
}
+ public void setShouldBlockAutoCorrection() {
+ mShouldBlockAutoCorrection = true;
+ }
+
+ public boolean shouldBlockAutoCorrection() {
+ return mShouldBlockAutoCorrection;
+ }
+
public static class Builder {
private List<CharSequence> mWords = new ArrayList<CharSequence>();
private boolean mTypedWordValid;
@@ -176,6 +186,7 @@ public class SuggestedWords {
return mWords.get(pos);
}
+ @Override
public String toString() {
// Pretty-print method to help debug
final StringBuilder sb = new StringBuilder("StringBuilder: mTypedWordValid = "
diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java
index 3271b8253..937c2c9ff 100644
--- a/java/src/com/android/inputmethod/latin/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java
@@ -303,6 +303,12 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
} else {
color = mColorTypedWord;
}
+ if (LatinImeLogger.sDBG) {
+ if (index == mCenterSuggestionIndex && suggestions.mHasAutoCorrectionCandidate
+ && suggestions.shouldBlockAutoCorrection()) {
+ return 0xFFFF0000;
+ }
+ }
final SuggestedWordInfo info = (pos < suggestions.size())
? suggestions.getInfo(pos) : null;
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index de2930460..f6343f1d7 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -167,7 +167,9 @@ public class Utils {
throw new RuntimeException("Can not find input method id for " + packageName);
}
- public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions,
+ // TODO: Resolve the inconsistencies between the native auto correction algorithms and
+ // this safety net
+ public static boolean shouldBlockAutoCorrectionBySafetyNet(SuggestedWords suggestions,
Suggest suggest) {
// Safety net for auto correction.
// Actually if we hit this safety net, it's actually a bug.
@@ -181,7 +183,8 @@ public class Utils {
if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) return false;
final CharSequence suggestionWord = suggestions.getWord(1);
final int typedWordLength = typedWord.length();
- final int maxEditDistanceOfNativeDictionary = typedWordLength < 5 ? 2 : typedWordLength / 2;
+ final int maxEditDistanceOfNativeDictionary =
+ (typedWordLength < 5 ? 2 : typedWordLength / 2) + 1;
final int distance = Utils.editDistance(typedWord, suggestionWord);
if (DBG) {
Log.d(TAG, "Autocorrected edit distance = " + distance
@@ -189,8 +192,8 @@ public class Utils {
}
if (distance > maxEditDistanceOfNativeDictionary) {
if (DBG) {
- Log.d(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord);
- Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. "
+ Log.e(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord);
+ Log.e(TAG, "(Error) The edit distance of this correction exceeds limit. "
+ "Turning off auto-correction.");
}
return true;
@@ -792,6 +795,7 @@ public class Utils {
}
public static boolean willAutoCorrect(SuggestedWords suggestions) {
- return !suggestions.mTypedWordValid && suggestions.mHasMinimalSuggestion;
+ return !suggestions.mTypedWordValid && suggestions.mHasAutoCorrectionCandidate
+ && !suggestions.shouldBlockAutoCorrection();
}
}