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

Commit 10c080c1 authored by Ahaan Ugale's avatar Ahaan Ugale Committed by Automerger Merge Worker
Browse files

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

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14094192

Change-Id: I278368bf7f80c69a839a8e4d51ac9c08c32da0db
parents 55a95b12 4b163155
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -78,11 +78,24 @@ public class TranslationTransformationMethod implements TransformationMethod2 {
        if (TextUtils.isEmpty(translatedText) || isWhitespace(translatedText.toString())) {
        if (TextUtils.isEmpty(translatedText) || isWhitespace(translatedText.toString())) {
            return source;
            return source;
        } else {
        } 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
            // TODO(b/174283799): apply the spans to the text
            return translatedText;
            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
    @Override
    public void onFocusChanged(View view, CharSequence sourceText,
    public void onFocusChanged(View view, CharSequence sourceText,
            boolean focused, int direction,
            boolean focused, int direction,