-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColumnManager.cs
More file actions
145 lines (116 loc) · 3.37 KB
/
ColumnManager.cs
File metadata and controls
145 lines (116 loc) · 3.37 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using Android.Graphics;
using System.Collections.Generic;
namespace Escorp.Android.Views
{
internal class ColumnManager
{
internal readonly List<Column> columns = new List<Column>();
private readonly DrawMetrics metrics;
private CharacterList[] characterLists;
private List<char> supportedCharacters;
internal ColumnManager(DrawMetrics metrics) => this.metrics = metrics;
internal virtual void SetCharacterLists(params string[] characterLists)
{
this.characterLists = new CharacterList[characterLists.Length];
for (int i = 0; i < characterLists.Length; i++) this.characterLists[i] = new CharacterList(characterLists[i]);
supportedCharacters = new List<char>();
for (int i = 0; i < characterLists.Length; i++) supportedCharacters.AddRange(this.characterLists[i].SupportedCharacters);
foreach (Column tickerColumn in columns) tickerColumn.CharacterLists = this.characterLists;
}
internal virtual CharacterList[] GetCharacterLists() => characterLists;
internal virtual char[] Text
{
set
{
if (characterLists == null) SetCharacterLists(Utils.ProvideNumberList, Utils.ProvideAlphabeticalList);
for (int i = 0; i < columns.Count;)
{
Column tickerColumn = columns[i];
if (tickerColumn.CurrentWidth > 0)
i++;
else
columns.RemoveAt(i);
}
int[] actions = LevenshteinUtils.ComputeColumnActions(CurrentText, value, supportedCharacters);
int columnIndex = 0;
int textIndex = 0;
for (int i = 0; i < actions.Length; i++)
{
switch (actions[i])
{
case LevenshteinUtils.ActionInsert:
columns.Insert(columnIndex, new Column(characterLists, metrics));
goto case LevenshteinUtils.ActionSame;
case LevenshteinUtils.ActionSame:
columns[columnIndex].TargetChar = value[textIndex];
columnIndex++;
textIndex++;
break;
case LevenshteinUtils.ActionDelete:
columns[columnIndex].TargetChar = Utils.EmptyChar;
columnIndex++;
break;
default:
throw new System.ArgumentException("Unknown action: " + actions[i]);
}
}
}
}
internal virtual void OnAnimationEnd()
{
for (int i = 0, size = columns.Count; i < size; i++)
{
Column column = columns[i];
column.OnAnimationEnd();
}
}
internal virtual float AnimationProgress
{
set
{
for (int i = 0, size = columns.Count; i < size; i++)
{
Column column = columns[i];
column.AnimationProgress = value;
}
}
}
internal virtual float MinimumRequiredWidth
{
get
{
float width = 0f;
for (int i = 0, size = columns.Count; i < size; i++) width += columns[i].MinimumRequiredWidth;
return width;
}
}
internal virtual float CurrentWidth
{
get
{
float width = 0f;
for (int i = 0, size = columns.Count; i < size; i++) width += columns[i].CurrentWidth;
return width;
}
}
internal virtual char[] CurrentText
{
get
{
int size = columns.Count;
char[] currentText = new char[size];
for (int i = 0; i < size; i++) currentText[i] = columns[i].CurrentChar;
return currentText;
}
}
internal virtual void Draw(Canvas canvas, Paint textPaint)
{
for (int i = 0, size = columns.Count; i < size; i++)
{
Column column = columns[i];
column.Draw(canvas, textPaint);
canvas.Translate(column.CurrentWidth, 0f);
}
}
}
}