public class TextLayout extends java.lang.Object implements ContentView.OptionsChangeListener
Modifier and Type | Class and Description |
---|---|
class |
TextLayout.LinesIterator
iterator to quick access to lines properties
developed to support MultiColumnTextViewEx's height==MeasureSpec.UNSPECIFIED
|
class |
TextLayout.Options |
class |
TextLayout.TextLine |
Modifier and Type | Field and Description |
---|---|
protected char[] |
chars |
protected int |
height |
protected boolean |
justification |
protected java.util.List<TextLayout.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)
render calculated lines to canvas
|
int |
draw(java.util.List<TextLayout.TextLine> lines,
int startLine,
int endLine,
char[] text,
android.graphics.Canvas canvas,
float width,
float height,
android.text.TextPaint paint,
int selectionStart,
int selectionEnd,
int selectionColor,
int highlightStart,
int highlightEnd,
int highlightColor,
boolean justification) |
protected char[] |
getChars() |
int |
getEnd() |
int |
getHeight() |
int |
getLineBottom(int line) |
float |
getLineDescent(int line) |
int |
getLineEnd(int line) |
int |
getLineForPosition(int 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(TextLayout.TextLine line,
int atX) |
ContentView.Options |
getOptions()
return layout's Options
|
android.text.TextPaint |
getPaint() |
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 |
invalidateMeasurement()
called when font size was changed
|
protected void |
invalidateMeasurementInternal() |
boolean |
isLayouted() |
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() |
protected void |
onFinish(java.util.List<TextLayout.TextLine> lines,
int height)
method, where handles layout finish
|
protected boolean |
onProgress(java.util.List<TextLayout.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 |
removeHighlight(int start,
int end) |
void |
resetHighlight()
reset hightlits (similar to setHighlight(0,0,0))
|
void |
setHighlight(int start,
int end,
int color)
set highlight text range
|
void |
setInvalidateListener(TextLayoutListener listener) |
protected void |
setIsLayoutedInternal(boolean value) |
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,
int argb)
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
|
protected 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 boolean justification
protected int viewHeight
protected java.util.List<TextLayout.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 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 int getLineForVertical(float y)
y-coordinate
- on canvaspublic void setInvalidateListener(TextLayoutListener listener)
public int getWidth()
public TextLayout.LinesIterator getLinesIterator()
public java.lang.String getState()
public int getOffsetForCoordinates(android.view.View view, float x, float y, int startsFromLine)
view
- - view we attached tox
- - x coordinatey
- - y coordinatestartsFromLine
- public 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()
public void draw(android.graphics.Canvas canvas, int left, int top, int right, int bottom, int startLine, int endLine)
canvas
- - canvasleft
- - left offset of layout recttop
- - top offset of layout rectright
- - right bound of layout rectbottom
- - bottom bound of layout rectpublic 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, int argb)
start
- - range startend
- - range endargb
- - color (ARGB)protected int getSelectionColor()
public void resetHighlight()
public int getSelectionStarts()
public int getSelectionEnds()
public float getLineDescent(int line)
line
- public int getLineForPosition(int position)
public 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 invalidateLines()
invalidateLines
in interface ContentView.OptionsChangeListener
protected void invalidateMeasurementInternal()
protected void stopReflowIfNeed()
protected boolean updateGeometry(int[] geometry)
geometry
- protected java.lang.String log_single_line(int line)
protected boolean onProgress(java.util.List<TextLayout.TextLine> lines, int collectedHeight, boolean viewHeightExceed)
lines
- collectedHeight
- viewHeightExceed
- protected void onFinish(java.util.List<TextLayout.TextLine> lines, int height)
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<TextLayout.TextLine> lines, int startLine, int endLine, char[] text, android.graphics.Canvas canvas, float width, float height, android.text.TextPaint paint, int selectionStart, int selectionEnd, int selectionColor, int highlightStart, int highlightEnd, int highlightColor, boolean justification)
public final int getOffsetForHorizontal(TextLayout.TextLine line, int atX)
line
- - number of line (atX
- - x-coordinate from line starts