@Test public void testCreate_withNull() { final Params param = new Params.Builder(PAINT).build(); try { PrecomputedTextCompat.create(NULL_CHAR_SEQUENCE, param); fail(); } catch (NullPointerException e) { } try { PrecomputedTextCompat.create(STRING, null); fail(); } catch (NullPointerException e) { } }
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); }
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) { 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); } }
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) { 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); } private  PrecomputedTextCompat(@NonNull CharSequence text, @NonNull Params params,
            @NonNull int[] paraEnds); @RequiresApi(28) private  PrecomputedTextCompat(@NonNull PrecomputedText precomputed, @NonNull Params params); }
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) { 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); } private  PrecomputedTextCompat(@NonNull CharSequence text, @NonNull Params params,
            @NonNull int[] paraEnds); @RequiresApi(28) private  PrecomputedTextCompat(@NonNull PrecomputedText precomputed, @NonNull Params params); static PrecomputedTextCompat create(@NonNull CharSequence text, @NonNull Params params); @NonNull Params getParams(); @IntRange(from = 0) int getParagraphCount(); @IntRange(from = 0) int getParagraphStart(@IntRange(from = 0) int paraIndex); @IntRange(from = 0) int getParagraphEnd(@IntRange(from = 0) int paraIndex); @Override void setSpan(Object what, int start, int end, int flags); @Override void removeSpan(Object what); @Override T[] getSpans(int start, int end, Class<T> type); @Override int getSpanStart(Object tag); @Override int getSpanEnd(Object tag); @Override int getSpanFlags(Object tag); @Override int nextSpanTransition(int start, int limit, Class type); @Override int length(); @Override char charAt(int index); @Override CharSequence subSequence(int start, int end); @Override String toString(); }
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) { 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); } private  PrecomputedTextCompat(@NonNull CharSequence text, @NonNull Params params,
            @NonNull int[] paraEnds); @RequiresApi(28) private  PrecomputedTextCompat(@NonNull PrecomputedText precomputed, @NonNull Params params); static PrecomputedTextCompat create(@NonNull CharSequence text, @NonNull Params params); @NonNull Params getParams(); @IntRange(from = 0) int getParagraphCount(); @IntRange(from = 0) int getParagraphStart(@IntRange(from = 0) int paraIndex); @IntRange(from = 0) int getParagraphEnd(@IntRange(from = 0) int paraIndex); @Override void setSpan(Object what, int start, int end, int flags); @Override void removeSpan(Object what); @Override T[] getSpans(int start, int end, Class<T> type); @Override int getSpanStart(Object tag); @Override int getSpanEnd(Object tag); @Override int getSpanFlags(Object tag); @Override int nextSpanTransition(int start, int limit, Class type); @Override int length(); @Override char charAt(int index); @Override CharSequence subSequence(int start, int end); @Override String toString();  }