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.
17 using Tizen.NUI.BaseComponents;
18 using Tizen.NUI.Binding;
19 using System.ComponentModel;
21 namespace Tizen.NUI.Components
24 /// The Progress class of nui component. It's used to show the ongoing status with a long narrow bar.
26 /// <since_tizen> 6 </since_tizen>
27 public class Progress : Control
29 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public static readonly BindableProperty MaxValueProperty = BindableProperty.Create(nameof(MaxValue), typeof(float), typeof(Progress), default(float), propertyChanged: (bindable, oldValue, newValue) =>
33 var instance = (Progress)bindable;
36 instance.maxValue = (float)newValue;
37 instance.UpdateValue();
40 defaultValueCreator: (bindable) =>
42 var instance = (Progress)bindable;
43 return instance.maxValue;
46 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
47 [EditorBrowsable(EditorBrowsableState.Never)]
48 public static readonly BindableProperty MinValueProperty = BindableProperty.Create(nameof(MinValue), typeof(float), typeof(Progress), default(float), propertyChanged: (bindable, oldValue, newValue) =>
50 var instance = (Progress)bindable;
53 instance.minValue = (float)newValue;
54 instance.UpdateValue();
57 defaultValueCreator: (bindable) =>
59 var instance = (Progress)bindable;
60 return instance.minValue;
63 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 public static readonly BindableProperty CurrentValueProperty = BindableProperty.Create(nameof(CurrentValue), typeof(float), typeof(Progress), default(float), propertyChanged: (bindable, oldValue, newValue) =>
67 var instance = (Progress)bindable;
70 if ((float)newValue > instance.maxValue || (float)newValue < instance.minValue)
74 instance.currentValue = (float)newValue;
75 instance.UpdateValue();
78 defaultValueCreator: (bindable) =>
80 var instance = (Progress)bindable;
81 return instance.currentValue;
84 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
85 [EditorBrowsable(EditorBrowsableState.Never)]
86 public static readonly BindableProperty BufferValueProperty = BindableProperty.Create(nameof(BufferValue), typeof(float), typeof(Progress), default(float), propertyChanged: (bindable, oldValue, newValue) =>
88 var instance = (Progress)bindable;
91 if ((float)newValue > instance.maxValue || (float)newValue < instance.minValue)
95 instance.bufferValue = (float)newValue;
96 instance.UpdateValue();
99 defaultValueCreator: (bindable) =>
101 var instance = (Progress)bindable;
102 return instance.bufferValue;
105 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
106 [EditorBrowsable(EditorBrowsableState.Never)]
107 public static readonly BindableProperty ProgressStateProperty = BindableProperty.Create(nameof(ProgressState), typeof(ProgressStatusType), typeof(Progress), ProgressStatusType.Indeterminate, propertyChanged: (bindable, oldValue, newValue) =>
109 var instance = (Progress)bindable;
110 if (newValue != null)
112 instance.state = (ProgressStatusType)newValue;
113 instance.UpdateStates();
116 defaultValueCreator: (bindable) =>
118 var instance = (Progress)bindable;
119 return instance.state;
122 /// This needs to be considered more if public-open is necessary.
123 private ProgressStatusType state = ProgressStatusType.Determinate;
125 private const float round = 0.5f;
126 private ImageView trackImage = null;
127 private ImageView progressImage = null;
128 private ImageView bufferImage = null;
129 private float maxValue = 100;
130 private float minValue = 0;
131 private float currentValue = 0;
132 private float bufferValue = 0;
133 private ProgressStyle progressStyle => ViewStyle as ProgressStyle;
135 static Progress() { }
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> 8 </since_tizen>
150 public Progress(string style) : base(style)
156 /// The constructor of the Progress class with specific style.
158 /// <param name="progressStyle">The style object to initialize the Progress.</param>
159 /// <since_tizen> 8 </since_tizen>
160 public Progress(ProgressStyle progressStyle) : base(progressStyle)
166 /// The status type of the Progress.
168 /// <since_tizen> 6 </since_tizen>
169 public enum ProgressStatusType
174 /// <since_tizen> 6 </since_tizen>
178 /// Show ProgressImage and BufferImage
180 /// <since_tizen> 6 </since_tizen>
186 /// <since_tizen> 6 </since_tizen>
191 /// Get style of progress.
193 /// <since_tizen> 8 </since_tizen>
194 public new ProgressStyle Style
198 var result = new ProgressStyle(progressStyle);
199 result.CopyPropertiesFromView(this);
200 result.Track.CopyPropertiesFromView(trackImage);
201 result.Progress.CopyPropertiesFromView(progressImage);
202 result.Buffer.CopyPropertiesFromView(bufferImage);
208 /// The property to get/set Track image object URL of the Progress.
210 /// <since_tizen> 6 </since_tizen>
211 public string TrackImageURL
215 return progressStyle?.Track?.ResourceUrl?.All;
219 if (null != progressStyle?.Track)
221 progressStyle.Track.ResourceUrl = value;
227 /// The property to get/set Progress object image URL of the Progress.
229 /// <since_tizen> 6 </since_tizen>
230 public string ProgressImageURL
234 return progressStyle?.Progress?.ResourceUrl?.All;
238 if (null != progressStyle?.Progress)
240 progressStyle.Progress.ResourceUrl = value;
246 /// The property to get/set Buffer object image resource URL of the Progress.
248 /// <since_tizen> 6 </since_tizen>
249 public string BufferImageURL
253 return progressStyle?.Buffer?.ResourceUrl?.All;
257 if (null != progressStyle?.Buffer)
259 progressStyle.Buffer.ResourceUrl = value;
266 /// The property to get/set Track object color of the Progress.
268 /// <since_tizen> 6 </since_tizen>
269 public Color TrackColor
273 return progressStyle?.Track?.BackgroundColor?.All;
277 if (null != progressStyle?.Track)
279 progressStyle.Track.BackgroundColor = value;
285 /// The property to get/set Progress object color of the Progress.
287 /// <since_tizen> 6 </since_tizen>
288 public Color ProgressColor
292 return progressStyle?.Progress?.BackgroundColor?.All;
296 if (null != progressStyle?.Progress)
298 progressStyle.Progress.BackgroundColor = value;
304 /// The property to get/set Buffer object color of the Progress.
306 /// <since_tizen> 6 </since_tizen>
307 public Color BufferColor
311 return progressStyle?.Buffer?.BackgroundColor?.All;
315 if (null != progressStyle?.Buffer)
317 progressStyle.Buffer.BackgroundColor = value;
323 /// The property to get/set the maximum value of the Progress.
325 /// <since_tizen> 6 </since_tizen>
326 public float MaxValue
330 return (float)GetValue(MaxValueProperty);
334 SetValue(MaxValueProperty, value);
339 /// The property to get/set the minim value of the Progress.
341 /// <since_tizen> 6 </since_tizen>
342 public float MinValue
346 return (float)GetValue(MinValueProperty);
350 SetValue(MinValueProperty, value);
355 /// The property to get/set the current value of the Progress.
357 /// <since_tizen> 6 </since_tizen>
358 public float CurrentValue
362 return (float)GetValue(CurrentValueProperty);
366 SetValue(CurrentValueProperty, value);
371 /// The property to get/set the buffer value of the Progress.
373 /// <since_tizen> 6 </since_tizen>
374 public float BufferValue
378 return (float)GetValue(BufferValueProperty);
382 SetValue(BufferValueProperty, value);
387 /// Gets or sets state of progress.
389 /// <since_tizen> 6 </since_tizen>
390 public ProgressStatusType ProgressState
394 return (ProgressStatusType)GetValue(ProgressStateProperty);
398 SetValue(ProgressStateProperty, value);
403 /// Dispose Progress and all children on it.
405 /// <param name="type">Dispose type.</param>
406 /// <since_tizen> 6 </since_tizen>
407 protected override void Dispose(DisposeTypes type)
414 if (type == DisposeTypes.Explicit)
417 //Release your own managed resources here.
418 //You should release all of your own disposable objects here.
419 Utility.Dispose(trackImage);
420 Utility.Dispose(progressImage);
421 Utility.Dispose(bufferImage);
424 //You must call base.Dispose(type) just before exit.
429 /// Theme change callback when theme is changed, this callback will be trigger.
431 /// <param name="sender">The sender</param>
432 /// <param name="e">The event data</param>
433 [EditorBrowsable(EditorBrowsableState.Never)]
434 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
436 ProgressStyle tempStyle = StyleManager.Instance.GetViewStyle(StyleName) as ProgressStyle;
437 if (null != tempStyle)
439 progressStyle.CopyFrom(tempStyle);
445 /// Change Image status. It can be override.
447 /// <since_tizen> 6 </since_tizen>
448 /// This needs to be considered more if public-open is necessary.
449 [EditorBrowsable(EditorBrowsableState.Never)]
450 private void UpdateStates()
452 ChangeImageState(state);
456 /// Update progress value
458 /// <since_tizen> 6 </since_tizen>
459 /// This needs to be considered more if public-open is necessary.
460 [EditorBrowsable(EditorBrowsableState.Never)]
461 private void UpdateValue()
463 if (null == trackImage || null == progressImage)
468 if (minValue >= maxValue || currentValue < minValue || currentValue > maxValue)
473 float width = this.SizeWidth;
474 float height = this.SizeHeight;
475 float progressRatio = (float)(currentValue - minValue) / (float)(maxValue - minValue);
476 float progressWidth = width * progressRatio;
477 progressImage.Size2D = new Size2D((int)(progressWidth + round), (int)height); //Add const round to reach Math.Round function.
478 if (null != bufferImage)
480 if (bufferValue < minValue || bufferValue > maxValue)
485 float bufferRatio = (float)(bufferValue - minValue) / (float)(maxValue - minValue);
486 float bufferWidth = width * bufferRatio;
487 bufferImage.Size2D = new Size2D((int)(bufferWidth + round), (int)height); //Add const round to reach Math.Round function.
492 /// Get Progress style.
494 /// <returns>The default progress style.</returns>
495 /// <since_tizen> 8 </since_tizen>
496 protected override ViewStyle CreateViewStyle()
498 return new ProgressStyle();
502 /// Change Image status
504 /// <since_tizen> 6 </since_tizen>
505 /// <param name="statusType">New status type</param>
506 protected void ChangeImageState(ProgressStatusType statusType)
508 if (state == ProgressStatusType.Buffering)
511 progressImage.Hide();
513 else if (state == ProgressStatusType.Determinate)
516 progressImage.Show();
522 progressImage.Hide();
526 private void Initialize()
528 // create necessary components
531 InitializeProgress();
534 private void InitializeTrack()
536 if (null == trackImage)
538 trackImage = new ImageView
540 WidthResizePolicy = ResizePolicyType.FillToParent,
541 HeightResizePolicy = ResizePolicyType.FillToParent,
542 PositionUsesPivotPoint = true,
543 ParentOrigin = NUI.ParentOrigin.TopLeft,
544 PivotPoint = NUI.PivotPoint.TopLeft
547 trackImage.ApplyStyle(progressStyle.Track);
551 private void InitializeProgress()
553 if (null == progressImage)
555 progressImage = new ImageView
557 WidthResizePolicy = ResizePolicyType.FillToParent,
558 HeightResizePolicy = ResizePolicyType.FillToParent,
559 PositionUsesPivotPoint = true,
560 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
561 PivotPoint = Tizen.NUI.PivotPoint.TopLeft
564 progressImage.ApplyStyle(progressStyle.Progress);
568 private void InitializeBuffer()
570 if (null == bufferImage)
572 bufferImage = new ImageView
574 WidthResizePolicy = ResizePolicyType.FillToParent,
575 HeightResizePolicy = ResizePolicyType.FillToParent,
576 PositionUsesPivotPoint = true,
577 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
578 PivotPoint = Tizen.NUI.PivotPoint.TopLeft
581 bufferImage.ApplyStyle(progressStyle.Buffer);