aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/ClipTouchEventWindowCallback.java75
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java95
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java12
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java81
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java6
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java22
-rw-r--r--java/src/com/android/inputmethod/latin/WindowCallbackAdapter.java168
7 files changed, 154 insertions, 305 deletions
diff --git a/java/src/com/android/inputmethod/latin/ClipTouchEventWindowCallback.java b/java/src/com/android/inputmethod/latin/ClipTouchEventWindowCallback.java
deleted file mode 100644
index d12c70075..000000000
--- a/java/src/com/android/inputmethod/latin/ClipTouchEventWindowCallback.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.latin;
-
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.Window;
-
-public class ClipTouchEventWindowCallback extends WindowCallbackAdapter {
- private final View mDecorView;
- private final int mKeyboardBottomRowVerticalCorrection;
-
- public ClipTouchEventWindowCallback(Window window, int keyboardBottomRowVerticalCorrection) {
- super(window.getCallback());
- mDecorView = window.getDecorView();
- mKeyboardBottomRowVerticalCorrection = keyboardBottomRowVerticalCorrection;
- }
-
- @Override
- public boolean dispatchTouchEvent(MotionEvent me) {
- final int height = mDecorView.getHeight();
- final MotionEvent event = clipMotionEvent(me, height,
- height + mKeyboardBottomRowVerticalCorrection);
- return super.dispatchTouchEvent(event);
- }
-
- private static MotionEvent clipMotionEvent(MotionEvent me, int minHeight, int maxHeight) {
- final int pointerCount = me.getPointerCount();
- boolean shouldClip = false;
- for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) {
- final float y = me.getY(pointerIndex);
- if (y >= minHeight && y < maxHeight) {
- shouldClip = true;
- break;
- }
- }
- if (!shouldClip)
- return me;
-
- if (pointerCount == 1) {
- me.setLocation(me.getX(), minHeight - 1);
- return me;
- }
-
- final int[] pointerIds = new int[pointerCount];
- final MotionEvent.PointerCoords[] pointerCoords =
- new MotionEvent.PointerCoords[pointerCount];
- for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) {
- pointerIds[pointerIndex] = me.getPointerId(pointerIndex);
- final MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
- me.getPointerCoords(pointerIndex, coords);
- pointerCoords[pointerIndex] = coords;
- if (coords.y >= minHeight && coords.y < maxHeight)
- coords.y = minHeight - 1;
- }
- return MotionEvent.obtain(
- me.getDownTime(), me.getEventTime(), me.getAction(), pointerCount, pointerIds,
- pointerCoords, me.getMetaState(), me.getXPrecision(), me.getYPrecision(),
- me.getDeviceId(), me.getEdgeFlags(), me.getSource(), me.getFlags());
- }
-}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 198d34f4a..8166e0b4e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -37,6 +37,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.inputmethodservice.InputMethodService;
import android.media.AudioManager;
+import android.net.ConnectivityManager;
import android.os.Debug;
import android.os.Handler;
import android.os.Message;
@@ -97,10 +98,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Key events coming any faster than this are long-presses.
private static final int QUICK_PRESS = 200;
- // Contextual menu positions
- private static final int POS_METHOD = 0;
- private static final int POS_SETTINGS = 1;
-
private int mSuggestionVisibility;
private static final int SUGGESTION_VISIBILILTY_SHOW_VALUE
= R.string.prefs_suggestion_visibility_show_value;
@@ -161,8 +158,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private int mConfigDelayBeforeFadeoutLanguageOnSpacebar;
private int mConfigDurationOfFadeoutLanguageOnSpacebar;
private float mConfigFinalFadeoutFactorOfLanguageOnSpacebar;
- // For example, to deal with status bar on tablet.
- private int mKeyboardBottomRowVerticalCorrection;
private int mCorrectionMode;
private int mCommittedLength;
@@ -379,8 +374,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
R.integer.config_duration_of_fadeout_language_on_spacebar);
mConfigFinalFadeoutFactorOfLanguageOnSpacebar = res.getInteger(
R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f;
- mKeyboardBottomRowVerticalCorrection = (int)res.getDimension(
- R.dimen.keyboard_bottom_row_vertical_correction);
Utils.GCUtils.getInstance().reset();
boolean tryGC = true;
@@ -396,8 +389,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mOrientation = res.getConfiguration().orientation;
initSuggestPuncList();
- // register to receive ringer mode changes for silent mode
- IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
+ // register to receive ringer mode change and network state change.
+ final IntentFilter filter = new IntentFilter();
+ filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
+ filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(mReceiver, filter);
mVoiceConnector = VoiceIMEConnector.init(this, prefs, mHandler);
prefs.registerOnSharedPreferenceChangeListener(this);
@@ -573,14 +568,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mVoiceConnector.onStartInputView(inputView.getWindowToken());
- if (mKeyboardBottomRowVerticalCorrection > 0) {
- final Window window = getWindow().getWindow();
- if (!(window.getCallback() instanceof ClipTouchEventWindowCallback)) {
- window.setCallback(new ClipTouchEventWindowCallback(
- window, mKeyboardBottomRowVerticalCorrection));
- }
- }
-
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
}
@@ -895,13 +882,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mCandidateViewContainer != null) {
ViewParent candidateParent = mCandidateViewContainer.getParent();
if (candidateParent instanceof FrameLayout) {
- final FrameLayout fl = (FrameLayout) candidateParent;
- // Check frame layout's visibility
- if (fl.getVisibility() == View.INVISIBLE) {
- y = fl.getHeight();
- height += y;
- } else if (fl.getVisibility() == View.VISIBLE) {
- height += fl.getHeight();
+ FrameLayout fl = (FrameLayout) candidateParent;
+ if (fl != null) {
+ // Check frame layout's visibility
+ if (fl.getVisibility() == View.INVISIBLE) {
+ y = fl.getHeight();
+ height += y;
+ } else if (fl.getVisibility() == View.VISIBLE) {
+ height += fl.getHeight();
+ }
}
}
}
@@ -1466,6 +1455,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private boolean isCandidateStripVisible() {
+ if (mCandidateView == null)
+ return false;
if (mCandidateView.isShowingAddToDictionaryHint() || TextEntryState.isCorrecting())
return true;
if (!isShowingSuggestionsStrip())
@@ -1589,7 +1580,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) {
setSuggestions(suggestedWords);
if (suggestedWords.size() > 0) {
- if (Utils.shouldBlockedBySafetyNetForAutoCorrection(suggestedWords)) {
+ if (Utils.shouldBlockedBySafetyNetForAutoCorrection(suggestedWords, mSuggest)) {
mBestWord = typedWord;
} else if (suggestedWords.hasAutoCorrectionWord()) {
mBestWord = suggestedWords.getWord(1);
@@ -2000,11 +1991,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
- // receive ringer mode changes to detect silent mode
+ // receive ringer mode change and network state change.
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- updateRingerMode();
+ final String action = intent.getAction();
+ if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
+ updateRingerMode();
+ } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
+ mSubtypeSwitcher.onNetworkStateChanged(intent);
+ }
}
};
@@ -2226,15 +2222,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private void showSubtypeSelectorAndSettings() {
- showOptionsMenuInternal(new DialogInterface.OnClickListener() {
+ final CharSequence title = getString(R.string.english_ime_input_options);
+ final CharSequence[] items = new CharSequence[] {
+ // TODO: Should use new string "Select active input modes".
+ getString(R.string.language_selection_title),
+ getString(R.string.english_ime_settings),
+ };
+ final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface di, int position) {
di.dismiss();
switch (position) {
- case POS_SETTINGS:
- launchSettings();
- break;
- case POS_METHOD:
+ case 0:
Intent intent = new Intent(
android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
@@ -2244,38 +2243,46 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mInputMethodId);
startActivity(intent);
break;
+ case 1:
+ launchSettings();
+ break;
}
}
- });
+ };
+ showOptionsMenuInternal(title, items, listener);
}
private void showOptionsMenu() {
- showOptionsMenuInternal(new DialogInterface.OnClickListener() {
+ final CharSequence title = getString(R.string.english_ime_input_options);
+ final CharSequence[] items = new CharSequence[] {
+ getString(R.string.selectInputMethod),
+ getString(R.string.english_ime_settings),
+ };
+ final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface di, int position) {
di.dismiss();
switch (position) {
- case POS_SETTINGS:
+ case 0:
launchSettings();
break;
- case POS_METHOD:
+ case 1:
mImm.showInputMethodPicker();
break;
}
}
- });
+ };
+ showOptionsMenuInternal(title, items, listener);
}
- private void showOptionsMenuInternal(DialogInterface.OnClickListener listener) {
+ private void showOptionsMenuInternal(CharSequence title, CharSequence[] items,
+ DialogInterface.OnClickListener listener) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setIcon(R.drawable.ic_dialog_keyboard);
builder.setNegativeButton(android.R.string.cancel, null);
- CharSequence itemSettings = getString(R.string.english_ime_settings);
- CharSequence itemInputMethod = getString(R.string.selectInputMethod);
- builder.setItems(new CharSequence[] {
- itemInputMethod, itemSettings}, listener);
- builder.setTitle(mResources.getString(R.string.english_ime_input_options));
+ builder.setItems(items, listener);
+ builder.setTitle(title);
mOptionsDialog = builder.create();
mOptionsDialog.setCanceledOnTouchOutside(true);
Window window = mOptionsDialog.getWindow();
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 653dbeaba..12338ce61 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -75,6 +75,7 @@ public class Settings extends PreferenceActivity
private CheckBoxPreference mQuickFixes;
private ListPreference mVoicePreference;
private ListPreference mSettingsKeyPreference;
+ private ListPreference mShowCorrectionSuggestionsPreference;
private ListPreference mAutoCorrectionThreshold;
private CheckBoxPreference mBigramSuggestion;
private boolean mVoiceOn;
@@ -102,6 +103,8 @@ public class Settings extends PreferenceActivity
mQuickFixes = (CheckBoxPreference) findPreference(PREF_QUICK_FIXES);
mVoicePreference = (ListPreference) findPreference(PREF_VOICE_SETTINGS_KEY);
mSettingsKeyPreference = (ListPreference) findPreference(PREF_SETTINGS_KEY);
+ mShowCorrectionSuggestionsPreference =
+ (ListPreference) findPreference(PREF_SHOW_SUGGESTIONS_SETTING);
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
prefs.registerOnSharedPreferenceChangeListener(this);
@@ -188,6 +191,7 @@ public class Settings extends PreferenceActivity
updateVoiceModeSummary();
}
updateSettingsKeySummary();
+ updateShowCorrectionSuggestionsSummary();
}
@Override
@@ -212,6 +216,7 @@ public class Settings extends PreferenceActivity
.equals(mVoiceModeOff));
updateVoiceModeSummary();
updateSettingsKeySummary();
+ updateShowCorrectionSuggestionsSummary();
}
@Override
@@ -230,6 +235,13 @@ public class Settings extends PreferenceActivity
return false;
}
+ private void updateShowCorrectionSuggestionsSummary() {
+ mShowCorrectionSuggestionsPreference.setSummary(
+ getResources().getStringArray(R.array.prefs_suggestion_visibilities)
+ [mShowCorrectionSuggestionsPreference.findIndexOfValue(
+ mShowCorrectionSuggestionsPreference.getValue())]);
+ }
+
private void updateSettingsKeySummary() {
mSettingsKeyPreference.setSummary(
getResources().getStringArray(R.array.settings_key_modes)
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 7a1ac2e27..f4262cc99 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -17,16 +17,21 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
+import com.android.inputmethod.keyboard.LatinKeyboard;
+import com.android.inputmethod.keyboard.LatinKeyboardView;
import com.android.inputmethod.voice.SettingsUtil;
import com.android.inputmethod.voice.VoiceIMEConnector;
import com.android.inputmethod.voice.VoiceInput;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
@@ -47,6 +52,8 @@ public class SubtypeSwitcher {
private static final char LOCALE_SEPARATER = '_';
private static final String KEYBOARD_MODE = "keyboard";
private static final String VOICE_MODE = "voice";
+ private static final String SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY =
+ "requireNetworkConnectivity";
private final TextUtils.SimpleStringSplitter mLocaleSplitter =
new TextUtils.SimpleStringSplitter(LOCALE_SEPARATER);
@@ -55,17 +62,17 @@ public class SubtypeSwitcher {
private /* final */ SharedPreferences mPrefs;
private /* final */ InputMethodManager mImm;
private /* final */ Resources mResources;
+ private /* final */ ConnectivityManager mConnectivityManager;
+ private /* final */ boolean mConfigUseSpacebarLanguageSwitcher;
private final ArrayList<InputMethodSubtype> mEnabledKeyboardSubtypesOfCurrentInputMethod =
new ArrayList<InputMethodSubtype>();
private final ArrayList<String> mEnabledLanguagesOfCurrentInputMethod = new ArrayList<String>();
- private boolean mConfigUseSpacebarLanguageSwitcher;
-
/*-----------------------------------------------------------*/
// Variants which should be changed only by reload functions.
private boolean mNeedsToDisplayLanguage;
private boolean mIsSystemLanguageSameAsInputLanguage;
- private InputMethodInfo mShortcutInfo;
+ private InputMethodInfo mShortcutInputMethodInfo;
private InputMethodSubtype mShortcutSubtype;
private List<InputMethodSubtype> mAllEnabledSubtypesOfCurrentInputMethod;
private Locale mSystemLocale;
@@ -75,13 +82,14 @@ public class SubtypeSwitcher {
private VoiceInput mVoiceInput;
/*-----------------------------------------------------------*/
+ private boolean mIsNetworkConnected;
+
public static SubtypeSwitcher getInstance() {
return sInstance;
}
public static void init(LatinIME service, SharedPreferences prefs) {
- sInstance.mPrefs = prefs;
- sInstance.resetParams(service);
+ sInstance.initialize(service, prefs);
sInstance.updateAllParameters();
SubtypeLocale.init(service);
@@ -91,10 +99,13 @@ public class SubtypeSwitcher {
// Intentional empty constructor for singleton.
}
- private void resetParams(LatinIME service) {
+ private void initialize(LatinIME service, SharedPreferences prefs) {
mService = service;
+ mPrefs = prefs;
mResources = service.getResources();
mImm = (InputMethodManager) service.getSystemService(Context.INPUT_METHOD_SERVICE);
+ mConnectivityManager = (ConnectivityManager) service.getSystemService(
+ Context.CONNECTIVITY_SERVICE);
mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
mEnabledLanguagesOfCurrentInputMethod.clear();
mSystemLocale = null;
@@ -109,6 +120,9 @@ public class SubtypeSwitcher {
R.bool.config_use_spacebar_language_switcher);
if (mConfigUseSpacebarLanguageSwitcher)
initLanguageSwitcher(service);
+
+ final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
+ mIsNetworkConnected = (info != null && info.isConnected());
}
// Update all parameters stored in SubtypeSwitcher.
@@ -165,7 +179,8 @@ public class SubtypeSwitcher {
private void updateShortcutIME() {
if (DBG) {
Log.d(TAG, "Update shortcut IME from : "
- + (mShortcutInfo == null ? "<null>" : mShortcutInfo.getId()) + ", "
+ + (mShortcutInputMethodInfo == null
+ ? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
+ (mShortcutSubtype == null ? "<null>" : (mShortcutSubtype.getLocale()
+ ", " + mShortcutSubtype.getMode())));
}
@@ -176,7 +191,7 @@ public class SubtypeSwitcher {
List<InputMethodSubtype> subtypes = shortcuts.get(imi);
// TODO: Returns the first found IMI for now. Should handle all shortcuts as
// appropriate.
- mShortcutInfo = imi;
+ mShortcutInputMethodInfo = imi;
// TODO: Pick up the first found subtype for now. Should handle all subtypes
// as appropriate.
mShortcutSubtype = subtypes.size() > 0 ? subtypes.get(0) : null;
@@ -184,7 +199,8 @@ public class SubtypeSwitcher {
}
if (DBG) {
Log.d(TAG, "Update shortcut IME to : "
- + (mShortcutInfo == null ? "<null>" : mShortcutInfo.getId()) + ", "
+ + (mShortcutInputMethodInfo == null
+ ? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
+ (mShortcutSubtype == null ? "<null>" : (mShortcutSubtype.getLocale()
+ ", " + mShortcutSubtype.getMode())));
}
@@ -288,15 +304,22 @@ public class SubtypeSwitcher {
////////////////////////////
public void switchToShortcutIME() {
- IBinder token = mService.getWindow().getWindow().getAttributes().token;
- if (token == null || mShortcutInfo == null) {
+ final IBinder token = mService.getWindow().getWindow().getAttributes().token;
+ if (token == null || mShortcutInputMethodInfo == null) {
return;
}
- mImm.setInputMethodAndSubtype(token, mShortcutInfo.getId(), mShortcutSubtype);
+ final String imiId = mShortcutInputMethodInfo.getId();
+ final InputMethodSubtype subtype = mShortcutSubtype;
+ new Thread("SwitchToShortcutIME") {
+ @Override
+ public void run() {
+ mImm.setInputMethodAndSubtype(token, imiId, subtype);
+ }
+ }.start();
}
public Drawable getShortcutIcon() {
- return getSubtypeIcon(mShortcutInfo, mShortcutSubtype);
+ return getSubtypeIcon(mShortcutInputMethodInfo, mShortcutSubtype);
}
private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtype subtype) {
@@ -325,6 +348,38 @@ public class SubtypeSwitcher {
return null;
}
+ private static boolean contains(String[] hay, String needle) {
+ for (String element : hay) {
+ if (element.equals(needle))
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isShortcutAvailable() {
+ if (mShortcutInputMethodInfo == null)
+ return false;
+ if (mShortcutSubtype != null && contains(mShortcutSubtype.getExtraValue().split(","),
+ SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY)) {
+ return mIsNetworkConnected;
+ }
+ return true;
+ }
+
+ public void onNetworkStateChanged(Intent intent) {
+ final boolean noConnection = intent.getBooleanExtra(
+ ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
+ mIsNetworkConnected = !noConnection;
+
+ final LatinKeyboardView inputView = KeyboardSwitcher.getInstance().getInputView();
+ if (inputView != null) {
+ final LatinKeyboard keyboard = inputView.getLatinKeyboard();
+ if (keyboard != null) {
+ keyboard.updateShortcutKey(isShortcutAvailable(), inputView);
+ }
+ }
+ }
+
//////////////////////////////////
// Language Switching functions //
//////////////////////////////////
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 1772b2669..ced355bb2 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -163,6 +163,10 @@ public class Suggest implements Dictionary.WordCallback {
mAutoCorrectionThreshold = threshold;
}
+ public boolean isAggressiveAutoCorrectionMode() {
+ return (mAutoCorrectionThreshold == 0);
+ }
+
/**
* Number of suggestions to generate from the input key sequence. This has
* to be a number between 1 and 100 (inclusive).
@@ -290,7 +294,7 @@ public class Suggest implements Dictionary.WordCallback {
typedWord, mSuggestions.get(0), mPriorities[0]);
if (LatinImeLogger.sDBG) {
Log.d(TAG, "Normalized " + typedWord + "," + mSuggestions.get(0) + ","
- + mPriorities[0] + normalizedScore
+ + mPriorities[0] + ", " + normalizedScore
+ "(" + mAutoCorrectionThreshold + ")");
}
if (normalizedScore >= mAutoCorrectionThreshold) {
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index 5059860d7..e980d3a30 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -38,6 +38,7 @@ import java.util.Date;
public class Utils {
private static final String TAG = Utils.class.getSimpleName();
+ private static final int MINIMUM_SAFETY_NET_CHAR_LENGTH = 4;
private static boolean DBG = LatinImeLogger.sDBG;
/**
@@ -106,11 +107,18 @@ public class Utils {
throw new RuntimeException("Can not find input method id for " + packageName);
}
- public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions) {
+ public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions,
+ Suggest suggest) {
// Safety net for auto correction.
// Actually if we hit this safety net, it's actually a bug.
if (suggestions.size() <= 1 || suggestions.mTypedWordValid) return false;
+ // If user selected aggressive auto correction mode, there is no need to use the safety
+ // net.
+ if (suggest.isAggressiveAutoCorrectionMode()) return false;
CharSequence typedWord = suggestions.getWord(0);
+ // If the length of typed word is less than MINIMUM_SAFETY_NET_CHAR_LENGTH,
+ // we should not use net because relatively edit distance can be big.
+ if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) return false;
CharSequence candidateWord = suggestions.getWord(1);
final int typedWordLength = typedWord.length();
final int maxEditDistanceOfNativeDictionary = typedWordLength < 5 ? 2 : typedWordLength / 2;
@@ -120,8 +128,11 @@ public class Utils {
+ ", " + maxEditDistanceOfNativeDictionary);
}
if (distance > maxEditDistanceOfNativeDictionary) {
- Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. "
- + "Turning off auto-correction.");
+ if (DBG) {
+ Log.d(TAG, "Safety net: before = " + typedWord + ", after = " + candidateWord);
+ Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. "
+ + "Turning off auto-correction.");
+ }
return true;
} else {
return false;
@@ -267,9 +278,12 @@ public class Utils {
public static double calcNormalizedScore(CharSequence before, CharSequence after, int score) {
final int beforeLength = before.length();
final int afterLength = after.length();
+ if (beforeLength == 0 || afterLength == 0) return 0;
final int distance = editDistance(before, after);
+ // If afterLength < beforeLength, the algorithm is suggesting a word by excessive character
+ // correction.
final double maximumScore = MAX_INITIAL_SCORE
- * Math.pow(TYPED_LETTER_MULTIPLIER, beforeLength)
+ * Math.pow(TYPED_LETTER_MULTIPLIER, Math.min(beforeLength, afterLength))
* FULL_WORD_MULTIPLYER;
// add a weight based on edit distance.
// distance <= max(afterLength, beforeLength) == afterLength,
diff --git a/java/src/com/android/inputmethod/latin/WindowCallbackAdapter.java b/java/src/com/android/inputmethod/latin/WindowCallbackAdapter.java
deleted file mode 100644
index be9bb2bd8..000000000
--- a/java/src/com/android/inputmethod/latin/WindowCallbackAdapter.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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.latin;
-
-import android.view.ActionMode;
-import android.view.ActionMode.Callback;
-import android.view.KeyEvent;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.Window;
-import android.view.WindowManager.LayoutParams;
-import android.view.accessibility.AccessibilityEvent;
-
-public class WindowCallbackAdapter implements Window.Callback {
- private final Window.Callback mPreviousCallback;
-
- public WindowCallbackAdapter(Window.Callback previousCallback) {
- mPreviousCallback = previousCallback;
- }
-
- @Override
- public boolean dispatchKeyEvent(KeyEvent event) {
- if (mPreviousCallback != null)
- return mPreviousCallback.dispatchKeyEvent(event);
- return false;
- }
-
- @Override
- public boolean dispatchKeyShortcutEvent(KeyEvent event) {
- if (mPreviousCallback != null)
- return mPreviousCallback.dispatchKeyShortcutEvent(event);
- return false;
- }
-
- @Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
- if (mPreviousCallback != null)
- return mPreviousCallback.dispatchPopulateAccessibilityEvent(event);
- return false;
- }
-
- @Override
- public boolean dispatchTouchEvent(MotionEvent event) {
- if (mPreviousCallback != null)
- return mPreviousCallback.dispatchTouchEvent(event);
- return false;
- }
-
- @Override
- public boolean dispatchTrackballEvent(MotionEvent event) {
- if (mPreviousCallback != null)
- return mPreviousCallback.dispatchTrackballEvent(event);
- return false;
- }
-
- @Override
- public void onActionModeFinished(ActionMode mode) {
- if (mPreviousCallback != null)
- mPreviousCallback.onActionModeFinished(mode);
- }
-
- @Override
- public void onActionModeStarted(ActionMode mode) {
- if (mPreviousCallback != null)
- mPreviousCallback.onActionModeStarted(mode);
- }
-
- @Override
- public void onAttachedToWindow() {
- if (mPreviousCallback != null)
- mPreviousCallback.onAttachedToWindow();
- }
-
- @Override
- public void onContentChanged() {
- if (mPreviousCallback != null)
- mPreviousCallback.onContentChanged();
- }
-
- @Override
- public boolean onCreatePanelMenu(int featureId, Menu menu) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onCreatePanelMenu(featureId, menu);
- return false;
- }
-
- @Override
- public View onCreatePanelView(int featureId) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onCreatePanelView(featureId);
- return null;
- }
-
- @Override
- public void onDetachedFromWindow() {
- if (mPreviousCallback != null)
- mPreviousCallback.onDetachedFromWindow();
- }
-
- @Override
- public boolean onMenuItemSelected(int featureId, MenuItem item) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onMenuItemSelected(featureId, item);
- return false;
- }
-
- @Override
- public boolean onMenuOpened(int featureId, Menu menu) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onMenuOpened(featureId, menu);
- return false;
- }
-
- @Override
- public void onPanelClosed(int featureId, Menu menu) {
- if (mPreviousCallback != null)
- mPreviousCallback.onPanelClosed(featureId, menu);
- }
-
- @Override
- public boolean onPreparePanel(int featureId, View view, Menu menu) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onPreparePanel(featureId, view, menu);
- return false;
- }
-
- @Override
- public boolean onSearchRequested() {
- if (mPreviousCallback != null)
- return mPreviousCallback.onSearchRequested();
- return false;
- }
-
- @Override
- public void onWindowAttributesChanged(LayoutParams attrs) {
- if (mPreviousCallback != null)
- mPreviousCallback.onWindowAttributesChanged(attrs);
- }
-
- @Override
- public void onWindowFocusChanged(boolean hasFocus) {
- if (mPreviousCallback != null)
- mPreviousCallback.onWindowFocusChanged(hasFocus);
- }
-
- @Override
- public ActionMode onWindowStartingActionMode(Callback callback) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onWindowStartingActionMode(callback);
- return null;
- }
-}