mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "Fix showing important notice even at beginning of sentence"
This commit is contained in:
commit
0055d26164
@ -595,8 +595,9 @@ public class DictionaryFacilitator {
|
|||||||
final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo,
|
final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo,
|
||||||
final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId) {
|
final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId) {
|
||||||
final DictionaryGroup[] dictionaryGroups = mDictionaryGroups;
|
final DictionaryGroup[] dictionaryGroups = mDictionaryGroups;
|
||||||
final SuggestionResults suggestionResults =
|
final SuggestionResults suggestionResults = new SuggestionResults(
|
||||||
new SuggestionResults(SuggestedWords.MAX_SUGGESTIONS);
|
SuggestedWords.MAX_SUGGESTIONS,
|
||||||
|
prevWordsInfo.mPrevWordsInfo[0].mIsBeginningOfSentence);
|
||||||
final float[] languageWeight = new float[] { Dictionary.NOT_A_LANGUAGE_WEIGHT };
|
final float[] languageWeight = new float[] { Dictionary.NOT_A_LANGUAGE_WEIGHT };
|
||||||
for (final DictionaryGroup dictionaryGroup : dictionaryGroups) {
|
for (final DictionaryGroup dictionaryGroup : dictionaryGroups) {
|
||||||
for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS) {
|
for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS) {
|
||||||
|
@ -1491,19 +1491,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||||||
final boolean isEmptyApplicationSpecifiedCompletions =
|
final boolean isEmptyApplicationSpecifiedCompletions =
|
||||||
currentSettingsValues.isApplicationSpecifiedCompletionsOn()
|
currentSettingsValues.isApplicationSpecifiedCompletionsOn()
|
||||||
&& suggestedWords.isEmpty();
|
&& suggestedWords.isEmpty();
|
||||||
final boolean noSuggestionsToShow = (SuggestedWords.EMPTY == suggestedWords)
|
final boolean noSuggestionsFromDictionaries = (SuggestedWords.EMPTY == suggestedWords)
|
||||||
|| suggestedWords.isPunctuationSuggestions()
|
|| suggestedWords.isPunctuationSuggestions()
|
||||||
|| isEmptyApplicationSpecifiedCompletions;
|
|| isEmptyApplicationSpecifiedCompletions;
|
||||||
if (shouldShowImportantNotice && noSuggestionsToShow) {
|
final boolean isBeginningOfSentencePrediction = (suggestedWords.mInputStyle
|
||||||
|
== SuggestedWords.INPUT_STYLE_BEGINNING_OF_SENTENCE_PREDICTION);
|
||||||
|
final boolean noSuggestionsToOverrideImportantNotice = noSuggestionsFromDictionaries
|
||||||
|
|| isBeginningOfSentencePrediction;
|
||||||
|
if (shouldShowImportantNotice && noSuggestionsToOverrideImportantNotice) {
|
||||||
if (mSuggestionStripView.maybeShowImportantNoticeTitle()) {
|
if (mSuggestionStripView.maybeShowImportantNoticeTitle()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentSettingsValues.isSuggestionsEnabledPerUserSettings()
|
if (currentSettingsValues.isSuggestionsEnabledPerUserSettings()
|
||||||
// We should clear suggestions if there is no suggestion to show.
|
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn()
|
||||||
|| noSuggestionsToShow
|
// We should clear the contextual strip if there is no suggestion from dictionaries.
|
||||||
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn()) {
|
|| noSuggestionsFromDictionaries) {
|
||||||
mSuggestionStripView.setSuggestions(suggestedWords,
|
mSuggestionStripView.setSuggestions(suggestedWords,
|
||||||
SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype()));
|
SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype()));
|
||||||
}
|
}
|
||||||
|
@ -188,8 +188,14 @@ public final class Suggest {
|
|||||||
suggestionsList = suggestionsContainer;
|
suggestionsList = suggestionsContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int inputStyle = resultsArePredictions ? SuggestedWords.INPUT_STYLE_PREDICTION :
|
final int inputStyle;
|
||||||
inputStyleIfNotPrediction;
|
if (resultsArePredictions) {
|
||||||
|
inputStyle = suggestionResults.mIsBeginningOfSentence
|
||||||
|
? SuggestedWords.INPUT_STYLE_BEGINNING_OF_SENTENCE_PREDICTION
|
||||||
|
: SuggestedWords.INPUT_STYLE_PREDICTION;
|
||||||
|
} else {
|
||||||
|
inputStyle = inputStyleIfNotPrediction;
|
||||||
|
}
|
||||||
callback.onGetSuggestedWords(new SuggestedWords(suggestionsList,
|
callback.onGetSuggestedWords(new SuggestedWords(suggestionsList,
|
||||||
suggestionResults.mRawSuggestions,
|
suggestionResults.mRawSuggestions,
|
||||||
// TODO: this first argument is lying. If this is a whitelisted word which is an
|
// TODO: this first argument is lying. If this is a whitelisted word which is an
|
||||||
@ -244,6 +250,8 @@ public final class Suggest {
|
|||||||
|
|
||||||
// In the batch input mode, the most relevant suggested word should act as a "typed word"
|
// In the batch input mode, the most relevant suggested word should act as a "typed word"
|
||||||
// (typedWordValid=true), not as an "auto correct word" (willAutoCorrect=false).
|
// (typedWordValid=true), not as an "auto correct word" (willAutoCorrect=false).
|
||||||
|
// Note that because this method is never used to get predictions, there is no need to
|
||||||
|
// modify inputType such in getSuggestedWordsForNonBatchInput.
|
||||||
callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer,
|
callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer,
|
||||||
suggestionResults.mRawSuggestions,
|
suggestionResults.mRawSuggestions,
|
||||||
true /* typedWordValid */,
|
true /* typedWordValid */,
|
||||||
|
@ -39,6 +39,7 @@ public class SuggestedWords {
|
|||||||
public static final int INPUT_STYLE_APPLICATION_SPECIFIED = 4;
|
public static final int INPUT_STYLE_APPLICATION_SPECIFIED = 4;
|
||||||
public static final int INPUT_STYLE_RECORRECTION = 5;
|
public static final int INPUT_STYLE_RECORRECTION = 5;
|
||||||
public static final int INPUT_STYLE_PREDICTION = 6;
|
public static final int INPUT_STYLE_PREDICTION = 6;
|
||||||
|
public static final int INPUT_STYLE_BEGINNING_OF_SENTENCE_PREDICTION = 7;
|
||||||
|
|
||||||
// The maximum number of suggestions available.
|
// The maximum number of suggestions available.
|
||||||
public static final int MAX_SUGGESTIONS = 18;
|
public static final int MAX_SUGGESTIONS = 18;
|
||||||
@ -80,10 +81,9 @@ public class SuggestedWords {
|
|||||||
final int inputStyle,
|
final int inputStyle,
|
||||||
final int sequenceNumber) {
|
final int sequenceNumber) {
|
||||||
this(suggestedWordInfoList, rawSuggestions,
|
this(suggestedWordInfoList, rawSuggestions,
|
||||||
(suggestedWordInfoList.isEmpty() || INPUT_STYLE_PREDICTION == inputStyle) ? null
|
(suggestedWordInfoList.isEmpty() || isPrediction(inputStyle)) ? null
|
||||||
: suggestedWordInfoList.get(INDEX_OF_TYPED_WORD).mWord,
|
: suggestedWordInfoList.get(INDEX_OF_TYPED_WORD).mWord,
|
||||||
typedWordValid, willAutoCorrect, isObsoleteSuggestions, inputStyle,
|
typedWordValid, willAutoCorrect, isObsoleteSuggestions, inputStyle, sequenceNumber);
|
||||||
sequenceNumber);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
|
public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
|
||||||
@ -180,6 +180,7 @@ public class SuggestedWords {
|
|||||||
return "SuggestedWords:"
|
return "SuggestedWords:"
|
||||||
+ " mTypedWordValid=" + mTypedWordValid
|
+ " mTypedWordValid=" + mTypedWordValid
|
||||||
+ " mWillAutoCorrect=" + mWillAutoCorrect
|
+ " mWillAutoCorrect=" + mWillAutoCorrect
|
||||||
|
+ " mInputStyle=" + mInputStyle
|
||||||
+ " words=" + Arrays.toString(mSuggestedWordInfoList.toArray());
|
+ " words=" + Arrays.toString(mSuggestedWordInfoList.toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,8 +387,13 @@ public class SuggestedWords {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isPrediction(final int inputStyle) {
|
||||||
|
return INPUT_STYLE_PREDICTION == inputStyle
|
||||||
|
|| INPUT_STYLE_BEGINNING_OF_SENTENCE_PREDICTION == inputStyle;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isPrediction() {
|
public boolean isPrediction() {
|
||||||
return INPUT_STYLE_PREDICTION == mInputStyle;
|
return isPrediction(mInputStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SuggestedWords is an immutable object, as much as possible. We must not just remove
|
// SuggestedWords is an immutable object, as much as possible. We must not just remove
|
||||||
|
@ -22,7 +22,6 @@ import com.android.inputmethod.latin.define.ProductionFlags;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,14 +30,17 @@ import java.util.TreeSet;
|
|||||||
*/
|
*/
|
||||||
public final class SuggestionResults extends TreeSet<SuggestedWordInfo> {
|
public final class SuggestionResults extends TreeSet<SuggestedWordInfo> {
|
||||||
public final ArrayList<SuggestedWordInfo> mRawSuggestions;
|
public final ArrayList<SuggestedWordInfo> mRawSuggestions;
|
||||||
|
// TODO: Instead of a boolean , we may want to include the context of this suggestion results,
|
||||||
|
// such as {@link PrevWordsInfo}.
|
||||||
|
public final boolean mIsBeginningOfSentence;
|
||||||
private final int mCapacity;
|
private final int mCapacity;
|
||||||
|
|
||||||
public SuggestionResults(final int capacity) {
|
public SuggestionResults(final int capacity, final boolean isBeginningOfSentence) {
|
||||||
this(sSuggestedWordInfoComparator, capacity);
|
this(sSuggestedWordInfoComparator, capacity, isBeginningOfSentence);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuggestionResults(final Comparator<SuggestedWordInfo> comparator,
|
private SuggestionResults(final Comparator<SuggestedWordInfo> comparator,
|
||||||
final int capacity) {
|
final int capacity, final boolean isBeginningOfSentence) {
|
||||||
super(comparator);
|
super(comparator);
|
||||||
mCapacity = capacity;
|
mCapacity = capacity;
|
||||||
if (ProductionFlags.INCLUDE_RAW_SUGGESTIONS) {
|
if (ProductionFlags.INCLUDE_RAW_SUGGESTIONS) {
|
||||||
@ -46,6 +48,7 @@ public final class SuggestionResults extends TreeSet<SuggestedWordInfo> {
|
|||||||
} else {
|
} else {
|
||||||
mRawSuggestions = null;
|
mRawSuggestions = null;
|
||||||
}
|
}
|
||||||
|
mIsBeginningOfSentence = isBeginningOfSentence;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user