[NUI.Components] Fix BackgroundImage doesn't works issue (#1240)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Slider.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using Tizen.NUI.BaseComponents;
19 using System.ComponentModel;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.Components
23 {
24     /// <summary>
25     /// A slider lets users select a value from a continuous or discrete range of values by moving the slider thumb.
26     /// </summary>
27     /// <since_tizen> 6 </since_tizen>
28     public class Slider : Control
29     {
30         // the background track image object
31         private ImageView bgTrackImage = null;
32         // the slided track image object
33         private ImageView slidedTrackImage = null;
34         // the thumb image object
35         private ImageView thumbImage = null;
36         // the low indicator image object
37         private ImageView lowIndicatorImage = null;
38         // the high indicator image object
39         private ImageView highIndicatorImage = null;
40         // the low indicator text object
41         private TextLabel lowIndicatorText = null;
42         // the high indicator text object
43         private TextLabel highIndicatorText = null;
44         // the direction type
45         private DirectionType direction = DirectionType.Horizontal;
46         // the indicator type
47         private IndicatorType indicatorType = IndicatorType.None;
48         private const float round = 0.5f;
49         // the minimum value
50         private float? minValue = null;
51         // the maximum value
52         private float? maxValue = null;
53         // the current value
54         private float? curValue = null;
55         // the size of the low indicator
56         private Size lowIndicatorSize = null;
57         // the size of the high indicator
58         private Size highIndicatorSize = null;
59         // the track thickness value
60         private uint? trackThickness = null;
61         // the value of the space between track and indicator object
62         private Extents _spaceBetweenTrackAndIndicator = null;
63         private Extents spaceBetweenTrackAndIndicator
64         {
65             get
66             {
67                 if (null == _spaceBetweenTrackAndIndicator)
68                 {
69                     _spaceBetweenTrackAndIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
70                     {
71                         Extents extents = new Extents(start, end, top, bottom);
72                         _spaceBetweenTrackAndIndicator.CopyFrom(extents);
73                     }, 0, 0, 0, 0);
74                 }
75
76                 return _spaceBetweenTrackAndIndicator;
77             }
78         }
79
80
81         private PanGestureDetector panGestureDetector = null;
82         private float currentSlidedOffset;
83         private EventHandler<ValueChangedArgs> valueChangedHandler;
84         private EventHandler<SlidingFinishedArgs> slidingFinishedHandler;
85         private EventHandler<StateChangedArgs> stateChangedHandler;
86
87         bool isFocused = false;
88         bool isPressed = false;
89
90         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
91         [EditorBrowsable(EditorBrowsableState.Never)]
92         public static readonly BindableProperty IndicatorTypeProperty = BindableProperty.Create("IndicatorType", typeof(IndicatorType), typeof(Slider), IndicatorType.None, propertyChanged: (bindable, oldValue, newValue) =>
93         {
94             var instance = (Slider)bindable;
95             if (newValue != null)
96             {
97                 instance.privateIndicatorType = (IndicatorType)newValue;
98             }
99         },
100         defaultValueCreator: (bindable) =>
101         {
102             var instance = (Slider)bindable;
103             return instance.privateIndicatorType;
104         });
105         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
106         [EditorBrowsable(EditorBrowsableState.Never)]
107         public static readonly BindableProperty SpaceBetweenTrackAndIndicatorProperty = BindableProperty.Create(nameof(SpaceBetweenTrackAndIndicator), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
108         {
109             var instance = (Slider)bindable;
110             if (newValue != null)
111             {
112                 instance.privateSpaceBetweenTrackAndIndicator = (uint)newValue;
113             }
114         },
115         defaultValueCreator: (bindable) =>
116         {
117             var instance = (Slider)bindable;
118             return instance.privateSpaceBetweenTrackAndIndicator;
119         });
120         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
121         [EditorBrowsable(EditorBrowsableState.Never)]
122         public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
123         {
124             var instance = (Slider)bindable;
125             if (newValue != null)
126             {
127                 instance.privateTrackThickness = (uint)newValue;
128             }
129         },
130         defaultValueCreator: (bindable) =>
131         {
132             var instance = (Slider)bindable;
133             return instance.privateTrackThickness;
134         });
135         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
136         [EditorBrowsable(EditorBrowsableState.Never)]
137         public static readonly BindableProperty TrackPaddingProperty = BindableProperty.Create(nameof(TrackPadding), typeof(Extents), typeof(Slider), null, propertyChanged: (bindable, oldValue, newValue) =>
138         {
139             var instance = (Slider)bindable;
140             if (newValue != null)
141             {
142                 instance.privateTrackPadding.CopyFrom((Extents)newValue);
143             }
144         },
145         defaultValueCreator: (bindable) =>
146         {
147             var instance = (Slider)bindable;
148             return instance.privateTrackPadding;
149         });
150         static Slider() { }
151
152         /// <summary>
153         /// The constructor of the Slider class.
154         /// </summary>
155         /// <since_tizen> 6 </since_tizen>
156         public Slider() 
157         {
158             Initialize();
159         }
160
161         /// <summary>
162         /// The constructor of the Slider class with specific style.
163         /// </summary>
164         /// <param name="style">The string to initialize the Slider</param>
165         /// <since_tizen> 6 </since_tizen>
166         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
167         [EditorBrowsable(EditorBrowsableState.Never)]
168         public Slider(string style) : base(style)
169         {
170             Initialize();
171         }
172
173         /// <summary>
174         /// The constructor of the Slider class with specific style.
175         /// </summary>
176         /// <param name="style">The style object to initialize the Slider</param>
177         /// <since_tizen> 6 </since_tizen>
178         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
179         [EditorBrowsable(EditorBrowsableState.Never)]
180         public Slider(SliderStyle style) : base(style)
181         {
182             Initialize();
183         }
184
185         /// <summary>
186         /// The value changed event handler.
187         /// </summary>
188         /// <since_tizen> 6 </since_tizen>
189         public event EventHandler<ValueChangedArgs> ValueChangedEvent
190         {
191             add
192             {
193                 valueChangedHandler += value;
194             }
195             remove
196             {
197                 valueChangedHandler -= value;
198             }
199         }
200
201         /// <summary>
202         /// The sliding finished event handler.
203         /// </summary>
204         /// <since_tizen> 6 </since_tizen>
205         public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
206         {
207             add
208             {
209                 slidingFinishedHandler += value;
210             }
211             remove
212             {
213                 slidingFinishedHandler -= value;
214             }
215         }
216
217         /// <summary>
218         /// The state changed event handler.
219         /// </summary>
220         /// <since_tizen> 6 </since_tizen>
221         public event EventHandler<StateChangedArgs> StateChangedEvent
222         {
223             add
224             {
225                 stateChangedHandler += value;
226             }
227             remove
228             {
229                 stateChangedHandler -= value;
230             }
231         }
232
233         /// <summary>
234         /// The direction type of slider.
235         /// </summary>
236         /// <since_tizen> 6 </since_tizen>
237         public enum DirectionType
238         {
239             /// <summary>
240             /// The Horizontal type.
241             /// </summary>
242             /// <since_tizen> 6 </since_tizen>
243             Horizontal,
244
245             /// <summary>
246             /// The Vertical type.
247             /// </summary>
248             /// <since_tizen> 6 </since_tizen>
249             Vertical
250         }
251
252         /// <summary>
253         /// The indicator type of slider.
254         /// </summary>
255         /// <since_tizen> 6 </since_tizen>
256         public enum IndicatorType
257         {
258             /// <summary> Only contains slider bar.</summary>
259             /// <since_tizen> 6 </since_tizen>
260             None,
261
262             /// <summary> Contains slider bar, IndicatorImage.</summary>
263             /// <since_tizen> 6 </since_tizen>
264             Image,
265
266             /// <summary> Contains slider bar, IndicatorText.</summary>
267             /// <since_tizen> 6 </since_tizen>
268             Text
269         }
270
271         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
272         [EditorBrowsable(EditorBrowsableState.Never)]
273         public new SliderStyle Style => ViewStyle as SliderStyle;
274
275         /// <summary>
276         /// Gets or sets the direction type of slider.
277         /// </summary>
278         /// <since_tizen> 6 </since_tizen>
279         public DirectionType Direction
280         {
281             get
282             {
283                 return direction;
284             }
285             set
286             {
287                 if (direction == value)
288                 {
289                     return;
290                 }
291                 direction = value;
292                 RelayoutBaseComponent(false);
293                 UpdateBgTrackSize();
294                 UpdateBgTrackPosition();
295                 UpdateValue();
296             }
297         }
298
299         /// <summary>
300         /// Gets or sets the indicator type, arrow or sign.
301         /// </summary>
302         /// <since_tizen> 6 </since_tizen>
303         public IndicatorType Indicator
304         {
305             get
306             {
307                 return (IndicatorType)GetValue(IndicatorTypeProperty);
308             }
309             set
310             {
311                 SetValue(IndicatorTypeProperty, value);
312             }
313         }
314         private IndicatorType privateIndicatorType
315         {
316             get
317             {
318                 return indicatorType;
319             }
320             set
321             {
322                 if (indicatorType == value)
323                 {
324                     return;
325                 }
326                 indicatorType = value;
327                 RelayoutBaseComponent(false);
328                 UpdateBgTrackSize();
329                 UpdateBgTrackPosition();
330                 UpdateValue();
331             }
332         }
333
334         /// <summary>
335         /// Gets or sets the minimum value of slider.
336         /// </summary>
337         /// <since_tizen> 6 </since_tizen>
338         public float MinValue
339         {
340             get
341             {
342                 return minValue ?? 0;
343             }
344             set
345             {
346                 minValue = value;
347                 UpdateValue();
348             }
349         }
350
351         /// <summary>
352         /// Gets or sets the maximum value of slider.
353         /// </summary>
354         /// <since_tizen> 6 </since_tizen>
355         public float MaxValue
356         {
357             get
358             {
359                 return maxValue ?? 100;
360             }
361             set
362             {
363                 maxValue = value;
364                 UpdateValue();
365             }
366         }
367
368         /// <summary>
369         /// Gets or sets the current value of slider.
370         /// </summary>
371         /// <since_tizen> 6 </since_tizen>
372         public float CurrentValue
373         {
374             get
375             {
376                 return curValue ?? 0;
377             }
378             set
379             {
380                 curValue = value;
381                 UpdateValue();
382             }
383         }
384
385         /// <summary>
386         /// Gets or sets the size of the thumb image object.
387         /// </summary>
388         /// <since_tizen> 6 </since_tizen>
389         public Size ThumbSize
390         {
391             get
392             {
393                 return Style.Thumb?.Size;
394             }
395             set
396             {
397                 Style.Thumb.Size = value;
398             }
399         }
400
401         /// <summary>
402         /// Gets or sets the resource url of the thumb image object.
403         /// </summary>
404         /// <since_tizen> 6 </since_tizen>
405         public string ThumbImageURL
406         {
407             get
408             {
409                 return Style?.Thumb?.ResourceUrl?.All;
410             }
411             set
412             {
413                 if (null != Style?.Thumb)
414                 {
415                     Style.Thumb.ResourceUrl = value; 
416                 }
417             }
418         }
419
420         private StringSelector thumbImageURLSelector = new StringSelector();
421         /// <summary>
422         /// Gets or sets the resource url selector of the thumb image object.
423         /// </summary>
424         /// <since_tizen> 6 </since_tizen>
425         public StringSelector ThumbImageURLSelector
426         {
427             get
428             {
429                 return thumbImageURLSelector;
430             }
431             set
432             {
433                 thumbImageURLSelector.Clone(value);
434             }
435         }
436
437         /// <summary>
438         /// Gets or sets the color of the background track image object.
439         /// </summary>
440         /// <since_tizen> 6 </since_tizen>
441         public Color BgTrackColor
442         {
443             get
444             {
445                 return Style?.Track?.BackgroundColor?.All;
446             }
447             set
448             {
449                 if (null != Style?.Track)
450                 {
451                     Style.Track.BackgroundColor = value;
452                 }
453             }
454         }
455
456         /// <summary>
457         /// Gets or sets the color of the slided track image object.
458         /// </summary>
459         /// <since_tizen> 6 </since_tizen>
460         public Color SlidedTrackColor
461         {
462             get
463             {
464                 return Style?.Progress?.BackgroundColor?.All;
465             }
466             set
467             {
468                 if (null != Style?.Progress)
469                 {
470                     Style.Progress.BackgroundColor = value;
471                 }
472             }
473         }
474
475         /// <summary>
476         /// Gets or sets the thickness value of the track.
477         /// </summary>
478         /// <since_tizen> 6 </since_tizen>
479         public uint TrackThickness
480         {
481             get
482             {
483                 return (uint)GetValue(TrackThicknessProperty);
484             }
485             set
486             {
487                 SetValue(TrackThicknessProperty, value);
488             }
489         }
490         private uint privateTrackThickness
491         {
492             get
493             {
494                 return trackThickness ?? 0;
495             }
496             set
497             {
498                 trackThickness = value;
499                 if (bgTrackImage != null)
500                 {
501                     if (direction == DirectionType.Horizontal)
502                     {
503                         bgTrackImage.SizeHeight = (float)trackThickness.Value;
504                     }
505                     else if (direction == DirectionType.Vertical)
506                     {
507                         bgTrackImage.SizeWidth = (float)trackThickness.Value;
508                     }
509                 }
510                 if (slidedTrackImage != null)
511                 {
512                     if (direction == DirectionType.Horizontal)
513                     {
514                         slidedTrackImage.SizeHeight = (float)trackThickness.Value;
515                     }
516                     else if (direction == DirectionType.Vertical)
517                     {
518                         slidedTrackImage.SizeWidth = (float)trackThickness.Value;
519                     }
520                 }
521             }
522         }
523
524         /// <summary>
525         /// Gets or sets the resource url of the low indicator image object.
526         /// </summary>
527         /// <since_tizen> 6 </since_tizen>
528         public string LowIndicatorImageURL
529         {
530             get
531             {
532                 return Style?.LowIndicatorImage?.ResourceUrl?.All;
533             }
534             set
535             {
536                 if (null != Style?.LowIndicatorImage)
537                 {
538                     Style.LowIndicatorImage.ResourceUrl = value;
539                 }
540             }
541         }
542
543         /// <summary>
544         /// Gets or sets the resource url of the high indicator image object.
545         /// </summary>
546         /// <since_tizen> 6 </since_tizen>
547         public string HighIndicatorImageURL
548         {
549             get
550             {
551                 return Style?.HighIndicatorImage?.ResourceUrl?.All;
552             }
553             set
554             {
555                 if (null != Style?.HighIndicatorImage)
556                 {
557                     Style.HighIndicatorImage.ResourceUrl = value;
558                 }
559             }
560         }
561
562         /// <summary>
563         /// Gets or sets the text content of the low indicator text object.
564         /// </summary>
565         /// <since_tizen> 6 </since_tizen>
566         public string LowIndicatorTextContent
567         {
568             get
569             {
570                 return Style?.LowIndicator?.Text?.All;
571             }
572             set
573             {
574                 if (null != Style?.LowIndicator)
575                 {
576                     Style.LowIndicator.Text= value;
577                 }
578             }
579         }
580
581         /// <summary>
582         /// Gets or sets the text content of the high indicator text object.
583         /// </summary>
584         /// <since_tizen> 6 </since_tizen>
585         public string HighIndicatorTextContent
586         {
587             get
588             {
589                 return Style?.HighIndicator?.Text?.All;
590             }
591             set
592             {
593                 if (null != Style?.HighIndicator)
594                 {
595                     Style.HighIndicator.Text = value;
596                 }
597             }
598         }
599
600         /// <summary>
601         /// Gets or sets the size of the low indicator object(image or text).
602         /// </summary>
603         /// <since_tizen> 6 </since_tizen>
604         public Size LowIndicatorSize
605         {
606             get
607             {
608                 return lowIndicatorSize;
609             }
610             set
611             {
612                 lowIndicatorSize = value;
613                 UpdateLowIndicatorSize();
614                 UpdateBgTrackSize();
615                 UpdateBgTrackPosition();
616                 UpdateValue();
617             }
618         }
619
620         /// <summary>
621         /// Gets or sets the size of the high indicator object(image or text).
622         /// </summary>
623         /// <since_tizen> 6 </since_tizen>
624         public Size HighIndicatorSize
625         {
626             get
627             {
628                 return Style.HighIndicator.Size;
629             }
630             set
631             {
632                 Style.HighIndicator.Size = value;
633             }
634         }
635
636         /// <summary>
637         /// Gets or sets the value of the space between track and indicator.
638         /// </summary>
639         /// <since_tizen> 6 </since_tizen>
640         public uint SpaceBetweenTrackAndIndicator
641         {
642             get
643             {
644                 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
645             }
646             set
647             {
648                 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
649             }
650         }
651         private uint privateSpaceBetweenTrackAndIndicator
652         {
653             get
654             {
655                 return TrackPadding.Start;
656             }
657             set
658             {
659                 ushort val = (ushort)value;
660                 TrackPadding = new Extents(val, val, val, val);
661             }
662         }
663
664         /// <summary>
665         /// Gets or sets the value of the space between track and indicator.
666         /// </summary>
667         /// <since_tizen> 6 </since_tizen>
668         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
669         [EditorBrowsable(EditorBrowsableState.Never)]
670         public Extents TrackPadding
671         {
672             get
673             {
674                 return (Extents)GetValue(TrackPaddingProperty);
675             }
676             set
677             {
678                 SetValue(TrackPaddingProperty, value);
679             }
680         }
681         private Extents privateTrackPadding
682         {
683             get
684             {
685                 return spaceBetweenTrackAndIndicator;
686             }
687             set
688             {
689                 spaceBetweenTrackAndIndicator.CopyFrom(value);
690                 UpdateComponentByIndicatorTypeChanged();
691                 UpdateBgTrackSize();
692                 UpdateBgTrackPosition();
693                 UpdateValue();
694             }
695         }
696
697         /// <summary>
698         /// Focus gained callback.
699         /// </summary>
700         /// <since_tizen> 6 </since_tizen>
701         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
702         [EditorBrowsable(EditorBrowsableState.Never)]
703         public override void OnFocusGained()
704         {
705             //State = ControlStates.Focused;
706             UpdateState(true, isPressed);
707             base.OnFocusGained();
708         }
709
710         /// <summary>
711         /// Focus Lost callback.
712         /// </summary>
713         /// <since_tizen> 6 </since_tizen>
714         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
715         [EditorBrowsable(EditorBrowsableState.Never)]
716         public override void OnFocusLost()
717         {
718             //State = ControlStates.Normal;
719             UpdateState(false, isPressed);
720             base.OnFocusLost();
721         }
722
723         /// <summary>
724         /// Get Slider attribues.
725         /// </summary>
726         /// <since_tizen> 6 </since_tizen>
727         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
728         [EditorBrowsable(EditorBrowsableState.Never)]
729         protected override ViewStyle GetViewStyle()
730         {
731             return new SliderStyle();
732         }
733
734         /// <summary>
735         /// Dispose Slider.
736         /// </summary>
737         /// <param name="type">Dispose type.</param>
738         /// <since_tizen> 6 </since_tizen>
739         protected override void Dispose(DisposeTypes type)
740         {
741             if (disposed)
742             {
743                 return;
744             }
745
746             if (type == DisposeTypes.Explicit)
747             {
748                 if (null != panGestureDetector)
749                 {
750                     if (null != thumbImage)
751                     {
752                         panGestureDetector.Detach(thumbImage);
753                     }
754                     panGestureDetector.Detected -= OnPanGestureDetected;
755                     panGestureDetector.Dispose();
756                     panGestureDetector = null;
757                 }
758                 
759                 if (null != thumbImage)
760                 {
761                     thumbImage.TouchEvent -= OnTouchEventForThumb;
762                     Utility.Dispose(thumbImage);
763                 }
764                 Utility.Dispose(slidedTrackImage);
765                 if (null != bgTrackImage)
766                 {
767                     bgTrackImage.TouchEvent -= OnTouchEventForBgTrack;
768                     Utility.Dispose(bgTrackImage);
769                 }
770                 Utility.Dispose(lowIndicatorImage);
771                 Utility.Dispose(highIndicatorImage);
772                 Utility.Dispose(lowIndicatorText);
773                 Utility.Dispose(highIndicatorText);
774             }
775
776             base.Dispose(type);
777         }
778
779         /// <summary>
780         /// Update Slider by attributes.
781         /// </summary>
782         /// <since_tizen> 6 </since_tizen>
783         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
784         [EditorBrowsable(EditorBrowsableState.Never)]
785         protected override void OnUpdate()
786         {
787             RelayoutBaseComponent();
788
789             UpdateComponentByIndicatorTypeChanged();
790             UpdateBgTrackSize();
791             UpdateBgTrackPosition();
792             UpdateLowIndicatorSize();
793             UpdateValue();
794         }
795
796         /// <summary>
797         /// Theme change callback when theme is changed, this callback will be trigger.
798         /// </summary>
799         /// <param name="sender">serder object</param>
800         /// <param name="e">ThemeChangeEventArgs</param>
801         /// <since_tizen> 6 </since_tizen>
802         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
803         [EditorBrowsable(EditorBrowsableState.Never)]
804         protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
805         {
806             SliderStyle sliderStyle = StyleManager.Instance.GetViewStyle(style) as SliderStyle;
807             if (sliderStyle != null)
808             {
809                 Style?.CopyFrom(sliderStyle);
810                 RelayoutRequest();
811             }
812         }
813
814         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
815         [EditorBrowsable(EditorBrowsableState.Never)]
816         public override void ApplyStyle(ViewStyle viewStyle)
817         {
818             base.ApplyStyle(viewStyle);
819
820             SliderStyle sliderStyle = viewStyle as SliderStyle;
821
822             if (null != sliderStyle?.Progress)
823             {
824                 CreateSlidedTrackAttributes();
825             }
826
827             if (null != sliderStyle?.LowIndicator)
828             {
829                 CreateLowIndicatorTextAttributes();
830             }
831
832             if (null != sliderStyle?.HighIndicator)
833             {
834                 CreateHighIndicatorTextAttributes();
835             }
836
837             if (null != sliderStyle?.Track)
838             {
839                 CreateBackgroundTrackAttributes();
840             }
841
842             if (null != sliderStyle?.Thumb)
843             {
844                 CreateThumbAttributes();
845             }
846         }
847
848         private void Initialize()
849         {
850             currentSlidedOffset = 0;
851             isFocused = false;
852             isPressed = false;
853             LayoutDirectionChanged += OnLayoutDirectionChanged;
854         }
855
856         private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
857         {
858             RelayoutRequest();
859         }
860
861         private void CreateSlidedTrackAttributes()
862         {
863             if (null == slidedTrackImage)
864             {
865                 slidedTrackImage = new ImageView()
866                 {
867                     WidthResizePolicy = ResizePolicyType.Fixed,
868                     HeightResizePolicy = ResizePolicyType.Fixed
869                 };
870
871                 if (bgTrackImage != null)
872                 {
873                     bgTrackImage.Add(slidedTrackImage);
874                 }
875
876                 if (null != thumbImage)
877                 {
878                     slidedTrackImage.Add(thumbImage);
879                 }
880             }
881
882             if (null == Style.Progress)
883             {
884                 Style.Progress = new ImageViewStyle();
885             }
886
887             slidedTrackImage.ApplyStyle(Style.Progress);
888         }
889
890         private void CreateLowIndicatorTextAttributes()
891         {
892             if (null == lowIndicatorText)
893             {
894                 lowIndicatorText = new TextLabel()
895                 {
896                     WidthResizePolicy = ResizePolicyType.Fixed,
897                     HeightResizePolicy = ResizePolicyType.Fixed
898                 };
899                 this.Add(lowIndicatorText);
900             }
901
902             if (null == Style.LowIndicator)
903             {
904                 Style.LowIndicator = new TextLabelStyle();
905             }
906
907             lowIndicatorText.ApplyStyle(Style.LowIndicator);
908         }
909
910         private void CreateHighIndicatorTextAttributes()
911         {
912             if (null == highIndicatorText)
913             {
914                 highIndicatorText = new TextLabel()
915                 {
916                     WidthResizePolicy = ResizePolicyType.Fixed,
917                     HeightResizePolicy = ResizePolicyType.Fixed
918                 };
919                 this.Add(highIndicatorText);
920             }
921
922             if (null == Style.HighIndicator)
923             {
924                 Style.HighIndicator = new TextLabelStyle();
925             }
926
927             highIndicatorText.ApplyStyle(Style.HighIndicator);
928         }
929
930         private void CreateBackgroundTrackAttributes()
931         {
932             if (null == bgTrackImage)
933             {
934                 bgTrackImage = new ImageView()
935                 {
936                     WidthResizePolicy = ResizePolicyType.Fixed,
937                     HeightResizePolicy = ResizePolicyType.Fixed,
938                     ParentOrigin = Tizen.NUI.ParentOrigin.Center,
939                     PivotPoint = Tizen.NUI.PivotPoint.Center,
940                     PositionUsesPivotPoint = true
941                 };
942                 this.Add(bgTrackImage);
943
944                 if (null != slidedTrackImage)
945                 {
946                     bgTrackImage.Add(slidedTrackImage);
947                 }
948
949                 bgTrackImage.TouchEvent += OnTouchEventForBgTrack;
950             }
951
952             if (null == Style.Track)
953             {
954                 Style.Track = new ImageViewStyle();
955             }
956
957             bgTrackImage.ApplyStyle(Style.Track);
958         }
959
960         private void CreateThumbAttributes()
961         {
962             if (null == thumbImage)
963             {
964                 thumbImage = new ImageView()
965                 {
966                     WidthResizePolicy = ResizePolicyType.Fixed,
967                     HeightResizePolicy = ResizePolicyType.Fixed,
968                     ParentOrigin = NUI.ParentOrigin.Center,
969                     PivotPoint = NUI.PivotPoint.Center,
970                     PositionUsesPivotPoint = true
971                 };
972                 if (slidedTrackImage != null)
973                 {
974                     slidedTrackImage.Add(thumbImage);
975                 }
976                 thumbImage.TouchEvent += OnTouchEventForThumb;
977
978                 panGestureDetector = new PanGestureDetector();
979                 panGestureDetector.Attach(thumbImage);
980                 panGestureDetector.Detected += OnPanGestureDetected;
981             }
982
983             if (null == Style.Thumb)
984             {
985                 Style.Thumb= new ImageViewStyle();
986             }
987
988             thumbImage.ApplyStyle(Style.Thumb);
989         }
990
991         private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
992         {
993             if (e.PanGesture.State == Gesture.StateType.Started)
994             {
995                 if (direction == DirectionType.Horizontal)
996                 {
997                     currentSlidedOffset = slidedTrackImage.SizeWidth;
998                 }
999                 else if (direction == DirectionType.Vertical)
1000                 {
1001                     currentSlidedOffset = slidedTrackImage.SizeHeight;
1002                 }
1003                 UpdateState(isFocused, true);
1004             }
1005
1006             if (e.PanGesture.State == Gesture.StateType.Continuing || e.PanGesture.State == Gesture.StateType.Started)
1007             {
1008                 if (direction == DirectionType.Horizontal)
1009                 {
1010                     CalculateCurrentValueByGesture(e.PanGesture.Displacement.X);
1011                 }
1012                 else if (direction == DirectionType.Vertical)
1013                 {
1014                     CalculateCurrentValueByGesture(-e.PanGesture.Displacement.Y);
1015                 }
1016                 UpdateValue();
1017             }
1018
1019             if (e.PanGesture.State == Gesture.StateType.Finished)
1020             {
1021                 if (null != slidingFinishedHandler)
1022                 {
1023                     SlidingFinishedArgs args = new SlidingFinishedArgs();
1024                     args.CurrentValue = curValue.Value;
1025                     slidingFinishedHandler(this, args);
1026                 }
1027
1028                 UpdateState(isFocused, false);
1029             }
1030         }
1031
1032         // Relayout basic component: track, thumb and indicator
1033         private void RelayoutBaseComponent(bool isInitial = true)
1034         {
1035             if (direction == DirectionType.Horizontal)
1036             {
1037                 if (slidedTrackImage != null)
1038                 {
1039                     slidedTrackImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1040                     slidedTrackImage.PivotPoint = NUI.PivotPoint.CenterLeft;
1041                     slidedTrackImage.PositionUsesPivotPoint = true;
1042                 }
1043                 if (thumbImage != null)
1044                 {
1045                     thumbImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
1046                     thumbImage.PivotPoint = NUI.PivotPoint.Center;
1047                     thumbImage.PositionUsesPivotPoint = true;
1048                 }
1049                 if (lowIndicatorImage != null)
1050                 {
1051                     lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1052                     lowIndicatorImage.PivotPoint = NUI.PivotPoint.CenterLeft;
1053                     lowIndicatorImage.PositionUsesPivotPoint = true;
1054                 }
1055                 if (highIndicatorImage != null)
1056                 {
1057                     highIndicatorImage.ParentOrigin = NUI.ParentOrigin.CenterRight;
1058                     highIndicatorImage.PivotPoint = NUI.PivotPoint.CenterRight;
1059                     highIndicatorImage.PositionUsesPivotPoint = true;
1060                 }
1061                 if (lowIndicatorText != null)
1062                 {
1063                     lowIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1064                     lowIndicatorText.PivotPoint = NUI.PivotPoint.CenterLeft;
1065                     lowIndicatorText.PositionUsesPivotPoint = true;
1066                 }
1067                 if (highIndicatorText != null)
1068                 {
1069                     highIndicatorText.ParentOrigin = NUI.ParentOrigin.CenterRight;
1070                     highIndicatorText.PivotPoint = NUI.PivotPoint.CenterRight;
1071                     highIndicatorText.PositionUsesPivotPoint = true;
1072                 }
1073                 if (panGestureDetector != null)
1074                 {
1075                     if (!isInitial)
1076                     {
1077                         panGestureDetector.RemoveDirection(PanGestureDetector.DirectionVertical);
1078                     }
1079                     panGestureDetector.AddDirection(PanGestureDetector.DirectionHorizontal);
1080                 }
1081             }
1082             else if (direction == DirectionType.Vertical)
1083             {
1084                 if (slidedTrackImage != null)
1085                 {
1086                     slidedTrackImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1087                     slidedTrackImage.PivotPoint = NUI.PivotPoint.BottomCenter;
1088                     slidedTrackImage.PositionUsesPivotPoint = true;
1089                 }
1090                 if (thumbImage != null)
1091                 {
1092                     thumbImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
1093                     thumbImage.PivotPoint = NUI.PivotPoint.Center;
1094                     thumbImage.PositionUsesPivotPoint = true;
1095                 }
1096                 if (lowIndicatorImage != null)
1097                 {
1098                     lowIndicatorImage.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1099                     lowIndicatorImage.PivotPoint = NUI.PivotPoint.BottomCenter;
1100                     lowIndicatorImage.PositionUsesPivotPoint = true;
1101                 }
1102                 if (highIndicatorImage != null)
1103                 {
1104                     highIndicatorImage.ParentOrigin = NUI.ParentOrigin.TopCenter;
1105                     highIndicatorImage.PivotPoint = NUI.PivotPoint.TopCenter;
1106                     highIndicatorImage.PositionUsesPivotPoint = true;
1107                 }
1108                 if (lowIndicatorText != null)
1109                 {
1110                     lowIndicatorText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1111                     lowIndicatorText.PivotPoint = NUI.PivotPoint.BottomCenter;
1112                     lowIndicatorText.PositionUsesPivotPoint = true;
1113                 }
1114                 if (highIndicatorText != null)
1115                 {
1116                     highIndicatorText.ParentOrigin = NUI.ParentOrigin.TopCenter;
1117                     highIndicatorText.PivotPoint = NUI.PivotPoint.TopCenter;
1118                     highIndicatorText.PositionUsesPivotPoint = true;
1119                 }
1120                 if (panGestureDetector != null)
1121                 {
1122                     if (!isInitial)
1123                     {
1124                         panGestureDetector.RemoveDirection(PanGestureDetector.DirectionHorizontal);
1125                     }
1126                     panGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
1127                 }
1128             }
1129         }
1130
1131         private int BgTrackLength()
1132         {
1133             int bgTrackLength = 0;
1134             IndicatorType type = CurrentIndicatorType();
1135
1136             if (type == IndicatorType.None)
1137             {
1138                 if (direction == DirectionType.Horizontal)
1139                 {
1140                     bgTrackLength = this.Size2D.Width;
1141                 }
1142                 else if (direction == DirectionType.Vertical)
1143                 {
1144                     bgTrackLength = this.Size2D.Height;
1145                 }
1146             }
1147             else if (type == IndicatorType.Image)
1148             {// <lowIndicatorImage> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorImage>
1149                 Size lowIndicatorImageSize = LowIndicatorImageSize();
1150                 Size highIndicatorImageSize = HighIndicatorImageSize();
1151                 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1152                 if (direction == DirectionType.Horizontal)
1153                 {
1154                     int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
1155                     int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
1156                     bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
1157                 }
1158                 else if (direction == DirectionType.Vertical)
1159                 {
1160                     int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
1161                     int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
1162                     bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
1163                 }
1164             }
1165             else if (type == IndicatorType.Text)
1166             {// <lowIndicatorText> <spaceBetweenTrackAndIndicator> <bgTrack> <spaceBetweenTrackAndIndicator> <highIndicatorText>
1167                 Size lowIndicatorTextSize = LowIndicatorTextSize();
1168                 Size highIndicatorTextSize = HighIndicatorTextSize();
1169                 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1170                 if (direction == DirectionType.Horizontal)
1171                 {
1172                     int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
1173                     int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
1174                     bgTrackLength = this.Size2D.Width - lowIndicatorSpace - highIndicatorSpace;
1175                 }
1176                 else if (direction == DirectionType.Vertical)
1177                 {
1178                     int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
1179                     int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
1180                     bgTrackLength = this.Size2D.Height - lowIndicatorSpace - highIndicatorSpace;
1181                 }
1182             }
1183             return bgTrackLength;
1184         }
1185
1186         private void UpdateLowIndicatorSize()
1187         {
1188             if (lowIndicatorSize != null)
1189             {
1190                 if (lowIndicatorImage != null)
1191                 {
1192                     lowIndicatorImage.Size = lowIndicatorSize;
1193                 }
1194                 if (lowIndicatorText != null)
1195                 {
1196                     lowIndicatorText.Size = lowIndicatorSize;
1197                 }
1198             }
1199             else
1200             {
1201                 if (lowIndicatorImage != null && Style != null && Style.LowIndicatorImage!= null && Style.LowIndicatorImage.Size != null)
1202                 {
1203                     lowIndicatorImage.Size = Style.LowIndicatorImage.Size;
1204                 }
1205                 if (lowIndicatorText != null && Style != null && Style.LowIndicator!= null && Style.LowIndicator.Size != null)
1206                 {
1207                     lowIndicatorText.Size = Style.LowIndicator.Size;
1208                 }
1209             }
1210         }
1211
1212         private void UpdateBgTrackSize()
1213         {
1214             if(bgTrackImage == null)
1215             {
1216                 return;
1217             }
1218             int curTrackThickness = (int)CurrentTrackThickness();
1219             int bgTrackLength = BgTrackLength();
1220             if (direction == DirectionType.Horizontal)
1221             {
1222                 bgTrackImage.Size2D = new Size2D(bgTrackLength, curTrackThickness);
1223             }
1224             else if (direction == DirectionType.Vertical)
1225             {
1226                 bgTrackImage.Size2D = new Size2D(curTrackThickness, bgTrackLength);
1227             }
1228         }
1229
1230         private void UpdateBgTrackPosition()
1231         {
1232             if (bgTrackImage == null)
1233             {
1234                 return;
1235             }
1236             IndicatorType type = CurrentIndicatorType();
1237
1238             if (type == IndicatorType.None)
1239             {
1240                 bgTrackImage.Position2D = new Position2D(0, 0);
1241             }
1242             else if (type == IndicatorType.Image)
1243             {
1244                 Size lowIndicatorImageSize = LowIndicatorImageSize();
1245                 Size highIndicatorImageSize = HighIndicatorImageSize();
1246                 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1247                 if (direction == DirectionType.Horizontal)
1248                 {
1249                     int lowIndicatorSpace = ((lowIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Width)));
1250                     int highIndicatorSpace = ((highIndicatorImageSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Width)));
1251                     bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
1252                 }
1253                 else if (direction == DirectionType.Vertical)
1254                 {
1255                     int lowIndicatorSpace = ((lowIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorImageSize.Height)));
1256                     int highIndicatorSpace = ((highIndicatorImageSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorImageSize.Height)));
1257                     bgTrackImage.Position2D = new Position2D(0, lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2);
1258                 }
1259             }
1260             else if (type == IndicatorType.Text)
1261             {
1262                 Size lowIndicatorTextSize = LowIndicatorTextSize();
1263                 Size highIndicatorTextSize = HighIndicatorTextSize();
1264                 int curSpace = (int)CurrentSpaceBetweenTrackAndIndicator();
1265                 if (direction == DirectionType.Horizontal)
1266                 {
1267                     int lowIndicatorSpace = ((lowIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Width)));
1268                     int highIndicatorSpace = ((highIndicatorTextSize.Width == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Width)));
1269                     bgTrackImage.Position2D = new Position2D(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2, 0);
1270                 }
1271                 else if (direction == DirectionType.Vertical)
1272                 {
1273                     int lowIndicatorSpace = ((lowIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + lowIndicatorTextSize.Height)));
1274                     int highIndicatorSpace = ((highIndicatorTextSize.Height == 0) ? (0) : ((int)(curSpace + highIndicatorTextSize.Height)));
1275                     bgTrackImage.Position2D = new Position2D(0, -(lowIndicatorSpace - (lowIndicatorSpace + highIndicatorSpace) / 2));
1276                 }
1277             }
1278         }
1279
1280         private void UpdateValue()
1281         {
1282             if (slidedTrackImage == null || curValue == null || minValue == null || maxValue == null)
1283             {
1284                 return;
1285             }
1286             if (curValue < minValue || curValue > maxValue || minValue >= maxValue)
1287             {
1288                 return;
1289             }
1290             
1291             float ratio = 0;
1292             ratio = (float)(curValue - minValue) / (float)(maxValue - minValue);
1293
1294             uint curTrackThickness = CurrentTrackThickness();
1295
1296             if (direction == DirectionType.Horizontal)
1297             {
1298                 if (LayoutDirection == ViewLayoutDirectionType.RTL)
1299                 {
1300                     ratio = 1.0f - ratio;
1301                 }
1302                 float slidedTrackLength = (float)BgTrackLength() * ratio;
1303                 slidedTrackImage.Size2D = new Size2D((int)(slidedTrackLength + round), (int)curTrackThickness); //Add const round to reach Math.Round function.
1304             }
1305             else if (direction == DirectionType.Vertical)
1306             {
1307                 float slidedTrackLength = (float)BgTrackLength() * ratio;
1308                 slidedTrackImage.Size2D = new Size2D((int)(curTrackThickness + round), (int)slidedTrackLength); //Add const round to reach Math.Round function.
1309             }
1310         }
1311
1312         private uint CurrentTrackThickness()
1313         {
1314             uint curTrackThickness = 0;
1315             if (trackThickness != null)
1316             {
1317                 curTrackThickness = trackThickness.Value;
1318             }
1319             else
1320             {
1321                 if (Style != null && Style.TrackThickness != null)
1322                 {
1323                     curTrackThickness = Style.TrackThickness.Value;
1324                 }
1325             }
1326             return curTrackThickness;
1327         }
1328
1329         private uint CurrentSpaceBetweenTrackAndIndicator()
1330         {
1331             uint curSpace = 0;
1332             if (spaceBetweenTrackAndIndicator != null)
1333             {
1334                 curSpace = spaceBetweenTrackAndIndicator.Start;
1335             }
1336             else
1337             {
1338                 if (Style != null && Style.TrackPadding != null)
1339                 {
1340                     curSpace = Style.TrackPadding.Start;
1341                 }
1342             }
1343             return curSpace;
1344         }
1345
1346         private IndicatorType CurrentIndicatorType()
1347         {
1348             IndicatorType type = IndicatorType.None;
1349             if (Style != null)
1350             {
1351                 type = (IndicatorType)Style.IndicatorType;
1352             }
1353             return type;
1354         }
1355
1356         private Size LowIndicatorImageSize()
1357         {
1358             Size size = new Size(0, 0);
1359             if (lowIndicatorSize != null)
1360             {
1361                 size = lowIndicatorSize;
1362             }
1363             else
1364             {
1365                 if (Style != null && Style.LowIndicatorImage!= null && Style.LowIndicatorImage.Size != null)
1366                 {
1367                     size = Style.LowIndicatorImage.Size;
1368                 }
1369             }
1370             return size;
1371         }
1372
1373         private Size HighIndicatorImageSize()
1374         {
1375             Size size = new Size(0, 0);
1376             if (highIndicatorSize != null)
1377             {
1378                 size = highIndicatorSize;
1379             }
1380             else
1381             {
1382                 if (Style != null && Style.HighIndicatorImage!= null && Style.HighIndicatorImage.Size != null)
1383                 {
1384                     size = Style.HighIndicatorImage.Size;
1385                 }
1386             }
1387             return size;
1388         }
1389
1390         private Size LowIndicatorTextSize()
1391         {
1392             Size size = new Size(0, 0);
1393             if (lowIndicatorSize != null)
1394             {
1395                 size = lowIndicatorSize;
1396             }
1397             else
1398             {
1399                 if (Style != null && Style.LowIndicator!= null && Style.LowIndicator.Size != null)
1400                 {
1401                     size = Style.LowIndicator.Size;
1402                 }
1403             }
1404             return size;
1405         }
1406
1407         private Size HighIndicatorTextSize()
1408         {
1409             Size size = new Size(0, 0);
1410             if (highIndicatorSize != null)
1411             {
1412                 size = highIndicatorSize;
1413             }
1414             else
1415             {
1416                 if (Style != null && Style.HighIndicator!= null && Style.HighIndicator.Size != null)
1417                 {
1418                     size = Style.HighIndicator.Size;
1419                 }
1420             }
1421             return size;
1422         }
1423
1424         private void CalculateCurrentValueByGesture(float offset)
1425         {
1426             currentSlidedOffset += offset;
1427
1428             if (currentSlidedOffset <= 0)
1429             {
1430                 curValue = minValue;
1431             }
1432             else if (currentSlidedOffset >= BgTrackLength())
1433             {
1434                 curValue = maxValue;
1435             }
1436             else
1437             {
1438                 int bgTrackLength = BgTrackLength();
1439                 if (bgTrackLength != 0)
1440                 {
1441                     curValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1442                 }
1443             }
1444             if (valueChangedHandler != null)
1445             {
1446                 ValueChangedArgs args = new ValueChangedArgs();
1447                 args.CurrentValue = curValue.Value;
1448                 valueChangedHandler(this, args);
1449             }
1450         }
1451
1452         private bool OnTouchEventForBgTrack(object source, TouchEventArgs e)
1453         {
1454             PointStateType state = e.Touch.GetState(0);
1455             if (state == PointStateType.Down)
1456             {
1457                 Vector2 pos = e.Touch.GetLocalPosition(0);
1458                 CalculateCurrentValueByTouch(pos);
1459                 UpdateValue();
1460                 if (null != slidingFinishedHandler)
1461                 {
1462                     SlidingFinishedArgs args = new SlidingFinishedArgs();
1463                     args.CurrentValue = curValue.Value;
1464                     slidingFinishedHandler(this, args);
1465                 }
1466             }
1467             return false;
1468         }
1469
1470         private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1471         {
1472             PointStateType state = e.Touch.GetState(0);
1473             if (state == PointStateType.Down)
1474             {
1475                 UpdateState(isFocused, true);
1476             }
1477             else if (state == PointStateType.Up)
1478             {
1479                 UpdateState(isFocused, false);
1480             }
1481             return true;
1482         }
1483
1484         private void CalculateCurrentValueByTouch(Vector2 pos)
1485         {
1486             int bgTrackLength = BgTrackLength();
1487             if (direction == DirectionType.Horizontal)
1488             {
1489                 currentSlidedOffset = pos.X;
1490             }
1491             else if (direction == DirectionType.Vertical)
1492             {
1493                 currentSlidedOffset = bgTrackLength - pos.Y;
1494             }
1495             if (bgTrackLength != 0)
1496             {
1497                 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1498                 if (null != valueChangedHandler)
1499                 {
1500                     ValueChangedArgs args = new ValueChangedArgs();
1501                     args.CurrentValue = curValue.Value;
1502                     valueChangedHandler(this, args);
1503                 }
1504             }
1505         }
1506
1507         private void UpdateState(bool isFocusedNew, bool isPressedNew)
1508         {
1509             if (isFocused == isFocusedNew && isPressed == isPressedNew)
1510             {
1511                 return;
1512             }
1513             if (thumbImage == null || Style == null)
1514             {
1515                 return;
1516             }
1517             isFocused = isFocusedNew;
1518             isPressed = isPressedNew;
1519
1520             if (!isFocused && !isPressed)
1521             {
1522                 ControlState = ControlStates.Normal;
1523                 if (stateChangedHandler != null)
1524                 {
1525                     StateChangedArgs args = new StateChangedArgs();
1526                     args.CurrentState = (ControlStates)ControlStates.Normal;
1527                     stateChangedHandler(this, args);
1528                 }
1529             }
1530             else if (isPressed)
1531             {
1532                 ControlState = ControlStates.Pressed;
1533
1534                 if (stateChangedHandler != null)
1535                 {
1536                     StateChangedArgs args = new StateChangedArgs();
1537                     args.CurrentState = (ControlStates)ControlStates.Pressed;
1538                     stateChangedHandler(this, args);
1539                 }
1540             }
1541             else if (!isPressed && isFocused)
1542             {
1543                 ControlState = ControlStates.Focused;
1544
1545                 if (stateChangedHandler != null)
1546                 {
1547                     StateChangedArgs args = new StateChangedArgs();
1548                     args.CurrentState = (ControlStates)ControlStates.Focused;
1549                     stateChangedHandler(this, args);
1550                 }
1551             }
1552         }
1553
1554         private void UpdateComponentByIndicatorTypeChanged()
1555         {
1556             IndicatorType type = CurrentIndicatorType();
1557             if (type == IndicatorType.None)
1558             {
1559                 if (lowIndicatorImage != null)
1560                 {
1561                     lowIndicatorImage.Hide();
1562                 }
1563                 if (highIndicatorImage != null)
1564                 {
1565                     highIndicatorImage.Hide();
1566                 }
1567                 if (lowIndicatorText != null)
1568                 {
1569                     lowIndicatorText.Hide();
1570                 }
1571                 if (highIndicatorText != null)
1572                 {
1573                     highIndicatorText.Hide();
1574                 }
1575             }
1576             else if (type == IndicatorType.Image)
1577             {
1578                 if (lowIndicatorImage != null)
1579                 {
1580                     lowIndicatorImage.Show();
1581                 }
1582                 if (highIndicatorImage != null)
1583                 {
1584                     highIndicatorImage.Show();
1585                 }
1586                 if (lowIndicatorText != null)
1587                 {
1588                     lowIndicatorText.Hide();
1589                 }
1590                 if (highIndicatorText != null)
1591                 {
1592                     highIndicatorText.Hide();
1593                 }
1594             }
1595             else if (type == IndicatorType.Text)
1596             {
1597                 if (lowIndicatorText != null)
1598                 {
1599                     lowIndicatorText.Show();
1600                 }
1601                 if (highIndicatorText != null)
1602                 {
1603                     highIndicatorText.Show();
1604                 }
1605                 if (lowIndicatorImage != null)
1606                 {
1607                     lowIndicatorImage.Hide();
1608                 }
1609                 if (highIndicatorImage != null)
1610                 {
1611                     highIndicatorImage.Hide();
1612                 }
1613             }
1614         }
1615
1616         /// <summary>
1617         /// Value Changed event data.
1618         /// </summary>
1619         /// <since_tizen> 6 </since_tizen>
1620         public class ValueChangedArgs : EventArgs
1621         {
1622             /// <summary>
1623             /// Curren value
1624             /// </summary>
1625             /// <since_tizen> 6 </since_tizen>
1626             public float CurrentValue;
1627         }
1628
1629         /// <summary>
1630         /// Value Changed event data.
1631         /// </summary>
1632         /// <since_tizen> 6 </since_tizen>
1633         public class SlidingFinishedArgs : EventArgs
1634         {
1635             /// <summary>
1636             /// Curren value
1637             /// </summary>
1638             /// <since_tizen> 6 </since_tizen>
1639             public float CurrentValue;
1640         }
1641
1642         /// <summary>
1643         /// State Changed event data.
1644         /// </summary>
1645         /// <since_tizen> 6 </since_tizen>
1646         public class StateChangedArgs : EventArgs
1647         {
1648             /// <summary>
1649             /// Curent state
1650             /// </summary>
1651             /// <since_tizen> 6 </since_tizen>
1652             public ControlStates CurrentState;
1653         }
1654     }
1655 }