Release 8.0.0.15408
[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 partial class Slider : Control
29     {
30         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
31         [EditorBrowsable(EditorBrowsableState.Never)]
32         public static readonly BindableProperty IndicatorTypeProperty = BindableProperty.Create("IndicatorType", typeof(IndicatorType), typeof(Slider), IndicatorType.None, propertyChanged: (bindable, oldValue, newValue) =>
33         {
34             var instance = (Slider)bindable;
35             if (newValue != null)
36             {
37                 instance.privateIndicatorType = (IndicatorType)newValue;
38             }
39         },
40         defaultValueCreator: (bindable) =>
41         {
42             var instance = (Slider)bindable;
43             return instance.privateIndicatorType;
44         });
45         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
46         [EditorBrowsable(EditorBrowsableState.Never)]
47         public static readonly BindableProperty SpaceBetweenTrackAndIndicatorProperty = BindableProperty.Create(nameof(SpaceBetweenTrackAndIndicator), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
48         {
49             var instance = (Slider)bindable;
50             if (newValue != null)
51             {
52                 instance.privateSpaceBetweenTrackAndIndicator = (uint)newValue;
53             }
54         },
55         defaultValueCreator: (bindable) =>
56         {
57             var instance = (Slider)bindable;
58             return instance.privateSpaceBetweenTrackAndIndicator;
59         });
60         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
61         [EditorBrowsable(EditorBrowsableState.Never)]
62         public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
63         {
64             var instance = (Slider)bindable;
65             if (newValue != null)
66             {
67                 instance.privateTrackThickness = (uint)newValue;
68             }
69         },
70         defaultValueCreator: (bindable) =>
71         {
72             var instance = (Slider)bindable;
73             return instance.privateTrackThickness;
74         });
75
76         static Slider() { }
77
78         /// <summary>
79         /// The constructor of the Slider class.
80         /// </summary>
81         /// <since_tizen> 6 </since_tizen>
82         public Slider() 
83         {
84             Initialize();
85         }
86
87         /// <summary>
88         /// The constructor of the Slider class with specific style.
89         /// </summary>
90         /// <param name="style">The string to initialize the Slider</param>
91         /// <since_tizen> 8 </since_tizen>
92         public Slider(string style) : base(style)
93         {
94             Initialize();
95         }
96
97         /// <summary>
98         /// The constructor of the Slider class with specific style.
99         /// </summary>
100         /// <param name="sliderStyle">The style object to initialize the Slider</param>
101         /// <since_tizen> 8 </since_tizen>
102         public Slider(SliderStyle sliderStyle) : base(sliderStyle)
103         {
104             Initialize();
105         }
106
107         /// <summary>
108         /// The value changed event handler.
109         /// </summary>
110         /// <since_tizen> 6 </since_tizen>
111         public event EventHandler<ValueChangedArgs> ValueChangedEvent
112         {
113             add
114             {
115                 valueChangedHandler += value;
116             }
117             remove
118             {
119                 valueChangedHandler -= value;
120             }
121         }
122
123         /// <summary>
124         /// The sliding finished event handler.
125         /// </summary>
126         /// <since_tizen> 6 </since_tizen>
127         public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
128         {
129             add
130             {
131                 slidingFinishedHandler += value;
132             }
133             remove
134             {
135                 slidingFinishedHandler -= value;
136             }
137         }
138
139         /// <summary>
140         /// The state changed event handler.
141         /// </summary>
142         /// <since_tizen> 6 </since_tizen>
143         [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEvent")]
144         public event EventHandler<StateChangedArgs> StateChangedEvent
145         {
146             add
147             {
148                 stateChangedHandler += value;
149             }
150             remove
151             {
152                 stateChangedHandler -= value;
153             }
154         }
155
156         /// <summary>
157         /// The direction type of slider.
158         /// </summary>
159         /// <since_tizen> 6 </since_tizen>
160         public enum DirectionType
161         {
162             /// <summary>
163             /// The Horizontal type.
164             /// </summary>
165             /// <since_tizen> 6 </since_tizen>
166             Horizontal,
167
168             /// <summary>
169             /// The Vertical type.
170             /// </summary>
171             /// <since_tizen> 6 </since_tizen>
172             Vertical
173         }
174
175         /// <summary>
176         /// The indicator type of slider.
177         /// </summary>
178         /// <since_tizen> 6 </since_tizen>
179         public enum IndicatorType
180         {
181             /// <summary> Only contains slider bar.</summary>
182             /// <since_tizen> 6 </since_tizen>
183             None,
184
185             /// <summary> Contains slider bar, IndicatorImage.</summary>
186             /// <since_tizen> 6 </since_tizen>
187             Image,
188
189             /// <summary> Contains slider bar, IndicatorText.</summary>
190             /// <since_tizen> 6 </since_tizen>
191             Text
192         }
193
194         /// <summary>
195         /// Return a copied Style instance of Slider
196         /// </summary>
197         /// <remarks>
198         /// It returns copied Style instance and changing it does not effect to the Slider.
199         /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
200         /// </remarks>
201         /// <since_tizen> 8 </since_tizen>
202         public new SliderStyle Style
203         {
204             get
205             {
206                 var result = new SliderStyle(sliderStyle);
207                 result.CopyPropertiesFromView(this);
208                 result.Track.CopyPropertiesFromView(bgTrackImage);
209                 result.Progress.CopyPropertiesFromView(slidedTrackImage);
210                 result.Thumb.CopyPropertiesFromView(thumbImage);
211                 result.LowIndicatorImage.CopyPropertiesFromView(lowIndicatorImage);
212                 result.HighIndicatorImage.CopyPropertiesFromView(highIndicatorImage);
213                 result.LowIndicator.CopyPropertiesFromView(lowIndicatorText);
214                 result.HighIndicator.CopyPropertiesFromView(highIndicatorText);
215                 return result;
216             }
217         }
218
219         /// <summary>
220         /// Return a copied Style instance of Slider
221         /// </summary>
222         private SliderStyle sliderStyle => ViewStyle as SliderStyle;
223
224         /// <summary>
225         /// Gets or sets the direction type of slider.
226         /// </summary>
227         /// <since_tizen> 6 </since_tizen>
228         public DirectionType Direction
229         {
230             get
231             {
232                 return direction;
233             }
234             set
235             {
236                 if (direction == value)
237                 {
238                     return;
239                 }
240                 direction = value;
241                 RelayoutBaseComponent(false);
242                 UpdateBgTrackSize();
243                 UpdateBgTrackPosition();
244                 UpdateValue();
245             }
246         }
247
248         /// <summary>
249         /// Gets or sets the indicator type, arrow or sign.
250         /// </summary>
251         /// <since_tizen> 6 </since_tizen>
252         public IndicatorType Indicator
253         {
254             get
255             {
256                 return (IndicatorType)GetValue(IndicatorTypeProperty);
257             }
258             set
259             {
260                 SetValue(IndicatorTypeProperty, value);
261             }
262         }
263
264         /// <summary>
265         /// Gets or sets the minimum value of slider.
266         /// </summary>
267         /// <since_tizen> 6 </since_tizen>
268         public float MinValue
269         {
270             get
271             {
272                 return minValue;
273             }
274             set
275             {
276                 minValue = value;
277                 UpdateValue();
278             }
279         }
280
281         /// <summary>
282         /// Gets or sets the maximum value of slider.
283         /// </summary>
284         /// <since_tizen> 6 </since_tizen>
285         public float MaxValue
286         {
287             get
288             {
289                 return maxValue;
290             }
291             set
292             {
293                 maxValue = value;
294                 UpdateValue();
295             }
296         }
297
298         /// <summary>
299         /// Gets or sets the current value of slider.
300         /// </summary>
301         /// <since_tizen> 6 </since_tizen>
302         public float CurrentValue
303         {
304             get
305             {
306                 return curValue;
307             }
308             set
309             {
310                 curValue = value;
311                 UpdateValue();
312             }
313         }
314
315         /// <summary>
316         /// Gets or sets the size of the thumb image object.
317         /// </summary>
318         /// <since_tizen> 6 </since_tizen>
319         public Size ThumbSize
320         {
321             get
322             {
323                 return thumbImage?.Size;
324             }
325             set
326             {
327                 if (null != thumbImage)
328                 {
329                     thumbImage.Size = value;
330                     sliderStyle.Thumb.Size = value;
331                 }
332             }
333         }
334
335         /// <summary>
336         /// Gets or sets the resource url of the thumb image object.
337         /// </summary>
338         /// <since_tizen> 6 </since_tizen>
339         public string ThumbImageURL
340         {
341             get
342             {
343                 return thumbImage?.ResourceUrl;
344             }
345             set
346             {
347                 if (null != thumbImage)
348                 {
349                     thumbImage.ResourceUrl = value;
350                     sliderStyle.Thumb.ResourceUrl = value;
351                 }
352             }
353         }
354
355         /// <summary>
356         /// Gets or sets the resource url selector of the thumb image object.
357         /// Getter returns copied selector value if exist, null otherwise.
358         /// </summary>
359         /// <since_tizen> 6 </since_tizen>
360         public StringSelector ThumbImageURLSelector
361         {
362             get => thumbImage == null ? null : new StringSelector((Selector<string>)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty));
363             set => thumbImage?.SetValue(ImageView.ResourceUrlSelectorProperty, value);
364         }
365
366         /// <summary>
367         /// Gets or sets the color of the background track image object.
368         /// </summary>
369         /// <since_tizen> 6 </since_tizen>
370         public Color BgTrackColor
371         {
372             get
373             {
374                 return bgTrackImage?.BackgroundColor;
375             }
376             set
377             {
378                 if (null != bgTrackImage)
379                 {
380                     bgTrackImage.BackgroundColor = value;
381                     sliderStyle.Track.BackgroundColor = value;
382                 }
383             }
384         }
385
386         /// <summary>
387         /// Gets or sets the color of the slided track image object.
388         /// </summary>
389         /// <since_tizen> 6 </since_tizen>
390         public Color SlidedTrackColor
391         {
392             get
393             {
394                 return slidedTrackImage?.BackgroundColor;
395             }
396             set
397             {
398                 if (null != slidedTrackImage)
399                 {
400                     slidedTrackImage.BackgroundColor = value;
401                     sliderStyle.Progress.BackgroundColor = value;
402                 }
403             }
404         }
405
406         /// <summary>
407         /// Gets or sets the thickness value of the track.
408         /// </summary>
409         /// <since_tizen> 6 </since_tizen>
410         public uint TrackThickness
411         {
412             get
413             {
414                 return (uint)GetValue(TrackThicknessProperty);
415             }
416             set
417             {
418                 SetValue(TrackThicknessProperty, value);
419             }
420         }
421
422         /// <summary>
423         /// Gets or sets the resource url of the low indicator image object.
424         /// </summary>
425         /// <since_tizen> 6 </since_tizen>
426         public string LowIndicatorImageURL
427         {
428             get
429             {
430                 return lowIndicatorImage?.ResourceUrl;
431             }
432             set
433             {
434                 if (null != lowIndicatorImage)
435                 {
436                     lowIndicatorImage.ResourceUrl = value;
437                     sliderStyle.LowIndicatorImage.ResourceUrl = value;
438                 }
439             }
440         }
441
442         /// <summary>
443         /// Gets or sets the resource url of the high indicator image object.
444         /// </summary>
445         /// <since_tizen> 6 </since_tizen>
446         public string HighIndicatorImageURL
447         {
448             get
449             {
450                 return highIndicatorImage?.ResourceUrl;
451             }
452             set
453             {
454                 if (null != highIndicatorImage)
455                 {
456                     highIndicatorImage.ResourceUrl = value;
457                     sliderStyle.HighIndicatorImage.ResourceUrl = value;
458                 }
459             }
460         }
461
462         /// <summary>
463         /// Gets or sets the text content of the low indicator text object.
464         /// </summary>
465         /// <since_tizen> 6 </since_tizen>
466         public string LowIndicatorTextContent
467         {
468             get
469             {
470                 return lowIndicatorText?.Text;
471             }
472             set
473             {
474                 if (null != lowIndicatorText)
475                 {
476                     lowIndicatorText.Text= value;
477                     sliderStyle.LowIndicator.Text= value;
478                 }
479             }
480         }
481
482         /// <summary>
483         /// Gets or sets the text content of the high indicator text object.
484         /// </summary>
485         /// <since_tizen> 6 </since_tizen>
486         public string HighIndicatorTextContent
487         {
488             get
489             {
490                 return highIndicatorText?.Text;
491             }
492             set
493             {
494                 if (null != highIndicatorText)
495                 {
496                     highIndicatorText.Text = value;
497                     sliderStyle.HighIndicator.Text = value;
498                 }
499             }
500         }
501
502         /// <summary>
503         /// Gets or sets the size of the low indicator object(image or text).
504         /// </summary>
505         /// <since_tizen> 6 </since_tizen>
506         public Size LowIndicatorSize
507         {
508             get
509             {
510                 return lowIndicatorSize;
511             }
512             set
513             {
514                 lowIndicatorSize = value;
515                 UpdateLowIndicatorSize();
516                 UpdateBgTrackSize();
517                 UpdateBgTrackPosition();
518                 UpdateValue();
519             }
520         }
521
522         /// <summary>
523         /// Gets or sets the size of the high indicator object(image or text).
524         /// </summary>
525         /// <since_tizen> 6 </since_tizen>
526         public Size HighIndicatorSize
527         {
528             get
529             {
530                 return highIndicatorText?.Size;
531             }
532             set
533             {
534                 if (null != highIndicatorText)
535                 {
536                     highIndicatorText.Size = value;
537                     sliderStyle.HighIndicator.Size = value;
538                 }
539             }
540         }
541
542         /// <summary>
543         /// Gets or sets the value of the space between track and indicator.
544         /// </summary>
545         /// <since_tizen> 6 </since_tizen>
546         public uint SpaceBetweenTrackAndIndicator
547         {
548             get
549             {
550                 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
551             }
552             set
553             {
554                 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
555             }
556         }
557
558         private Extents spaceBetweenTrackAndIndicator
559         {
560             get
561             {
562                 if (null == _spaceBetweenTrackAndIndicator)
563                 {
564                     _spaceBetweenTrackAndIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
565                     {
566                         Extents extents = new Extents(start, end, top, bottom);
567                         _spaceBetweenTrackAndIndicator.CopyFrom(extents);
568                     }, 0, 0, 0, 0);
569                 }
570
571                 return _spaceBetweenTrackAndIndicator;
572             }
573         }
574
575         private IndicatorType privateIndicatorType
576         {
577             get
578             {
579                 return indicatorType;
580             }
581             set
582             {
583                 if (indicatorType == value)
584                 {
585                     return;
586                 }
587                 indicatorType = value;
588                 RelayoutBaseComponent(false);
589                 UpdateBgTrackSize();
590                 UpdateBgTrackPosition();
591                 UpdateValue();
592             }
593         }
594
595         private uint privateTrackThickness
596         {
597             get
598             {
599                 return trackThickness ?? 0;
600             }
601             set
602             {
603                 trackThickness = value;
604                 if (bgTrackImage != null)
605                 {
606                     if (direction == DirectionType.Horizontal)
607                     {
608                         bgTrackImage.SizeHeight = (float)trackThickness.Value;
609                     }
610                     else if (direction == DirectionType.Vertical)
611                     {
612                         bgTrackImage.SizeWidth = (float)trackThickness.Value;
613                     }
614                 }
615                 if (slidedTrackImage != null)
616                 {
617                     if (direction == DirectionType.Horizontal)
618                     {
619                         slidedTrackImage.SizeHeight = (float)trackThickness.Value;
620                     }
621                     else if (direction == DirectionType.Vertical)
622                     {
623                         slidedTrackImage.SizeWidth = (float)trackThickness.Value;
624                     }
625                 }
626             }
627         }
628
629         private uint privateSpaceBetweenTrackAndIndicator
630         {
631             get
632             {
633                 return privateTrackPadding.Start;
634             }
635             set
636             {
637                 ushort val = (ushort)value;
638                 privateTrackPadding = new Extents(val, val, val, val);
639             }
640         }
641
642         private Extents privateTrackPadding
643         {
644             get
645             {
646                 return spaceBetweenTrackAndIndicator;
647             }
648             set
649             {
650                 spaceBetweenTrackAndIndicator.CopyFrom(value);
651                 UpdateComponentByIndicatorTypeChanged();
652                 UpdateBgTrackSize();
653                 UpdateBgTrackPosition();
654                 UpdateValue();
655             }
656         }
657
658         /// <summary>
659         /// Focus gained callback.
660         /// </summary>
661         /// <since_tizen> 8 </since_tizen>
662         public override void OnFocusGained()
663         {
664             //State = ControlStates.Focused;
665             UpdateState(true, isPressed);
666             base.OnFocusGained();
667         }
668
669         /// <summary>
670         /// Focus Lost callback.
671         /// </summary>
672         /// <since_tizen> 8 </since_tizen>
673         public override void OnFocusLost()
674         {
675             //State = ControlStates.Normal;
676             UpdateState(false, isPressed);
677             base.OnFocusLost();
678         }
679
680         /// <summary>
681         /// Apply style to scrollbar.
682         /// </summary>
683         /// <param name="viewStyle">The style to apply.</param>
684         /// <since_tizen> 8 </since_tizen>
685         public override void ApplyStyle(ViewStyle viewStyle)
686         {
687             base.ApplyStyle(viewStyle);
688
689             SliderStyle sliderStyle = viewStyle as SliderStyle;
690
691             if (null != sliderStyle?.Progress)
692             {
693                 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
694             }
695
696             if (null != sliderStyle?.LowIndicator)
697             {
698                 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
699             }
700
701             if (null != sliderStyle?.HighIndicator)
702             {
703                 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
704             }
705
706             if (null != sliderStyle?.Track)
707             {
708                 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
709             }
710
711             if (null != sliderStyle?.Thumb)
712             {
713                 CreateThumb().ApplyStyle(sliderStyle.Thumb);
714             }
715
716             EnableControlStatePropagation = true;
717         }
718
719         /// <summary>
720         /// Get Slider style.
721         /// </summary>
722         /// <returns>The default slider style.</returns>
723         /// <since_tizen> 8 </since_tizen>
724         protected override ViewStyle CreateViewStyle()
725         {
726             return new SliderStyle();
727         }
728
729         /// <summary>
730         /// Dispose Slider.
731         /// </summary>
732         /// <param name="type">Dispose type.</param>
733         /// <since_tizen> 6 </since_tizen>
734         protected override void Dispose(DisposeTypes type)
735         {
736             if (disposed)
737             {
738                 return;
739             }
740
741             if (type == DisposeTypes.Explicit)
742             {
743                 if (null != panGestureDetector)
744                 {
745                     if (null != thumbImage)
746                     {
747                         panGestureDetector.Detach(thumbImage);
748                     }
749                     panGestureDetector.Detected -= OnPanGestureDetected;
750                     panGestureDetector.Dispose();
751                     panGestureDetector = null;
752                 }
753
754                 if (null != thumbImage)
755                 {
756                     thumbImage.TouchEvent -= OnTouchEventForThumb;
757                     Utility.Dispose(thumbImage);
758                 }
759                 Utility.Dispose(slidedTrackImage);
760                 if (null != bgTrackImage)
761                 {
762                     bgTrackImage.TouchEvent -= OnTouchEventForBgTrack;
763                     Utility.Dispose(bgTrackImage);
764                 }
765                 Utility.Dispose(lowIndicatorImage);
766                 Utility.Dispose(highIndicatorImage);
767                 Utility.Dispose(lowIndicatorText);
768                 Utility.Dispose(highIndicatorText);
769             }
770
771             base.Dispose(type);
772         }
773
774         /// <summary>
775         /// Update Slider by style.
776         /// </summary>
777         /// <since_tizen> 6 </since_tizen>
778         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
779         [EditorBrowsable(EditorBrowsableState.Never)]
780         protected override void OnUpdate()
781         {
782             RelayoutBaseComponent();
783
784             UpdateComponentByIndicatorTypeChanged();
785             UpdateBgTrackSize();
786             UpdateBgTrackPosition();
787             UpdateLowIndicatorSize();
788             UpdateValue();
789         }
790
791         /// <summary>
792         /// Theme change callback when theme is changed, this callback will be trigger.
793         /// </summary>
794         /// <param name="sender">The sender</param>
795         /// <param name="e">The event data</param>
796         [EditorBrowsable(EditorBrowsableState.Never)]
797         protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
798         {
799             SliderStyle sliderStyle = StyleManager.Instance.GetViewStyle(StyleName) as SliderStyle;
800             if (sliderStyle != null)
801             {
802                 ApplyStyle(sliderStyle);
803                 RelayoutRequest();
804             }
805         }
806
807         private void CalculateCurrentValueByGesture(float offset)
808         {
809             currentSlidedOffset += offset;
810
811             if (currentSlidedOffset <= 0)
812             {
813                 curValue = minValue;
814             }
815             else if (currentSlidedOffset >= BgTrackLength())
816             {
817                 curValue = maxValue;
818             }
819             else
820             {
821                 int bgTrackLength = BgTrackLength();
822                 if (bgTrackLength != 0)
823                 {
824                     curValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
825                 }
826             }
827             if (valueChangedHandler != null)
828             {
829                 ValueChangedArgs args = new ValueChangedArgs();
830                 args.CurrentValue = curValue;
831                 valueChangedHandler(this, args);
832             }
833         }
834
835         private bool OnTouchEventForBgTrack(object source, TouchEventArgs e)
836         {
837             PointStateType state = e.Touch.GetState(0);
838             if (state == PointStateType.Down)
839             {
840                 Vector2 pos = e.Touch.GetLocalPosition(0);
841                 CalculateCurrentValueByTouch(pos);
842                 UpdateValue();
843                 if (null != slidingFinishedHandler)
844                 {
845                     SlidingFinishedArgs args = new SlidingFinishedArgs();
846                     args.CurrentValue = curValue;
847                     slidingFinishedHandler(this, args);
848                 }
849             }
850             return false;
851         }
852
853         private bool OnTouchEventForThumb(object source, TouchEventArgs e)
854         {
855             PointStateType state = e.Touch.GetState(0);
856             if (state == PointStateType.Down)
857             {
858                 UpdateState(isFocused, true);
859             }
860             else if (state == PointStateType.Up)
861             {
862                 UpdateState(isFocused, false);
863             }
864             return true;
865         }
866
867         private void CalculateCurrentValueByTouch(Vector2 pos)
868         {
869             int bgTrackLength = BgTrackLength();
870             if (direction == DirectionType.Horizontal)
871             {
872                 currentSlidedOffset = pos.X;
873             }
874             else if (direction == DirectionType.Vertical)
875             {
876                 currentSlidedOffset = bgTrackLength - pos.Y;
877             }
878             if (bgTrackLength != 0)
879             {
880                 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
881                 if (null != valueChangedHandler)
882                 {
883                     ValueChangedArgs args = new ValueChangedArgs();
884                     args.CurrentValue = curValue;
885                     valueChangedHandler(this, args);
886                 }
887             }
888         }
889
890         private void UpdateState(bool isFocusedNew, bool isPressedNew)
891         {
892             if (isFocused == isFocusedNew && isPressed == isPressedNew)
893             {
894                 return;
895             }
896             if (thumbImage == null || Style == null)
897             {
898                 return;
899             }
900             isFocused = isFocusedNew;
901             isPressed = isPressedNew;
902
903             if (!isFocused && !isPressed)
904             {
905                 ControlState = ControlState.Normal;
906                 if (stateChangedHandler != null)
907                 {
908                     StateChangedArgs args = new StateChangedArgs();
909                     args.CurrentState = (ControlStates)ControlStates.Normal;
910                     stateChangedHandler(this, args);
911                 }
912             }
913             else if (isPressed)
914             {
915                 ControlState = ControlState.Pressed;
916
917                 if (stateChangedHandler != null)
918                 {
919                     StateChangedArgs args = new StateChangedArgs();
920                     args.CurrentState = (ControlStates)ControlStates.Pressed;
921                     stateChangedHandler(this, args);
922                 }
923             }
924             else if (!isPressed && isFocused)
925             {
926                 ControlState = ControlState.Focused;
927
928                 if (stateChangedHandler != null)
929                 {
930                     StateChangedArgs args = new StateChangedArgs();
931                     args.CurrentState = (ControlStates)ControlStates.Focused;
932                     stateChangedHandler(this, args);
933                 }
934             }
935         }
936
937         private void UpdateComponentByIndicatorTypeChanged()
938         {
939             IndicatorType type = CurrentIndicatorType();
940             if (type == IndicatorType.None)
941             {
942                 if (lowIndicatorImage != null)
943                 {
944                     lowIndicatorImage.Hide();
945                 }
946                 if (highIndicatorImage != null)
947                 {
948                     highIndicatorImage.Hide();
949                 }
950                 if (lowIndicatorText != null)
951                 {
952                     lowIndicatorText.Hide();
953                 }
954                 if (highIndicatorText != null)
955                 {
956                     highIndicatorText.Hide();
957                 }
958             }
959             else if (type == IndicatorType.Image)
960             {
961                 if (lowIndicatorImage != null)
962                 {
963                     lowIndicatorImage.Show();
964                 }
965                 if (highIndicatorImage != null)
966                 {
967                     highIndicatorImage.Show();
968                 }
969                 if (lowIndicatorText != null)
970                 {
971                     lowIndicatorText.Hide();
972                 }
973                 if (highIndicatorText != null)
974                 {
975                     highIndicatorText.Hide();
976                 }
977             }
978             else if (type == IndicatorType.Text)
979             {
980                 if (lowIndicatorText != null)
981                 {
982                     lowIndicatorText.Show();
983                 }
984                 if (highIndicatorText != null)
985                 {
986                     highIndicatorText.Show();
987                 }
988                 if (lowIndicatorImage != null)
989                 {
990                     lowIndicatorImage.Hide();
991                 }
992                 if (highIndicatorImage != null)
993                 {
994                     highIndicatorImage.Hide();
995                 }
996             }
997         }
998
999         /// <summary>
1000         /// Value Changed event data.
1001         /// </summary>
1002         /// <since_tizen> 6 </since_tizen>
1003         public class ValueChangedArgs : EventArgs
1004         {
1005             /// <summary>
1006             /// Curren value
1007             /// </summary>
1008             /// <since_tizen> 6 </since_tizen>
1009             public float CurrentValue;
1010         }
1011
1012         /// <summary>
1013         /// Value Changed event data.
1014         /// </summary>
1015         /// <since_tizen> 6 </since_tizen>
1016         public class SlidingFinishedArgs : EventArgs
1017         {
1018             /// <summary>
1019             /// Curren value
1020             /// </summary>
1021             /// <since_tizen> 6 </since_tizen>
1022             public float CurrentValue;
1023         }
1024
1025         /// <summary>
1026         /// State Changed event data.
1027         /// </summary>
1028         /// <since_tizen> 6 </since_tizen>
1029         [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
1030         public class StateChangedArgs : EventArgs
1031         {
1032             /// <summary>
1033             /// Curent state
1034             /// </summary>
1035             /// <since_tizen> 6 </since_tizen>
1036             [Obsolete("Deprecated in API8; Will be removed in API10")]
1037             public ControlStates CurrentState;
1038         }
1039     }
1040 }