aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/MainKeyboardView.java8
-rw-r--r--java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java19
-rw-r--r--java/src/com/android/inputmethod/keyboard/MoreKeysPanel.java12
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java2
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java53
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java38
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java8
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java2
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/FormatSpec.java11
-rw-r--r--java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java2
-rw-r--r--java/src/com/android/inputmethod/latin/settings/Settings.java1
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsValues.java5
-rw-r--r--java/src/com/android/inputmethod/latin/utils/StringUtils.java18
13 files changed, 111 insertions, 68 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index 1400e05c8..4b6e12f8e 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -932,11 +932,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override
public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
locatePreviewPlacerView();
- // TODO: Remove this check
- if (panel.isShowingInParent()) {
- panel.dismissMoreKeysPanel();
- }
- mPreviewPlacerView.addView(panel.getContainerView());
+ panel.showInParent(mPreviewPlacerView);
mMoreKeysPanel = panel;
dimEntireKeyboard(true /* dimmed */);
}
@@ -954,7 +950,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
public void onDismissMoreKeysPanel(final MoreKeysPanel panel) {
dimEntireKeyboard(false /* dimmed */);
if (isShowingMoreKeysPanel()) {
- mPreviewPlacerView.removeView(mMoreKeysPanel.getContainerView());
+ mMoreKeysPanel.removeFromParent();
mMoreKeysPanel = null;
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
index a7c468538..5b13e9a41 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
@@ -21,6 +21,7 @@ import android.content.res.Resources;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
+import android.view.ViewGroup;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R;
@@ -216,12 +217,26 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
return true;
}
- @Override
- public View getContainerView() {
+ private View getContainerView() {
return (View)getParent();
}
@Override
+ public void showInParent(final ViewGroup parentView) {
+ removeFromParent();
+ parentView.addView(getContainerView());
+ }
+
+ @Override
+ public void removeFromParent() {
+ final View containerView = getContainerView();
+ final ViewGroup currentParent = (ViewGroup)containerView.getParent();
+ if (currentParent != null) {
+ currentParent.removeView(containerView);
+ }
+ }
+
+ @Override
public boolean isShowingInParent() {
return (getContainerView().getParent() != null);
}
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysPanel.java b/java/src/com/android/inputmethod/keyboard/MoreKeysPanel.java
index 886c6286f..4a33e6536 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysPanel.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysPanel.java
@@ -17,6 +17,7 @@
package com.android.inputmethod.keyboard;
import android.view.View;
+import android.view.ViewGroup;
public interface MoreKeysPanel {
public interface Controller {
@@ -119,9 +120,16 @@ public interface MoreKeysPanel {
public int translateY(int y);
/**
- * Return the view containing the more keys panel.
+ * Show this {@link MoreKeysPanel} in the parent view.
+ *
+ * @param parentView the {@link ViewGroup} that hosts this {@link MoreKeysPanel}.
+ */
+ public void showInParent(ViewGroup parentView);
+
+ /**
+ * Remove this {@link MoreKeysPanel} from the parent view.
*/
- public View getContainerView();
+ public void removeFromParent();
/**
* Return whether the panel is currently being shown.
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index 7afd657a0..f785835b8 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -140,7 +140,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
// only, which right now use format 2 (dicts using format 4 use Decaying*, which overrides
// this method).
// TODO: Migrate these dicts to ver4 format, and remove this function.
- return formatVersion == 2;
+ return formatVersion == FormatSpec.VERSION2;
}
public boolean isValidDictionary() {
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 8b466559c..72d5435a8 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1469,7 +1469,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
ResearchLogger.latinIME_maybeDoubleSpacePeriod(textToInsert,
false /* isBatchMode */);
}
- mWordComposer.doubleSpacePeriod();
+ mWordComposer.discardPreviousWordForSuggestion();
mKeyboardSwitcher.updateShiftState();
return true;
}
@@ -2565,29 +2565,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final SettingsValues currentSettings = mSettings.getCurrent();
final int[] additionalFeaturesOptions = currentSettings.mAdditionalFeaturesSettingValues;
- final String previousWord;
- if (mWordComposer.isComposingWord() || mWordComposer.isBatchMode()) {
- previousWord = mWordComposer.getPreviousWord();
- } else {
- // Not composing: this is for prediction.
- // TODO: read the previous word earlier for prediction, like we are doing for
- // normal suggestions.
- previousWord = getNthPreviousWordForSuggestion(currentSettings, 1 /* nthPreviousWord*/);
- }
if (DEBUG) {
- // TODO: this is for checking consistency with older versions. Remove this when
- // we are confident this is stable.
- // We're checking the previous word in the text field against the memorized previous
- // word. If we are composing a word we should have the second word before the cursor
- // memorized, otherwise we should have the first.
- final String rereadPrevWord = getNthPreviousWordForSuggestion(currentSettings,
- mWordComposer.isComposingWord() ? 2 : 1);
- if (!TextUtils.equals(previousWord, rereadPrevWord)) {
- throw new RuntimeException("Unexpected previous word: "
- + previousWord + " <> " + rereadPrevWord);
- }
- }
- suggest.getSuggestedWords(mWordComposer, mWordComposer.getPreviousWord(),
+ if (mWordComposer.isComposingWord() || mWordComposer.isBatchMode()) {
+ final String previousWord = mWordComposer.getPreviousWordForSuggestion();
+ // TODO: this is for checking consistency with older versions. Remove this when
+ // we are confident this is stable.
+ // We're checking the previous word in the text field against the memorized previous
+ // word. If we are composing a word we should have the second word before the cursor
+ // memorized, otherwise we should have the first.
+ final String rereadPrevWord = getNthPreviousWordForSuggestion(currentSettings,
+ mWordComposer.isComposingWord() ? 2 : 1);
+ if (!TextUtils.equals(previousWord, rereadPrevWord)) {
+ throw new RuntimeException("Unexpected previous word: "
+ + previousWord + " <> " + rereadPrevWord);
+ }
+ }
+ }
+ suggest.getSuggestedWords(mWordComposer, mWordComposer.getPreviousWordForSuggestion(),
keyboard.getProximityInfo(),
currentSettings.mBlockPotentiallyOffensive, currentSettings.mCorrectionEnabled,
additionalFeaturesOptions, sessionId, sequenceNumber, callback);
@@ -2830,6 +2824,19 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// strings.
mLastComposedWord = mWordComposer.commitWord(commitType, chosenWord, separatorString,
prevWord);
+ final boolean shouldDiscardPreviousWordForSuggestion;
+ if (0 == StringUtils.codePointCount(separatorString)) {
+ // Separator is 0-length. Discard the word only if the current language has spaces.
+ shouldDiscardPreviousWordForSuggestion =
+ mSettings.getCurrent().mCurrentLanguageHasSpaces;
+ } else {
+ // Otherwise, we discard if the separator contains any non-whitespace.
+ shouldDiscardPreviousWordForSuggestion =
+ !StringUtils.containsOnlyWhitespace(separatorString);
+ }
+ if (shouldDiscardPreviousWordForSuggestion) {
+ mWordComposer.discardPreviousWordForSuggestion();
+ }
}
private void setPunctuationSuggestions() {
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 5ecfc67b2..7da97e57a 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -50,8 +50,9 @@ public final class WordComposer {
private final StringBuilder mTypedWord;
// The previous word (before the composing word). Used as context for suggestions. May be null
// after resetting and before starting a new composing word, or when there is no context like
- // at the start of text for example.
- private String mPreviousWord;
+ // at the start of text for example. It can also be set to null externally when the user
+ // enters a separator that does not let bigrams across, like a period or a comma.
+ private String mPreviousWordForSuggestion;
private String mAutoCorrection;
private boolean mIsResumed;
private boolean mIsBatchMode;
@@ -89,7 +90,7 @@ public final class WordComposer {
mIsBatchMode = false;
mCursorPositionWithinWord = 0;
mRejectedBatchModeSuggestion = null;
- mPreviousWord = null;
+ mPreviousWordForSuggestion = null;
refreshSize();
}
@@ -106,7 +107,7 @@ public final class WordComposer {
mIsBatchMode = source.mIsBatchMode;
mCursorPositionWithinWord = source.mCursorPositionWithinWord;
mRejectedBatchModeSuggestion = source.mRejectedBatchModeSuggestion;
- mPreviousWord = source.mPreviousWord;
+ mPreviousWordForSuggestion = source.mPreviousWordForSuggestion;
refreshSize();
}
@@ -124,7 +125,7 @@ public final class WordComposer {
mIsBatchMode = false;
mCursorPositionWithinWord = 0;
mRejectedBatchModeSuggestion = null;
- mPreviousWord = null;
+ mPreviousWordForSuggestion = null;
refreshSize();
}
@@ -305,7 +306,7 @@ public final class WordComposer {
addKeyInfo(codePoint, keyboard);
}
mIsResumed = true;
- mPreviousWord = previousWord;
+ mPreviousWordForSuggestion = previousWord;
}
/**
@@ -356,8 +357,8 @@ public final class WordComposer {
return mTypedWord.toString();
}
- public String getPreviousWord() {
- return mPreviousWord;
+ public String getPreviousWordForSuggestion() {
+ return mPreviousWordForSuggestion;
}
/**
@@ -419,7 +420,7 @@ public final class WordComposer {
public void setCapitalizedModeAndPreviousWordAtStartComposingTime(final int mode,
final String previousWord) {
mCapitalizedMode = mode;
- mPreviousWord = previousWord;
+ mPreviousWordForSuggestion = previousWord;
}
/**
@@ -471,12 +472,7 @@ public final class WordComposer {
mCapsCount = 0;
mDigitsCount = 0;
mIsBatchMode = false;
- final boolean isWhitespace = 1 == StringUtils.codePointCount(separatorString)
- && Character.isWhitespace(separatorString.codePointAt(0));
- // If not whitespace, we don't use the previous word for suggestion. This is consistent
- // with how we get the previous word for suggestion: see RichInputConnection#spaceRegex and
- // LatinIME#getNthPreviousWordForSuggestion.
- mPreviousWord = isWhitespace ? mTypedWord.toString() : null;
+ mPreviousWordForSuggestion = mTypedWord.toString();
mTypedWord.setLength(0);
mCodePointSize = 0;
mTrailingSingleQuotesCount = 0;
@@ -490,11 +486,11 @@ public final class WordComposer {
return lastComposedWord;
}
- public void doubleSpacePeriod() {
- // When a period was entered with a double space, the separator we got has been
- // changed by a period (see #commitWord). We should not use the previous word for
- // suggestion.
- mPreviousWord = null;
+ // Call this when the recorded previous word should be discarded. This is typically called
+ // when the user inputs a separator that's not whitespace (including the case of the
+ // double-space-to-period feature).
+ public void discardPreviousWordForSuggestion() {
+ mPreviousWordForSuggestion = null;
}
public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord,
@@ -509,7 +505,7 @@ public final class WordComposer {
mCursorPositionWithinWord = mCodePointSize;
mRejectedBatchModeSuggestion = null;
mIsResumed = true;
- mPreviousWord = previousWord;
+ mPreviousWordForSuggestion = previousWord;
}
public boolean isBatchMode() {
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
index 7f0aa777f..acabea10d 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
@@ -436,7 +436,7 @@ public final class BinaryDictDecoderUtils {
final FormatOptions options) {
dictDecoder.setPosition(headerSize);
final int count = dictDecoder.readPtNodeCount();
- int groupPos = headerSize + BinaryDictIOUtils.getPtNodeCountSize(count);
+ int groupPos = dictDecoder.getPosition();
final StringBuilder builder = new StringBuilder();
WeightedString result = null;
@@ -498,9 +498,9 @@ public final class BinaryDictDecoderUtils {
do { // Scan the linked-list node.
final int nodeArrayHeadPos = dictDecoder.getPosition();
final int count = dictDecoder.readPtNodeCount();
- int groupOffsetPos = nodeArrayHeadPos + BinaryDictIOUtils.getPtNodeCountSize(count);
+ int groupPos = dictDecoder.getPosition();
for (int i = count; i > 0; --i) { // Scan the array of PtNode.
- PtNodeInfo info = dictDecoder.readPtNode(groupOffsetPos, options);
+ PtNodeInfo info = dictDecoder.readPtNode(groupPos, options);
if (BinaryDictIOUtils.isMovedPtNode(info.mFlags, options)) continue;
ArrayList<WeightedString> shortcutTargets = info.mShortcutTargets;
ArrayList<WeightedString> bigrams = null;
@@ -536,7 +536,7 @@ public final class BinaryDictDecoderUtils {
0 != (info.mFlags & FormatSpec.FLAG_IS_NOT_A_WORD),
0 != (info.mFlags & FormatSpec.FLAG_IS_BLACKLISTED)));
}
- groupOffsetPos = info.mEndAddress;
+ groupPos = info.mEndAddress;
}
// reach the end of the array.
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
index 640d778bb..efe1b7b34 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
@@ -87,7 +87,7 @@ public final class BinaryDictIOUtils {
if (p.mNumOfPtNode == Position.NOT_READ_PTNODE_COUNT) {
p.mNumOfPtNode = dictDecoder.readPtNodeCount();
- p.mAddress += getPtNodeCountSize(p.mNumOfPtNode);
+ p.mAddress = dictDecoder.getPosition();
p.mPosition = 0;
}
if (p.mNumOfPtNode == 0) {
diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
index 2f6f194aa..437fa942b 100644
--- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
+++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
@@ -188,7 +188,7 @@ public final class FormatSpec {
// us to change the format during development while having testing devices remove
// older files with each upgrade, while still having a readable versioning scheme.
public static final int VERSION2 = 2;
- public static final int VERSION4 = 400;
+ public static final int VERSION4 = 401;
static final int MINIMUM_SUPPORTED_VERSION = VERSION2;
static final int MAXIMUM_SUPPORTED_VERSION = VERSION4;
@@ -351,18 +351,19 @@ public final class FormatSpec {
public static final String DICTIONARY_ID_ATTRIBUTE = "dictionary";
private static final String DICTIONARY_DESCRIPTION_ATTRIBUTE = "description";
public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
- final FormatOptions formatOptions) {
+ final FormatOptions formatOptions) throws UnsupportedFormatException {
mDictionaryOptions = dictionaryOptions;
mFormatOptions = formatOptions;
mBodyOffset = formatOptions.mVersion < VERSION4 ? headerSize : 0;
if (null == getLocaleString()) {
- throw new RuntimeException("Cannot create a FileHeader without a locale");
+ throw new UnsupportedFormatException("Cannot create a FileHeader without a locale");
}
if (null == getVersion()) {
- throw new RuntimeException("Cannot create a FileHeader without a version");
+ throw new UnsupportedFormatException(
+ "Cannot create a FileHeader without a version");
}
if (null == getId()) {
- throw new RuntimeException("Cannot create a FileHeader without an ID");
+ throw new UnsupportedFormatException("Cannot create a FileHeader without an ID");
}
}
diff --git a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
index 9b573b4b8..3a5c11554 100644
--- a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
+++ b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
@@ -53,7 +53,7 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
public static final int FREQUENCY_FOR_WORDS_IN_DICTS = FREQUENCY_FOR_TYPED;
public static final int FREQUENCY_FOR_WORDS_NOT_IN_DICTS = Dictionary.NOT_A_PROBABILITY;
- public static final int REQUIRED_BINARY_DICTIONARY_VERSION = 4;
+ public static final int REQUIRED_BINARY_DICTIONARY_VERSION = FormatSpec.VERSION4;
/** Locale for which this user history dictionary is storing words */
private final Locale mLocale;
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 714c3a97a..94f145813 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -53,6 +53,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_MISC_SETTINGS = "misc_settings";
public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings";
public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict";
+ public static final String PREF_KEY_USE_PERSONALIZED_DICTS = "pref_key_use_personalized_dicts";
public static final String PREF_KEY_USE_DOUBLE_SPACE_PERIOD =
"pref_key_use_double_space_period";
public static final String PREF_BLOCK_POTENTIALLY_OFFENSIVE =
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 06406c19b..d98e547fc 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -29,11 +29,9 @@ import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
-import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.utils.CollectionUtils;
-import com.android.inputmethod.latin.utils.InputTypeUtils;
import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
@@ -71,6 +69,7 @@ public final class SettingsValues {
public final boolean mIncludesOtherImesInLanguageSwitchList;
public final boolean mShowsLanguageSwitchKey;
public final boolean mUseContactsDict;
+ public final boolean mUsePersonalizedDicts;
public final boolean mUseDoubleSpacePeriod;
public final boolean mBlockPotentiallyOffensive;
// Use bigrams to predict the next word when there is no input for it yet
@@ -148,6 +147,7 @@ public final class SettingsValues {
Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST, false);
mShowsLanguageSwitchKey = Settings.readShowsLanguageSwitchKey(prefs);
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
+ mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true);
mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true);
mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res);
mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res);
@@ -206,6 +206,7 @@ public final class SettingsValues {
mIncludesOtherImesInLanguageSwitchList = false;
mShowsLanguageSwitchKey = true;
mUseContactsDict = true;
+ mUsePersonalizedDicts = true;
mUseDoubleSpacePeriod = true;
mBlockPotentiallyOffensive = true;
mAutoCorrectEnabled = true;
diff --git a/java/src/com/android/inputmethod/latin/utils/StringUtils.java b/java/src/com/android/inputmethod/latin/utils/StringUtils.java
index df420417d..85f44541e 100644
--- a/java/src/com/android/inputmethod/latin/utils/StringUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/StringUtils.java
@@ -250,6 +250,24 @@ public final class StringUtils {
return true;
}
+ /**
+ * Returns true if all code points in text are whitespace, false otherwise. Empty is true.
+ */
+ // Interestingly enough, U+00A0 NO-BREAK SPACE and U+200B ZERO-WIDTH SPACE are not considered
+ // whitespace, while EN SPACE, EM SPACE and IDEOGRAPHIC SPACES are.
+ public static boolean containsOnlyWhitespace(final String text) {
+ final int length = text.length();
+ int i = 0;
+ while (i < length) {
+ final int codePoint = text.codePointAt(i);
+ if (!Character.isWhitespace(codePoint)) {
+ return false;
+ }
+ i += Character.charCount(codePoint);
+ }
+ return true;
+ }
+
@UsedForTesting
public static boolean looksValidForDictionaryInsertion(final CharSequence text,
final SettingsValues settings) {