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

improve inline suggestions #675

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
22 changes: 17 additions & 5 deletions app/src/main/java/helium314/keyboard/latin/LatinIME.java
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,10 @@ void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restart
// Space state must be updated before calling updateShiftState
switcher.requestUpdatingShiftState(getCurrentAutoCapsState(), getCurrentRecapitalizeState());
}
// This will remove old "stuck" inline suggestions
if (hasSuggestionStripView()) {
mSuggestionStripView.resetInlineSuggestions();
}
// This will set the punctuation suggestions if next word suggestion is off;
// otherwise it will clear the suggestion strip.
if (!mHandler.hasPendingResumeSuggestions()) {
Expand Down Expand Up @@ -1315,6 +1319,11 @@ public InlineSuggestionsRequest onCreateInlineSuggestionsRequest(@NonNull Bundle
@RequiresApi(api = Build.VERSION_CODES.R)
public boolean onInlineSuggestionsResponse(InlineSuggestionsResponse response) {
Log.d(TAG,"onInlineSuggestionsResponse called");
// Ignore spammy requests if inline suggestions are already displayed or dismissed
if (!hasSuggestionStripView() || mSuggestionStripView.isInlineAutofillSuggestionsVisible()
|| mSuggestionStripView.areInlineSuggestionsDismissed()) {
return false;
}
final List<InlineSuggestion> inlineSuggestions = response.getInlineSuggestions();
if (inlineSuggestions.isEmpty()) {
return false;
Expand Down Expand Up @@ -1601,11 +1610,14 @@ private void setSuggestedWords(final SuggestedWords suggestedWords) {
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn()
// We should clear the contextual strip if there is no suggestion from dictionaries.
|| noSuggestionsFromDictionaries) {
mSuggestionStripView.setSuggestions(suggestedWords,
mRichImm.getCurrentSubtype().isRtlSubtype());
// Auto hide the toolbar if dictionary suggestions are available
if (currentSettingsValues.mAutoHideToolbar && !noSuggestionsFromDictionaries) {
mSuggestionStripView.setToolbarVisibility(false);
if (mSuggestionStripView.isInlineAutofillSuggestionsVisible()){
mSuggestionStripView.updateSuggestedWords(suggestedWords);
} else {
mSuggestionStripView.setSuggestions(suggestedWords,
mRichImm.getCurrentSubtype().isRtlSubtype());
// Auto hide the toolbar if dictionary suggestions are available
if (currentSettingsValues.mAutoHideToolbar && !noSuggestionsFromDictionaries)
mSuggestionStripView.setToolbarVisibility(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public interface Listener {
private final Drawable mIncognitoIcon;
private final Drawable mToolbarArrowIcon;
private final Drawable mBinIcon;
private final Drawable mCloseIcon;
private final ViewGroup mToolbar;
private final View mToolbarContainer;
private final ViewGroup mPinnedKeys;
Expand All @@ -111,6 +112,7 @@ public interface Listener {
private final SuggestionStripLayoutHelper mLayoutHelper;
private final StripVisibilityGroup mStripVisibilityGroup;
private boolean isInlineAutofillSuggestionsVisible = false; // Required to disable the more suggestions if inline autofill suggestions are visible
private boolean areInlineSuggestionsDismissed = false;

private static class StripVisibilityGroup {
private final View mSuggestionStripView;
Expand Down Expand Up @@ -189,6 +191,7 @@ public SuggestionStripView(final Context context, final AttributeSet attrs, fina
mIncognitoIcon = keyboardAttr.getDrawable(R.styleable.Keyboard_iconIncognitoKey);
mToolbarArrowIcon = keyboardAttr.getDrawable(R.styleable.Keyboard_iconToolbarKey);
mBinIcon = keyboardAttr.getDrawable(R.styleable.Keyboard_iconBin);
mCloseIcon = keyboardAttr.getDrawable(R.styleable.Keyboard_iconClose);

final LinearLayout.LayoutParams toolbarKeyLayoutParams = new LinearLayout.LayoutParams(
getResources().getDimensionPixelSize(R.dimen.config_suggestions_strip_edge_key_width),
Expand Down Expand Up @@ -248,7 +251,11 @@ private void updateKeys() {
final View pinnedVoiceKey = mPinnedKeys.findViewWithTag(ToolbarKey.VOICE);
if (pinnedVoiceKey != null)
pinnedVoiceKey.setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : GONE);
mToolbarExpandKey.setImageDrawable(currentSettingsValues.mIncognitoModeEnabled ? mIncognitoIcon : mToolbarArrowIcon);
if (isInlineAutofillSuggestionsVisible){
mToolbarExpandKey.setImageDrawable(mCloseIcon);
} else {
mToolbarExpandKey.setImageDrawable(currentSettingsValues.mIncognitoModeEnabled ? mIncognitoIcon : mToolbarArrowIcon);
}
mToolbarExpandKey.setScaleX((mToolbarContainer.getVisibility() != VISIBLE ? 1f : -1f) * mRtl);

// hide pinned keys if device is locked, and avoid expanding toolbar
Expand All @@ -258,7 +265,6 @@ private void updateKeys() {
: km.isKeyguardLocked();
mToolbarExpandKey.setOnClickListener(hideToolbarKeys ? null : this);
mPinnedKeys.setVisibility(hideToolbarKeys ? GONE : mSuggestionsStrip.getVisibility());
isInlineAutofillSuggestionsVisible = false;
}

public void setRtl(final boolean isRtlLanguage) {
Expand All @@ -272,6 +278,10 @@ public void setRtl(final boolean isRtlLanguage) {
mStripVisibilityGroup.setLayoutDirection(layoutDirection);
}

public void updateSuggestedWords(final SuggestedWords suggestedWords){
mSuggestedWords = suggestedWords;
}

public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) {
clear();
setRtl(isRtlLanguage);
Expand All @@ -282,11 +292,24 @@ public void setSuggestions(final SuggestedWords suggestedWords, final boolean is
}

public void setInlineSuggestionsView(final View view) {
clear();
isInlineAutofillSuggestionsVisible = true;
mSuggestionsStrip.addView(view);
if (Settings.getInstance().getCurrent().mAutoHideToolbar)
setToolbarVisibility(false);
mSuggestionsStrip.addView(view, 0);
setToolbarVisibility(false);
updateKeys();
}

public void resetInlineSuggestions(){
areInlineSuggestionsDismissed = false;
clear();
updateKeys();
}

public boolean isInlineAutofillSuggestionsVisible(){
return isInlineAutofillSuggestionsVisible;
}

public boolean areInlineSuggestionsDismissed(){
return areInlineSuggestionsDismissed;
}

@Override
Expand All @@ -304,6 +327,7 @@ public void setMoreSuggestionsHeight(final int remainingHeight) {
@SuppressLint("ClickableViewAccessibility") // why would "null" need to call View#performClick?
private void clear() {
mSuggestionsStrip.removeAllViews();
isInlineAutofillSuggestionsVisible = false;
if (DEBUG_SUGGESTIONS)
removeAllDebugInfoViews();
if (mToolbarContainer.getVisibility() != VISIBLE)
Expand Down Expand Up @@ -657,7 +681,12 @@ public void onClick(final View view) {
}
}
if (view == mToolbarExpandKey) {
setToolbarVisibility(mToolbarContainer.getVisibility() != VISIBLE);
if (isInlineAutofillSuggestionsVisible) {
areInlineSuggestionsDismissed = true;
setSuggestions(mSuggestedWords, mRtl == -1);
} else {
setToolbarVisibility(mToolbarContainer.getVisibility() != VISIBLE);
}
}


Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/suggestions_strip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<LinearLayout
android:id="@+id/pinned_keys"
android:orientation="horizontal"
android:minWidth="0dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
style="?attr/suggestionWordStyle">
Expand Down