class PrecomputedTextCompat implements Spannable {

    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);
    }

    private  PrecomputedTextCompat(@NonNull CharSequence text, @NonNull Params params,
            @NonNull int[] paraEnds);
    @RequiresApi(28) private  PrecomputedTextCompat(@NonNull PrecomputedText precomputed, @NonNull Params params);

}