diff options
-rw-r--r-- | java/res/values/donottranslate.xml | 1 | ||||
-rw-r--r-- | java/res/xml/prefs_for_debug.xml | 6 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java | 25 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/KeyboardSet.java | 6 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java | 28 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java | 6 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java | 11 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/DebugSettings.java | 3 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 4 | ||||
-rw-r--r-- | native/src/correction.cpp | 26 | ||||
-rw-r--r-- | native/src/defines.h | 2 |
11 files changed, 77 insertions, 41 deletions
diff --git a/java/res/values/donottranslate.xml b/java/res/values/donottranslate.xml index e6f036d53..8bd25c00d 100644 --- a/java/res/values/donottranslate.xml +++ b/java/res/values/donottranslate.xml @@ -120,6 +120,7 @@ <!-- Title for Latin keyboard debug settings activity / dialog --> <string name="english_ime_debug_settings">Android keyboard Debug settings</string> <string name="prefs_debug_mode">Debug Mode</string> + <string name="prefs_force_non_distinct_multitouch">Force non-distinct multitouch</string> <!-- Keyboard theme names --> <string name="layout_basic">Basic</string> diff --git a/java/res/xml/prefs_for_debug.xml b/java/res/xml/prefs_for_debug.xml index 80613a56f..f38b85f0b 100644 --- a/java/res/xml/prefs_for_debug.xml +++ b/java/res/xml/prefs_for_debug.xml @@ -42,4 +42,10 @@ android:defaultValue="false" /> + <CheckBoxPreference + android:key="force_non_distinct_multitouch" + android:title="@string/prefs_force_non_distinct_multitouch" + android:persistent="true" + android:defaultValue="false" + /> </PreferenceScreen> diff --git a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java index bcdcef7dc..e1db36088 100644 --- a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java @@ -26,12 +26,16 @@ public class EditorInfoCompatUtils { EditorInfo.class, "IME_FLAG_NAVIGATE_NEXT"); private static final Field FIELD_IME_FLAG_NAVIGATE_PREVIOUS = CompatUtils.getField( EditorInfo.class, "IME_FLAG_NAVIGATE_PREVIOUS"); + private static final Field FIELD_IME_FLAG_FORCE_ASCII = CompatUtils.getField( + EditorInfo.class, "IME_FLAG_FORCE_ASCII"); private static final Field FIELD_IME_ACTION_PREVIOUS = CompatUtils.getField( EditorInfo.class, "IME_ACTION_PREVIOUS"); private static final Integer OBJ_IME_FLAG_NAVIGATE_NEXT = (Integer) CompatUtils .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_NEXT); private static final Integer OBJ_IME_FLAG_NAVIGATE_PREVIOUS = (Integer) CompatUtils .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_PREVIOUS); + private static final Integer OBJ_IME_FLAG_FORCE_ASCII = (Integer) CompatUtils + .getFieldValue(null, null, FIELD_IME_FLAG_FORCE_ASCII); private static final Integer OBJ_IME_ACTION_PREVIOUS = (Integer) CompatUtils .getFieldValue(null, null, FIELD_IME_ACTION_PREVIOUS); @@ -47,6 +51,12 @@ public class EditorInfoCompatUtils { return (imeOptions & OBJ_IME_FLAG_NAVIGATE_PREVIOUS) != 0; } + public static boolean hasFlagForceAscii(int imeOptions) { + if (OBJ_IME_FLAG_FORCE_ASCII == null) + return false; + return (imeOptions & OBJ_IME_FLAG_FORCE_ASCII) != 0; + } + public static void performEditorActionNext(InputConnection ic) { ic.performEditorAction(EditorInfo.IME_ACTION_NEXT); } @@ -93,10 +103,19 @@ public class EditorInfoCompatUtils { break; } } + final StringBuilder flags = new StringBuilder(); if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) { - return "flagNoEnterAction|" + action; - } else { - return action; + flags.append("flagNoEnterAction|"); + } + if (hasFlagNavigateNext(imeOptions)) { + flags.append("flagNavigateNext|"); + } + if (hasFlagNavigatePrevious(imeOptions)) { + flags.append("flagNavigatePrevious|"); + } + if (hasFlagForceAscii(imeOptions)) { + flags.append("flagForceAscii|"); } + return flags + action; } } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index 41696059d..285252044 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -25,6 +25,7 @@ import android.util.Log; import android.util.Xml; import android.view.inputmethod.EditorInfo; +import com.android.inputmethod.compat.EditorInfoCompatUtils; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LocaleUtils; @@ -179,8 +180,9 @@ public class KeyboardSet { // TODO: Use InputMethodSubtype object as argument. public Builder setSubtype(Locale inputLocale, boolean asciiCapable, boolean touchPositionCorrectionEnabled) { - final boolean forceAscii = Utils.inPrivateImeOptions( - mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo); + final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii(mParams.mImeOptions) + || Utils.inPrivateImeOptions( + mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo); mParams.mLocale = (forceAscii && !asciiCapable) ? Locale.US : inputLocale; mParams.mTouchPositionCorrectionEnabled = touchPositionCorrectionEnabled; return this; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index df61689e1..af1c3eeb9 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -28,6 +28,7 @@ import android.view.inputmethod.EditorInfo; import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; import com.android.inputmethod.keyboard.internal.KeyboardState; +import com.android.inputmethod.latin.DebugSettings; import com.android.inputmethod.latin.InputView; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; @@ -53,6 +54,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, private SubtypeSwitcher mSubtypeSwitcher; private SharedPreferences mPrefs; + private boolean mForceNonDistinctMultitouch; private InputView mCurrentInputView; private LatinKeyboardView mKeyboardView; @@ -92,6 +94,8 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, mState = new KeyboardState(this); setContextThemeWrapper(ims, getKeyboardThemeIndex(ims, prefs)); prefs.registerOnSharedPreferenceChangeListener(this); + mForceNonDistinctMultitouch = prefs.getBoolean( + DebugSettings.FORCE_NON_DISTINCT_MULTITOUCH_KEY, false); } private static int getKeyboardThemeIndex(Context context, SharedPreferences prefs) { @@ -221,19 +225,16 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, Keyboard keyboard = getKeyboard(); if (keyboard == null) return; - if (shiftMode == AUTOMATIC_SHIFT) { + switch (shiftMode) { + case AUTOMATIC_SHIFT: keyboard.setAutomaticTemporaryUpperCase(); - } else { - final boolean shifted = (shiftMode == MANUAL_SHIFT); - // TODO: Remove duplicated logic in KeyboardState#setShifted - // On non-distinct multi touch panel device, we should also turn off the shift locked - // state when shift key is pressed to go to normal mode. - // On the other hand, on distinct multi touch panel device, turning off the shift - // locked state with shift key pressing is handled by onReleaseShift(). - if (!hasDistinctMultitouch() && !shifted && mState.isShiftLocked()) { - setShiftLocked(false); - } - keyboard.setShifted(shifted); + break; + case MANUAL_SHIFT: + keyboard.setShifted(true); + break; + case UNSHIFT: + keyboard.setShifted(false); + break; } mKeyboardView.invalidateAllKeys(); } @@ -392,6 +393,9 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, mKeyboardView = (LatinKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view); mKeyboardView.setKeyboardActionListener(mInputMethodService); + if (mForceNonDistinctMultitouch) { + mKeyboardView.setDistinctMultitouch(false); + } // This always needs to be set since the accessibility state can // potentially change without the input view being re-created. diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 4d2aeeccf..8aa7f883b 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -115,7 +115,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke /** Listener for {@link KeyboardActionListener}. */ private KeyboardActionListener mKeyboardActionListener; - private final boolean mHasDistinctMultitouch; + private boolean mHasDistinctMultitouch; private int mOldPointerCount = 1; private Key mOldKey; @@ -371,6 +371,10 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke return mHasDistinctMultitouch; } + public void setDistinctMultitouch(boolean hasDistinctMultitouch) { + mHasDistinctMultitouch = hasDistinctMultitouch; + } + /** * When enabled, calls to {@link KeyboardActionListener#onCodeInput} will include key * codes for adjacent keys. When disabled, only the primary key code will be diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index 609593e44..bb75111b4 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -166,29 +166,20 @@ public class KeyboardState { if (DEBUG_STATE) { Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode)); } - // TODO: Remove this hack in conjunction with duplicated logic below. - boolean needsToTurnOffShiftLockedLater = false; if (shiftMode == SwitchActions.AUTOMATIC_SHIFT) { mKeyboardShiftState.setAutomaticTemporaryUpperCase(); } else { - // TODO: Remove duplicated logic in KeyboardSwitcher#setShifted() final boolean shifted = (shiftMode == SwitchActions.MANUAL_SHIFT); // On non-distinct multi touch panel device, we should also turn off the shift locked // state when shift key is pressed to go to normal mode. // On the other hand, on distinct multi touch panel device, turning off the shift // locked state with shift key pressing is handled by onReleaseShift(). if (!mHasDistinctMultitouch && !shifted && mKeyboardShiftState.isShiftLocked()) { - // Setting shift lock state should be delayed after - // mSwitchActions.setShifted(shiftMode) is called, because in that call the state - // is referenced. - needsToTurnOffShiftLockedLater = true; + mSwitchActions.setShiftLocked(false); } mKeyboardShiftState.setShifted(shifted); } mSwitchActions.setShifted(shiftMode); - if (needsToTurnOffShiftLockedLater) { - mKeyboardShiftState.setShiftLocked(false); - } } private void setShiftLocked(boolean shiftLocked) { diff --git a/java/src/com/android/inputmethod/latin/DebugSettings.java b/java/src/com/android/inputmethod/latin/DebugSettings.java index 2f1e7c2b8..3805da154 100644 --- a/java/src/com/android/inputmethod/latin/DebugSettings.java +++ b/java/src/com/android/inputmethod/latin/DebugSettings.java @@ -30,6 +30,7 @@ public class DebugSettings extends PreferenceActivity private static final String TAG = "DebugSettings"; private static final String DEBUG_MODE_KEY = "debug_mode"; + public static final String FORCE_NON_DISTINCT_MULTITOUCH_KEY = "force_non_distinct_multitouch"; private boolean mServiceNeedsRestart = false; private CheckBoxPreference mDebugMode; @@ -60,6 +61,8 @@ public class DebugSettings extends PreferenceActivity updateDebugMode(); mServiceNeedsRestart = true; } + } else if (key.equals(FORCE_NON_DISTINCT_MULTITOUCH_KEY)) { + mServiceNeedsRestart = true; } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 820b2e638..32e933064 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -104,10 +104,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar */ public static final String IME_OPTION_NO_SETTINGS_KEY = "noSettingsKey"; + // TODO: Remove this private option. /** * The private IME option used to indicate that the given text field needs * ASCII code points input. + * + * @deprecated Use {@link EditorInfo#IME_FLAG_FORCE_ASCII}. */ + @SuppressWarnings("dep-ann") public static final String IME_OPTION_FORCE_ASCII = "forceAscii"; /** diff --git a/native/src/correction.cpp b/native/src/correction.cpp index 75831b69d..5dc6f8737 100644 --- a/native/src/correction.cpp +++ b/native/src/correction.cpp @@ -653,9 +653,10 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const int finalFreq = freq; // TODO: Optimize this. - // TODO: Ignoring edit distance for transposed char, for now - if (transposedCount == 0 && (proximityMatchedCount > 0 || skipped || excessiveCount > 0)) { - ed = getCurrentEditDistance(editDistanceTable, inputLength, outputIndex + 1); + if (transposedCount > 0 || proximityMatchedCount > 0 || skipped || excessiveCount > 0) { + ed = getCurrentEditDistance(editDistanceTable, inputLength, outputIndex + 1) + - transposedCount; + const int matchWeight = powerIntCapped(typedLetterMultiplier, max(inputLength, outputIndex + 1) - ed); multiplyIntCapped(matchWeight, &finalFreq); @@ -667,21 +668,22 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const ed = max(0, ed - quoteDiffCount); - if (ed == 1 && (inputLength == outputIndex || inputLength == outputIndex + 2)) { - // Promote a word with just one skipped or excessive char - if (sameLength) { - multiplyRate(WORDS_WITH_JUST_ONE_CORRECTION_PROMOTION_RATE, &finalFreq); - } else { + if (transposedCount < 1) { + if (ed == 1 && (inputLength == outputIndex || inputLength == outputIndex + 2)) { + // Promote a word with just one skipped or excessive char + if (sameLength) { + multiplyRate(WORDS_WITH_JUST_ONE_CORRECTION_PROMOTION_RATE, &finalFreq); + } else { + multiplyIntCapped(typedLetterMultiplier, &finalFreq); + } + } else if (ed == 0) { multiplyIntCapped(typedLetterMultiplier, &finalFreq); + sameLength = true; } - } else if (ed == 0) { - multiplyIntCapped(typedLetterMultiplier, &finalFreq); - sameLength = true; } adjustedProximityMatchedCount = min(max(0, ed - (outputIndex + 1 - inputLength)), proximityMatchedCount); } else { - // TODO: Calculate the edit distance for transposed char const int matchWeight = powerIntCapped(typedLetterMultiplier, matchCount); multiplyIntCapped(matchWeight, &finalFreq); } diff --git a/native/src/defines.h b/native/src/defines.h index ce3f85acd..31175c369 100644 --- a/native/src/defines.h +++ b/native/src/defines.h @@ -190,7 +190,7 @@ static void prof_out(void) { #define WORDS_WITH_MISSING_SPACE_CHARACTER_DEMOTION_RATE 67 #define WORDS_WITH_EXCESSIVE_CHARACTER_DEMOTION_RATE 75 #define WORDS_WITH_EXCESSIVE_CHARACTER_OUT_OF_PROXIMITY_DEMOTION_RATE 75 -#define WORDS_WITH_TRANSPOSED_CHARACTERS_DEMOTION_RATE 60 +#define WORDS_WITH_TRANSPOSED_CHARACTERS_DEMOTION_RATE 70 #define FULL_MATCHED_WORDS_PROMOTION_RATE 120 #define WORDS_WITH_PROXIMITY_CHARACTER_DEMOTION_RATE 90 #define WORDS_WITH_MATCH_SKIP_PROMOTION_RATE 105 |