From b03447e1af950888d901fccbd2cc3e3b4a11ef98 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Thu, 18 Jul 2013 22:59:26 +0900 Subject: [PATCH] Move a couple classes to the utils package Change-Id: Ia14a2011d79bad7cd02697b9254705f6e2099442 --- java/src/com/android/inputmethod/latin/LatinIME.java | 5 +++-- java/src/com/android/inputmethod/latin/Suggest.java | 5 +++-- .../inputmethod/latin/UserHistoryDictionary.java | 1 + .../suggestions/SuggestionStripLayoutHelper.java | 4 ++-- .../AutoCorrectionUtils.java} | 12 ++++++++---- .../latin/{ => utils}/ByteArrayWrapper.java | 2 +- .../latin/makedict/BinaryDictIOTests.java | 2 +- .../latin/utils/UserHistoryDictIOUtilsTests.java | 2 +- tools/dicttool/Android.mk | 2 +- 9 files changed, 21 insertions(+), 14 deletions(-) rename java/src/com/android/inputmethod/latin/{AutoCorrection.java => utils/AutoCorrectionUtils.java} (93%) rename java/src/com/android/inputmethod/latin/{ => utils}/ByteArrayWrapper.java (97%) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 7890dbb3f..1e2a1a6bd 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -77,6 +77,7 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.suggestions.SuggestionStripView; import com.android.inputmethod.latin.utils.ApplicationUtils; +import com.android.inputmethod.latin.utils.AutoCorrectionUtils; import com.android.inputmethod.latin.utils.CapsModeUtils; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CompletionInfoUtils; @@ -2428,7 +2429,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen || SuggestedWordInfo.KIND_OOV_CORRECTION == suggestionInfo.mKind) && mSuggest != null // If the suggestion is not in the dictionary, the hint should be shown. - && !AutoCorrection.isValidWord(mSuggest, suggestion, true); + && !AutoCorrectionUtils.isValidWord(mSuggest, suggestion, true); if (mSettings.isInternal()) { LatinImeLoggerUtils.onSeparator((char)Constants.CODE_SPACE, @@ -2496,7 +2497,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } // We demote unrecognized words (frequency < 0, below) by specifying them as "invalid". // We don't add words with 0-frequency (assuming they would be profanity etc.). - final int maxFreq = AutoCorrection.getMaxFrequency( + final int maxFreq = AutoCorrectionUtils.getMaxFrequency( suggest.getUnigramDictionaries(), suggestion); if (maxFreq == 0) return null; userHistoryDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0); diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 8b31f4e99..ac497ec9f 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -22,6 +22,7 @@ import android.text.TextUtils; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; +import com.android.inputmethod.latin.utils.AutoCorrectionUtils; import com.android.inputmethod.latin.utils.BoundedTreeSet; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.StringUtils; @@ -231,7 +232,7 @@ public final class Suggest { // or if it's a 2+ characters non-word (i.e. it's not in the dictionary). final boolean allowsToBeAutoCorrected = (null != whitelistedWord && !whitelistedWord.equals(consideredWord)) - || (consideredWord.length() > 1 && !AutoCorrection.isValidWord(this, + || (consideredWord.length() > 1 && !AutoCorrectionUtils.isValidWord(this, consideredWord, wordComposer.isFirstCharCapitalized())); final boolean hasAutoCorrection; @@ -252,7 +253,7 @@ public final class Suggest { // auto-correct. hasAutoCorrection = false; } else { - hasAutoCorrection = AutoCorrection.suggestionExceedsAutoCorrectionThreshold( + hasAutoCorrection = AutoCorrectionUtils.suggestionExceedsAutoCorrectionThreshold( suggestionsSet.first(), consideredWord, mAutoCorrectionThreshold); } diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java index 8c668b810..2370ebe43 100644 --- a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java @@ -25,6 +25,7 @@ import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; +import com.android.inputmethod.latin.utils.ByteArrayWrapper; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils; import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.BigramDictionaryInterface; diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java index ce340b666..1dd04fc4d 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java @@ -45,10 +45,10 @@ import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; -import com.android.inputmethod.latin.AutoCorrection; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SuggestedWords; +import com.android.inputmethod.latin.utils.AutoCorrectionUtils; import com.android.inputmethod.latin.utils.ResourceUtils; import com.android.inputmethod.latin.utils.ViewLayoutUtils; @@ -279,7 +279,7 @@ final class SuggestionStripLayoutHelper { // If we auto-correct, then the autocorrection is in slot 0 and the typed word // is in slot 1. if (positionInStrip == mCenterPositionInStrip - && AutoCorrection.shouldBlockAutoCorrectionBySafetyNet( + && AutoCorrectionUtils.shouldBlockAutoCorrectionBySafetyNet( suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION), suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD))) { return 0xFFFF0000; diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/utils/AutoCorrectionUtils.java similarity index 93% rename from java/src/com/android/inputmethod/latin/AutoCorrection.java rename to java/src/com/android/inputmethod/latin/utils/AutoCorrectionUtils.java index 86be4295a..066c5fd32 100644 --- a/java/src/com/android/inputmethod/latin/AutoCorrection.java +++ b/java/src/com/android/inputmethod/latin/utils/AutoCorrectionUtils.java @@ -14,8 +14,12 @@ * limitations under the License. */ -package com.android.inputmethod.latin; +package com.android.inputmethod.latin.utils; +import com.android.inputmethod.latin.BinaryDictionary; +import com.android.inputmethod.latin.Dictionary; +import com.android.inputmethod.latin.LatinImeLogger; +import com.android.inputmethod.latin.Suggest; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import android.text.TextUtils; @@ -23,12 +27,12 @@ import android.util.Log; import java.util.concurrent.ConcurrentHashMap; -public final class AutoCorrection { +public final class AutoCorrectionUtils { private static final boolean DBG = LatinImeLogger.sDBG; - private static final String TAG = AutoCorrection.class.getSimpleName(); + private static final String TAG = AutoCorrectionUtils.class.getSimpleName(); private static final int MINIMUM_SAFETY_NET_CHAR_LENGTH = 4; - private AutoCorrection() { + private AutoCorrectionUtils() { // Purely static class: can't instantiate. } diff --git a/java/src/com/android/inputmethod/latin/ByteArrayWrapper.java b/java/src/com/android/inputmethod/latin/utils/ByteArrayWrapper.java similarity index 97% rename from java/src/com/android/inputmethod/latin/ByteArrayWrapper.java rename to java/src/com/android/inputmethod/latin/utils/ByteArrayWrapper.java index 15f70c50c..1bb27aa2b 100644 --- a/java/src/com/android/inputmethod/latin/ByteArrayWrapper.java +++ b/java/src/com/android/inputmethod/latin/utils/ByteArrayWrapper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.inputmethod.latin; +package com.android.inputmethod.latin.utils; import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface; diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java index 5ecacc1a8..ef4ed3396 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java @@ -22,12 +22,12 @@ import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; import android.util.SparseArray; -import com.android.inputmethod.latin.ByteArrayWrapper; import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface; import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader; import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup; import com.android.inputmethod.latin.makedict.FusionDictionary.Node; import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString; +import com.android.inputmethod.latin.utils.ByteArrayWrapper; import com.android.inputmethod.latin.utils.CollectionUtils; import java.io.File; diff --git a/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java index 0d829c5e6..8c301f446 100644 --- a/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java @@ -21,11 +21,11 @@ import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; -import com.android.inputmethod.latin.ByteArrayWrapper; import com.android.inputmethod.latin.UserHistoryDictionaryBigramList; import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup; +import com.android.inputmethod.latin.utils.ByteArrayWrapper; import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.BigramDictionaryInterface; import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.OnAddWordListener; diff --git a/tools/dicttool/Android.mk b/tools/dicttool/Android.mk index 7832c1463..d06be58a7 100644 --- a/tools/dicttool/Android.mk +++ b/tools/dicttool/Android.mk @@ -27,7 +27,7 @@ DICTTOOL_ONDEVICE_TESTS_DIRECTORY := \ $(LATINIME_DIR)/tests/src/com/android/inputmethod/latin/makedict/ USED_TARGETTED_UTILS := \ - $(LATINIME_CORE_SOURCE_DIRECTORY)/ByteArrayWrapper.java \ + $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/ByteArrayWrapper.java \ $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/CollectionUtils.java LOCAL_MAIN_SRC_FILES := $(call all-java-files-under, $(MAKEDICT_CORE_SOURCE_DIRECTORY))