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

Commit bc1827ae authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Fix issue where line breaks would be wrong

It's not possible to getLayout() after calling setText since the new
layout will only be calculated on the next onMeasure.

Test: visual
Bug: 78891765
Change-Id: I69ba425407e277156b702050a97dbbd29c8d66a9
parent f39ce10e
Loading
Loading
Loading
Loading
+21 −12
Original line number Diff line number Diff line
@@ -166,18 +166,6 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
            SliceItem mainTitle = header.getTitleItem();
            CharSequence title = mainTitle != null ? mainTitle.getText() : null;
            mTitle.setText(title);

            // Check if we're already ellipsizing the text.
            // We're going to figure out the best possible line break if not.
            Layout layout = mTitle.getLayout();
            if (layout != null){
                final int lineCount = layout.getLineCount();
                if (lineCount > 0) {
                    if (layout.getEllipsisCount(lineCount - 1) == 0) {
                        mTitle.setText(findBestLineBreak(title));
                    }
                }
            }
        }

        mClickActions.clear();
@@ -381,6 +369,27 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
        mIconSize = mContext.getResources().getDimensionPixelSize(R.dimen.widget_icon_size);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        // Find best ellipsis strategy for the title.
        // Done on onMeasure since TextView#getLayout needs a measure pass to calculate its bounds.
        Layout layout = mTitle.getLayout();
        if (layout != null) {
            final int lineCount = layout.getLineCount();
            if (lineCount > 0) {
                if (layout.getEllipsisCount(lineCount - 1) == 0) {
                    CharSequence title = mTitle.getText();
                    CharSequence bestLineBreak = findBestLineBreak(title);
                    if (!TextUtils.equals(title, bestLineBreak)) {
                        mTitle.setText(bestLineBreak);
                    }
                }
            }
        }
    }

    public static class Row extends LinearLayout {

        /**