2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Binding;
20 using System.ComponentModel;
22 namespace Tizen.NUI.Components
25 /// The Progress class of nui component. It's used to show the ongoing status with a long narrow bar.
27 /// <since_tizen> 6 </since_tizen>
28 public class Progress : Control
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 MaxValueProperty = BindableProperty.Create("MaxValue", typeof(float), typeof(Progress), default(float), propertyChanged: (bindable, oldValue, newValue) =>
34 var instance = (Progress)bindable;
37 instance.maxValue = (float)newValue;
38 instance.UpdateValue();
41 defaultValueCreator: (bindable) =>
43 var instance = (Progress)bindable;
44 return instance.maxValue;
47 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
48 [EditorBrowsable(EditorBrowsableState.Never)]
49 public static readonly BindableProperty MinValueProperty = BindableProperty.Create("MinValue", typeof(float), typeof(Progress), default(float), propertyChanged: (bindable, oldValue, newValue) =>
51 var instance = (Progress)bindable;
54 instance.minValue = (float)newValue;
55 instance.UpdateValue();
58 defaultValueCreator: (bindable) =>
60 var instance = (Progress)bindable;
61 return instance.minValue;
64 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
65 [EditorBrowsable(EditorBrowsableState.Never)]
66 public static readonly BindableProperty CurrentValueProperty = BindableProperty.Create("currentValue", typeof(float), typeof(Progress), default(float), propertyChanged: (bindable, oldValue, newValue) =>
68 var instance = (Progress)bindable;
71 if ((float)newValue > instance.maxValue || (float)newValue < instance.minValue)
75 instance.currentValue = (float)newValue;
76 instance.UpdateValue();
79 defaultValueCreator: (bindable) =>
81 var instance = (Progress)bindable;
82 return instance.currentValue;
85 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public static readonly BindableProperty BufferValueProperty = BindableProperty.Create("bufferValue", typeof(float), typeof(Progress), default(float), propertyChanged: (bindable, oldValue, newValue) =>
89 var instance = (Progress)bindable;
92 if ((float)newValue > instance.maxValue || (float)newValue < instance.minValue)
96 instance.bufferValue = (float)newValue;
97 instance.UpdateValue();
100 defaultValueCreator: (bindable) =>
102 var instance = (Progress)bindable;
103 return instance.bufferValue;
106 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
107 [EditorBrowsable(EditorBrowsableState.Never)]
108 public static readonly BindableProperty ProgressStateProperty = BindableProperty.Create("state", typeof(ProgressStatusType), typeof(Progress), ProgressStatusType.Indeterminate, propertyChanged: (bindable, oldValue, newValue) =>
110 var instance = (Progress)bindable;
111 if (newValue != null)
113 instance.state = (ProgressStatusType)newValue;
114 instance.UpdateStates();
117 defaultValueCreator: (bindable) =>
119 var instance = (Progress)bindable;
120 return instance.state;
123 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
124 [EditorBrowsable(EditorBrowsableState.Never)]
125 protected ProgressStatusType state = ProgressStatusType.Indeterminate;
127 private const float round = 0.5f;
128 private ImageView trackImage = null;
129 private ImageView progressImage = null;
130 private ImageView bufferImage = null;
131 private float maxValue = 100;
132 private float minValue = 0;
133 private float currentValue = 0;
134 private float bufferValue = 0;
137 /// The constructor of Progress
139 /// <since_tizen> 6 </since_tizen>
140 public Progress() : base()
146 /// The constructor of the Progress class with specific style.
148 /// <param name="style">style name</param>
149 /// <since_tizen> 6 </since_tizen>
150 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 public Progress(string style) : base(style)
158 /// The constructor of the Progress class with specific Attributes.
160 /// <param name="progressStyle">The Attributes object to initialize the Progress.</param>
161 /// <since_tizen> 6 </since_tizen>
162 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
163 [EditorBrowsable(EditorBrowsableState.Never)]
164 public Progress(ProgressStyle progressStyle) : base(progressStyle)
170 /// The status type of the Progress.
172 /// <since_tizen> 6 </since_tizen>
173 public enum ProgressStatusType
178 /// <since_tizen> 6 </since_tizen>
182 /// Show ProgressImage
184 /// <since_tizen> 6 </since_tizen>
188 /// Show LoadingImage
190 /// <since_tizen> 6 </since_tizen>
194 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
195 [EditorBrowsable(EditorBrowsableState.Never)]
196 public new ProgressStyle Style => ViewStyle as ProgressStyle;
199 /// The property to get/set Track image object URL of the Progress.
201 /// <since_tizen> 6 </since_tizen>
202 public string TrackImageURL
206 return Style.Track?.ResourceUrl?.All;
210 //CreateTrackImageAttributes();
211 if (Style.Track.ResourceUrl == null)
213 Style.Track.ResourceUrl = new StringSelector();
215 Style.Track.ResourceUrl.All = value;
221 /// The property to get/set Progress object image URL of the Progress.
223 /// <since_tizen> 6 </since_tizen>
224 public string ProgressImageURL
228 return Style.Progress?.ResourceUrl?.All;
232 //CreateProgressImageAttributes();
233 if (Style.Progress.ResourceUrl == null)
235 Style.Progress.ResourceUrl = new StringSelector();
237 Style.Progress.ResourceUrl.All = value;
243 /// The property to get/set Buffer object image resource URL of the Progress.
245 /// <since_tizen> 6 </since_tizen>
246 public string BufferImageURL
250 return Style.Buffer?.ResourceUrl?.All;
254 //CreateBufferImageAttributes();
255 if (Style.Buffer.ResourceUrl == null)
257 Style.Buffer.ResourceUrl = new StringSelector();
259 Style.Buffer.ResourceUrl.All = value;
265 /// The property to get/set Track object color of the Progress.
267 /// <since_tizen> 6 </since_tizen>
268 public Color TrackColor
272 return Style.Track?.BackgroundColor?.All;
276 //CreateTrackImageAttributes();
277 if (Style.Track.BackgroundColor == null)
279 Style.Track.BackgroundColor = new ColorSelector();
281 Style.Track.BackgroundColor.All = value;
287 /// The property to get/set Progress object color of the Progress.
289 /// <since_tizen> 6 </since_tizen>
290 public Color ProgressColor
294 return Style.Progress?.BackgroundColor?.All;
298 //CreateProgressImageAttributes();
299 if (null == Style.Progress.BackgroundColor)
301 Style.Progress.BackgroundColor = new ColorSelector();
303 Style.Progress.BackgroundColor.All = value;
309 /// The property to get/set Buffer object color of the Progress.
311 /// <since_tizen> 6 </since_tizen>
312 public Color BufferColor
316 return Style.Buffer?.BackgroundColor?.All;
320 //CreateBufferImageAttributes();
321 if (null == Style.Buffer.BackgroundColor)
323 Style.Buffer.BackgroundColor = new ColorSelector();
325 Style.Buffer.BackgroundColor.All = value;
331 /// The property to get/set the maximum value of the Progress.
333 /// <since_tizen> 6 </since_tizen>
334 public float MaxValue
338 return (float)GetValue(MaxValueProperty);
342 SetValue(MaxValueProperty, value);
347 /// The property to get/set the minim value of the Progress.
349 /// <since_tizen> 6 </since_tizen>
350 public float MinValue
354 return (float)GetValue(MinValueProperty);
358 SetValue(MinValueProperty, value);
363 /// The property to get/set the current value of the Progress.
365 /// <since_tizen> 6 </since_tizen>
366 public float CurrentValue
370 return (float)GetValue(CurrentValueProperty);
374 SetValue(CurrentValueProperty, value);
379 /// The property to get/set the buffer value of the Progress.
381 /// <since_tizen> 6 </since_tizen>
382 public float BufferValue
386 return (float)GetValue(BufferValueProperty);
390 SetValue(BufferValueProperty, value);
395 /// Gets or sets state of progress.
397 /// <since_tizen> 6 </since_tizen>
398 public ProgressStatusType ProgressState
402 return (ProgressStatusType)GetValue(ProgressStateProperty);
406 SetValue(ProgressStateProperty, value);
411 /// Dispose Progress and all children on it.
413 /// <param name="type">Dispose type.</param>
414 /// <since_tizen> 6 </since_tizen>
415 protected override void Dispose(DisposeTypes type)
422 if (type == DisposeTypes.Explicit)
425 //Release your own managed resources here.
426 //You should release all of your own disposable objects here.
427 Utility.Dispose(trackImage);
428 Utility.Dispose(progressImage);
429 Utility.Dispose(bufferImage);
432 //You must call base.Dispose(type) just before exit.
437 /// Theme change callback when theme is changed, this callback will be trigger.
439 /// <param name="sender">serder object</param>
440 /// <param name="e">ThemeChangeEventArgs</param>
441 /// <since_tizen> 6 </since_tizen>
442 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
443 [EditorBrowsable(EditorBrowsableState.Never)]
444 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
446 ProgressStyle tempStyle = StyleManager.Instance.GetAttributes(style) as ProgressStyle;
447 if (null != tempStyle)
449 Style.CopyFrom(tempStyle);
455 /// Change Image status. It can be override.
457 /// <since_tizen> 6 </since_tizen>
458 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
459 [EditorBrowsable(EditorBrowsableState.Never)]
460 protected virtual void UpdateStates()
462 ChangeImageState(state);
466 /// Update progress value
468 /// <since_tizen> 6 </since_tizen>
469 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
470 [EditorBrowsable(EditorBrowsableState.Never)]
471 protected virtual void UpdateValue()
473 if (null == trackImage || null == progressImage)
478 if (minValue >= maxValue || currentValue < minValue || currentValue > maxValue)
483 float width = this.SizeWidth;
484 float height = this.SizeHeight;
485 float progressRatio = (float)(currentValue - minValue) / (float)(maxValue - minValue);
486 float progressWidth = width * progressRatio;
487 progressImage.Size2D = new Size2D((int)(progressWidth + round), (int)height); //Add const round to reach Math.Round function.
488 if (null != bufferImage)
490 if (bufferValue < minValue || bufferValue > maxValue)
495 float bufferRatio = (float)(bufferValue - minValue) / (float)(maxValue - minValue);
496 float bufferWidth = width * bufferRatio;
497 bufferImage.Size2D = new Size2D((int)(bufferWidth + round), (int)height); //Add const round to reach Math.Round function.
502 /// Get Progress attribues.
504 /// <since_tizen> 6 </since_tizen>
505 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
506 [EditorBrowsable(EditorBrowsableState.Never)]
507 protected override ViewStyle GetViewStyle()
509 return new ProgressStyle();
513 /// Change Image status
515 /// <since_tizen> 6 </since_tizen>
516 /// <param name="statusType">New status type</param>
517 protected void ChangeImageState(ProgressStatusType statusType)
519 if (state == ProgressStatusType.Buffering)
522 progressImage.Hide();
524 else if (state == ProgressStatusType.Determinate)
527 progressImage.Show();
533 progressImage.Hide();
537 private void Initialize()
539 // create necessary components
542 InitializeProgress();
545 private void InitializeTrack()
547 if (null == trackImage)
549 trackImage = new ImageView
551 WidthResizePolicy = ResizePolicyType.FillToParent,
552 HeightResizePolicy = ResizePolicyType.FillToParent,
553 PositionUsesPivotPoint = true,
554 ParentOrigin = NUI.ParentOrigin.TopLeft,
555 PivotPoint = NUI.PivotPoint.TopLeft
558 trackImage.ApplyStyle(Style.Track);
562 private void InitializeProgress()
564 if (null == progressImage)
566 progressImage = new ImageView
568 WidthResizePolicy = ResizePolicyType.FillToParent,
569 HeightResizePolicy = ResizePolicyType.FillToParent,
570 PositionUsesPivotPoint = true,
571 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
572 PivotPoint = Tizen.NUI.PivotPoint.TopLeft
575 progressImage.ApplyStyle(Style.Progress);
579 private void InitializeBuffer()
581 if (null == bufferImage)
583 bufferImage = new ImageView
585 WidthResizePolicy = ResizePolicyType.FillToParent,
586 HeightResizePolicy = ResizePolicyType.FillToParent,
587 PositionUsesPivotPoint = true,
588 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
589 PivotPoint = Tizen.NUI.PivotPoint.TopLeft
592 bufferImage.ApplyStyle(Style.Buffer);