-
Notifications
You must be signed in to change notification settings - Fork 240
/
FlexibleView.cs
executable file
·879 lines (787 loc) · 30.3 KB
/
FlexibleView.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
/*
* Copyright(c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Tizen.NUI.BaseComponents;
using Tizen.NUI.Binding;
namespace Tizen.NUI.Components
{
/// <summary>
/// FlexibleView ItemClick Event Arguments.
/// </summary>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public class FlexibleViewItemClickedEventArgs : EventArgs
{
/// <summary>
/// The clicked FlexibleViewViewHolder.
/// </summary>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public FlexibleViewViewHolder ClickedView { get; set; }
}
/// <summary>
/// FlexibleView ItemTouch Event Arguments.
/// </summary>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public class FlexibleViewItemTouchEventArgs : View.TouchEventArgs
{
/// <summary>
/// The touched FlexibleViewViewHolder.
/// </summary>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public FlexibleViewViewHolder TouchedView { get; set; }
}
/// <summary>
/// A flexible view for providing a limited window into a large data set.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public partial class FlexibleView : Control
{
/// <summary>
/// PaddingProperty
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly new BindableProperty PaddingProperty = BindableProperty.Create(nameof(Padding), typeof(Extents), typeof(FlexibleView), null, propertyChanged: (bindable, oldValue, newValue) =>
{
var instance = (FlexibleView)bindable;
if (newValue is Extents extents)
{
instance.InternalPadding = extents;
}
},
defaultValueCreator: (bindable) =>
{
var instance = (FlexibleView)bindable;
return instance.InternalPadding;
});
/// <summary>
/// FocusedItemIndexProperty
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty FocusedItemIndexProperty = BindableProperty.Create(nameof(FocusedItemIndex), typeof(int), typeof(FlexibleView), default(int), propertyChanged: (bindable, oldValue, newValue) =>
{
var instance = (FlexibleView)bindable;
if (newValue != null)
{
instance.InternalFocusedItemIndex = (int)newValue;
}
},
defaultValueCreator: (bindable) =>
{
var instance = (FlexibleView)bindable;
return instance.InternalFocusedItemIndex;
});
/// <summary>
/// Constant value: -1.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "<Pending>")]
public static readonly int NO_POSITION = -1;
/// <summary>
/// Constant value: -1.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "<Pending>")]
public static readonly int INVALID_TYPE = -1;
private FlexibleViewAdapter adapter;
private FlexibleViewLayoutManager layout;
private FlexibleViewRecycler recycler;
private RecycledViewPool recyclerPool;
private ChildHelper childHelper;
private PanGestureDetector panGestureDetector;
private int focusedItemIndex = NO_POSITION;
private AdapterHelper adapteHelper;
private ScrollBar scrollBar = null;
private Timer scrollBarShowTimer = null;
private EventHandler<FlexibleViewItemClickedEventArgs> clickEventHandlers;
private EventHandler<FlexibleViewItemTouchEventArgs> touchEventHandlers;
private EventHandler<NUI.StyleManager.StyleChangedEventArgs> styleChangedEventHandlers;
/// <summary>
/// Creates a FlexibleView instance.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public FlexibleView()
{
recyclerPool = new RecycledViewPool(this);
recycler = new FlexibleViewRecycler(this);
recycler.SetRecycledViewPool(recyclerPool);
childHelper = new ChildHelper(this);
panGestureDetector = new PanGestureDetector();
panGestureDetector.Attach(this);
panGestureDetector.Detected += OnPanGestureDetected;
adapteHelper = new AdapterHelper(this);
ClippingMode = ClippingModeType.ClipToBoundingBox;
}
/// <summary>
/// Item click event.
/// </summary>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler<FlexibleViewItemClickedEventArgs> ItemClicked
{
add
{
clickEventHandlers += value;
}
remove
{
clickEventHandlers -= value;
}
}
/// <summary>
/// Item touch event.
/// </summary>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler<FlexibleViewItemTouchEventArgs> ItemTouch
{
add
{
touchEventHandlers += value;
}
remove
{
touchEventHandlers -= value;
}
}
/// <summary>
/// Style changed, for example default font size.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler<NUI.StyleManager.StyleChangedEventArgs> StyleChanged
{
add
{
styleChangedEventHandlers += value;
}
remove
{
styleChangedEventHandlers -= value;
}
}
private Extents padding;
/// <summary>
/// overwrite the Padding.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public new Extents Padding
{
get
{
return GetValue(PaddingProperty) as Extents;
}
set
{
SetValue(PaddingProperty, value);
NotifyPropertyChanged();
}
}
private Extents InternalPadding
{
get
{
if (null == padding)
{
padding = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
{
padding.Start = start;
padding.End = end;
padding.Top = top;
padding.Bottom = bottom;
}, 0, 0, 0, 0);
}
return padding;
}
set
{
if (null == padding)
{
padding = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
{
padding.Start = start;
padding.End = end;
padding.Top = top;
padding.Bottom = bottom;
}, 0, 0, 0, 0);
}
padding.CopyFrom(value);
}
}
/// <summary>
/// Gets or sets the focused item index(adapter position).
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public int FocusedItemIndex
{
get
{
return (int)GetValue(FocusedItemIndexProperty);
}
set
{
SetValue(FocusedItemIndexProperty, value);
NotifyPropertyChanged();
}
}
private int InternalFocusedItemIndex
{
get
{
return focusedItemIndex;
}
set
{
if (value == focusedItemIndex)
{
return;
}
if (adapter == null)
{
return;
}
if (layout == null)
{
return;
}
FlexibleViewViewHolder nextFocusView = FindViewHolderForAdapterPosition(value);
if (nextFocusView == null)
{
layout.ScrollToPosition(value);
}
else
{
layout.GetRectOfVisibleChild(this, nextFocusView, recycler, true);
DispatchFocusChanged(value);
}
}
}
/// <summary>
/// Set a new adapter to provide child views on demand.
/// </summary>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetAdapter(FlexibleViewAdapter adapter)
{
if (adapter == null)
{
return;
}
this.adapter = adapter;
this.adapter.ItemEvent += OnItemEvent;
}
/// <summary>
/// Retrieves the previously set adapter or null if no adapter is set.
/// </summary>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public FlexibleViewAdapter GetAdapter()
{
return adapter;
}
/// <summary>
/// Set the FlexibleViewLayoutManager that this FlexibleView will use.
/// </summary>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetLayoutManager(FlexibleViewLayoutManager layoutManager)
{
if (null == layoutManager) return;
layout = layoutManager;
layout.SetRecyclerView(this);
if (layout.CanScrollHorizontally())
{
panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
}
else if (layout.CanScrollVertically())
{
panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
}
}
/// <summary>
/// Return the FlexibleViewLayoutManager currently responsible for layout policy for this FlexibleView.
/// </summary>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public FlexibleViewLayoutManager GetLayoutManager()
{
return layout;
}
/// <summary>
/// Convenience method to scroll to a certain position
/// </summary>
/// <param name="position">Adapter position</param>
/// <param name="offset">The distance (in pixels) between the start edge of the item view and start edge of the FlexibleView.</param>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public void ScrollToPositionWithOffset(int position, int offset)
{
layout.ScrollToPositionWithOffset(position, offset);
}
/// <summary>
/// Move focus by direction.
/// </summary>
/// <param name="direction">Direction. Should be "Left", "Right", "Up" or "Down" </param>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public void MoveFocus(FlexibleViewLayoutManager.Direction direction)
{
layout.MoveFocus(direction, recycler);
}
/// <summary>
/// Attach a scrollbar to this FlexibleView.
/// </summary>
/// <param name="scrollBar">ScrollBar</param>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public void AttachScrollBar(ScrollBar scrollBar)
{
if (scrollBar == null)
{
return;
}
this.scrollBar = scrollBar;
base.Add(this.scrollBar);
}
/// <summary>
/// Detach the scrollbar from this FlexibleView.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public void DetachScrollBar()
{
if (scrollBar == null)
{
return;
}
Remove(scrollBar);
scrollBar = null;
}
/// <summary>
/// Return the FlexibleViewViewHolder for the item in the given position of the data set as of the latest layout pass.
/// This method checks only the children of FlexibleViewRecyclerView. If the item at the given position is not laid out, it will not create a new one.
/// </summary>
/// <param name="position">The position of the item in the data set of the adapter</param>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public FlexibleViewViewHolder FindViewHolderForLayoutPosition(int position)
{
int childCount = childHelper.GetChildCount();
for (int i = 0; i < childCount; i++)
{
if (childHelper.GetChildAt(i) is FlexibleViewViewHolder holder)
{
if (holder.LayoutPosition == position)
{
return holder;
}
}
}
return null;
}
/// <summary>
/// Return the FlexibleViewViewHolder for the item in the given position of the data set.
/// This method checks only the children of FlexibleViewRecyclerView. If the item at the given position is not laid out, it will not create a new one.
/// </summary>
/// <param name="position">The position of the item in the data set of the adapter</param>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public FlexibleViewViewHolder FindViewHolderForAdapterPosition(int position)
{
int childCount = childHelper.GetChildCount();
for (int i = 0; i < childCount; i++)
{
if (childHelper.GetChildAt(i) is FlexibleViewViewHolder holder)
{
if (holder.AdapterPosition == position)
{
return holder;
}
}
}
return null;
}
/// <summary>
/// Return the recycler instance.
/// </summary>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public FlexibleViewRecycler GetRecycler()
{
return recycler;
}
/// <summary>
/// you can override it to clean-up your own resources.
/// </summary>
/// <param name="type">DisposeTypes</param>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void Dispose(DisposeTypes type)
{
if (disposed)
{
return;
}
if (type == DisposeTypes.Explicit)
{
if (layout != null)
{
layout.StopScroll(false);
layout.ClearRecyclerView();
layout = null;
}
if (adapter != null)
{
adapter.ItemEvent -= OnItemEvent;
}
if (panGestureDetector != null)
{
panGestureDetector.Detected -= OnPanGestureDetected;
panGestureDetector.Dispose();
panGestureDetector = null;
}
if (scrollBarShowTimer != null)
{
scrollBarShowTimer.Tick -= OnShowTimerTick;
scrollBarShowTimer.Stop();
scrollBarShowTimer.Dispose();
scrollBarShowTimer = null;
}
if (recyclerPool != null)
{
recyclerPool.Clear();
recyclerPool = null;
}
if (childHelper != null)
{
childHelper.Clear();
childHelper.Dispose();
childHelper = null;
}
}
base.Dispose(type);
}
/// <summary>
/// you can override it to create your own default style.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
protected override ViewStyle CreateViewStyle()
{
return null;
}
/// <summary>
/// you can override it to relayout elements.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public override void OnRelayout(Vector2 size, RelayoutContainer container)
{
if (adapter == null)
{
return;
}
if (layout == null)
{
return;
}
DispatchLayoutStep1();
layout.OnLayoutChildren(recycler);
RemoveAndRecycleScrapInt();
}
private void DispatchLayoutStep1()
{
ProcessAdapterUpdates();
SaveOldPositions();
ClearOldPositions();
}
private void ProcessAdapterUpdates()
{
adapteHelper.PreProcess();
}
private void OffsetPositionRecordsForInsert(int positionStart, int itemCount)
{
int childCount = childHelper.GetChildCount();
for (int i = 0; i < childCount; i++)
{
FlexibleViewViewHolder holder = childHelper.GetChildAt(i);
if (holder != null && holder.AdapterPosition >= positionStart)
{
holder.OffsetPosition(itemCount, false);
}
}
if (positionStart <= focusedItemIndex)
{
focusedItemIndex += itemCount;
}
}
private void OffsetPositionRecordsForRemove(int positionStart, int itemCount, bool applyToPreLayout)
{
int positionEnd = positionStart + itemCount;
int childCount = childHelper.GetChildCount();
for (int i = 0; i < childCount; i++)
{
FlexibleViewViewHolder holder = childHelper.GetChildAt(i);
if (holder != null)
{
if (holder.AdapterPosition >= positionEnd)
{
holder.OffsetPosition(-itemCount, applyToPreLayout);
}
else if (holder.AdapterPosition >= positionStart)
{
holder.FlagRemovedAndOffsetPosition(positionStart - 1, -itemCount, applyToPreLayout);
}
}
}
if (positionEnd <= focusedItemIndex)
{
focusedItemIndex -= itemCount;
}
else if (positionStart <= focusedItemIndex)
{
focusedItemIndex = positionStart;
if (focusedItemIndex >= adapter.GetItemCount())
{
focusedItemIndex = adapter.GetItemCount() - 1;
}
}
}
private void SaveOldPositions()
{
int childCount = childHelper.GetChildCount();
for (int i = 0; i < childCount; i++)
{
FlexibleViewViewHolder holder = childHelper.GetChildAt(i);
holder.SaveOldPosition();
}
}
private void ClearOldPositions()
{
int childCount = childHelper.GetChildCount();
for (int i = 0; i < childCount; i++)
{
FlexibleViewViewHolder holder = childHelper.GetChildAt(i);
holder.ClearOldPosition();
}
}
private void RemoveAndRecycleScrapInt()
{
int scrapCount = recycler.GetScrapCount();
for (int i = 0; i < scrapCount; i++)
{
FlexibleViewViewHolder scrap = recycler.GetScrapViewAt(i);
childHelper.RemoveView(scrap);
recycler.RecycleView(scrap);
}
recycler.Clear();
}
private void ShowScrollBar(uint millisecond = 700, bool flagAni = false)
{
if (scrollBar == null || layout == null)
{
return;
}
float extent = layout.ComputeScrollExtent();
float range = layout.ComputeScrollRange();
if (range == 0)
{
return;
}
float offset = layout.ComputeScrollOffset();
float size = scrollBar.Direction == ScrollBar.DirectionType.Vertical ? scrollBar.SizeHeight : scrollBar.SizeWidth;
float thickness = scrollBar.Direction == ScrollBar.DirectionType.Vertical ? scrollBar.SizeWidth : scrollBar.SizeHeight;
float length = (float)Math.Round(size * extent / range);
// avoid the tiny thumb
float minLength = thickness * 2;
if (length < minLength)
{
length = minLength;
}
// avoid the too-big thumb
if (offset > range - extent)
{
offset = range - extent;
}
if (offset < 0)
{
offset = 0;
}
if (scrollBar.Direction == ScrollBar.DirectionType.Vertical)
{
scrollBar.ThumbSize = new Size(thickness, length);
}
else
{
scrollBar.ThumbSize = new Size(length, thickness);
}
scrollBar.MinValue = 0;
scrollBar.MaxValue = (int)(range - extent);
scrollBar.SetCurrentValue((int)offset, flagAni);
scrollBar.Show();
if (scrollBarShowTimer == null)
{
scrollBarShowTimer = new Timer(millisecond);
scrollBarShowTimer.Tick += OnShowTimerTick;
}
else
{
scrollBarShowTimer.Interval = millisecond;
}
scrollBarShowTimer.Start();
}
private bool OnShowTimerTick(object source, EventArgs e)
{
if (scrollBar != null)
{
scrollBar.Hide();
}
return false;
}
internal void DispatchFocusChanged(int nextFocusPosition)
{
adapter.OnFocusChange(this, focusedItemIndex, nextFocusPosition);
focusedItemIndex = nextFocusPosition;
ShowScrollBar();
}
private void DispatchChildAttached(FlexibleViewViewHolder holder)
{
if (adapter != null && holder != null)
{
adapter.OnViewAttachedToWindow(holder);
}
}
private void DispatchChildDetached(FlexibleViewViewHolder holder)
{
if (adapter != null && holder != null)
{
adapter.OnViewDetachedFromWindow(holder);
}
}
private void DispatchChildDestroyed(FlexibleViewViewHolder holder)
{
if (adapter != null && holder != null)
{
adapter.OnDestroyViewHolder(holder);
}
}
private void DispatchItemClicked(FlexibleViewViewHolder clickedHolder)
{
FlexibleViewItemClickedEventArgs args = new FlexibleViewItemClickedEventArgs();
args.ClickedView = clickedHolder;
OnClickEvent(this, args);
}
private void DispatchItemTouched(FlexibleViewViewHolder touchedHolder, Touch touchEvent)
{
FlexibleViewItemTouchEventArgs args = new FlexibleViewItemTouchEventArgs();
args.TouchedView = touchedHolder;
args.Touch = touchEvent;
OnTouchEvent(this, args);
}
private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
{
if (e.PanGesture.State == Gesture.StateType.Started)
{
layout.StopScroll(true);
}
else if (e.PanGesture.State == Gesture.StateType.Continuing)
{
if (layout.CanScrollVertically())
{
layout.ScrollVerticallyBy(e.PanGesture.Displacement.Y, recycler, true);
}
else if (layout.CanScrollHorizontally())
{
layout.ScrollHorizontallyBy(e.PanGesture.Displacement.X, recycler, true);
}
ShowScrollBar();
}
else if (e.PanGesture.State == Gesture.StateType.Finished)
{
if (layout.CanScrollVertically())
{
layout.ScrollVerticallyBy(e.PanGesture.Velocity.Y * 600, recycler, false);
}
else if (layout.CanScrollHorizontally())
{
layout.ScrollHorizontallyBy(e.PanGesture.Velocity.X * 600, recycler, false);
}
ShowScrollBar(1200, true);
}
}
private void OnItemEvent(object sender, FlexibleViewAdapter.ItemEventArgs e)
{
switch (e.EventType)
{
case FlexibleViewAdapter.ItemEventType.Insert:
adapteHelper.OnItemRangeInserted(e.param[0], e.param[1]);
ShowScrollBar();
break;
case FlexibleViewAdapter.ItemEventType.Remove:
adapteHelper.OnItemRangeRemoved(e.param[0], e.param[1]);
ShowScrollBar();
break;
case FlexibleViewAdapter.ItemEventType.Move:
break;
case FlexibleViewAdapter.ItemEventType.Change:
break;
default:
return;
}
RelayoutRequest();
}
private void OnClickEvent(object sender, FlexibleViewItemClickedEventArgs e)
{
clickEventHandlers?.Invoke(sender, e);
}
private void OnTouchEvent(object sender, FlexibleViewItemTouchEventArgs e)
{
touchEventHandlers?.Invoke(sender, e);
}
internal void LayoutManagerRelayoutRequest()
{
RelayoutRequest();
}
internal ChildHelper GetChildHelper()
{
return childHelper;
}
}
}