Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto toggle toolbar when suggestions are available #674

Merged
merged 17 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 11 additions & 0 deletions app/src/main/java/helium314/keyboard/latin/LatinIME.java
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,9 @@ private void setSuggestedWords(final SuggestedWords suggestedWords) {
mSuggestionStripView.setSuggestions(suggestedWords,
mRichImm.getCurrentSubtype().isRtlSubtype());
}
if (currentSettingsValues.mSuggestionsToggleToolbar) {
mSuggestionStripView.setToolbarVisibility(suggestedWords.isEmpty());
}
}

// TODO[IL]: Move this out of LatinIME.
Expand Down Expand Up @@ -1631,13 +1634,21 @@ public void pickSuggestionManually(final SuggestedWordInfo suggestionInfo) {

// This will show either an empty suggestion strip (if prediction is enabled) or
// punctuation suggestions (if it's disabled).
// The toolbar will toggle automatically if the relevant setting is enabled
// and there is no text before the cursor or it's the start of a new line.
@Override
public void setNeutralSuggestionStrip() {
final SettingsValues currentSettings = mSettings.getCurrent();
final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled
? SuggestedWords.getEmptyInstance()
: currentSettings.mSpacingAndPunctuations.mSuggestPuncList;
setSuggestedWords(neutralSuggestions);
if (hasSuggestionStripView() && currentSettings.mSuggestionsToggleToolbar) {
final int codePoint = mInputLogic.mConnection.getCodePointBeforeCursor();
if (codePoint == Constants.NOT_A_CODE || codePoint == Constants.CODE_ENTER) {
mSuggestionStripView.setToolbarVisibility(true);
}
}
Helium314 marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private void refreshEnabledSettings() {
setPreferenceVisible(Settings.PREF_MORE_AUTO_CORRECTION, Settings.readAutoCorrectEnabled(getSharedPreferences()));
setPreferenceVisible(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, getSharedPreferences().getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true));
setPreferenceVisible(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, getSharedPreferences().getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true));
setPreferenceVisible(Settings.PREF_SUGGESTIONS_TOGGLE_TOOLBAR, getSharedPreferences().getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true));
turnOffLookupContactsIfNoPermission();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = "dont_show_missing_dict_dialog";
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_SUGGESTIONS_TOGGLE_TOOLBAR = "suggestions_toggle_toolbar";

// Emoji
public static final String PREF_EMOJI_RECENT_KEYS = "emoji_recent_keys";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class SettingsValues {
public final float mKeyboardHeightScale;
public final boolean mUrlDetectionEnabled;
public final float mBottomPaddingScale;
public final boolean mSuggestionsToggleToolbar;

// From the input box
@NonNull
Expand Down Expand Up @@ -233,6 +234,7 @@ public SettingsValues(final Context context, final SharedPreferences prefs, fina
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);
mSuggestionsToggleToolbar = readSuggestionsEnabled(prefs) && prefs.getBoolean(Settings.PREF_SUGGESTIONS_TOGGLE_TOOLBAR, true);
}

public boolean isApplicationSpecifiedCompletionsOn() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ public void setInlineSuggestionsView(final View view) {
clear();
isInlineAutofillSuggestionsVisible = true;
mSuggestionsStrip.addView(view);
if (Settings.getInstance().getCurrent().mSuggestionsToggleToolbar)
setToolbarVisibility(false);
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -789,4 +789,8 @@ 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 expanding/collapsing the toolbar automatically -->
<string name="suggestions_toggle_toolbar">Suggestions toggle toolbar</string>
<!-- Description of the setting for expanding/collapsing the toolbar automatically -->
<string name="suggestions_toggle_toolbar_summary">Automatically toggle the toolbar when suggestions become available</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/xml/prefs_screen_correction.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@
android:defaultValue="true"
android:persistent="true" />

<SwitchPreference
android:key="suggestions_toggle_toolbar"
android:title="@string/suggestions_toggle_toolbar"
android:summary="@string/suggestions_toggle_toolbar_summary"
android:defaultValue="true"
android:persistent="true" />

<SwitchPreference
android:key="use_contacts"
android:title="@string/use_contacts_dict"
Expand Down