Fix horizontal resize bug with quotes in messages.

fork-5.53.8
Rashad Sookram 2022-01-06 12:41:50 -05:00 zatwierdzone przez Alex Hart
rodzic 7ff2b1ab33
commit 4e67752850
1 zmienionych plików z 30 dodań i 0 usunięć

Wyświetl plik

@ -159,9 +159,16 @@ public class EmojiTextView extends AppCompatTextView {
}
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int originalWidthMode = MeasureSpec.getMode(widthMeasureSpec);
widthMeasureSpec = applyWidthMeasureRoundingFix(widthMeasureSpec);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
widthMeasureSpec = getPreciseWidthForMaxLines(originalWidthMode);
if (widthMeasureSpec != 0) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
CharSequence text = getText();
if (getLayout() == null || !measureLastLine || text == null || text.length() == 0) {
lastLineWidth = -1;
@ -209,6 +216,29 @@ public class EmojiTextView extends AppCompatTextView {
return widthMeasureSpec;
}
/**
* Determines the width to use for this view based on the lines of text that will be shown, as
* opposed to the default behavior which will consider lines after the max lines constraint.
*
* @param originalWidthMode the original mode passed for the width measure spec in {@link #onMeasure(int, int)}
* @return the new measure spec to use for the width. 0 if the existing measurement should be used.
*/
private int getPreciseWidthForMaxLines(int originalWidthMode) {
if (originalWidthMode != MeasureSpec.EXACTLY && getLineCount() > getMaxLines() && getLayout() != null) {
float maxWidth = 0;
for (int i = 0; i < getMaxLines(); i++) {
maxWidth = Math.max(maxWidth, getLayout().getLineWidth(i));
}
double desiredWidth = Math.ceil(maxWidth);
if (desiredWidth < getMeasuredWidth()) {
return MeasureSpec.makeMeasureSpec((int) desiredWidth, MeasureSpec.AT_MOST);
}
}
return 0;
}
private boolean hasMetricAffectingSpan(@NonNull CharSequence text) {
if (!(text instanceof Spanned)) {
return false;