public class TextLayout extends java.lang.Object implements ITextLayout, ContentView.OptionsChangeListener
Modifier and Type | Class and Description |
---|---|
static class |
TextLayout.DefaultLineBreaker
default LineBreaker implementation
|
class |
TextLayout.LinesIterator
iterator to quick access to lines properties
developed to support MultiColumnTextViewEx's height==MeasureSpec.UNSPECIFIED
|
class |
TextLayout.Options |
Modifier and Type | Field and Description |
---|---|
protected char[] |
chars |
protected int |
height |
protected java.util.List<TextLine> |
lines |
protected su.whs.watl.text.LineSpan |
lineSpan |
protected TextLayoutListener |
listener |
protected int |
mViewsCount |
protected int |
reflowedHeight |
protected int |
reflowedWidth |
protected int |
requestedHeight |
protected int |
viewHeight |
protected int |
width |
Constructor and Description |
---|
TextLayout() |
TextLayout(android.text.Spanned text,
int start,
int end,
android.text.TextPaint paint,
ContentView.Options options,
TextLayoutListener invalidateListener) |
TextLayout(android.text.Spanned text,
int start,
int end,
android.text.TextPaint paint,
TextLayoutListener invalidateListener) |
TextLayout(android.text.Spanned text,
android.text.TextPaint paint) |
TextLayout(android.text.Spanned text,
android.text.TextPaint paint,
TextLayoutListener invalidateListener) |
Modifier and Type | Method and Description |
---|---|
void |
addHighlight(int start,
int end,
int color) |
void |
draw(android.graphics.Canvas canvas,
int left,
int top,
int right,
int bottom) |
void |
draw(android.graphics.Canvas canvas,
int left,
int top,
int right,
int bottom,
int startLine,
int endLine) |
int |
draw(java.util.List<TextLine> lines,
int startLine,
int endLine,
char[] text,
android.graphics.Canvas canvas,
android.graphics.Rect clipRect,
float width,
float height,
android.text.TextPaint paint,
int selectionStart,
int selectionEnd,
int selectionColor,
int highlightStart,
int highlightEnd,
int highlightColor,
boolean justification) |
void |
finalize() |
protected char[] |
getChars() |
android.graphics.drawable.Drawable.Callback |
getDrawableCallbacks() |
int |
getDynamicDrawablePosition(android.text.style.DynamicDrawableSpan span) |
boolean |
getDynamicDrawableSpanRect(android.text.style.DynamicDrawableSpan dds,
android.graphics.Rect out) |
int |
getEnd() |
int |
getHeight() |
TextLayoutListener |
getInvalidateListener() |
int |
getLineBottom(int line) |
float |
getLineDescent(int line) |
int |
getLineEnd(int line) |
int |
getLineForPosition(int position)
find line for character position
|
int |
getLineForVertical(float y) |
int |
getLineForVertical(float y,
int startLine) |
float |
getLineHeight(int line) |
int |
getLinesCount() |
TextLayout.LinesIterator |
getLinesIterator() |
protected su.whs.watl.text.LineSpan |
getLineSpan() |
int |
getLineStart(int line) |
int |
getLineTop(int line) |
int |
getOffsetForCoordinates(android.view.View view,
float x,
float y,
int startsFromLine) |
int |
getOffsetForHorizontal(TextLine line,
int x) |
ContentView.Options |
getOptions()
return layout's Options
|
android.text.TextPaint |
getPaint() |
android.graphics.drawable.Drawable.Callback |
getPlaceholderCallbacks() |
int |
getPrimaryHorizontal(int line,
int position)
calculate horizontal offset of character with index 'position'
|
protected int |
getSelectionColor() |
int |
getSelectionEnds() |
int |
getSelectionStarts() |
int |
getStart() |
java.lang.String |
getState() |
java.lang.CharSequence |
getText() |
android.text.TextPaint |
getTextPaint() |
int |
getWidth() |
void |
invalidate()
invalidate layout
actually, invalidate() works only if width/font size changed
|
void |
invalidateLines()
called when layout geometry was changed, or some handlers replaced
|
void |
invalidateLinesFrom(int position) |
void |
invalidateMeasurement()
called when font size was changed
|
void |
invalidateMeasurementFrom(int position) |
protected void |
invalidateMeasurementInternal() |
protected void |
invalidateMeasurementInternal(int line,
su.whs.watl.text.LineSpan span) |
boolean |
isLayouted() |
boolean |
isLineAreWrap(int line) |
protected boolean |
isReflowBackgroundTaskCancelled() |
boolean |
isReflowBackgroundTaskRunning() |
protected boolean |
isReflowFinished() |
protected java.lang.String |
log_single_line(int line) |
void |
notifyTextHeightChanged() |
protected void |
notifyTextInfoInvalidated() |
protected void |
notifyTextReady() |
void |
onFinish(java.util.List<TextLine> lines,
int height)
method, where handles layout finish
|
boolean |
onProgress(java.util.List<TextLine> lines,
int collectedHeight,
boolean viewHeightExceed)
method where handles interaction with TextLayoutListener
when overriden - onProgress() must increments mViewsCount on every viewHeightExceed==true
|
protected void |
reflow(char[] text,
int lineStartAt,
int textEnd,
su.whs.watl.text.LineSpan _startSpan,
float x,
int width,
int y,
int height,
int viewHeight,
android.text.TextPaint paint,
ContentView.Options options)
main method used for calculating spans geometry with given base TextPaint, width and height limit, and so on
|
void |
registerDrawable(android.text.style.DynamicDrawableSpan dds,
int placement,
int position) |
void |
release() |
void |
removeHighlight(int start,
int end) |
void |
resetHighlight()
reset hightlits (similar to setHighlight(0,0,0))
|
void |
setDrawableBounds(android.graphics.drawable.Drawable d,
int left,
int top,
int right,
int bottom) |
void |
setHighlight(int start,
int end,
int color)
set highlight text range
|
void |
setInvalidateListener(TextLayoutListener listener) |
protected void |
setIsLayoutedInternal(boolean value) |
void |
setMaxLines(int maxLines) |
protected void |
setPaint(android.text.TextPaint paint) |
protected void |
setReflowBackgroundTaskCancelled(boolean cancelled) |
protected void |
setReflowBackgroundTaskRunning(boolean running) |
protected void |
setReflowFinished(boolean finished) |
void |
setSelection(int start,
int end)
set selected text range
|
void |
setSize(int width,
int height) |
void |
setSize(int width,
int height,
int viewHeight)
set size for layout where 'visible height' < available height
used for split layout to pages
|
void |
setTextSize(float size) |
protected void |
stopReflowIfNeed()
stop background thread, if running
|
boolean |
updateGeometry(int[] geometry)
default implementation does not supports geometry change supports
|
protected char[] chars
protected su.whs.watl.text.LineSpan lineSpan
protected int width
protected int reflowedWidth
protected int height
protected int reflowedHeight
protected int requestedHeight
protected TextLayoutListener listener
protected int viewHeight
protected java.util.List<TextLine> lines
protected int mViewsCount
public TextLayout(android.text.Spanned text, int start, int end, android.text.TextPaint paint, TextLayoutListener invalidateListener)
public TextLayout(android.text.Spanned text, int start, int end, android.text.TextPaint paint, ContentView.Options options, TextLayoutListener invalidateListener)
text
- - Spanned instancestart
- - begin of text whe want to layoutend
- - end of textpaint
- - default paintinvalidateListener
- public TextLayout()
public TextLayout(android.text.Spanned text, android.text.TextPaint paint)
public TextLayout(android.text.Spanned text, android.text.TextPaint paint, TextLayoutListener invalidateListener)
public int getDynamicDrawablePosition(android.text.style.DynamicDrawableSpan span)
public boolean isLayouted()
protected void setIsLayoutedInternal(boolean value)
public void notifyTextHeightChanged()
protected void notifyTextInfoInvalidated()
protected void notifyTextReady()
public int getLineForVertical(float y, int startLine)
y
- startLine
- public boolean isLineAreWrap(int line)
public int getLineForVertical(float y)
y-coordinate
- on canvaspublic void setInvalidateListener(TextLayoutListener listener)
public TextLayoutListener getInvalidateListener()
public int getWidth()
public TextLayout.LinesIterator getLinesIterator()
public java.lang.String getState()
public void release()
public int getOffsetForCoordinates(android.view.View view, float x, float y, int startsFromLine)
view
- - view we attached tox
- - x coordinatey
- - y coordinatestartsFromLine
- public boolean getDynamicDrawableSpanRect(android.text.style.DynamicDrawableSpan dds, android.graphics.Rect out)
dds
- - DynamicDrawableSpanout
- - Rect instancepublic int getLinesCount()
public int getLineStart(int line)
public int getLineEnd(int line)
public int getLineTop(int line)
public int getLineBottom(int line)
public int getPrimaryHorizontal(int line, int position)
line
- position
- public int getHeight()
public android.text.TextPaint getTextPaint()
getTextPaint
in interface ContentView.OptionsChangeListener
public void setTextSize(float size)
setTextSize
in interface ContentView.OptionsChangeListener
size
- public void setSize(int width, int height)
width
- - width of viewheight
- - height of view or -1, if need height of all textpublic void setSize(int width, int height, int viewHeight)
width
- - width of viewheight
- - height (-1 if unlimited height)viewHeight
- - 'visible height'public void invalidate()
invalidate
in interface ContentView.OptionsChangeListener
protected void setPaint(android.text.TextPaint paint)
public ContentView.Options getOptions()
getOptions
in interface ITextLayout
public void draw(android.graphics.Canvas canvas, int left, int top, int right, int bottom, int startLine, int endLine)
public void draw(android.graphics.Canvas canvas, int left, int top, int right, int bottom)
canvas
- left
- top
- right
- bottom
- protected char[] getChars()
protected su.whs.watl.text.LineSpan getLineSpan()
public void setHighlight(int start, int end, int color)
start
- - range startend
- - - range endcolor
- - color (ARGB)public void addHighlight(int start, int end, int color)
start
- end
- color
- public void removeHighlight(int start, int end)
start
- end
- public void setSelection(int start, int end)
start
- - range startend
- - range endprotected int getSelectionColor()
public void resetHighlight()
public int getSelectionStarts()
public int getSelectionEnds()
public float getLineDescent(int line)
line
- public int getLineForPosition(int position)
position
- - character position in textpublic float getLineHeight(int line)
line
- public java.lang.CharSequence getText()
public int getStart()
public int getEnd()
public android.text.TextPaint getPaint()
public boolean isReflowBackgroundTaskRunning()
protected boolean isReflowBackgroundTaskCancelled()
protected void setReflowBackgroundTaskRunning(boolean running)
protected void setReflowBackgroundTaskCancelled(boolean cancelled)
protected void setReflowFinished(boolean finished)
protected boolean isReflowFinished()
public void invalidateMeasurement()
invalidateMeasurement
in interface ContentView.OptionsChangeListener
public void invalidateMeasurementFrom(int position)
public void invalidateLines()
invalidateLines
in interface ContentView.OptionsChangeListener
public void invalidateLinesFrom(int position)
protected void invalidateMeasurementInternal()
protected void invalidateMeasurementInternal(int line, su.whs.watl.text.LineSpan span)
protected void stopReflowIfNeed()
public boolean updateGeometry(int[] geometry)
updateGeometry
in interface ITextLayout
geometry
- protected java.lang.String log_single_line(int line)
public boolean onProgress(java.util.List<TextLine> lines, int collectedHeight, boolean viewHeightExceed)
onProgress
in interface ITextLayout
lines
- collectedHeight
- viewHeightExceed
- public void registerDrawable(android.text.style.DynamicDrawableSpan dds, int placement, int position)
registerDrawable
in interface ITextLayout
public android.graphics.drawable.Drawable.Callback getPlaceholderCallbacks()
getPlaceholderCallbacks
in interface ITextLayout
public android.graphics.drawable.Drawable.Callback getDrawableCallbacks()
getDrawableCallbacks
in interface ITextLayout
public void onFinish(java.util.List<TextLine> lines, int height)
onFinish
in interface ITextLayout
lines
- height
- protected void reflow(char[] text, int lineStartAt, int textEnd, su.whs.watl.text.LineSpan _startSpan, float x, int width, int y, int height, int viewHeight, android.text.TextPaint paint, ContentView.Options options)
text
- - array of charslineStartAt
- - first character of line we startstextEnd
- - last available character (so, we process only slice text[lineStartAt:textEnd]_startSpan
- - if not null - will continue reflow from _startSpan (used for lasy reflow)x
- - start from given x coordwidth
- - available width limit in pixelsy
- - start from given y coordheight
- - available height limit (or -1 if no known height - i.e. for scrollable) : TODOviewHeight
- - used for lazy reflow (we reflow at least viewHeight*1.5 for performance) : TODOpaint
- - base Paintoptions
- - optionspublic int draw(java.util.List<TextLine> lines, int startLine, int endLine, char[] text, android.graphics.Canvas canvas, android.graphics.Rect clipRect, float width, float height, android.text.TextPaint paint, int selectionStart, int selectionEnd, int selectionColor, int highlightStart, int highlightEnd, int highlightColor, boolean justification)
public void setDrawableBounds(android.graphics.drawable.Drawable d, int left, int top, int right, int bottom)
setDrawableBounds
in interface ITextLayout
public void setMaxLines(int maxLines)
setMaxLines
in interface ITextLayout
public final int getOffsetForHorizontal(TextLine line, int x)
line
- - number of line (x
- - x-coordinate from line startspublic void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable