Loading java/res/values-hi/donottranslate-config-spacing-and-punctuations.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- /* ** ** Copyright 2014, 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. */ --> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- The sentence separator code point, for double-space-to-period --> <!-- U+007C: "|" VERTICAL LINE ; 7Ch = 124d --> <integer name="sentence_separator">124</integer> </resources> java/src/com/android/inputmethod/latin/Constants.java +0 −1 Original line number Diff line number Diff line Loading @@ -230,7 +230,6 @@ public final class Constants { public static final String REGEXP_PERIOD = "\\."; public static final String STRING_SPACE = " "; public static final String STRING_PERIOD_AND_SPACE = ". "; /** * Special keys code. Must be negative. Loading java/src/com/android/inputmethod/latin/RichInputConnection.java +6 −4 Original line number Diff line number Diff line Loading @@ -729,17 +729,19 @@ public final class RichInputConnection { return TextUtils.equals(text, beforeText); } public boolean revertDoubleSpacePeriod() { public boolean revertDoubleSpacePeriod(final SpacingAndPunctuations spacingAndPunctuations) { if (DEBUG_BATCH_NESTING) checkBatchEdit(); // Here we test whether we indeed have a period and a space before us. This should not // be needed, but it's there just in case something went wrong. final CharSequence textBeforeCursor = getTextBeforeCursor(2, 0); if (!TextUtils.equals(Constants.STRING_PERIOD_AND_SPACE, textBeforeCursor)) { if (!TextUtils.equals(spacingAndPunctuations.mSentenceSeparatorAndSpace, textBeforeCursor)) { // Theoretically we should not be coming here if there isn't ". " before the // cursor, but the application may be changing the text while we are typing, so // anything goes. We should not crash. Log.d(TAG, "Tried to revert double-space combo but we didn't find " + "\"" + Constants.STRING_PERIOD_AND_SPACE + "\" just before the cursor."); Log.d(TAG, "Tried to revert double-space combo but we didn't find \"" + spacingAndPunctuations.mSentenceSeparatorAndSpace + "\" just before the cursor."); return false; } // Double-space results in ". ". A backspace to cancel this should result in a single Loading java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +5 −2 Original line number Diff line number Diff line Loading @@ -1115,7 +1115,8 @@ public final class InputLogic { } if (SpaceState.DOUBLE == inputTransaction.mSpaceState) { cancelDoubleSpacePeriodCountdown(); if (mConnection.revertDoubleSpacePeriod()) { if (mConnection.revertDoubleSpacePeriod( inputTransaction.mSettingsValues.mSpacingAndPunctuations)) { // No need to reset mSpaceState, it has already be done (that's why we // receive it as a parameter) inputTransaction.setRequiresUpdateSuggestions(); Loading Loading @@ -1298,7 +1299,9 @@ public final class InputLogic { if (null == lastTwo) return false; final int length = lastTwo.length(); if (length < 2) return false; if (lastTwo.charAt(length - 1) != Constants.CODE_SPACE) return false; if (lastTwo.charAt(length - 1) != Constants.CODE_SPACE) { return false; } // We know there is a space in pos -1, and we have at least two chars. If we have only two // chars, isSurrogatePairs can't return true as charAt(1) is a space, so this is fine. final int firstCodePoint = Loading tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java +30 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.inputmethod.latin; import android.test.suitebuilder.annotation.LargeTest; import com.android.inputmethod.latin.settings.Settings; @LargeTest public class InputLogicTestsNonEnglish extends InputTestsBase { final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction"; Loading Loading @@ -121,4 +123,32 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { assertEquals("auto-correct with umlaut for German", EXPECTED_RESULT, mEditText.getText().toString()); } // Corresponds to InputLogicTests#testDoubleSpace public void testDoubleSpaceHindi() { changeLanguage("hi"); // Set default pref just in case setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); // U+1F607 is an emoji final String[] STRINGS_TO_TYPE = new String[] { "this ", "a+ ", "\u1F607 ", "|| ", ") ", "( ", "% " }; final String[] EXPECTED_RESULTS = new String[] { "this| ", "a+| ", "\u1F607| ", "|| ", ")| ", "( ", "%| " }; for (int i = 0; i < STRINGS_TO_TYPE.length; ++i) { mEditText.setText(""); type(STRINGS_TO_TYPE[i]); assertEquals("double space processing", EXPECTED_RESULTS[i], mEditText.getText().toString()); } } // Corresponds to InputLogicTests#testCancelDoubleSpace public void testCancelDoubleSpaceHindi() { changeLanguage("hi"); final String STRING_TO_TYPE = "this "; final String EXPECTED_RESULT = "this "; type(STRING_TO_TYPE); type(Constants.CODE_DELETE); assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); } } Loading
java/res/values-hi/donottranslate-config-spacing-and-punctuations.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- /* ** ** Copyright 2014, 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. */ --> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- The sentence separator code point, for double-space-to-period --> <!-- U+007C: "|" VERTICAL LINE ; 7Ch = 124d --> <integer name="sentence_separator">124</integer> </resources>
java/src/com/android/inputmethod/latin/Constants.java +0 −1 Original line number Diff line number Diff line Loading @@ -230,7 +230,6 @@ public final class Constants { public static final String REGEXP_PERIOD = "\\."; public static final String STRING_SPACE = " "; public static final String STRING_PERIOD_AND_SPACE = ". "; /** * Special keys code. Must be negative. Loading
java/src/com/android/inputmethod/latin/RichInputConnection.java +6 −4 Original line number Diff line number Diff line Loading @@ -729,17 +729,19 @@ public final class RichInputConnection { return TextUtils.equals(text, beforeText); } public boolean revertDoubleSpacePeriod() { public boolean revertDoubleSpacePeriod(final SpacingAndPunctuations spacingAndPunctuations) { if (DEBUG_BATCH_NESTING) checkBatchEdit(); // Here we test whether we indeed have a period and a space before us. This should not // be needed, but it's there just in case something went wrong. final CharSequence textBeforeCursor = getTextBeforeCursor(2, 0); if (!TextUtils.equals(Constants.STRING_PERIOD_AND_SPACE, textBeforeCursor)) { if (!TextUtils.equals(spacingAndPunctuations.mSentenceSeparatorAndSpace, textBeforeCursor)) { // Theoretically we should not be coming here if there isn't ". " before the // cursor, but the application may be changing the text while we are typing, so // anything goes. We should not crash. Log.d(TAG, "Tried to revert double-space combo but we didn't find " + "\"" + Constants.STRING_PERIOD_AND_SPACE + "\" just before the cursor."); Log.d(TAG, "Tried to revert double-space combo but we didn't find \"" + spacingAndPunctuations.mSentenceSeparatorAndSpace + "\" just before the cursor."); return false; } // Double-space results in ". ". A backspace to cancel this should result in a single Loading
java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +5 −2 Original line number Diff line number Diff line Loading @@ -1115,7 +1115,8 @@ public final class InputLogic { } if (SpaceState.DOUBLE == inputTransaction.mSpaceState) { cancelDoubleSpacePeriodCountdown(); if (mConnection.revertDoubleSpacePeriod()) { if (mConnection.revertDoubleSpacePeriod( inputTransaction.mSettingsValues.mSpacingAndPunctuations)) { // No need to reset mSpaceState, it has already be done (that's why we // receive it as a parameter) inputTransaction.setRequiresUpdateSuggestions(); Loading Loading @@ -1298,7 +1299,9 @@ public final class InputLogic { if (null == lastTwo) return false; final int length = lastTwo.length(); if (length < 2) return false; if (lastTwo.charAt(length - 1) != Constants.CODE_SPACE) return false; if (lastTwo.charAt(length - 1) != Constants.CODE_SPACE) { return false; } // We know there is a space in pos -1, and we have at least two chars. If we have only two // chars, isSurrogatePairs can't return true as charAt(1) is a space, so this is fine. final int firstCodePoint = Loading
tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java +30 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.inputmethod.latin; import android.test.suitebuilder.annotation.LargeTest; import com.android.inputmethod.latin.settings.Settings; @LargeTest public class InputLogicTestsNonEnglish extends InputTestsBase { final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction"; Loading Loading @@ -121,4 +123,32 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { assertEquals("auto-correct with umlaut for German", EXPECTED_RESULT, mEditText.getText().toString()); } // Corresponds to InputLogicTests#testDoubleSpace public void testDoubleSpaceHindi() { changeLanguage("hi"); // Set default pref just in case setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); // U+1F607 is an emoji final String[] STRINGS_TO_TYPE = new String[] { "this ", "a+ ", "\u1F607 ", "|| ", ") ", "( ", "% " }; final String[] EXPECTED_RESULTS = new String[] { "this| ", "a+| ", "\u1F607| ", "|| ", ")| ", "( ", "%| " }; for (int i = 0; i < STRINGS_TO_TYPE.length; ++i) { mEditText.setText(""); type(STRINGS_TO_TYPE[i]); assertEquals("double space processing", EXPECTED_RESULTS[i], mEditText.getText().toString()); } } // Corresponds to InputLogicTests#testCancelDoubleSpace public void testCancelDoubleSpaceHindi() { changeLanguage("hi"); final String STRING_TO_TYPE = "this "; final String EXPECTED_RESULT = "this "; type(STRING_TO_TYPE); type(Constants.CODE_DELETE); assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); } }