Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/java/helium314/keyboard/latin/LatinIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,8 @@ class LatinIME : InputMethodService(),
handler.cancelUpdateSuggestionStrip()
setNeutralSuggestionStrip()
if (currentSettingsValues.mToolbarMode == ToolbarMode.EXPANDABLE && (currentSettingsValues.mAutoShowToolbar || currentSettingsValues.mAutoShowToolbarNoSuggestions) && suggestionStripView?.isExternalSuggestionVisible != true) {
// "on open" applies only here: later updates keep it open until auto-hide or the user closes it
if (currentSettingsValues.mAutoShowToolbar) suggestionStripView?.isToolbarManuallyOpen = true
suggestionStripView?.setToolbarVisibility(true)
}
if (currentSettingsValues.isSuggestionsEnabledPerUserSettings() && shouldRequestInitialPredictions(currentSettingsValues) && suggestionStripView?.isExternalSuggestionVisible != true) {
Expand Down Expand Up @@ -2026,7 +2028,6 @@ class LatinIME : InputMethodService(),
val shouldShow = when {
currentSettings.mToolbarMode == ToolbarMode.TOOLBAR_KEYS -> true
strip.isToolbarManuallyOpen -> true
currentSettings.mAutoShowToolbar -> true
currentSettings.mAutoShowToolbarNoSuggestions -> true
currentSettings.mAutoHideToolbar -> false
else -> false
Expand Down Expand Up @@ -2056,7 +2057,6 @@ class LatinIME : InputMethodService(),
val shouldShow = when {
currentSettings.mToolbarMode == ToolbarMode.TOOLBAR_KEYS -> true
strip.isToolbarManuallyOpen -> true
currentSettings.mAutoShowToolbar -> true
currentSettings.mAutoShowToolbarNoSuggestions -> true
currentSettings.mAutoHideToolbar -> false
else -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
val hasNoSuggestions = (suggestions.isEmpty || suggestions.isPunctuationSuggestions) && !isMissingDict
val shouldShow = when {
isToolbarManuallyOpen -> true
settingsValues.mAutoShowToolbar -> true
settingsValues.mAutoShowToolbarNoSuggestions && hasNoSuggestions -> true
settingsValues.mAutoHideToolbar && !hasNoSuggestions -> false
else -> false
Expand Down Expand Up @@ -617,7 +616,7 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
clear()
isExternalSuggestionVisible = false
updateSplitToolbarState()
setToolbarVisibility(isToolbarManuallyOpen || Settings.getValues().mAutoShowToolbar)
setToolbarVisibility(isToolbarManuallyOpen)
return
}
if (isVoiceActive) return
Expand Down Expand Up @@ -1315,7 +1314,7 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
suggestionsStrip.isVisible = true

// Show the toolbar if no suggestions are left and the auto-show setting is enabled
if (this.suggestedWords.isEmpty && (Settings.getValues().mAutoShowToolbarNoSuggestions || Settings.getValues().mAutoShowToolbar)) {
if (this.suggestedWords.isEmpty && Settings.getValues().mAutoShowToolbarNoSuggestions) {
setToolbarVisibility(true, saveState = false)
}
}
Expand Down Expand Up @@ -2027,7 +2026,6 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
if (settingsValues.mToolbarMode == ToolbarMode.EXPANDABLE && !settingsValues.mSplitToolbar) {
val shouldShow = when {
isToolbarManuallyOpen -> true
settingsValues.mAutoShowToolbar -> true
settingsValues.mAutoShowToolbarNoSuggestions -> true
settingsValues.mAutoHideToolbar -> false
else -> false
Expand Down
51 changes: 51 additions & 0 deletions app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,57 @@ class InputLogicTest {
}
}

private fun withAutoShownToolbar(autoHide: Boolean, block: (SuggestionStripView) -> Unit) {
reset()
latinIME.prefs().edit {
putBoolean(Settings.PREF_AUTO_SHOW_TOOLBAR, true)
putBoolean(Settings.PREF_AUTO_HIDE_TOOLBAR, autoHide)
}
latinIME.settings.loadSettings(latinIME, Locale.US, settingsValues.mInputAttributes, ScriptUtils.SCRIPT_LATIN)
val strip = SuggestionStripView(latinIME, null)
strip.setListener(latinIME, MainKeyboardView(latinIME, null).apply { id = R.id.keyboard_view })
val stripField = LatinIME::class.java.getDeclaredField("suggestionStripView").apply { isAccessible = true }
val originalStrip = stripField.get(latinIME)
stripField.set(latinIME, strip)
try {
assertTrue(strip.isToolbarShowing) // open when the keyboard appears
block(strip)
} finally {
stripField.set(latinIME, originalStrip)
latinIME.prefs().edit {
remove(Settings.PREF_AUTO_SHOW_TOOLBAR)
remove(Settings.PREF_AUTO_HIDE_TOOLBAR)
}
latinIME.settings.loadSettings(latinIME, Locale.US, settingsValues.mInputAttributes, ScriptUtils.SCRIPT_LATIN)
}
}

private fun predictions(): SuggestedWords {
val info = SuggestedWordInfo("next", "", 0, 0, Mockito.mock(Dictionary::class.java), 0, 0)
return SuggestedWords(arrayListOf(info), null, null, false, false, false, SuggestedWords.INPUT_STYLE_PREDICTION, 0)
}

@Test fun `auto show on open does not reopen the toolbar over predictions`() = withAutoShownToolbar(true) { strip ->
strip.foldToolbar() // what auto-hide does while a word is typed
strip.setSuggestions(predictions(), false)
assertFalse(strip.isToolbarShowing)
}

@Test fun `neutral strip does not reopen a folded toolbar`() = withAutoShownToolbar(true) { strip ->
strip.foldToolbar()
latinIME.setNeutralSuggestionStrip()
handleMessages()
assertFalse(strip.isToolbarShowing)
}

@Test fun `auto shown toolbar stays open without auto-hide`() = withAutoShownToolbar(false) { strip ->
strip.setSuggestions(predictions(), false)
assertTrue(strip.isToolbarShowing)
latinIME.setNeutralSuggestionStrip()
handleMessages()
assertTrue(strip.isToolbarShowing)
}

@Test @Config(sdk = [32, 35])
fun capsControlsHaveIconsInEveryStyleAndRespectUncasedLocales() {
reset()
Expand Down
Loading