auto show / hide toolbar (#674)

Co-authored-by: codokie <@>
Co-authored-by: Helium314 <helium314@disroot.org>
Co-authored-by: Helium314 <helium314@mailbox.org>
This commit is contained in:
codokie 2024-06-01 15:32:12 +03:00 committed by GitHub
parent c048ff6ff6
commit b9451e4f09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 63 additions and 5 deletions

View file

@ -353,6 +353,10 @@ public class LatinIME extends InputMethodService implements
return hasMessages(MSG_UPDATE_SUGGESTION_STRIP);
}
public boolean hasPendingResumeSuggestions() {
return hasMessages(MSG_RESUME_SUGGESTIONS);
}
public boolean hasPendingReopenDictionaries() {
return hasMessages(MSG_REOPEN_DICTIONARIES);
}
@ -989,7 +993,9 @@ public class LatinIME extends InputMethodService implements
// initialSelStart and initialSelEnd sometimes are lying. Make a best effort to
// work around this bug.
mInputLogic.mConnection.tryFixLyingCursorPosition();
if (mInputLogic.mConnection.isCursorTouchingWord(currentSettingsValues.mSpacingAndPunctuations, true)) {
mHandler.postResumeSuggestions(true /* shouldDelay */);
}
needToCallLoadKeyboardLater = false;
}
} else {
@ -1020,9 +1026,13 @@ public class LatinIME extends InputMethodService implements
}
// This will set the punctuation suggestions if next word suggestion is off;
// otherwise it will clear the suggestion strip.
setNeutralSuggestionStrip();
if (!mHandler.hasPendingResumeSuggestions()) {
mHandler.cancelUpdateSuggestionStrip();
setNeutralSuggestionStrip();
if (hasSuggestionStripView() && currentSettingsValues.mAutoShowToolbar) {
mSuggestionStripView.setToolbarVisibility(true);
}
}
mainKeyboardView.setMainDictionaryAvailability(mDictionaryFacilitator.hasAtLeastOneInitializedMainDictionary());
mainKeyboardView.setKeyPreviewPopupEnabled(currentSettingsValues.mKeyPreviewPopupOn);
@ -1593,6 +1603,10 @@ public class LatinIME extends InputMethodService implements
|| noSuggestionsFromDictionaries) {
mSuggestionStripView.setSuggestions(suggestedWords,
mRichImm.getCurrentSubtype().isRtlSubtype());
// Auto hide the toolbar if dictionary suggestions are available
if (currentSettingsValues.mAutoHideToolbar && !noSuggestionsFromDictionaries) {
mSuggestionStripView.setToolbarVisibility(false);
}
}
}
@ -1634,6 +1648,8 @@ public class LatinIME extends InputMethodService implements
// This will show either an empty suggestion strip (if prediction is enabled) or
// punctuation suggestions (if it's disabled).
// The toolbar will be shown automatically if the relevant setting is enabled
// and there is a selection of text or it's the start of a line.
@Override
public void setNeutralSuggestionStrip() {
final SettingsValues currentSettings = mSettings.getCurrent();
@ -1641,6 +1657,14 @@ public class LatinIME extends InputMethodService implements
? SuggestedWords.getEmptyInstance()
: currentSettings.mSpacingAndPunctuations.mSuggestPuncList;
setSuggestedWords(neutralSuggestions);
if (hasSuggestionStripView() && currentSettings.mAutoShowToolbar) {
final int codePointBeforeCursor = mInputLogic.mConnection.getCodePointBeforeCursor();
if (mInputLogic.mConnection.hasSelection()
|| codePointBeforeCursor == Constants.NOT_A_CODE
|| codePointBeforeCursor == Constants.CODE_ENTER) {
mSuggestionStripView.setToolbarVisibility(true);
}
}
}
@Override

View file

@ -149,6 +149,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_QUICK_PIN_TOOLBAR_KEYS = "quick_pin_toolbar_keys";
public static final String PREF_PINNED_TOOLBAR_KEYS = "pinned_toolbar_keys";
public static final String PREF_TOOLBAR_KEYS = "toolbar_keys";
public static final String PREF_AUTO_SHOW_TOOLBAR = "auto_show_toolbar";
public static final String PREF_AUTO_HIDE_TOOLBAR = "auto_hide_toolbar";
public static final String PREF_CLIPBOARD_TOOLBAR_KEYS = "clipboard_toolbar_keys";
// Emoji

