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

Commit 4b163155 authored by Ahaan Ugale's avatar Ahaan Ugale Committed by Android (Google) Code Review
Browse files

Merge "UiTranslation: Temporary fix for crash due to length increases." into sc-dev

parents dabc72e5 8c48915e
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -78,11 +78,24 @@ public class TranslationTransformationMethod implements TransformationMethod2 {
        if (TextUtils.isEmpty(translatedText) || isWhitespace(translatedText.toString())) {
            return source;
        } else {
            // TODO(b/179693024): Remove this once we have the fix to pad the view text instead.
            translatedText = ellipsize(translatedText, ((TextView) view).getText().length());
            // TODO(b/174283799): apply the spans to the text
            return translatedText;
        }
    }

    private static CharSequence ellipsize(CharSequence text, int newLength) {
        if (text.length() <= newLength) {
            return text;
        }
        String ellipsis = String.valueOf('\u2026');
        if (newLength == 1) {
            return ellipsis;
        }
        return TextUtils.concat(TextUtils.trimToSize(text, newLength - 1), ellipsis);
    }

    @Override
    public void onFocusChanged(View view, CharSequence sourceText,
            boolean focused, int direction,