diff options
author | 2010-12-27 20:13:16 +0900 | |
---|---|---|
committer | 2010-12-27 20:13:16 +0900 | |
commit | d12def6dc8ba3a2f47b90e6d5d442f315152c6d4 (patch) | |
tree | 7274b29f518f94d31cd5c995d1b46bfc323de818 /java/src/com/android/inputmethod/latin/SuggestedWords.java | |
parent | b80f171623a11bceb99b563594162d0034b9bde8 (diff) | |
parent | bfe2b534457d946645d483e311249787ba4fc3ae (diff) | |
download | latinime-d12def6dc8ba3a2f47b90e6d5d442f315152c6d4.tar.gz latinime-d12def6dc8ba3a2f47b90e6d5d442f315152c6d4.tar.xz latinime-d12def6dc8ba3a2f47b90e6d5d442f315152c6d4.zip |
Merge remote branch 'goog/master' into merge
Conflicts:
java/res/values-cs/strings.xml
java/res/values-da/strings.xml
java/res/values-de/strings.xml
java/res/values-el/strings.xml
java/res/values-es-rUS/strings.xml
java/res/values-es/strings.xml
java/res/values-fr/strings.xml
java/res/values-it/strings.xml
java/res/values-ja/strings.xml
java/res/values-ko/strings.xml
java/res/values-nb/strings.xml
java/res/values-nl/strings.xml
java/res/values-pl/strings.xml
java/res/values-pt-rPT/strings.xml
java/res/values-pt/strings.xml
java/res/values-ru/strings.xml
java/res/values-sv/strings.xml
java/res/values-tr/strings.xml
java/res/values-xlarge/dimens.xml
java/res/values-zh-rCN/strings.xml
java/res/values-zh-rTW/strings.xml
java/res/values/bools.xml
java/res/xml/kbd_qwerty_rows.xml
java/res/xml/method.xml
java/res/xml/prefs.xml
Change-Id: I8768d16965e6e82c14ee742b9ada56438497eb86
Diffstat (limited to 'java/src/com/android/inputmethod/latin/SuggestedWords.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/SuggestedWords.java | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java new file mode 100644 index 000000000..5398b77b2 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2010 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. + */ + +package com.android.inputmethod.latin; + +import android.view.inputmethod.CompletionInfo; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class SuggestedWords { + public static final SuggestedWords EMPTY = new SuggestedWords(null, false, false, false, null); + + public final List<CharSequence> mWords; + public final boolean mIsApplicationSpecifiedCompletions; + public final boolean mTypedWordValid; + public final boolean mHasMinimalSuggestion; + public final Object[] mDebugInfo; + + private SuggestedWords(List<CharSequence> words, boolean isApplicationSpecifiedCompletions, + boolean typedWordValid, boolean hasMinamlSuggestion, Object[] debugInfo) { + if (words != null) { + mWords = words; + } else { + mWords = Collections.emptyList(); + } + mIsApplicationSpecifiedCompletions = isApplicationSpecifiedCompletions; + mTypedWordValid = typedWordValid; + mHasMinimalSuggestion = hasMinamlSuggestion; + mDebugInfo = debugInfo; + } + + public int size() { + return mWords.size(); + } + + public CharSequence getWord(int pos) { + return mWords.get(pos); + } + + public boolean hasAutoCorrectionWord() { + return mHasMinimalSuggestion && size() > 1 && !mTypedWordValid; + } + + public boolean hasWordAboveAutoCorrectionScoreThreshold() { + return mHasMinimalSuggestion && ((size() > 1 && !mTypedWordValid) || mTypedWordValid); + } + + public static class Builder { + private List<CharSequence> mWords; + private boolean mIsCompletions; + private boolean mTypedWordValid; + private boolean mHasMinimalSuggestion; + private Object[] mDebugInfo; + + public Builder() { + // Nothing to do here. + } + + public Builder addWords(List<CharSequence> words) { + for (final CharSequence word : words) + addWord(word); + return this; + } + + public Builder setDebugInfo(Object[] debuginfo) { + mDebugInfo = debuginfo; + return this; + } + + public Builder addWord(int pos, CharSequence word) { + if (mWords == null) + mWords = new ArrayList<CharSequence>(); + mWords.add(pos, word); + return this; + } + + public Builder addWord(CharSequence word) { + if (mWords == null) + mWords = new ArrayList<CharSequence>(); + mWords.add(word); + return this; + } + + public Builder setApplicationSpecifiedCompletions(CompletionInfo[] infos) { + for (CompletionInfo info : infos) + addWord(info.getText()); + mIsCompletions = true; + return this; + } + + public Builder setTypedWordValid(boolean typedWordValid) { + mTypedWordValid = typedWordValid; + return this; + } + + public Builder setHasMinimalSuggestion(boolean hasMinamlSuggestion) { + mHasMinimalSuggestion = hasMinamlSuggestion; + return this; + } + + // Should get rid of the first one (what the user typed previously) from suggestions + // and replace it with what the user currently typed. + public Builder addTypedWordAndPreviousSuggestions(CharSequence typedWord, + SuggestedWords previousSuggestions) { + if (mWords != null) mWords.clear(); + addWord(typedWord); + final int previousSize = previousSuggestions.size(); + for (int pos = 1; pos < previousSize; pos++) + addWord(previousSuggestions.getWord(pos)); + mIsCompletions = false; + mTypedWordValid = false; + mHasMinimalSuggestion = (previousSize > 1); + return this; + } + + public SuggestedWords build() { + return new SuggestedWords(mWords, mIsCompletions, mTypedWordValid, + mHasMinimalSuggestion, mDebugInfo); + } + + public int size() { + return mWords == null ? 0 : mWords.size(); + } + + public CharSequence getWord(int pos) { + return mWords.get(pos); + } + } +} |