belongs to Maven artifact androidx.core:core:1.0.0-alpha1

PrecomputedTextCompat

public class PrecomputedTextCompat
extends Object implements Spannable

java.lang.Object
   ↳ androidx.core.text.PrecomputedTextCompat


A text which has the character metrics data. A text object that contains the character metrics data and can be used to improve the performance of text layout operations. When a PrecomputedTextCompat is created with a given CharSequence, it will measure the text metrics during the creation. This PrecomputedText instance can be set on TextView or StaticLayout. Since the text layout information will be included in this instance, TextView or StaticLayout will not have to recalculate this information. On API 28 or later, there is full PrecomputedText support by framework. From API 21 to API 27, PrecomputedTextCompat relies on internal text layout cache. PrecomputedTextCompat immediately computes the text layout in the constuctor to warm up the internal text layout cache. On API 20 or before, PrecomputedTextCompat does nothing. Note that any NoCopySpan attached to the original text won't be passed to PrecomputedText.

Summary

Nested classes

class PrecomputedTextCompat.Params

The information required for building PrecomputedTextCompat

Inherited constants

Public methods

char charAt(int index)
static PrecomputedTextCompat create(CharSequence text, PrecomputedTextCompat.Params params)

Create a new PrecomputedText which will pre-compute text measurement and glyph positioning information.

int getParagraphCount()

Returns the count of paragraphs.

int getParagraphEnd(int paraIndex)

Returns the paragraph end offset of the text.

int getParagraphStart(int paraIndex)

Returns the paragraph start offset of the text.

PrecomputedTextCompat.Params getParams()

Returns the layout parameters used to measure this text.

int getSpanEnd(Object tag)
int getSpanFlags(Object tag)
int getSpanStart(Object tag)
<T> T[] getSpans(int start, int end, Class<T> type)
int length()
int nextSpanTransition(int start, int limit, Class type)
void removeSpan(Object what)
void setSpan(Object what, int start, int end, int flags)
CharSequence subSequence(int start, int end)
String toString()

Inherited methods

Public methods

charAt

char charAt (int index)

Parameters
index int

Returns
char

create

PrecomputedTextCompat create (CharSequence text, 
                PrecomputedTextCompat.Params params)

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 NoCopySpan attached to the text won't be passed to the created PrecomputedText.

Parameters
text CharSequence: the text to be measured

params PrecomputedTextCompat.Params: parameters that define how text will be precomputed

Returns
PrecomputedTextCompat A PrecomputedText

getParagraphCount

int getParagraphCount ()

Returns the count of paragraphs.

Returns
int

getParagraphEnd

int getParagraphEnd (int paraIndex)

Returns the paragraph end offset of the text.

Parameters
paraIndex int

Returns
int

getParagraphStart

int getParagraphStart (int paraIndex)

Returns the paragraph start offset of the text.

Parameters
paraIndex int

Returns
int

getParams

PrecomputedTextCompat.Params getParams ()

Returns the layout parameters used to measure this text.

Returns
PrecomputedTextCompat.Params

getSpanEnd

int getSpanEnd (Object tag)

Parameters
tag Object

Returns
int

getSpanFlags

int getSpanFlags (Object tag)

Parameters
tag Object

Returns
int

getSpanStart

int getSpanStart (Object tag)

Parameters
tag Object

Returns
int

getSpans

T[] getSpans (int start, 
                int end, 
                Class<T> type)

Parameters
start int

end int

type Class

Returns
T[]

length

int length ()

Returns
int

nextSpanTransition

int nextSpanTransition (int start, 
                int limit, 
                Class type)

Parameters
start int

limit int

type Class

Returns
int

removeSpan

void removeSpan (Object what)

Parameters
what Object

Throws
IllegalArgumentException if MetricAffectingSpan is specified.

setSpan

void setSpan (Object what, 
                int start, 
                int end, 
                int flags)

Parameters
what Object

start int

end int

flags int

Throws
IllegalArgumentException if MetricAffectingSpan is specified.

subSequence

CharSequence subSequence (int start, 
                int end)

Parameters
start int

end int

Returns
CharSequence

toString

String toString ()

Returns
String