Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba4997ac authored by Gilles Debunne's avatar Gilles Debunne
Browse files

All SuggestionSpans are removed when the window loses focus.

SuggestionSpans should have a limited, well defined life-span.
Saving these in onSaveInstanceState is inappropriate since these can
be very large and will not necessarily be saved/loaded by the application.

Keeping them in the application when it is dismissed is not consistent
since they may be garbage collected while the application is not active.

Change-Id: Icebf6cb0218528f9d162a689ad33efeb770fbede
parent f0cae1a3
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -7260,11 +7260,23 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                mInputContentType.enterDown = false;
            }
            hideControllers();
            removeAllSuggestionSpans();
        }

        startStopMarquee(hasWindowFocus);
    }

    private void removeAllSuggestionSpans() {
        if (mText instanceof Editable) {
            Editable editable = ((Editable) mText);
            SuggestionSpan[] spans = editable.getSpans(0, mText.length(), SuggestionSpan.class);
            final int length = spans.length;
            for (int i = 0; i < length; i++) {
                editable.removeSpan(spans[i]);
            }
        }
    }

    @Override
    protected void onVisibilityChanged(View changedView, int visibility) {
        super.onVisibilityChanged(changedView, visibility);