Merge "Refactor logic to determine showing suggestions strip or not"

main
Tadashi G. Takaoka 2014-06-06 10:48:00 +00:00 committed by Android (Google) Code Review
commit 2385314be0
3 changed files with 34 additions and 61 deletions

View File

@ -1003,7 +1003,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
null /* rawSuggestions */, false /* typedWordValid */, false /* willAutoCorrect */, null /* rawSuggestions */, false /* typedWordValid */, false /* willAutoCorrect */,
false /* isObsoleteSuggestions */, false /* isPrediction */); false /* isObsoleteSuggestions */, false /* isPrediction */);
// When in fullscreen mode, show completions generated by the application forcibly // When in fullscreen mode, show completions generated by the application forcibly
setSuggestedWords(suggestedWords, true /* isSuggestionStripVisible */); setSuggestedWords(suggestedWords);
} }
private int getAdjustedBackingViewHeight() { private int getAdjustedBackingViewHeight() {
@ -1306,30 +1306,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Nothing to do so far. // 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() { public boolean hasSuggestionStripView() {
return null != mSuggestionStripView; return null != mSuggestionStripView;
} }
@ -1347,9 +1323,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mSuggestionStripView.dismissAddToDictionaryHint(); mSuggestionStripView.dismissAddToDictionaryHint();
} }
// TODO[IL]: Define a clear interface for this private void setSuggestedWords(final SuggestedWords suggestedWords) {
public void setSuggestedWords(final SuggestedWords suggestedWords,
final boolean isSuggestionStripVisible) {
mInputLogic.setSuggestedWords(suggestedWords); mInputLogic.setSuggestedWords(suggestedWords);
// TODO: Modify this when we support suggestions with hard keyboard // TODO: Modify this when we support suggestions with hard keyboard
if (!hasSuggestionStripView()) { if (!hasSuggestionStripView()) {
@ -1359,27 +1333,34 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return; return;
} }
mSuggestionStripView.updateVisibility(isSuggestionStripVisible, isFullscreenMode()); final SettingsValues currentSettingsValues = mSettings.getCurrent();
if (!isSuggestionStripVisible) { 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; return;
} }
final SettingsValues currentSettings = mSettings.getCurrent(); final boolean isEmptyApplicationSpecifiedCompletions =
final boolean showSuggestions; currentSettingsValues.isApplicationSpecifiedCompletionsOn()
// May show the important notice when there are no suggestions to show, && suggestedWords.isEmpty();
if (SuggestedWords.EMPTY == suggestedWords final boolean noSuggestionsToShow = (SuggestedWords.EMPTY == suggestedWords)
// or the suggestion strip is expected to show punctuation suggestions,
|| suggestedWords.isPunctuationSuggestions() || suggestedWords.isPunctuationSuggestions()
// or it's not requested to show suggestions by the input field, || isEmptyApplicationSpecifiedCompletions;
|| !currentSettings.isSuggestionsRequested() final boolean isShowingImportantNotice;
// or the "show correction suggestions" settings is off by users preference. if (shouldShowImportantNotice && noSuggestionsToShow) {
|| !currentSettings.isCurrentOrientationAllowingSuggestionsPerUserSettings()) { isShowingImportantNotice = mSuggestionStripView.maybeShowImportantNoticeTitle();
showSuggestions = !mSuggestionStripView.maybeShowImportantNoticeTitle(
currentSettings.mInputAttributes);
} else { } else {
showSuggestions = true; isShowingImportantNotice = false;
} }
if (showSuggestions) {
if (currentSettingsValues.isSuggestionsRequested() && !isShowingImportantNotice) {
mSuggestionStripView.setSuggestions(suggestedWords, mSuggestionStripView.setSuggestions(suggestedWords,
SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype())); SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype()));
} }
@ -1442,7 +1423,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
setNeutralSuggestionStrip(); setNeutralSuggestionStrip();
} else { } else {
mInputLogic.mWordComposer.setAutoCorrection(autoCorrection); mInputLogic.mWordComposer.setAutoCorrection(autoCorrection);
setSuggestedWords(suggestedWords, isSuggestionStripVisible()); setSuggestedWords(suggestedWords);
} }
// Cache the auto-correction in accessibility code so we can speak it if the user // Cache the auto-correction in accessibility code so we can speak it if the user
// touches a key that will insert it. // touches a key that will insert it.
@ -1475,7 +1456,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final SettingsValues currentSettings = mSettings.getCurrent(); final SettingsValues currentSettings = mSettings.getCurrent();
final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled
? SuggestedWords.EMPTY : currentSettings.mSpacingAndPunctuations.mSuggestPuncList; ? SuggestedWords.EMPTY : currentSettings.mSpacingAndPunctuations.mSuggestPuncList;
setSuggestedWords(neutralSuggestions, isSuggestionStripVisible()); setSuggestedWords(neutralSuggestions);
} }
// TODO: Make this private // TODO: Make this private

View File

@ -42,7 +42,6 @@ import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.keyboard.MoreKeysPanel; import com.android.inputmethod.keyboard.MoreKeysPanel;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager; import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords; 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); final int visibility = shouldBeVisible ? VISIBLE : (isFullscreenMode ? GONE : INVISIBLE);
setVisibility(visibility); setVisibility(visibility);
final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent(); final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent();
final boolean shouldShowVoiceKey = (currentSettingsValues != null) mVoiceKey.setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : INVISIBLE);
&& currentSettingsValues.mShowsVoiceInputKey;
mVoiceKey.setVisibility(shouldShowVoiceKey ? VISIBLE : INVISIBLE);
} }
public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) { 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 // 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 // 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. // the notice. In all cases, it returns true if it was shown, false otherwise.
public boolean maybeShowImportantNoticeTitle(final InputAttributes inputAttributes) { public boolean maybeShowImportantNoticeTitle() {
if (!ImportantNoticeUtils.shouldShowImportantNotice(getContext(), inputAttributes)) { if (!ImportantNoticeUtils.shouldShowImportantNotice(getContext())) {
return false; return false;
} }
if (getWidth() <= 0) { 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. // 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. // This may be overriden by showing suggestions later, if applicable.
if (oldw <= 0 && w > 0) { if (oldw <= 0 && w > 0) {
maybeShowImportantNoticeTitle(Settings.getInstance().getCurrent().mInputAttributes); maybeShowImportantNoticeTitle();
} }
} }
} }

View File

@ -23,7 +23,6 @@ import android.provider.Settings.SettingNotFoundException;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
public final class ImportantNoticeUtils { public final class ImportantNoticeUtils {
@ -78,14 +77,7 @@ public final class ImportantNoticeUtils {
return getCurrentImportantNoticeVersion(context) > lastVersion; return getCurrentImportantNoticeVersion(context) > lastVersion;
} }
public static boolean shouldShowImportantNotice(final Context context, public static boolean shouldShowImportantNotice(final Context context) {
final InputAttributes inputAttributes) {
if (inputAttributes == null || inputAttributes.mIsPasswordField) {
return false;
}
if (isInSystemSetupWizard(context)) {
return false;
}
if (!hasNewImportantNotice(context)) { if (!hasNewImportantNotice(context)) {
return false; return false;
} }
@ -93,6 +85,9 @@ public final class ImportantNoticeUtils {
if (TextUtils.isEmpty(importantNoticeTitle)) { if (TextUtils.isEmpty(importantNoticeTitle)) {
return false; return false;
} }
if (isInSystemSetupWizard(context)) {
return false;
}
return true; return true;
} }