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 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 /// 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 Progress : Control
31 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
32 [EditorBrowsable(EditorBrowsableState.Never)]
33 protected ProgressAttributes progressAttrs = null;
34 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 protected ProgressStatusType state = ProgressStatusType.Indeterminate;
38 private const float round = 0.5f;
39 private ImageView trackObj = null;
40 private ImageView progressObj = null;
41 private ImageView bufferObj = null;
42 private ImageView loadingObj = null;
43 private float maxValue = 100;
44 private float minValue = 0;
45 private float currentValue = 0;
46 private float bufferValue = 0;
49 /// The constructor of Progress
51 /// <since_tizen> 6 </since_tizen>
52 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
53 [EditorBrowsable(EditorBrowsableState.Never)]
54 public Progress() : base()
60 /// The constructor of the Progress class with specific style.
62 /// <param name="style">style name</param>
63 /// <since_tizen> 6 </since_tizen>
64 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
65 [EditorBrowsable(EditorBrowsableState.Never)]
66 public Progress(string style) : base(style)
72 /// The constructor of the Progress class with specific Attributes.
74 /// <param name="attributes">The Attributes object to initialize the Progress.</param>
75 /// <since_tizen> 6 </since_tizen>
76 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
77 [EditorBrowsable(EditorBrowsableState.Never)]
78 public Progress(ProgressAttributes attributes) : base(attributes)
84 /// The status type of the Progress.
86 /// <since_tizen> 6 </since_tizen>
87 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
88 [EditorBrowsable(EditorBrowsableState.Never)]
89 public enum ProgressStatusType
94 /// <since_tizen> 6 </since_tizen>
95 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
96 [EditorBrowsable(EditorBrowsableState.Never)]
100 /// Show ProgressImage
102 /// <since_tizen> 6 </since_tizen>
103 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
104 [EditorBrowsable(EditorBrowsableState.Never)]
108 /// Show LoadingImage
110 /// <since_tizen> 6 </since_tizen>
111 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
112 [EditorBrowsable(EditorBrowsableState.Never)]
117 /// The property to get/set Track image object URL of the Progress.
119 /// <since_tizen> 6 </since_tizen>
120 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
121 [EditorBrowsable(EditorBrowsableState.Never)]
122 public string TrackImageURL
126 return progressAttrs.TrackImageAttributes?.ResourceURL?.All;
130 CreateTrackImageAttributes();
131 if (progressAttrs.TrackImageAttributes.ResourceURL == null)
133 progressAttrs.TrackImageAttributes.ResourceURL = new StringSelector();
135 progressAttrs.TrackImageAttributes.ResourceURL.All = value;
141 /// The property to get/set Progress object image URL of the Progress.
143 /// <since_tizen> 6 </since_tizen>
144 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
145 [EditorBrowsable(EditorBrowsableState.Never)]
146 public string ProgressImageURL
150 return progressAttrs.ProgressImageAttributes?.ResourceURL?.All;
154 CreateProgressImageAttributes();
155 if (progressAttrs.ProgressImageAttributes.ResourceURL == null)
157 progressAttrs.ProgressImageAttributes.ResourceURL = new StringSelector();
159 progressAttrs.ProgressImageAttributes.ResourceURL.All = value;
165 /// The property to get/set Buffer object image resource URL of the Progress.
167 /// <since_tizen> 6 </since_tizen>
168 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
169 [EditorBrowsable(EditorBrowsableState.Never)]
170 public string BufferImageURL
174 return progressAttrs.BufferImageAttributes?.ResourceURL?.All;
178 CreateBufferImageAttributes();
179 if (progressAttrs.BufferImageAttributes.ResourceURL == null)
181 progressAttrs.BufferImageAttributes.ResourceURL = new StringSelector();
183 progressAttrs.BufferImageAttributes.ResourceURL.All = value;
189 /// The property to get/set Track object color of the Progress.
191 /// <since_tizen> 6 </since_tizen>
192 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
193 [EditorBrowsable(EditorBrowsableState.Never)]
194 public Color TrackColor
198 return progressAttrs.TrackImageAttributes?.BackgroundColor?.All;
202 CreateTrackImageAttributes();
203 if (progressAttrs.TrackImageAttributes.BackgroundColor == null)
205 progressAttrs.TrackImageAttributes.BackgroundColor = new ColorSelector();
207 progressAttrs.TrackImageAttributes.BackgroundColor.All = value;
213 /// The property to get/set Progress object color of the Progress.
215 /// <since_tizen> 6 </since_tizen>
216 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
217 [EditorBrowsable(EditorBrowsableState.Never)]
218 public Color ProgressColor
222 return progressAttrs.ProgressImageAttributes?.BackgroundColor?.All;
226 CreateProgressImageAttributes();
227 if (null == progressAttrs.ProgressImageAttributes.BackgroundColor)
229 progressAttrs.ProgressImageAttributes.BackgroundColor = new ColorSelector();
231 progressAttrs.ProgressImageAttributes.BackgroundColor.All = value;
237 /// The property to get/set Buffer object color of the Progress.
239 /// <since_tizen> 6 </since_tizen>
240 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
241 [EditorBrowsable(EditorBrowsableState.Never)]
242 public Color BufferColor
246 return progressAttrs.BufferImageAttributes?.BackgroundColor?.All;
250 CreateBufferImageAttributes();
251 if (null == progressAttrs.BufferImageAttributes.BackgroundColor)
253 progressAttrs.BufferImageAttributes.BackgroundColor = new ColorSelector();
255 progressAttrs.BufferImageAttributes.BackgroundColor.All = value;
261 /// The property to get/set the maximum value of the Progress.
263 /// <since_tizen> 6 </since_tizen>
264 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
265 [EditorBrowsable(EditorBrowsableState.Never)]
266 public float MaxValue
280 /// The property to get/set the minim value of the Progress.
282 /// <since_tizen> 6 </since_tizen>
283 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
284 [EditorBrowsable(EditorBrowsableState.Never)]
285 public float MinValue
299 /// The property to get/set the current value of the Progress.
301 /// <since_tizen> 6 </since_tizen>
302 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
303 [EditorBrowsable(EditorBrowsableState.Never)]
304 public float CurrentValue
312 if (value > maxValue || value < minValue)
316 currentValue = value;
322 /// The property to get/set the buffer value of the Progress.
324 /// <since_tizen> 6 </since_tizen>
325 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
326 [EditorBrowsable(EditorBrowsableState.Never)]
327 public float BufferValue
335 if (value > maxValue || value < minValue)
345 /// Gets or sets state of progress.
347 /// <since_tizen> 6 </since_tizen>
348 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
349 [EditorBrowsable(EditorBrowsableState.Never)]
350 public ProgressStatusType ProgressState
364 /// Dispose Progress and all children on it.
366 /// <param name="type">Dispose type.</param>
367 /// <since_tizen> 6 </since_tizen>
368 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
369 [EditorBrowsable(EditorBrowsableState.Never)]
370 protected override void Dispose(DisposeTypes type)
377 if (type == DisposeTypes.Explicit)
380 //Release your own managed resources here.
381 //You should release all of your own disposable objects here.
382 Utility.Dispose(trackObj);
383 Utility.Dispose(progressObj);
384 Utility.Dispose(bufferObj);
385 Utility.Dispose(loadingObj);
388 //Release your own unmanaged resources here.
389 //You should not access any managed member here except static instance.
390 //because the execution order of Finalizes is non-deterministic.
391 //Unreference this from if a static instance refer to this.
393 //You must call base.Dispose(type) just before exit.
398 /// The method to update Attributes.
400 /// <since_tizen> 6 </since_tizen>
401 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
402 [EditorBrowsable(EditorBrowsableState.Never)]
403 protected override void OnUpdate()
405 ApplyAttributes(this, progressAttrs);
406 ApplyAttributes(trackObj, progressAttrs.TrackImageAttributes);
407 ApplyAttributes(progressObj, progressAttrs.ProgressImageAttributes);
408 ApplyAttributes(loadingObj, progressAttrs.LoadingImageAttributes);
409 ApplyAttributes(bufferObj, progressAttrs.BufferImageAttributes);
413 /// Theme change callback when theme is changed, this callback will be trigger.
415 /// <param name="sender">serder object</param>
416 /// <param name="e">ThemeChangeEventArgs</param>
417 /// <since_tizen> 6 </since_tizen>
418 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
419 [EditorBrowsable(EditorBrowsableState.Never)]
420 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
422 ProgressAttributes tempAttributes = StyleManager.Instance.GetAttributes(style) as ProgressAttributes;
423 if (null != tempAttributes)
425 attributes = progressAttrs = tempAttributes;
431 /// Change Image status. It can be override.
433 /// <since_tizen> 6 </since_tizen>
434 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
435 [EditorBrowsable(EditorBrowsableState.Never)]
436 protected virtual void UpdateStates()
438 ChangeImageState(state);
442 /// Update progress value
444 /// <since_tizen> 6 </since_tizen>
445 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
446 [EditorBrowsable(EditorBrowsableState.Never)]
447 protected virtual void UpdateValue()
449 if (null == trackObj || null == progressObj)
454 if (minValue >= maxValue || currentValue < minValue || currentValue > maxValue)
459 float width = this.SizeWidth;
460 float height = this.SizeHeight;
461 float progressRatio = (float)(currentValue - minValue) / (float)(maxValue - minValue);
462 float progressWidth = width * progressRatio;
463 progressObj.Size2D = new Size2D((int)(progressWidth + round), (int)height); //Add const round to reach Math.Round function.
464 if (null != bufferObj)
466 if (bufferValue < minValue || bufferValue > maxValue)
471 float bufferRatio = (float)(bufferValue - minValue) / (float)(maxValue - minValue);
472 float bufferWidth = width * bufferRatio;
473 bufferObj.Size2D = new Size2D((int)(bufferWidth + round), (int)height); //Add const round to reach Math.Round function.
478 /// Get Progress attribues.
480 /// <since_tizen> 6 </since_tizen>
481 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
482 [EditorBrowsable(EditorBrowsableState.Never)]
483 protected override Attributes GetAttributes()
485 return new ProgressAttributes();
489 /// Change Image status
491 /// <since_tizen> 6 </since_tizen>
492 /// <param name="statusType">New status type</param>
493 protected void ChangeImageState(ProgressStatusType statusType)
495 if (state == ProgressStatusType.Buffering)
501 else if (state == ProgressStatusType.Determinate)
516 private void Initialize()
518 progressAttrs = attributes as ProgressAttributes;
519 if (null == progressAttrs)
521 throw new Exception("Progress attribute parse error.");
524 // create necessary components
527 InitializeProgress();
531 private void InitializeTrack()
533 if (null == trackObj)
535 trackObj = new ImageView
537 WidthResizePolicy = ResizePolicyType.FillToParent,
538 HeightResizePolicy = ResizePolicyType.FillToParent,
539 PositionUsesPivotPoint = true,
540 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
541 PivotPoint = Tizen.NUI.PivotPoint.TopLeft
547 private void InitializeProgress()
549 if (null == progressObj)
551 progressObj = new ImageView
553 WidthResizePolicy = ResizePolicyType.FillToParent,
554 HeightResizePolicy = ResizePolicyType.FillToParent,
555 PositionUsesPivotPoint = true,
556 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
557 PivotPoint = Tizen.NUI.PivotPoint.TopLeft
563 private void InitializeBuffer()
565 if (null == bufferObj)
567 bufferObj = new ImageView
569 WidthResizePolicy = ResizePolicyType.FillToParent,
570 HeightResizePolicy = ResizePolicyType.FillToParent,
571 PositionUsesPivotPoint = true,
572 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
573 PivotPoint = Tizen.NUI.PivotPoint.TopLeft
579 private void InitializeLoading()
581 if (null == loadingObj)
583 loadingObj = 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
595 private void CreateTrackImageAttributes()
597 if (null == progressAttrs.TrackImageAttributes)
599 progressAttrs.TrackImageAttributes = new ImageAttributes();
603 private void CreateProgressImageAttributes()
605 if (null == progressAttrs.ProgressImageAttributes)
607 progressAttrs.ProgressImageAttributes = new ImageAttributes();
611 private void CreateBufferImageAttributes()
613 if (null == progressAttrs.BufferImageAttributes)
615 progressAttrs.BufferImageAttributes = new ImageAttributes();