Skip to content

Commit 29d0e4b

Browse files
committed
feat: add toolbar auto-fold toggle and fix pinned keys overlay bug
- Add PREF_AUTO_FOLD_TOOLBAR setting (default: true) to collapse toolbar when keyboard opens, controlled via Settings > Toolbar - Fix pinned keys showing alongside expanded toolbar by ensuring pinnedKeys container hides when toolbar is expanded - Fix rebuildToolbarKeys to correctly include/exclude pinned keys based on autoHidePinnedKeys setting - Fix hideTranslateLanguageSelector to use setToolbarVisibility() instead of bypassing unified visibility logic - Remove debug log from setToolbarVisibility()
1 parent cc94c94 commit 29d0e4b

7 files changed

Lines changed: 84 additions & 61 deletions

File tree

app/src/main/java/helium314/keyboard/latin/LatinIME.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,10 @@ void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restart
10031003
// Space state must be updated before calling updateShiftState
10041004
switcher.requestUpdatingShiftState(getCurrentAutoCapsState(), getCurrentRecapitalizeState());
10051005
}
1006+
// Auto-fold: collapse toolbar when keyboard opens (if enabled)
1007+
if (hasSuggestionStripView() && currentSettingsValues.mAutoFoldToolbar) {
1008+
mSuggestionStripView.foldToolbar();
1009+
}
10061010
// Set neutral suggestions and show the toolbar if the "Auto show toolbar"
10071011
// setting is enabled.
10081012
if (!mHandler.hasPendingResumeSuggestions()) {
@@ -1686,10 +1690,10 @@ public void setNeutralSuggestionStrip() {
16861690
? currentSettings.mSpacingAndPunctuations.mSuggestPuncList
16871691
: SuggestedWords.getEmptyInstance();
16881692
setSuggestedWords(neutralSuggestions);
1689-
if (hasSuggestionStripView() && currentSettings.mAutoShowToolbarOnSelect) {
1690-
if (mInputLogic.getConnection().hasSelection()) {
1693+
if (hasSuggestionStripView()) {
1694+
if (currentSettings.mAutoShowToolbarOnSelect && mInputLogic.getConnection().hasSelection()) {
16911695
mSuggestionStripView.setToolbarVisibility(true);
1692-
} else {
1696+
} else if (currentSettings.mAutoShowToolbarOnSelect) {
16931697
mSuggestionStripView.setToolbarVisibility(mSuggestionStripView.isToolbarManuallyOpen());
16941698
}
16951699
}

app/src/main/java/helium314/keyboard/latin/settings/Defaults.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ object Defaults {
172172
const val PREF_AUTO_SHOW_TOOLBAR = false
173173
const val PREF_AUTO_SHOW_TOOLBAR_ON_SELECT = false
174174
const val PREF_AUTO_HIDE_TOOLBAR = true
175-
const val PREF_AUTO_HIDE_PINNED_KEYS = false
176-
const val PREF_REMEMBER_TOOLBAR_STATE = true
175+
const val PREF_AUTO_HIDE_PINNED_KEYS = true
176+
const val PREF_AUTO_FOLD_TOOLBAR = true
177177
const val PREF_TOOLBAR_EXPANDED = false
178178
val PREF_CLIPBOARD_TOOLBAR_KEYS = defaultClipboardToolbarPref
179179
const val PREF_ABC_AFTER_EMOJI = false

app/src/main/java/helium314/keyboard/latin/settings/Settings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
179179
public static final String PREF_AUTO_SHOW_TOOLBAR_ON_SELECT = "auto_show_toolbar_on_select";
180180
public static final String PREF_AUTO_HIDE_TOOLBAR = "auto_hide_toolbar";
181181
public static final String PREF_AUTO_HIDE_PINNED_KEYS = "auto_hide_pinned_keys";
182-
public static final String PREF_REMEMBER_TOOLBAR_STATE = "remember_toolbar_state";
182+
public static final String PREF_AUTO_FOLD_TOOLBAR = "auto_fold_toolbar";
183183
public static final String PREF_TOOLBAR_EXPANDED = "toolbar_expanded";
184184
public static final String PREF_CLIPBOARD_TOOLBAR_KEYS = "clipboard_toolbar_keys";
185185
public static final String PREF_ABC_AFTER_EMOJI = "abc_after_emoji";

app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public class SettingsValues {
131131
public final boolean mAutoShowToolbarOnSelect;
132132
public final boolean mAutoHideToolbar;
133133
public final boolean mAutoHidePinnedKeys;
134-
public final boolean mRememberToolbarState;
134+
public final boolean mAutoFoldToolbar;
135135
public final boolean mAlphaAfterEmojiInEmojiView;
136136
public final boolean mAlphaAfterClipHistoryEntry;
137137
public final boolean mAlphaAfterSymbolAndSpace;
@@ -383,7 +383,12 @@ public SettingsValues(final Context context, final SharedPreferences prefs, fina
383383
mAutoHidePinnedKeys = mToolbarMode == ToolbarMode.EXPANDABLE
384384
&& !mSplitToolbar
385385
&& prefs.getBoolean(Settings.PREF_AUTO_HIDE_PINNED_KEYS, Defaults.PREF_AUTO_HIDE_PINNED_KEYS);
386-
mRememberToolbarState = prefs.getBoolean(Settings.PREF_REMEMBER_TOOLBAR_STATE, Defaults.PREF_REMEMBER_TOOLBAR_STATE);
386+
mAutoFoldToolbar = prefs.getBoolean(Settings.PREF_AUTO_FOLD_TOOLBAR,
387+
Defaults.PREF_AUTO_FOLD_TOOLBAR);
388+
// Migration: clear any old saved value and reset to default
389+
if (!prefs.contains(Settings.PREF_AUTO_HIDE_PINNED_KEYS)) {
390+
prefs.edit().putBoolean(Settings.PREF_AUTO_HIDE_PINNED_KEYS, Defaults.PREF_AUTO_HIDE_PINNED_KEYS).apply();
391+
}
387392
mAlphaAfterEmojiInEmojiView = prefs.getBoolean(Settings.PREF_ABC_AFTER_EMOJI,
388393
Defaults.PREF_ABC_AFTER_EMOJI);
389394
mAlphaAfterClipHistoryEntry = prefs.getBoolean(Settings.PREF_ABC_AFTER_CLIP,

app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.kt

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -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

app/src/main/java/helium314/keyboard/settings/screens/ToolbarScreen.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fun ToolbarScreen(
7777
if (toolbarMode == ToolbarMode.EXPANDABLE && !isSplitToolbar) Settings.PREF_AUTO_SHOW_TOOLBAR_ON_SELECT else null,
7878
if (toolbarMode == ToolbarMode.EXPANDABLE && !isSplitToolbar) Settings.PREF_AUTO_HIDE_TOOLBAR else null,
7979
if (toolbarMode == ToolbarMode.EXPANDABLE && !isSplitToolbar) Settings.PREF_AUTO_HIDE_PINNED_KEYS else null,
80-
if (toolbarMode == ToolbarMode.EXPANDABLE && !isSplitToolbar) Settings.PREF_REMEMBER_TOOLBAR_STATE else null,
80+
if (toolbarMode == ToolbarMode.EXPANDABLE) Settings.PREF_AUTO_FOLD_TOOLBAR else null,
8181
if (toolbarMode != ToolbarMode.HIDDEN) Settings.PREF_VARIABLE_TOOLBAR_DIRECTION else null,
8282
)
8383
SearchSettingsScreen(
@@ -154,11 +154,13 @@ fun createToolbarSettings(context: Context): List<Setting> {
154154
},
155155
Setting(context, Settings.PREF_AUTO_HIDE_PINNED_KEYS, R.string.auto_hide_pinned_keys, R.string.auto_hide_pinned_keys_summary)
156156
{
157-
SwitchPreference(it, Defaults.PREF_AUTO_HIDE_PINNED_KEYS)
157+
SwitchPreference(it, Defaults.PREF_AUTO_HIDE_PINNED_KEYS) { _ ->
158+
KeyboardSwitcher.getInstance().setThemeNeedsReload()
159+
}
158160
},
159-
Setting(context, Settings.PREF_REMEMBER_TOOLBAR_STATE, R.string.remember_toolbar_state, R.string.remember_toolbar_state_summary)
161+
Setting(context, Settings.PREF_AUTO_FOLD_TOOLBAR, R.string.auto_fold_toolbar, R.string.auto_fold_toolbar_summary)
160162
{
161-
SwitchPreference(it, Defaults.PREF_REMEMBER_TOOLBAR_STATE)
163+
SwitchPreference(it, Defaults.PREF_AUTO_FOLD_TOOLBAR)
162164
},
163165
Setting(context, Settings.PREF_VARIABLE_TOOLBAR_DIRECTION,
164166
R.string.var_toolbar_direction, R.string.var_toolbar_direction_summary)

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,10 +1124,10 @@ New dictionary:
11241124
<string name="auto_hide_pinned_keys">Auto hide pinned keys</string>
11251125
<!-- Description of the setting to auto hide pinned keys when toolbar is expanded -->
11261126
<string name="auto_hide_pinned_keys_summary">Hide pinned keys when the toolbar is expanded</string>
1127-
<!-- Title of the setting to remember toolbar expanded/collapsed state -->
1128-
<string name="remember_toolbar_state">Remember toolbar state</string>
1129-
<!-- Description of the setting to remember toolbar expanded/collapsed state -->
1130-
<string name="remember_toolbar_state_summary">Remember whether the toolbar was expanded or collapsed</string>
1127+
<!-- Title of the setting to auto fold toolbar on keyboard open -->
1128+
<string name="auto_fold_toolbar">Auto-fold toolbar</string>
1129+
<!-- Description of the setting to auto fold toolbar on keyboard open -->
1130+
<string name="auto_fold_toolbar_summary">Automatically collapse the toolbar when the keyboard opens</string>
11311131
<!-- Content description for the close button in translate language selector -->
11321132
<string name="close_translate_language_selector">Close language selector</string>
11331133
<!-- Toast message shown when content is copied to the clipboard -->

0 commit comments

Comments
 (0)