Package icyllis.modernui.text
Class DynamicLayout.Builder
java.lang.Object
icyllis.modernui.text.DynamicLayout.Builder
- Enclosing class:
DynamicLayout
Builder for dynamic layouts. The builder is the preferred pattern for constructing
DynamicLayout objects and should be preferred over the constructors, particularly to access
newer features. To build a dynamic layout, first call
DynamicLayout.builder(java.lang.CharSequence, icyllis.modernui.text.TextPaint, int)
with the required
arguments (base, paint, and width), then call setters for optional parameters, and finally
build()
to build the DynamicLayout object. Parameters not explicitly set will get
default values.-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build theDynamicLayout
after options have been set.setAlignment
(Layout.Alignment alignment) Set the alignment.setDisplayText
(CharSequence display) Set the transformed text (password transformation being the primary example of a transformation) that will be updated as the base text is changed.setEllipsize
(TextUtils.TruncateAt ellipsize) Set ellipsizing on the layout.setEllipsizedWidth
(int ellipsizedWidth) Set the width as used for ellipsizing purposes, if it differs from the normal layout width.setFallbackLineSpacing
(boolean fallbackLineSpacing) Set whether to respect the ascent and descent of the fallback fonts that are used in displaying the text (which is needed to avoid text from consecutive lines running into each other).setIncludePad
(boolean includePad) Set whether to include extra space beyond font ascent and descent (which is needed to avoid clipping in some languages, such as Arabic and Kannada).setTextDirection
(TextDirectionHeuristic textDir) Set the text direction heuristic.
-
Method Details
-
setDisplayText
Set the transformed text (password transformation being the primary example of a transformation) that will be updated as the base text is changed. The default is the 'base' text passed to the builder's constructor.- Parameters:
display
- the transformed text- Returns:
- this builder, useful for chaining
-
setAlignment
Set the alignment. The default isLayout.Alignment.ALIGN_NORMAL
.- Parameters:
alignment
- Alignment for the resultingDynamicLayout
- Returns:
- this builder, useful for chaining
-
setTextDirection
Set the text direction heuristic. The text direction heuristic is used to resolve text direction per-paragraph based on the input text. The default isTextDirectionHeuristics.FIRSTSTRONG_LTR
.- Parameters:
textDir
- text direction heuristic for resolving bidi behavior.- Returns:
- this builder, useful for chaining
-
setIncludePad
Set whether to include extra space beyond font ascent and descent (which is needed to avoid clipping in some languages, such as Arabic and Kannada). The default istrue
.- Parameters:
includePad
- whether to include padding- Returns:
- this builder, useful for chaining
-
setFallbackLineSpacing
Set whether to respect the ascent and descent of the fallback fonts that are used in displaying the text (which is needed to avoid text from consecutive lines running into each other). If set, fallback fonts that end up getting used can increase the ascent and descent of the lines that they are used on.The default is
true
. It is required to be true if text could be in languages like Burmese or Tibetan where text is typically much taller or deeper than Latin text.- Parameters:
fallbackLineSpacing
- whether to expand line spacing based on fallback fonts- Returns:
- this builder, useful for chaining
-
setEllipsizedWidth
Set the width as used for ellipsizing purposes, if it differs from the normal layout width. The default is thewidth
passed tobuild()
.- Parameters:
ellipsizedWidth
- width used for ellipsizing, in pixels- Returns:
- this builder, useful for chaining
-
setEllipsize
Set ellipsizing on the layout. Causes words that are longer than the view is wide, or exceeding the number of lines (see #setMaxLines) in the case ofTextUtils.TruncateAt.END
orTextUtils.TruncateAt.MARQUEE
, to be ellipsized instead of broken. The default isnull
, indicating no ellipsis is to be applied.- Parameters:
ellipsize
- type of ellipsis behavior- Returns:
- this builder, useful for chaining
-
build
Build theDynamicLayout
after options have been set.Note: the builder object must not be reused in any way after calling this method. Setting parameters after calling this method, or calling it a second time on the same builder object, will likely lead to unexpected results.
- Returns:
- the newly constructed
DynamicLayout
object
-