compat/src/main/java/androidx/core/text/PrecomputedTextCompat.java
public static PrecomputedTextCompat create(@NonNull CharSequence text, @NonNull Params params) {
        Preconditions.checkNotNull(text);
        Preconditions.checkNotNull(params);

        if (BuildCompat.isAtLeastP() && params.mWrapped != null) {
            return new PrecomputedTextCompat(PrecomputedText.create(text, params.mWrapped), params);
        }

        ArrayList<Integer> ends = new ArrayList<>();

        int paraEnd = 0;
        int end = text.length();
        for (int paraStart = 0; paraStart < end; paraStart = paraEnd) {
            paraEnd = TextUtils.indexOf(text, LINE_FEED, paraStart, end);
            if (paraEnd < 0) {
                // No LINE_FEED(U+000A) character found. Use end of the text as the paragraph
                // end.
                paraEnd = end;
            } else {
                paraEnd++;  // Includes LINE_FEED(U+000A) to the prev paragraph.
            }

            ends.add(paraEnd);
        }
        int[] result = new int[ends.size()];
        for (int i = 0; i < ends.size(); ++i) {
            result[i] = ends.get(i);
        }

        // No framework support for PrecomputedText
        // Compute text layout and throw away StaticLayout for the purpose of warming up the
        // internal text layout cache.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            StaticLayout.Builder.obtain(text, 0, text.length(), params.getTextPaint(),
                    Integer.MAX_VALUE)
                    .setBreakStrategy(params.getBreakStrategy())
                    .setHyphenationFrequency(params.getHyphenationFrequency())
                    .setTextDirection(params.getTextDirection())
                    .build();
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            new StaticLayout(text, params.getTextPaint(), Integer.MAX_VALUE,
                    Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        } else {
            // There is no way of precomputing text layout on API 20 or before
            // Do nothing
        }

        return new PrecomputedTextCompat(text, params, result);
    }
/**
     * Create a new {@link PrecomputedText} which will pre-compute text measurement and glyph
     * positioning information.
     * <p>
     * This can be expensive, so computing this on a background thread before your text will be
     * presented can save work on the UI thread.
     * </p>
     *
     * Note that any {@link android.text.NoCopySpan} attached to the text won't be passed to the
     * created PrecomputedText.
     *
     * @param text the text to be measured
     * @param params parameters that define how text will be precomputed
     * @return A {@link PrecomputedText}
     */
Create a new  PrecomputedText which will pre-compute text measurement and glyph
positioning information.

This can be expensive, so computing this on a background thread before your text will be
presented can save work on the UI thread.

Note that any  android.text.NoCopySpan attached to the text won't be passed to the
created PrecomputedText.

@param text the text to be measured
@param params parameters that define how text will be precomputed
@return A  PrecomputedText
Create a new PrecomputedText which will pre - compute text measurement and glyph positioning information . This can be expensive so computing this on a background thread before your text will be presented can save work on the UI thread . Note that any android . text . NoCopySpan attached to the text won ' t be passed to the created PrecomputedText . @param text the text to be measured @param params parameters that define how text will be precomputed @return A PrecomputedText
public static PrecomputedTextCompat create(@NonNull CharSequence text, @NonNull Params params) {
        Preconditions.checkNotNull(text);
        Preconditions.checkNotNull(params);
        if (BuildCompat.isAtLeastP() && params.mWrapped != null) {
            return new PrecomputedTextCompat(PrecomputedText.create(text, params.mWrapped), params);
        }
        ArrayList<Integer> ends = new ArrayList<>();
        int paraEnd = 0;
        int end = text.length();
        for (int paraStart = 0; paraStart < end; paraStart = paraEnd) {
            paraEnd = TextUtils.indexOf(text, LINE_FEED, paraStart, end);
            if (paraEnd < 0) {
                paraEnd = end;
            } else {
                paraEnd++;  
            }
            ends.add(paraEnd);
        }
        int[] result = new int[ends.size()];
        for (int i = 0; i < ends.size(); ++i) {
            result[i] = ends.get(i);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            StaticLayout.Builder.obtain(text, 0, text.length(), params.getTextPaint(),
                    Integer.MAX_VALUE)
                    .setBreakStrategy(params.getBreakStrategy())
                    .setHyphenationFrequency(params.getHyphenationFrequency())
                    .setTextDirection(params.getTextDirection())
                    .build();
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            new StaticLayout(text, params.getTextPaint(), Integer.MAX_VALUE,
                    Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        } else {
        }
        return new PrecomputedTextCompat(text, params, result);
    }
public static PrecomputedTextCompat create ( @ NonNull CharSequence text , @ NonNull Params params ) { Preconditions . checkNotNull ( text ) ; Preconditions . checkNotNull ( params ) ; if ( BuildCompat . isAtLeastP ( ) && params . mWrapped != null ) { return new PrecomputedTextCompat ( PrecomputedText . create ( text , params . mWrapped ) , params ) ; } ArrayList < Integer > ends = new ArrayList < > ( ) ; int paraEnd = 0 ; int end = text . length ( ) ; for ( int paraStart = 0 ; paraStart < end ; paraStart = paraEnd ) { paraEnd = TextUtils . indexOf ( text , LINE_FEED , paraStart , end ) ; if ( paraEnd < 0 ) { paraEnd = end ; } else { paraEnd ++ ; } ends . add ( paraEnd ) ; } int [ ] result = new int [ ends . size ( ) ] ; for ( int i = 0 ; i < ends . size ( ) ; ++ i ) { result [ i ] = ends . get ( i ) ; } if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . M ) { StaticLayout . Builder . obtain ( text , 0 , text . length ( ) , params . getTextPaint ( ) , Integer . MAX_VALUE ) . setBreakStrategy ( params . getBreakStrategy ( ) ) . setHyphenationFrequency ( params . getHyphenationFrequency ( ) ) . setTextDirection ( params . getTextDirection ( ) ) . build ( ) ; } else if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . LOLLIPOP ) { new StaticLayout ( text , params . getTextPaint ( ) , Integer . MAX_VALUE , Layout . Alignment . ALIGN_NORMAL , 1.0f , 0.0f , false ) ; } else { } return new PrecomputedTextCompat ( text , params , result ) ; }
Create a new {@link PrecomputedText} which will pre-compute text measurement and glyph
 positioning information.
Create a new { @link PrecomputedText } which will pre - compute text measurement and glyph positioning information .
// No LINE_FEED(U+000A) character found. Use end of the text as the paragraph // end. // Includes LINE_FEED(U+000A) to the prev paragraph. // No framework support for PrecomputedText // Compute text layout and throw away StaticLayout for the purpose of warming up the // internal text layout cache. // There is no way of precomputing text layout on API 20 or before // Do nothing