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

Commit bffbd309 authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Reduce the number of TextAppearanceSpan objects for highlighting.

This CL removes unnecessary TextAppearanceSpan objects creation.

The hightlight text appearance of all suggestion items in popup window
are the same, so it is not make much sense to create TextAppearanceSpan
objects for each suggestion item.

This CL is a part of groundwork for Bug 15347319 and no user visible
change is intended with this CL.

Bug: 15347319
Change-Id: Ibad2e9842a76611a34187a3c942bae4ff7ea355f
parent 4e77e3ff
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -2643,6 +2643,8 @@ public class Editor {
        private SuggestionAdapter mSuggestionsAdapter;
        private final Comparator<SuggestionSpan> mSuggestionSpanComparator;
        private final HashMap<SuggestionSpan, Integer> mSpansLengths;
        private final TextAppearanceSpan mHighlightSpan = new TextAppearanceSpan(
                mTextView.getContext(), android.R.style.TextAppearance_SuggestionHighlight);

        private class CustomPopupWindow extends PopupWindow {
            public CustomPopupWindow(Context context, int defStyleAttr) {
@@ -2708,8 +2710,6 @@ public class Editor {
            SuggestionSpan suggestionSpan; // the SuggestionSpan that this TextView represents
            int suggestionIndex; // the index of this suggestion inside suggestionSpan
            SpannableStringBuilder text = new SpannableStringBuilder();
            TextAppearanceSpan highlightSpan = new TextAppearanceSpan(mTextView.getContext(),
                    android.R.style.TextAppearance_SuggestionHighlight);
        }

        private class SuggestionAdapter extends BaseAdapter {
@@ -2941,7 +2941,7 @@ public class Editor {
                    suggestionInfo.suggestionIndex = ADD_TO_DICTIONARY;
                    suggestionInfo.text.replace(0, suggestionInfo.text.length(), mTextView.
                            getContext().getString(com.android.internal.R.string.addToDictionary));
                    suggestionInfo.text.setSpan(suggestionInfo.highlightSpan, 0, 0,
                    suggestionInfo.text.setSpan(mHighlightSpan, 0, 0,
                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

                    mNumberOfSuggestions++;
@@ -2954,8 +2954,7 @@ public class Editor {
            suggestionInfo.suggestionIndex = DELETE_TEXT;
            suggestionInfo.text.replace(0, suggestionInfo.text.length(),
                    mTextView.getContext().getString(com.android.internal.R.string.deleteText));
            suggestionInfo.text.setSpan(suggestionInfo.highlightSpan, 0, 0,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            suggestionInfo.text.setSpan(mHighlightSpan, 0, 0, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mNumberOfSuggestions++;

            if (mSuggestionRangeSpan == null) mSuggestionRangeSpan = new SuggestionRangeSpan();
@@ -2986,8 +2985,8 @@ public class Editor {
            suggestionInfo.suggestionEnd = suggestionInfo.suggestionStart
                    + suggestionInfo.text.length();

            suggestionInfo.text.setSpan(suggestionInfo.highlightSpan, 0,
                    suggestionInfo.text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            suggestionInfo.text.setSpan(mHighlightSpan, 0, suggestionInfo.text.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

            // Add the text before and after the span.
            final String textAsString = text.toString();