/
TagTextRecycler.java
77 lines (68 loc) · 2.54 KB
/
TagTextRecycler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.zpf.views.tagtext;
import androidx.annotation.NonNull;
import java.util.ArrayList;
import java.util.List;
public class TagTextRecycler {
private int index = 0;
private int itemPosition = 0;
private int paddingStart;
private int paddingTop;
private float textHeight;
private int lineHeight;
private List<TagTextPieceInfo> partList;
private List<TagTextItem> itemList;
public TagTextRecycler() {
itemList = new ArrayList<>(16);
partList = new ArrayList<>(48);
for (int i = 0; i < 48; i++) {
partList.add(new TagTextPieceInfo());
if (i < 16) {
itemList.add(new TagTextItem());
}
}
}
public TagTextItem obtainTextItem(int id, String text, TagTextStyle style) {
return obtainTextItem(id, text, style,true);
}
public TagTextItem obtainTextItem(int id, String text, TagTextStyle style, boolean next) {
if (next) {
itemPosition++;
} else {
itemPosition = 0;
}
while (itemList.size() <= itemPosition) {
itemList.add(new TagTextItem());
}
TagTextItem tagTextItem = itemList.get(itemPosition);
tagTextItem.textId = id;
tagTextItem.textStr = text;
tagTextItem.style.copyStyle(style);
return tagTextItem;
}
public void reset(int dX, int dY, float tHeight, int lHeight) {
index = 0;
textHeight = tHeight;
lineHeight = lHeight;
paddingTop = dY;
paddingStart = dX;
}
public TagTextPieceInfo obtainOnePiece(int startIndex, int endIndex, float left, float width, int line, float addParagraphSpace) {
while (partList.size() <= index) {
partList.add(new TagTextPieceInfo());
}
TagTextPieceInfo textPart = partList.get(index);
recombination(textPart, startIndex, endIndex, left, width, line, addParagraphSpace);
index++;
return textPart;
}
public void recombination(@NonNull TagTextPieceInfo pieceInfo, int startIndex, int endIndex, float left, float width, int line, float addParagraphSpace) {
pieceInfo.startIndex = startIndex;
pieceInfo.endIndex = endIndex;
pieceInfo.left = paddingStart + left;
pieceInfo.top = paddingTop + lineHeight * (line - 1) + addParagraphSpace;
pieceInfo.right = left + width;
pieceInfo.bottom = pieceInfo.top + lineHeight;
pieceInfo.drawX = left;
pieceInfo.drawY = pieceInfo.top + (lineHeight + textHeight) / 2;
}
}