Refactor logic to determine showing suggestions strip or not
The logic to determine when the suggestions strip (a.k.a. the contextual strip) should be shown is already complex. In addition to that the voice input key get shown on the strip as well. There are a several factors to be considered and a few things to control. - The password input field shouldn't have the strip. - Show voice input key on the strip or not. - User preference settings "Show Voice Input Key". - A voice IME exists and is enabled. - The input field may have a private IME option to prevent the voice input key from being displayed. - Application can specify auto completions. - Full screen mode or not. - User preference settings "Show correction suggestions". - Always show, Show in portrait mode, Always hide. - The input field may have flags to prevent showing suggestions or auto corrections. - Suggestions is empty or not. - An important notice may be shown. Bug: 14981852 Bug: 15436479 Change-Id: I3050fd53ee6271fc64a8f17b6b12d9581d37b750
This commit is contained in:
parent
8cae9f50b4
commit
987bff9136
3 changed files with 34 additions and 61 deletions
|
@ -1003,7 +1003,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
null /* rawSuggestions */, false /* typedWordValid */, false /* willAutoCorrect */,
|
||||
false /* isObsoleteSuggestions */, false /* isPrediction */);
|
||||
// When in fullscreen mode, show completions generated by the application forcibly
|
||||
setSuggestedWords(suggestedWords, true /* isSuggestionStripVisible */);
|
||||
setSuggestedWords(suggestedWords);
|
||||
}
|
||||
|
||||
private int getAdjustedBackingViewHeight() {
|
||||
|
@ -1306,30 +1306,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
// Nothing to do so far.
|
||||
}
|
||||
|
||||
private boolean isSuggestionStripVisible() {
|
||||
if (!hasSuggestionStripView()) {
|
||||
return false;
|
||||
}
|
||||
if (mSuggestionStripView.isShowingAddToDictionaryHint()) {
|
||||
return true;
|
||||
}
|
||||
final SettingsValues currentSettings = mSettings.getCurrent();
|
||||
if (null == currentSettings) {
|
||||
return false;
|
||||
}
|
||||
if (ImportantNoticeUtils.shouldShowImportantNotice(this,
|
||||
currentSettings.mInputAttributes)) {
|
||||
return true;
|
||||
}
|
||||
if (!currentSettings.isCurrentOrientationAllowingSuggestionsPerUserSettings()) {
|
||||
return false;
|
||||
}
|
||||
if (currentSettings.isApplicationSpecifiedCompletionsOn()) {
|
||||
return true;
|
||||
}
|
||||
return currentSettings.isSuggestionsRequested();
|
||||
}
|
||||
|
||||
public boolean hasSuggestionStripView() {
|
||||
return null != mSuggestionStripView;
|
||||
}
|
||||
|
@ -1347,9 +1323,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
mSuggestionStripView.dismissAddToDictionaryHint();
|
||||
}
|
||||
|
||||
// TODO[IL]: Define a clear interface for this
|
||||
public void setSuggestedWords(final SuggestedWords suggestedWords,
|
||||
final boolean isSuggestionStripVisible) {
|
||||
private void setSuggestedWords(final SuggestedWords suggestedWords) {
|
||||
mInputLogic.setSuggestedWords(suggestedWords);
|
||||
// TODO: Modify this when we support suggestions with hard keyboard
|
||||
if (!hasSuggestionStripView()) {
|
||||
|
@ -1359,27 +1333,34 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
return;
|
||||
}
|
||||
|
||||
mSuggestionStripView.updateVisibility(isSuggestionStripVisible, isFullscreenMode());
|
||||
if (!isSuggestionStripVisible) {
|
||||
final SettingsValues currentSettingsValues = mSettings.getCurrent();
|
||||
final boolean shouldShowImportantNotice =
|
||||
ImportantNoticeUtils.shouldShowImportantNotice(this);
|
||||
final boolean shouldShowSuggestionsStripUnlessPassword = shouldShowImportantNotice
|
||||
|| currentSettingsValues.mShowsVoiceInputKey
|
||||
|| currentSettingsValues.isSuggestionsRequested()
|
||||
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn();
|
||||
final boolean shouldShowSuggestionsStrip = shouldShowSuggestionsStripUnlessPassword
|
||||
&& !currentSettingsValues.mInputAttributes.mIsPasswordField;
|
||||
mSuggestionStripView.updateVisibility(shouldShowSuggestionsStrip, isFullscreenMode());
|
||||
if (!shouldShowSuggestionsStrip) {
|
||||
return;
|
||||
}
|
||||
|
||||
final SettingsValues currentSettings = mSettings.getCurrent();
|
||||
final boolean showSuggestions;
|
||||
// May show the important notice when there are no suggestions to show,
|
||||
if (SuggestedWords.EMPTY == suggestedWords
|
||||
// or the suggestion strip is expected to show punctuation suggestions,
|
||||
final boolean isEmptyApplicationSpecifiedCompletions =
|
||||
currentSettingsValues.isApplicationSpecifiedCompletionsOn()
|
||||
&& suggestedWords.isEmpty();
|
||||
final boolean noSuggestionsToShow = (SuggestedWords.EMPTY == suggestedWords)
|
||||
|| suggestedWords.isPunctuationSuggestions()
|
||||
// or it's not requested to show suggestions by the input field,
|
||||
|| !currentSettings.isSuggestionsRequested()
|
||||
// or the "show correction suggestions" settings is off by users preference.
|
||||
|| !currentSettings.isCurrentOrientationAllowingSuggestionsPerUserSettings()) {
|
||||
showSuggestions = !mSuggestionStripView.maybeShowImportantNoticeTitle(
|
||||
currentSettings.mInputAttributes);
|
||||
|| isEmptyApplicationSpecifiedCompletions;
|
||||
final boolean isShowingImportantNotice;
|
||||
if (shouldShowImportantNotice && noSuggestionsToShow) {
|
||||
isShowingImportantNotice = mSuggestionStripView.maybeShowImportantNoticeTitle();
|
||||
} else {
|
||||
showSuggestions = true;
|
||||
isShowingImportantNotice = false;
|
||||
}
|
||||
if (showSuggestions) {
|
||||
|
||||
if (currentSettingsValues.isSuggestionsRequested() && !isShowingImportantNotice) {
|
||||
mSuggestionStripView.setSuggestions(suggestedWords,
|
||||
SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype()));
|
||||
}
|
||||
|
@ -1442,7 +1423,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
setNeutralSuggestionStrip();
|
||||
} else {
|
||||
mInputLogic.mWordComposer.setAutoCorrection(autoCorrection);
|
||||
setSuggestedWords(suggestedWords, isSuggestionStripVisible());
|
||||
setSuggestedWords(suggestedWords);
|
||||
}
|
||||
// Cache the auto-correction in accessibility code so we can speak it if the user
|
||||
// touches a key that will insert it.
|
||||
|
@ -1475,7 +1456,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
final SettingsValues currentSettings = mSettings.getCurrent();
|
||||
final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled
|
||||
? SuggestedWords.EMPTY : currentSettings.mSpacingAndPunctuations.mSuggestPuncList;
|
||||
setSuggestedWords(neutralSuggestions, isSuggestionStripVisible());
|
||||
setSuggestedWords(neutralSuggestions);
|
||||
}
|
||||
|
||||
// TODO: Make this private
|
||||
|
|
|
@ -42,7 +42,6 @@ import com.android.inputmethod.keyboard.MainKeyboardView;
|
|||
import com.android.inputmethod.keyboard.MoreKeysPanel;
|
||||
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
|
||||
import com.android.inputmethod.latin.Constants;
|
||||
import com.android.inputmethod.latin.InputAttributes;
|
||||
import com.android.inputmethod.latin.LatinImeLogger;
|
||||
import com.android.inputmethod.latin.R;
|
||||
import com.android.inputmethod.latin.SuggestedWords;
|
||||
|
@ -207,9 +206,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
final int visibility = shouldBeVisible ? VISIBLE : (isFullscreenMode ? GONE : INVISIBLE);
|
||||
setVisibility(visibility);
|
||||
final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent();
|
||||
final boolean shouldShowVoiceKey = (currentSettingsValues != null)
|
||||
&& currentSettingsValues.mShowsVoiceInputKey;
|
||||
mVoiceKey.setVisibility(shouldShowVoiceKey ? VISIBLE : INVISIBLE);
|
||||
mVoiceKey.setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : INVISIBLE);
|
||||
}
|
||||
|
||||
public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) {
|
||||
|
@ -249,8 +246,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
// This method checks if we should show the important notice (checks on permanent storage if
|
||||
// it has been shown once already or not, and if in the setup wizard). If applicable, it shows
|
||||
// the notice. In all cases, it returns true if it was shown, false otherwise.
|
||||
public boolean maybeShowImportantNoticeTitle(final InputAttributes inputAttributes) {
|
||||
if (!ImportantNoticeUtils.shouldShowImportantNotice(getContext(), inputAttributes)) {
|
||||
public boolean maybeShowImportantNoticeTitle() {
|
||||
if (!ImportantNoticeUtils.shouldShowImportantNotice(getContext())) {
|
||||
return false;
|
||||
}
|
||||
if (getWidth() <= 0) {
|
||||
|
@ -475,7 +472,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
// Called by the framework when the size is known. Show the important notice if applicable.
|
||||
// This may be overriden by showing suggestions later, if applicable.
|
||||
if (oldw <= 0 && w > 0) {
|
||||
maybeShowImportantNoticeTitle(Settings.getInstance().getCurrent().mInputAttributes);
|
||||
maybeShowImportantNoticeTitle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import android.provider.Settings.SettingNotFoundException;
|
|||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.inputmethod.latin.InputAttributes;
|
||||
import com.android.inputmethod.latin.R;
|
||||
|
||||
public final class ImportantNoticeUtils {
|
||||
|
@ -78,14 +77,7 @@ public final class ImportantNoticeUtils {
|
|||
return getCurrentImportantNoticeVersion(context) > lastVersion;
|
||||
}
|
||||
|
||||
public static boolean shouldShowImportantNotice(final Context context,
|
||||
final InputAttributes inputAttributes) {
|
||||
if (inputAttributes == null || inputAttributes.mIsPasswordField) {
|
||||
return false;
|
||||
}
|
||||
if (isInSystemSetupWizard(context)) {
|
||||
return false;
|
||||
}
|
||||
public static boolean shouldShowImportantNotice(final Context context) {
|
||||
if (!hasNewImportantNotice(context)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -93,6 +85,9 @@ public final class ImportantNoticeUtils {
|
|||
if (TextUtils.isEmpty(importantNoticeTitle)) {
|
||||
return false;
|
||||
}
|
||||
if (isInSystemSetupWizard(context)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue