aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java2
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java28
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java26
-rw-r--r--tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java78
4 files changed, 99 insertions, 35 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index eeb5bf536..045d06f0e 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -490,6 +490,7 @@ public final class InputLogic {
handler.showGesturePreviewAndSuggestionStrip(
SuggestedWords.EMPTY, false /* dismissGestureFloatingPreviewText */);
handler.cancelUpdateSuggestionStrip();
+ ++mAutoCommitSequenceNumber;
mConnection.beginBatchEdit();
if (mWordComposer.isComposingWord()) {
if (settingsValues.mIsInternal) {
@@ -587,6 +588,7 @@ public final class InputLogic {
public void onEndBatchInput(final SettingsValues settingValues,
final InputPointers batchPointers) {
mInputLogicHandler.onEndBatchInput(batchPointers, mAutoCommitSequenceNumber);
+ ++mAutoCommitSequenceNumber;
}
// TODO: remove this argument
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
index 71e120c5f..bf776cfc5 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
@@ -120,16 +120,10 @@ public class Ver2DictDecoder extends AbstractDictDecoder {
// used only for testing.
private final DictionaryBufferFactory mBufferFactory;
protected DictBuffer mDictBuffer;
- private final BinaryDictionary mBinaryDictionary;
/* package */ Ver2DictDecoder(final File file, final int factoryFlag) {
mDictionaryBinaryFile = file;
mDictBuffer = null;
- // dictType is not being used in dicttool. Passing an empty string.
- mBinaryDictionary = new BinaryDictionary(file.getAbsolutePath(),
- 0 /* offset */, file.length() /* length */, true /* useFullEditDistance */,
- null /* locale */, "" /* dictType */, false /* isUpdatable */);
-
if ((factoryFlag & MASK_DICTBUFFER) == USE_READONLY_BYTEBUFFER) {
mBufferFactory = new DictionaryBufferFromReadOnlyByteBufferFactory();
} else if ((factoryFlag & MASK_DICTBUFFER) == USE_BYTEARRAY) {
@@ -144,10 +138,6 @@ public class Ver2DictDecoder extends AbstractDictDecoder {
/* package */ Ver2DictDecoder(final File file, final DictionaryBufferFactory factory) {
mDictionaryBinaryFile = file;
mBufferFactory = factory;
- // dictType is not being used in dicttool. Passing an empty string.
- mBinaryDictionary = new BinaryDictionary(file.getAbsolutePath(),
- 0 /* offset */, file.length() /* length */, true /* useFullEditDistance */,
- null /* locale */, "" /* dictType */, false /* isUpdatable */);
}
@Override
@@ -172,7 +162,13 @@ public class Ver2DictDecoder extends AbstractDictDecoder {
@Override
public DictionaryHeader readHeader() throws IOException, UnsupportedFormatException {
- final DictionaryHeader header = mBinaryDictionary.getHeader();
+ // dictType is not being used in dicttool. Passing an empty string.
+ final BinaryDictionary binaryDictionary = new BinaryDictionary(
+ mDictionaryBinaryFile.getAbsolutePath(), 0 /* offset */,
+ mDictionaryBinaryFile.length() /* length */, true /* useFullEditDistance */,
+ null /* locale */, "" /* dictType */, false /* isUpdatable */);
+ final DictionaryHeader header = binaryDictionary.getHeader();
+ binaryDictionary.close();
if (header == null) {
throw new IOException("Cannot read the dictionary header.");
}
@@ -254,6 +250,11 @@ public class Ver2DictDecoder extends AbstractDictDecoder {
@Override
public FusionDictionary readDictionaryBinary(final boolean deleteDictIfBroken)
throws FileNotFoundException, IOException, UnsupportedFormatException {
+ // dictType is not being used in dicttool. Passing an empty string.
+ final BinaryDictionary binaryDictionary = new BinaryDictionary(
+ mDictionaryBinaryFile.getAbsolutePath(), 0 /* offset */,
+ mDictionaryBinaryFile.length() /* length */, true /* useFullEditDistance */,
+ null /* locale */, "" /* dictType */, false /* isUpdatable */);
final DictionaryHeader header = readHeader();
final FusionDictionary fusionDict =
new FusionDictionary(new FusionDictionary.PtNodeArray(), header.mDictionaryOptions);
@@ -261,11 +262,11 @@ public class Ver2DictDecoder extends AbstractDictDecoder {
final ArrayList<WordProperty> wordProperties = CollectionUtils.newArrayList();
do {
final BinaryDictionary.GetNextWordPropertyResult result =
- mBinaryDictionary.getNextWordProperty(token);
+ binaryDictionary.getNextWordProperty(token);
final WordProperty wordProperty = result.mWordProperty;
if (wordProperty == null) {
+ binaryDictionary.close();
if (deleteDictIfBroken) {
- mBinaryDictionary.close();
mDictionaryBinaryFile.delete();
}
return null;
@@ -294,6 +295,7 @@ public class Ver2DictDecoder extends AbstractDictDecoder {
fusionDict.setBigram(word0, bigram.mWord, bigram.mProbabilityInfo);
}
}
+ binaryDictionary.close();
return fusionDict;
}
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
index 88fff38f2..afe82317e 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
@@ -35,7 +35,6 @@ public class Ver4DictDecoder extends AbstractDictDecoder {
private static final String TAG = Ver4DictDecoder.class.getSimpleName();
final File mDictDirectory;
- final BinaryDictionary mBinaryDictionary;
@UsedForTesting
/* package */ Ver4DictDecoder(final File dictDirectory, final int factoryFlag) {
@@ -45,24 +44,32 @@ public class Ver4DictDecoder extends AbstractDictDecoder {
@UsedForTesting
/* package */ Ver4DictDecoder(final File dictDirectory, final DictionaryBufferFactory factory) {
mDictDirectory = dictDirectory;
- // dictType is not being used in dicttool. Passing an empty string.
- mBinaryDictionary = new BinaryDictionary(dictDirectory.getAbsolutePath(),
- 0 /* offset */, 0 /* length */, true /* useFullEditDistance */, null /* locale */,
- "" /* dictType */, true /* isUpdatable */);
+
}
@Override
public DictionaryHeader readHeader() throws IOException, UnsupportedFormatException {
- final DictionaryHeader header = mBinaryDictionary.getHeader();
+ // dictType is not being used in dicttool. Passing an empty string.
+ final BinaryDictionary binaryDictionary= new BinaryDictionary(
+ mDictDirectory.getAbsolutePath(), 0 /* offset */, 0 /* length */,
+ true /* useFullEditDistance */, null /* locale */,
+ "" /* dictType */, true /* isUpdatable */);
+ final DictionaryHeader header = binaryDictionary.getHeader();
+ binaryDictionary.close();
if (header == null) {
throw new IOException("Cannot read the dictionary header.");
}
- return mBinaryDictionary.getHeader();
+ return header;
}
@Override
public FusionDictionary readDictionaryBinary(final boolean deleteDictIfBroken)
throws FileNotFoundException, IOException, UnsupportedFormatException {
+ // dictType is not being used in dicttool. Passing an empty string.
+ final BinaryDictionary binaryDictionary = new BinaryDictionary(
+ mDictDirectory.getAbsolutePath(), 0 /* offset */, 0 /* length */,
+ true /* useFullEditDistance */, null /* locale */,
+ "" /* dictType */, true /* isUpdatable */);
final DictionaryHeader header = readHeader();
final FusionDictionary fusionDict =
new FusionDictionary(new FusionDictionary.PtNodeArray(), header.mDictionaryOptions);
@@ -70,11 +77,11 @@ public class Ver4DictDecoder extends AbstractDictDecoder {
final ArrayList<WordProperty> wordProperties = CollectionUtils.newArrayList();
do {
final BinaryDictionary.GetNextWordPropertyResult result =
- mBinaryDictionary.getNextWordProperty(token);
+ binaryDictionary.getNextWordProperty(token);
final WordProperty wordProperty = result.mWordProperty;
if (wordProperty == null) {
+ binaryDictionary.close();
if (deleteDictIfBroken) {
- mBinaryDictionary.close();
FileUtils.deleteRecursively(mDictDirectory);
}
return null;
@@ -103,6 +110,7 @@ public class Ver4DictDecoder extends AbstractDictDecoder {
fusionDict.setBigram(word0, bigram.mWord, bigram.mProbabilityInfo);
}
}
+ binaryDictionary.close();
return fusionDict;
}
}
diff --git a/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java b/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java
index 24af09484..2cc22fae4 100644
--- a/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java
+++ b/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java
@@ -20,6 +20,8 @@ import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
+import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.utils.RunInLocale;
@@ -32,6 +34,18 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
private static final int ARMENIAN_FULL_STOP = '\u0589';
private static final int ARMENIAN_COMMA = '\u055D';
+ private int mScreenMetrics;
+
+ private boolean isPhone() {
+ return mScreenMetrics == Constants.SCREEN_METRICS_SMALL_PHONE
+ || mScreenMetrics == Constants.SCREEN_METRICS_LARGE_PHONE;
+ }
+
+ private boolean isTablet() {
+ return mScreenMetrics == Constants.SCREEN_METRICS_SMALL_TABLET
+ || mScreenMetrics == Constants.SCREEN_METRICS_LARGE_TABLET;
+ }
+
private SpacingAndPunctuations ENGLISH;
private SpacingAndPunctuations FRENCH;
private SpacingAndPunctuations GERMAN;
@@ -56,6 +70,8 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
protected void setUp() throws Exception {
super.setUp();
+ mScreenMetrics = mContext.getResources().getInteger(R.integer.config_screen_metrics);
+
// Language only
ENGLISH = getSpacingAndPunctuations(Locale.ENGLISH);
FRENCH = getSpacingAndPunctuations(Locale.FRENCH);
@@ -373,23 +389,39 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
assertTrue(SWISS_GERMAN.mUsesGermanRules);
}
- private static final String[] PUNCTUATION_LABELS_LTR = {
+ // Punctuations for phone.
+ private static final String[] PUNCTUATION_LABELS_PHONE = {
"!", "?", ",", ":", ";", "\"", "(", ")", "'", "-", "/", "@", "_"
};
- private static final String[] PUNCTUATION_WORDS_LTR = PUNCTUATION_LABELS_LTR;
- private static final String[] PUNCTUATION_WORDS_HEBREW = {
+ private static final String[] PUNCTUATION_WORDS_PHONE_LTR = PUNCTUATION_LABELS_PHONE;
+ private static final String[] PUNCTUATION_WORDS_PHONE_HEBREW = {
"!", "?", ",", ":", ";", "\"", ")", "(", "'", "-", "/", "@", "_"
};
// U+061F: "؟" ARABIC QUESTION MARK
// U+060C: "،" ARABIC COMMA
// U+061B: "؛" ARABIC SEMICOLON
- private static final String[] PUNCTUATION_LABELS_ARABIC_PERSIAN = {
+ private static final String[] PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN = {
"!", "\u061F", "\u060C", ":", "\u061B", "\"", "(", ")", "'", "-", "/", "@", "_"
};
- private static final String[] PUNCTUATION_WORDS_ARABIC_PERSIAN = {
+ private static final String[] PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN = {
"!", "\u061F", "\u060C", ":", "\u061B", "\"", ")", "(", "'", "-", "/", "@", "_"
};
+ // Punctuations for tablet.
+ private static final String[] PUNCTUATION_LABELS_TABLET = {
+ ":", ";", "\"", "(", ")", "'", "-", "/", "@", "_"
+ };
+ private static final String[] PUNCTUATION_WORDS_TABLET_LTR = PUNCTUATION_LABELS_TABLET;
+ private static final String[] PUNCTUATION_WORDS_TABLET_HEBREW = {
+ ":", ";", "\"", ")", "(", "'", "-", "/", "@", "_"
+ };
+ private static final String[] PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN = {
+ "!", "\u061F", ":", "\u061B", "\"", "'", "(", ")", "-", "/", "@", "_"
+ };
+ private static final String[] PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN = {
+ "!", "\u061F", ":", "\u061B", "\"", "'", ")", "(", "-", "/", "@", "_"
+ };
+
private static void testingStandardPunctuationSuggestions(final SpacingAndPunctuations sp,
final String[] punctuationLabels, final String[] punctuationWords) {
final SuggestedWords suggestedWords = sp.mSuggestPuncList;
@@ -407,19 +439,39 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
}
}
- // TODO: Add tests for tablet as well
- public void testPunctuationSuggestions() {
+ public void testPhonePunctuationSuggestions() {
+ if (!isPhone()) {
+ return;
+ }
+ testingStandardPunctuationSuggestions(ENGLISH,
+ PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR);
+ testingStandardPunctuationSuggestions(FRENCH,
+ PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR);
+ testingStandardPunctuationSuggestions(GERMAN,
+ PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR);
+ testingStandardPunctuationSuggestions(ARABIC,
+ PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN, PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN);
+ testingStandardPunctuationSuggestions(PERSIAN,
+ PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN, PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN);
+ testingStandardPunctuationSuggestions(HEBREW,
+ PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_HEBREW);
+ }
+
+ public void testTabletPunctuationSuggestions() {
+ if (!isTablet()) {
+ return;
+ }
testingStandardPunctuationSuggestions(ENGLISH,
- PUNCTUATION_LABELS_LTR, PUNCTUATION_WORDS_LTR);
+ PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR);
testingStandardPunctuationSuggestions(FRENCH,
- PUNCTUATION_LABELS_LTR, PUNCTUATION_WORDS_LTR);
+ PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR);
testingStandardPunctuationSuggestions(GERMAN,
- PUNCTUATION_LABELS_LTR, PUNCTUATION_WORDS_LTR);
+ PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR);
testingStandardPunctuationSuggestions(ARABIC,
- PUNCTUATION_LABELS_ARABIC_PERSIAN, PUNCTUATION_WORDS_ARABIC_PERSIAN);
+ PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN, PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN);
testingStandardPunctuationSuggestions(PERSIAN,
- PUNCTUATION_LABELS_ARABIC_PERSIAN, PUNCTUATION_WORDS_ARABIC_PERSIAN);
+ PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN, PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN);
testingStandardPunctuationSuggestions(HEBREW,
- PUNCTUATION_LABELS_LTR, PUNCTUATION_WORDS_HEBREW);
+ PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_HEBREW);
}
}