-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlowTextViewSharp.cs
1031 lines (824 loc) · 24.7 KB
/
FlowTextViewSharp.cs
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using Android.Content;
using Android.Content.Res;
using Android.Graphics;
using Android.Text;
using Android.Text.Style;
using Android.Util;
using Android.Views;
using Android.Widget;
using Java.Lang;
using Java.Util;
using Math = System.Math;
using Object = Java.Lang.Object;
namespace com.kobynet.text
{
public class FlowTextViewSharp : RelativeLayout
{
public FlowTextViewSharp(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
{
init(context);
}
public FlowTextViewSharp(Context context, IAttributeSet attrs) : base(context, attrs)
{
init(context);
}
public FlowTextViewSharp(Context context) : base(context)
{
init(context);
}
private Color mColor = Color.Black;
private int pageHeight = 0;
public virtual Color Color
{
set
{
this.mColor = value;
if (mTextPaint != null)
{
mTextPaint.Color = mColor;
}
foreach (TextPaint paint in mPaintHeap)
{
paint.Color = mColor;
}
this.Invalidate();
}
}
private void init(Context context)
{
mTextPaint = new TextPaint(PaintFlags.AntiAlias) {
Density = Resources.DisplayMetrics.Density,
TextSize = mTextsize,
Color = Color.Black
};
mLinkPaint = new TextPaint(PaintFlags.AntiAlias) {
Density = Resources.DisplayMetrics.Density,
TextSize = mTextsize,
Color = Color.Blue,
UnderlineText = true
};
this.SetBackgroundColor (Color.Transparent);
this.SetOnTouchListener (new OnTouchListenerAnonymousInnerClassHelper (this));
//this.OnTouchListener = new OnTouchListenerAnonymousInnerClassHelper(this);
}
private class OnTouchListenerAnonymousInnerClassHelper : IOnTouchListener
{
private readonly FlowTextViewSharp _outerInstance;
public OnTouchListenerAnonymousInnerClassHelper(FlowTextViewSharp outerInstance)
{
_outerInstance = outerInstance;
distance = 0;
}
internal double distance;
internal float x1, y1, x2, y2;
public bool OnTouch(View v, MotionEvent e)
{
var event_code = e.Action;
if (event_code == MotionEventActions.Down)
{
distance = 0;
x1 = e.GetX();
y1 = e.GetY();
}
if (event_code == MotionEventActions.Down)
{
x2 = e.GetX ();
y2 = e.GetY ();
distance = getPointDistance(x1, y1, x2, y2);
}
if (distance < 10)
{
if (event_code == MotionEventActions.Up)
{
_outerInstance.onClick(e.GetX(), @e.GetY());
}
return true;
}
else
{
return false;
}
}
public void Dispose ()
{
}
public IntPtr Handle { get; private set; }
}
private static double getPointDistance(float x1, float y1, float x2, float y2)
{
double dist = Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
return dist;
}
private TextPaint mTextPaint;
private TextPaint mLinkPaint;
private int mTextsize = 20;
public virtual int TextSize
{
set
{
this.mTextsize = value;
mTextPaint.TextSize = mTextsize;
mLinkPaint.TextSize = mTextsize;
Invalidate();
}
}
private Typeface typeFace;
public virtual Typeface Typeface
{
set
{
typeFace = value;
mTextPaint.SetTypeface (typeFace);
mLinkPaint.SetTypeface (typeFace);
Invalidate();
}
}
private int mDesiredHeight = 100; // height of the whole view
private float mSpacingMult = 1.0f;
private float mSpacingAdd = 0.0f;
private float mViewWidth;
internal class Area
{
private readonly FlowTextViewSharp outerInstance;
public Area(FlowTextViewSharp outerInstance)
{
this.outerInstance = outerInstance;
}
internal float x1;
internal float x2;
internal float width;
}
private List<Box> mLineboxes = new List<FlowTextViewSharp.Box>();
private List<Area> mAreas = new List<FlowTextViewSharp.Area>();
private void onClick(float x, float y)
{
foreach (HtmlLink link in mLinks)
{
float tlX = link.xOffset;
float tlY = link.yOffset;
float brX = link.xOffset + link.width;
float brY = link.yOffset + link.height;
if (x > tlX && x < brX)
{
if (y > tlY && y < brY)
{
// collision
onLinkClick(link.url);
return;
}
}
}
}
private IOnLinkClickListener mOnLinkClickListener;
public virtual IOnLinkClickListener OnLinkClickListener
{
set
{
this.mOnLinkClickListener = value;
}
}
public interface IOnLinkClickListener
{
void onLinkClick(string url);
}
private void onLinkClick(string url)
{
if (mOnLinkClickListener != null)
{
mOnLinkClickListener.onLinkClick(url);
}
}
private Line getLine(float lineYbottom, int lineHeight)
{
Line line = new Line(this);
line.leftBound = 0;
line.rightBound = mViewWidth;
float lineYtop = lineYbottom - lineHeight;
mAreas.Clear();
mLineboxes.Clear();
foreach (Box box in boxes)
{
if (box.topLefty > lineYbottom || box.bottomRighty < lineYtop)
{
}
else
{
Area leftArea = new Area(this);
leftArea.x1 = 0;
foreach (Box innerBox in boxes)
{
if (innerBox.topLefty > lineYbottom || innerBox.bottomRighty < lineYtop)
{
}
else
{
if (innerBox.topLeftx < box.topLeftx)
{
leftArea.x1 = innerBox.bottomRightx;
}
}
}
leftArea.x2 = box.topLeftx;
leftArea.width = leftArea.x2 - leftArea.x1;
Area rightArea = new Area(this);
rightArea.x1 = box.bottomRightx;
rightArea.x2 = mViewWidth;
foreach (Box innerBox in boxes)
{
if (innerBox.topLefty > lineYbottom || innerBox.bottomRighty < lineYtop)
{
}
else
{
if (innerBox.bottomRightx > box.bottomRightx)
{
rightArea.x2 = innerBox.topLeftx;
}
}
}
rightArea.width = rightArea.x2 - rightArea.x1;
mAreas.Add(leftArea);
mAreas.Add(rightArea);
}
}
mLargestArea = null;
if (mAreas.Count > 0) // if there is no areas then the whole line is clear, if there is areas, return the largest (it means there is one or more boxes colliding with this line)
{
foreach (Area area in mAreas)
{
if (mLargestArea == null)
{
mLargestArea = area;
}
else
{
if (area.width > mLargestArea.width)
{
mLargestArea = area;
}
}
}
line.leftBound = mLargestArea.x1;
line.rightBound = mLargestArea.x2;
}
return line;
}
internal Area mLargestArea;
private int getChunk(string text, float maxWidth)
{
int length = mTextPaint.BreakText(text, true, maxWidth, null);
if (length <= 0) // if its 0 or less, return it, can't fit any chars on this line
{
return length;
}
else if (length >= text.Length) // we can fit the whole string in
{
return length;
}
else if (text[length - 1] == ' ') // if break char is a space -- return
{
return length;
}
else
{
if (text.Length > length) // or if the following char is a space then return this length - it is fine
{
if (text[length] == ' ')
{
return length + 1;
}
}
}
// otherwise, count back until we hit a space and return that as the break length
int tempLength = length - 1;
while (text[tempLength] != ' ')
{
//char test = text.charAt(tempLength);
tempLength--;
if (tempLength <= 0) // if we count all the way back to 0 then this line cannot be broken, just return the original break length
{
return length;
}
}
//char test = text.charAt(tempLength);
return tempLength + 1; // return the nicer break length which doesn't split a word up
}
protected override void OnDraw(Canvas canvas)
{
Log.Debug("flowText", "onDraw");
base.OnDraw (canvas);
mViewWidth = this.Width;
int lowestYCoord = 0;
boxes.Clear();
int childCount = this.ChildCount;
for (int i = 0; i < childCount; i++)
{
View child = GetChildAt(i);
if (child.Visibility != ViewStates.Gone)
{
Box box = new Box(this);
box.topLeftx = (int) child.Left;
box.topLefty = (int) child.Top;
box.bottomRightx = box.topLeftx + child.Width;
box.bottomRighty = box.topLefty + child.Height;
boxes.Add(box);
if (box.bottomRighty > lowestYCoord)
{
lowestYCoord = box.bottomRighty;
}
}
}
//var blocks = mText.ToString().Split ("\n", true);
var blocks = mText.ToString ().Split (new[] {"\n"}, StringSplitOptions.RemoveEmptyEntries);
var charOffsetStart = 0; // tells us where we are in the original string
var charOffsetEnd = 0; // tells us where we are in the original string
var lineIndex = 0;
float xOffset = 0; // left margin off a given line
float maxWidth = mViewWidth; // how far to the right it can strectch
float yOffset = 0;
string thisLineStr;
int chunkSize;
int lineHeight = LineHeight;
List<HtmlObject> lineObjects = new List<FlowTextViewSharp.HtmlObject>();
object[] spans = new object[0];
HtmlObject htmlLine; // = new HtmlObject(); // reuse for single plain lines
mLinks.Clear();
for (int block_no = 0; block_no <= blocks.Length - 1; block_no++)
{
string thisBlock = blocks[block_no];
if (thisBlock.Length <= 0)
{
lineIndex++; //is a line break
charOffsetEnd += 2;
charOffsetStart = charOffsetEnd;
}
else
{
while (thisBlock.Length > 0)
{
lineIndex++;
yOffset = lineIndex * lineHeight;
Line thisLine = getLine(yOffset, lineHeight);
xOffset = thisLine.leftBound;
maxWidth = thisLine.rightBound - thisLine.leftBound;
float actualWidth = 0;
do
{
Log.Debug("tv", "maxWidth: " + maxWidth);
chunkSize = getChunk(thisBlock, maxWidth);
int thisCharOffset = charOffsetEnd + chunkSize;
if (chunkSize > 1)
{
thisLineStr = thisBlock.Substring(0, chunkSize);
}
else
{
thisLineStr = "";
}
lineObjects.Clear();
if (mIsHtml)
{
spans = ((ISpanned) mText).GetSpans(charOffsetStart, thisCharOffset, Class.FromType (typeof(object)));
if (spans.Length > 0)
{
actualWidth = parseSpans(lineObjects, spans, charOffsetStart, thisCharOffset, xOffset);
}
else
{
actualWidth = maxWidth; // if no spans then the actual width will be <= maxwidth anyway
}
}
else
{
actualWidth = maxWidth; // if not html then the actual width will be <= maxwidth anyway
}
Log.Debug("tv", "actualWidth: " + actualWidth);
if (actualWidth > maxWidth)
{
maxWidth -= 5; // if we end up looping - start slicing chars off till we get a suitable size
}
} while (actualWidth > maxWidth);
// chunk is ok
charOffsetEnd += chunkSize;
Log.Debug("tv", "charOffsetEnd: " + charOffsetEnd);
if (lineObjects.Count <= 0) // no funky objects found, add the whole chunk as one object
{
htmlLine = new HtmlObject(this, thisLineStr, 0, 0, xOffset, mTextPaint);
lineObjects.Add(htmlLine);
}
foreach (HtmlObject thisHtmlObject in lineObjects)
{
if (thisHtmlObject is HtmlLink)
{
HtmlLink thisLink = (HtmlLink) thisHtmlObject;
float thisLinkWidth = thisLink.paint.MeasureText(thisHtmlObject.content);
addLink(thisLink, yOffset, thisLinkWidth, lineHeight);
}
paintObject(canvas, thisHtmlObject.content, thisHtmlObject.xOffset, yOffset, thisHtmlObject.paint);
if (thisHtmlObject.recycle)
{
recyclePaint(thisHtmlObject.paint);
}
}
if (chunkSize >= 1)
{
thisBlock = thisBlock.Substring(chunkSize, thisBlock.Length - chunkSize);
}
charOffsetStart = charOffsetEnd;
}
}
}
yOffset += (lineHeight / 2);
View child1 = GetChildAt(ChildCount - 1);
if (child1.Tag != null)
{
if (child1.Tag.ToString ().Equals ("hideable", StringComparison.CurrentCultureIgnoreCase))
{
if (yOffset > pageHeight)
{
if (yOffset < boxes[boxes.Count - 1].topLefty - LineHeight)
{
child1.Visibility = ViewStates.Gone;
//lowestYCoord = (int) yOffset;
}
else
{
//lowestYCoord = boxes.get(boxes.size()-1).bottomRighty + getLineHeight();
child1.Visibility = ViewStates.Visible;
}
}
else
{
child1.Visibility = ViewStates.Gone;
//lowestYCoord = (int) yOffset;
}
}
}
mDesiredHeight = Math.Max(lowestYCoord, (int) yOffset);
if (needsMeasure)
{
needsMeasure = false;
RequestLayout();
}
}
protected override void OnConfigurationChanged(Configuration newConfig)
{
base.OnConfigurationChanged (newConfig);
Invalidate();
}
public override void Invalidate()
{
needsMeasure = true;
base.Invalidate ();
}
internal bool needsMeasure = true;
private void paintObject(Canvas canvas, string thisLineStr, float xOffset, float yOffset, Paint paint)
{
canvas.DrawText(thisLineStr, xOffset, yOffset, paint);
}
private class Box
{
private readonly FlowTextViewSharp outerInstance;
public Box(FlowTextViewSharp outerInstance)
{
this.outerInstance = outerInstance;
}
public int topLeftx;
public int topLefty;
public int bottomRightx;
public int bottomRighty;
}
private class Line
{
private readonly FlowTextViewSharp outerInstance;
public Line(FlowTextViewSharp outerInstance)
{
this.outerInstance = outerInstance;
}
public float leftBound;
public float rightBound;
}
private List<Box> boxes = new List<FlowTextViewSharp.Box>();
private static readonly BoringLayout.Metrics UNKNOWN_BORING = new BoringLayout.Metrics();
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
Log.Debug("flowText", "onMeasure");
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
MeasureSpecMode widthMode = MeasureSpec.GetMode(widthMeasureSpec);
MeasureSpecMode heightMode = MeasureSpec.GetMode (heightMeasureSpec);
int widthSize = MeasureSpec.GetSize (widthMeasureSpec);
int heightSize = MeasureSpec.GetSize (heightMeasureSpec);
int width = 0;
int height = 0;
if (widthMode == MeasureSpecMode.Exactly)
{
// Parent has told us how big to be. So be it.
width = widthSize;
}
else
{
width = Width;
}
if (heightMode == MeasureSpecMode.Exactly)
{
// Parent has told us how big to be. So be it.
height = heightSize;
}
else
{
height = mDesiredHeight;
}
SetMeasuredDimension(width, height + LineHeight);
//setMeasuredDimension(800, 1400);
}
public virtual int LineHeight
{
get
{
return (int) Math.Round(mTextPaint.GetFontMetricsInt(null) * mSpacingMult + mSpacingAdd);
}
}
private IEnumerable<char> mText = "";
private bool mIsHtml = false;
//private URLSpan[] urls;
internal class HtmlObject
{
private readonly FlowTextViewSharp outerInstance;
public HtmlObject(FlowTextViewSharp outerInstance, string content, int start, int end, float xOffset, TextPaint paint) : base()
{
this.outerInstance = outerInstance;
this.content = content;
this.start = start;
this.end = end;
this.xOffset = xOffset;
this.paint = paint;
}
public string content;
public int start;
public int end;
public float xOffset;
public TextPaint paint;
public bool recycle = false;
}
internal class HtmlLink : HtmlObject
{
private readonly FlowTextViewSharp outerInstance;
public HtmlLink(FlowTextViewSharp outerInstance, string content, int start, int end, float xOffset, TextPaint paint, string url) : base(outerInstance, content, start, end, xOffset, paint)
{
this.outerInstance = outerInstance;
this.url = url;
}
public float width;
public float height;
public float yOffset;
public string url;
}
private bool[] charFlags;
internal int charFlagSize = 0;
internal int charFlagIndex = 0;
internal int spanStart = 0;
internal int spanEnd = 0;
internal int charCounter;
internal float objPixelwidth;
internal Dictionary<int?, HtmlObject> sorterMap = new Dictionary<int?, FlowTextViewSharp.HtmlObject>();
private float parseSpans(List<HtmlObject> objects, object[] spans, int lineStart, int lineEnd, float baseXOffset)
{
sorterMap.Clear();
charFlagSize = lineEnd - lineStart;
charFlags = new bool[charFlagSize];
foreach (var span in spans)
{
spanStart = mSpannable .GetSpanStart((Object) span);
spanEnd = mSpannable.GetSpanEnd((Object) span);
if (spanStart < lineStart)
{
spanStart = lineStart;
}
if (spanEnd > lineEnd)
{
spanEnd = lineEnd;
}
for (charCounter = spanStart; charCounter < spanEnd; charCounter++) // mark these characters as rendered
{
charFlagIndex = charCounter - lineStart;
charFlags[charFlagIndex] = true;
}
tempString = extractText(spanStart, spanEnd);
sorterMap[spanStart] = parseSpan(span, tempString, spanStart, spanEnd);
//objects.add();
}
charCounter = 0;
while (!isArrayFull(charFlags))
{
while (true)
{
if (charCounter >= charFlagSize)
{
break;
}
if (charFlags[charCounter] == true)
{
charCounter++;
continue;
}
temp1 = charCounter;
while (true)
{
if (charCounter > charFlagSize)
{
break;
}
if (charCounter < charFlagSize)
{
if (charFlags[charCounter] == false)
{
charFlags[charCounter] = true; // mark as filled
charCounter++;
continue;
}
}
temp2 = charCounter;
spanStart = lineStart + temp1;
spanEnd = lineStart + temp2;
tempString = extractText(spanStart, spanEnd);
sorterMap[spanStart] = parseSpan(null, tempString, spanStart, spanEnd);
break;
}
}
}
sorterKeys = new[] {sorterMap.Keys.ToArray ()};
Arrays.Sort((Object[]) sorterKeys);
float thisXoffset = baseXOffset;
for (charCounter = 0; charCounter < sorterKeys.Length; charCounter++)
{
HtmlObject thisObj = sorterMap[(int?) sorterKeys[charCounter]];
thisObj.xOffset = thisXoffset;
tempFloat = thisObj.paint.MeasureText(thisObj.content);
thisXoffset += tempFloat;
objects.Add(thisObj);
}
return (thisXoffset - baseXOffset);
}
internal float tempFloat;
internal object[] sorterKeys;
internal int[] sortedKeys;
internal string tempString;
internal int temp1;
internal int temp2;
internal int arrayIndex = 0;
private bool isArrayFull(bool[] array)
{
for (arrayIndex = 0; arrayIndex < array.Length; arrayIndex++)
{
if (array[arrayIndex] == false)
{
return false;
}
}
return true;
}
private HtmlObject parseSpan(object span, string content, int start, int end)
{
if (span is URLSpan)
{
return getHtmlLink((URLSpan) span, content, start, end, 0);
}
else if (span is StyleSpan)
{
return getStyledObject((StyleSpan) span, content, start, end, 0);
}
else
{
return getHtmlObject(content, start, end, 0);
}
}
private string extractText(int start, int end)
{
if (start < 0)
{
start = 0;
}
if (end > mTextLength - 1)
{
end = mTextLength - 1;
}
return mSpannable.SubSequence(start, end).ToString();
}
private List<TextPaint> mPaintHeap = new List<TextPaint>();
private TextPaint PaintFromHeap
{
get
{
if (mPaintHeap.Count > 0) {
var res = mPaintHeap.First ();
mPaintHeap.Remove (res);
return res;
}
else
{
return new TextPaint(PaintFlags.AntiAlias);
}
}
}
private void recyclePaint(TextPaint paint)
{
mPaintHeap.Add(paint);
}
private HtmlObject getStyledObject(StyleSpan span, string content, int start, int end, float thisXOffset)
{
TextPaint paint = PaintFromHeap;
paint.SetTypeface(Typeface.DefaultFromStyle(span.Style));
paint.TextSize = mTextsize;
paint.Color = mColor;
span.UpdateDrawState(paint);
span.UpdateMeasureState(paint);
HtmlObject obj = new HtmlObject(this, content, start, end, thisXOffset, paint);
obj.recycle = true;
return obj;
}
private HtmlObject getHtmlObject(string content, int start, int end, float thisXOffset)
{
HtmlObject obj = new HtmlObject(this, content, start, end, thisXOffset, mTextPaint);
return obj;
}
private List<HtmlLink> mLinks = new List<FlowTextViewSharp.HtmlLink>();
private HtmlLink getHtmlLink(URLSpan span, string content, int start, int end, float thisXOffset)
{
HtmlLink obj = new HtmlLink(this, content, start, end, thisXOffset, mLinkPaint, span.URL);
mLinks.Add(obj);
return obj;
}
private void addLink(HtmlLink thisLink, float yOffset, float width, float height)
{
thisLink.yOffset = yOffset - 20;
thisLink.width = width;
thisLink.height = height + 20;
mLinks.Add(thisLink);
}
private SpannableString mSpannable;
internal int mTextLength = 0;
public virtual IEnumerable<char> Text
{
set
{
mText = value;
if (value is SpannableString)
{
mIsHtml = true;
mSpannable = (SpannableString)value;
object[] urls = mSpannable.GetSpans(0, mSpannable.Length(), Class.FromType (typeof(object)));
}
else
{
mIsHtml = false;
}
mTextLength = mText.Count ();
this.Invalidate();
}
}
private List<BitmapSpec> bitmaps = new List<FlowTextViewSharp.BitmapSpec>();
public virtual BitmapSpec addImage(Bitmap bitmap, int xOffset, int yOffset, int padding)
{
BitmapSpec spec = new BitmapSpec(this, bitmap, xOffset, yOffset, padding);
bitmaps.Add(spec);
return spec;
}
public virtual List<BitmapSpec> Bitmaps
{
get
{
return bitmaps;
}
set
{
this.bitmaps = value;
}
}
public class BitmapSpec