View file

@ -107,6 +107,8 @@ public class SettingsValues {
public final float mKeyboardHeightScale;
public final boolean mUrlDetectionEnabled;
public final float mBottomPaddingScale;
public final boolean mAutoShowToolbar;
public final boolean mAutoHideToolbar;
// From the input box
@NonNull
@ -241,6 +243,8 @@ public class SettingsValues {
mSpacingAndPunctuations = new SpacingAndPunctuations(res, mUrlDetectionEnabled);
mBottomPaddingScale = prefs.getFloat(Settings.PREF_BOTTOM_PADDING_SCALE, DEFAULT_SIZE_SCALE);
mLongPressSymbolsForNumpad = prefs.getBoolean(Settings.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD, false);
mAutoShowToolbar = prefs.getBoolean(Settings.PREF_AUTO_SHOW_TOOLBAR, true);
mAutoHideToolbar = readSuggestionsEnabled(prefs) && prefs.getBoolean(Settings.PREF_AUTO_HIDE_TOOLBAR, true);
mHasCustomFunctionalLayout = CustomLayoutUtilsKt.hasCustomFunctionalLayout(selectedSubtype, context);
}

View file

@ -257,7 +257,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
? km.isDeviceLocked()
: km.isKeyguardLocked();
mToolbarExpandKey.setOnClickListener(hideToolbarKeys ? null : this);
mPinnedKeys.setVisibility(hideToolbarKeys ? GONE : VISIBLE);
mPinnedKeys.setVisibility(hideToolbarKeys ? GONE : mSuggestionsStrip.getVisibility());
isInlineAutofillSuggestionsVisible = false;
}
@ -285,6 +285,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
clear();
isInlineAutofillSuggestionsVisible = true;
mSuggestionsStrip.addView(view);
if (Settings.getInstance().getCurrent().mAutoHideToolbar)
setToolbarVisibility(false);
}
@Override
@ -482,6 +484,10 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mStartIndexOfMoreSuggestions = mLayoutHelper.layoutAndReturnStartIndexOfMoreSuggestions(
getContext(), mSuggestedWords, mSuggestionsStrip, SuggestionStripView.this);
mStripVisibilityGroup.showSuggestionsStrip();
// Show the toolbar if no suggestions are left and the "Auto show toolbar" setting is enabled
if (mSuggestedWords.isEmpty() && Settings.getInstance().getCurrent().mAutoShowToolbar){
setToolbarVisibility(true);
}
}
boolean showMoreSuggestions() {

View file

@ -830,6 +830,14 @@ New dictionary:
<string name="var_toolbar_direction">Variable toolbar direction</string>
<!-- Description of the variable toolbar direction setting -->
<string name="var_toolbar_direction_summary">Reverse direction when a right-to-left keyboard subtype is selected</string>
<!-- Title of the setting for showing the toolbar automatically -->
<string name="auto_show_toolbar">Auto show toolbar</string>
<!-- Description of the setting for showing the toolbar automatically -->
<string name="auto_show_toolbar_summary">Show the toolbar if input starts or text is selected</string>
<!-- Title of the setting for hiding the toolbar automatically -->
<string name="auto_hide_toolbar">Auto hide toolbar</string>
<!-- Description of the setting for hiding the toolbar automatically -->
<string name="auto_hide_toolbar_summary">Hide the toolbar when suggestions become available</string>
<!-- Toast message shown when content is copied to the clipboard -->
<string name="toast_msg_clipboard_copy">Content copied</string>
</resources>

View file

@ -108,6 +108,20 @@
android:defaultValue="@bool/config_center_suggestion_text_to_enter"
android:persistent="true" />
<SwitchPreference
android:key="auto_show_toolbar"
android:title="@string/auto_show_toolbar"
android:summary="@string/auto_show_toolbar_summary"
android:defaultValue="true"
android:persistent="true" />
<SwitchPreference
android:key="auto_hide_toolbar"
android:title="@string/auto_hide_toolbar"
android:summary="@string/auto_hide_toolbar_summary"
android:defaultValue="true"
android:persistent="true" />
<SwitchPreference
android:key="use_contacts"
android:title="@string/use_contacts_dict"