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