@@ -173,13 +173,9 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
173173 if (mToolbarMode == ToolbarMode .TOOLBAR_KEYS ) {
174174 setToolbarVisibility(true , saveState = false )
175175 } else if (mToolbarMode == ToolbarMode .EXPANDABLE ) {
176- // Restore saved toolbar state if enabled
177- val settingsValues = Settings .getValues()
178- if (settingsValues.mRememberToolbarState) {
179- val savedExpanded = context.prefs().getBoolean(Settings .PREF_TOOLBAR_EXPANDED , false )
180- isToolbarManuallyOpen = savedExpanded || settingsValues.mAutoShowToolbar
181- setToolbarVisibility(isToolbarManuallyOpen, saveState = false )
182- }
176+ // Always start with toolbar collapsed (unless auto-show is enabled)
177+ isToolbarManuallyOpen = Settings .getValues().mAutoShowToolbar
178+ setToolbarVisibility(isToolbarManuallyOpen, saveState = false )
183179 }
184180
185181 // toolbar keys setup
@@ -317,19 +313,12 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
317313 suggestionsStrip.layoutDirection = newLayoutDirection
318314 }
319315
320- // Overload for Java compatibility (default saveState = true )
316+ // Overload for Java compatibility (default saveState = false )
321317 @JvmOverloads
322- fun setToolbarVisibility (toolbarVisible : Boolean , saveState : Boolean = true ) {
318+ fun setToolbarVisibility (toolbarVisible : Boolean , saveState : Boolean = false ) {
323319 // avoid showing toolbar keys when locked
324320 val locked = isDeviceLocked(context)
325321 val split = Settings .getValues().mSplitToolbar
326- val settingsValues = Settings .getValues()
327- val autoHidePinnedKeys = settingsValues.mAutoHidePinnedKeys
328-
329- // Save toolbar state if requested
330- if (saveState && settingsValues.mRememberToolbarState) {
331- context.prefs().edit().putBoolean(Settings .PREF_TOOLBAR_EXPANDED , toolbarVisible).apply ()
332- }
333322
334323 // In split mode, show only full toolbar, hide pinned keys
335324 if (split) {
@@ -340,9 +329,9 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
340329 toolbarExpandKey.isVisible = false // Hide expand key
341330 updateSplitToolbarState()
342331 } else {
343- // Auto-hide pinned keys when toolbar is expanded
344- val shouldHidePinnedKeys = autoHidePinnedKeys && toolbarVisible && ! locked
345- pinnedKeys.isVisible = ! locked && ! toolbarVisible && ! shouldHidePinnedKeys
332+ // When toolbar expands: show toolbar container, hide pinnedKeys container and suggestions
333+ // When toolbar collapsed: show suggestions + pinnedKeys container, hide toolbar container
334+ pinnedKeys.isVisible = ! locked && ! toolbarVisible
346335 suggestionsStrip.isVisible = locked || ! toolbarVisible
347336 toolbarContainer.isVisible = ! locked && toolbarVisible
348337 }
@@ -356,6 +345,12 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
356345 toolbarExpandKey.scaleX = (if (toolbarVisible && ! locked) - 1f else 1f ) * direction
357346 }
358347
348+ /* * Collapse the toolbar and show suggestions instead. Called from LatinIME.onStartInputView(). */
349+ fun foldToolbar () {
350+ isToolbarManuallyOpen = false
351+ setToolbarVisibility(false , saveState = false )
352+ }
353+
359354 fun setSuggestions (suggestions : SuggestedWords , isRtlLanguage : Boolean ) {
360355 if (isExternalSuggestionVisible && (suggestions.isEmpty || suggestions.isPunctuationSuggestions)) {
361356 // Keep external suggestion (clipboard/screenshot) if new suggestions are empty or just punctuation
@@ -369,6 +364,11 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
369364 context, suggestedWords, suggestionsStrip, this
370365 )
371366 updateKeys()
367+ // Update toolbar visibility state
368+ val settingsValues = Settings .getValues()
369+ if (settingsValues.mToolbarMode == ToolbarMode .EXPANDABLE && ! settingsValues.mSplitToolbar) {
370+ setToolbarVisibility(isToolbarManuallyOpen, saveState = false )
371+ }
372372 updateSplitToolbarState()
373373 }
374374
@@ -478,10 +478,10 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
478478 override fun onSharedPreferenceChanged (prefs : SharedPreferences , key : String? ) {
479479 setToolbarButtonsActivatedStateOnPrefChange(pinnedKeys, key)
480480 setToolbarButtonsActivatedStateOnPrefChange(toolbar, key)
481- if (key == Settings .PREF_PINNED_TOOLBAR_KEYS || key == Settings .PREF_TOOLBAR_KEYS || key == Settings .PREF_QUICK_PIN_TOOLBAR_KEYS ) {
481+ if (key == Settings .PREF_PINNED_TOOLBAR_KEYS || key == Settings .PREF_TOOLBAR_KEYS || key == Settings .PREF_QUICK_PIN_TOOLBAR_KEYS || key == Settings . PREF_AUTO_HIDE_PINNED_KEYS || key == Settings . PREF_SPLIT_TOOLBAR ) {
482482 rebuildToolbarKeys()
483- // Also update visibility in case split mode changed or keys emptying affected layout
484- updateKeys( )
483+ // Update visibility with auto-hide logic
484+ setToolbarVisibility(isToolbarManuallyOpen, false )
485485 }
486486 }
487487
@@ -518,6 +518,16 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
518518 if (isExternalSuggestionVisible) {
519519 return false
520520 }
521+
522+ // In split mode, don't intercept touches on the top row (toolbar row)
523+ // to prevent accidentally cancelling long presses on toolbar buttons.
524+ if (Settings .getValues().mSplitToolbar) {
525+ val stripHeight = resources.getDimensionPixelSize(R .dimen.config_suggestions_strip_height)
526+ if (motionEvent.y < stripHeight) {
527+ return false
528+ }
529+ }
530+
521531 // Detecting sliding up finger to show MoreSuggestionsView.
522532 return moreSuggestionsView.shouldInterceptTouchEvent(motionEvent)
523533 }
@@ -543,7 +553,7 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
543553 if (view == = toolbarExpandKey) {
544554 val willBeVisible = toolbarContainer.visibility != VISIBLE
545555 isToolbarManuallyOpen = willBeVisible
546- setToolbarVisibility(willBeVisible)
556+ setToolbarVisibility(willBeVisible, saveState = false )
547557 }
548558
549559 // tag for word views is set in SuggestionStripLayoutHelper (setupWordViewsTextAndColor, layoutPunctuationSuggestions)
@@ -583,23 +593,21 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
583593 return
584594 }
585595
586- // Disable pinning and long press actions when split toolbar is enabled
587- if (Settings .getValues().mSplitToolbar) return
588-
589- if (Settings .getValues().mQuickPinToolbarKeys) {
596+ // Disable pinning when split toolbar is enabled
597+ if (Settings .getValues().mSplitToolbar || ! Settings .getValues().mQuickPinToolbarKeys) {
598+ // Quick Pin disabled or Split Toolbar enabled: Perform standard long-press action
599+ val longClickCode = getCodeForToolbarKeyLongClick(tag)
600+ if (longClickCode != KeyCode .UNSPECIFIED ) {
601+ listener.onCodeInput(longClickCode, Constants .SUGGESTION_STRIP_COORDINATE , Constants .SUGGESTION_STRIP_COORDINATE , false )
602+ }
603+ } else {
590604 if (view.parent == = toolbar) {
591605 // Pin: Move from toolbar to pinned keys
592606 addPinnedKey(context.prefs(), tag)
593607 } else if (view.parent == = pinnedKeys) {
594608 // Unpin: Move from pinned keys back to toolbar
595609 removePinnedKey(context.prefs(), tag)
596610 }
597- } else {
598- // Quick Pin disabled: Perform standard long-press action
599- val longClickCode = getCodeForToolbarKeyLongClick(tag)
600- if (longClickCode != KeyCode .UNSPECIFIED ) {
601- listener.onCodeInput(longClickCode, Constants .SUGGESTION_STRIP_COORDINATE , Constants .SUGGESTION_STRIP_COORDINATE , false )
602- }
603611 }
604612 }
605613
@@ -793,9 +801,7 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
793801 val settingsValues = Settings .getValues()
794802 if (! settingsValues.mSplitToolbar) {
795803 toolbarExpandKey.isVisible = settingsValues.mToolbarMode == ToolbarMode .EXPANDABLE
796- pinnedKeys.isVisible = ! isDeviceLocked(context) && ! isToolbarManuallyOpen
797- toolbarContainer.isVisible = ! isDeviceLocked(context) && isToolbarManuallyOpen
798- suggestionsStrip.isVisible = isDeviceLocked(context) || ! isToolbarManuallyOpen
804+ setToolbarVisibility(isToolbarManuallyOpen, saveState = false )
799805 } else {
800806 toolbarContainer.isVisible = ! isDeviceLocked(context)
801807 toolbar.visibility = VISIBLE
@@ -820,15 +826,16 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
820826 if (split) {
821827 toolbarExpandKey.isVisible = false
822828 pinnedKeys.isVisible = false // Hide pinned keys completely in split mode
823-
829+
824830 toolbarContainer.isVisible = ! hideToolbarKeys // Show full toolbar container
825831 toolbar.visibility = VISIBLE // Show toolbar
826-
832+
827833 updateVoiceKey() // Re-apply voice logic to pinned keys
828834 layoutHelper.setSuggestionsCountInStrip(5 )
829835 } else {
830836 toolbarExpandKey.isVisible = toolbarIsExpandable
831- pinnedKeys.visibility = if (hideToolbarKeys) GONE else suggestionsStrip.visibility
837+ // Don't manage visibility here - let setToolbarVisibility handle it
838+ // This prevents conflicts with auto-hide pinned keys logic
832839 layoutHelper.setSuggestionsCountInStrip(3 )
833840 }
834841 isExternalSuggestionVisible = false
@@ -855,15 +862,15 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
855862 // Toolbar keys setup
856863 // Always populate toolbar keys if mode allows, visibility handled in updateKeys
857864 if (mToolbarMode == ToolbarMode .TOOLBAR_KEYS || mToolbarMode == ToolbarMode .EXPANDABLE ) {
858- // Filter out pinned keys from toolbar to avoid duplication and keep UI clean
859- // In split mode, we show ALL enabled keys in the toolbar, ignoring pin status
860- val keysToRender = if (isSplitToolbar) {
861- getEnabledToolbarKeys(context.prefs())
865+ // In split mode, show ALL enabled keys in the toolbar, ignoring pin status
866+ // When autoHidePinnedKeys=false: include pinned keys in toolbar too (they show side-by-side)
867+ // When autoHidePinnedKeys=true: exclude pinned keys from toolbar (pinnedKeys container handles them)
868+ val keysToRender = if (isSplitToolbar || ! Settings .getValues().mAutoHidePinnedKeys) {
869+ getEnabledToolbarKeys(context.prefs())
862870 } else {
863871 getEnabledToolbarKeys(context.prefs()).filterNot { it in pinnedKeysList }
864872 }
865- for (key in keysToRender) {
866- val button = createToolbarKey(context, key)
873+ for (key in keysToRender) { val button = createToolbarKey(context, key)
867874 button.layoutParams = toolbarKeyLayoutParams
868875 setupKey(button, colors)
869876 toolbar.addView(button)
@@ -1014,6 +1021,11 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
10141021 isShowingEmojiSuggestions = false
10151022 suggestionsStrip.removeAllViews()
10161023 updateKeys()
1024+ // Update toolbar visibility state
1025+ val settingsValues = Settings .getValues()
1026+ if (settingsValues.mToolbarMode == ToolbarMode .EXPANDABLE && ! settingsValues.mSplitToolbar) {
1027+ setToolbarVisibility(isToolbarManuallyOpen, saveState = false )
1028+ }
10171029 updateSplitToolbarState()
10181030 }
10191031
0 commit comments