2 * Copyright(c) 2020 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 System.Collections.Generic;
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Binding;
22 using Tizen.NUI.Accessibility;
24 namespace Tizen.NUI.Components
27 /// The Loading class of nui component. It's used to indicate informs users of the ongoing operation.
29 /// <since_tizen> 6 </since_tizen>
30 public class Loading : Control
32 /// <summary>The ImageArray bindable property.</summary>
33 [EditorBrowsable(EditorBrowsableState.Never)]
34 public static readonly BindableProperty ImageArrayProperty = BindableProperty.Create(nameof(ImageArray), typeof(string[]), typeof(Loading), null, propertyChanged: (bindable, oldValue, newValue) =>
36 var instance = (Loading)bindable;
39 instance.loadingStyle.Images = (string[])newValue;
40 instance.imageVisual.URLS = instance.loadingStyle.ImageList as List<string>;
43 defaultValueCreator: (bindable) =>
45 var instance = (Loading)bindable;
46 return instance.loadingStyle.Images;
48 /// <summary>The ImageList bindable property.</summary>
49 [EditorBrowsable(EditorBrowsableState.Never)]
50 public static readonly BindableProperty ImageListProperty = BindableProperty.Create(nameof(ImageList), typeof(IList<string>), typeof(Loading), null, propertyChanged: (bindable, oldValue, newValue) =>
52 var instance = (Loading)bindable;
55 var newValueList = newValue as List<string>;
56 instance.loadingStyle.ImageList = newValueList;
57 if (instance.imageVisual != null) instance.imageVisual.URLS = newValueList;
60 defaultValueCreator: (bindable) =>
62 return ((Loading)bindable).loadingStyle.ImageList;
64 /// <summary>The Size bindable property.</summary>
65 [EditorBrowsable(EditorBrowsableState.Never)]
66 public new static readonly BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(Size), typeof(Loading), new Size(0, 0), propertyChanged: (bindable, oldValue, newValue) =>
68 var instance = (Loading)bindable;
71 Size size = (Size)newValue;
72 ((View)bindable).Size = size;
73 instance.loadingStyle.LoadingSize = size;
76 defaultValueCreator: (bindable) =>
78 var instance = (View)bindable;
81 /// <summary>The FrameRate bindable property.</summary>
82 [EditorBrowsable(EditorBrowsableState.Never)]
83 public static readonly BindableProperty FrameRateProperty = BindableProperty.Create(nameof(FrameRate), typeof(int), typeof(Loading), (int)(1000 / 16.6f), propertyChanged: (bindable, oldValue, newValue) =>
85 var instance = (Loading)bindable;
88 int frameRate = (int)newValue;
89 if (0 != frameRate) //It will crash if 0
91 instance.loadingStyle.FrameRate = frameRate;
92 instance.imageVisual.FrameDelay = 1000.0f / frameRate;
96 defaultValueCreator: (bindable) =>
98 var instance = (Loading)bindable;
99 return instance.loadingStyle.FrameRate?.All ?? (int)(1000 / 16.6f);
102 private AnimatedImageVisual imageVisual = null;
103 private LoadingStyle loadingStyle => ViewStyle as LoadingStyle;
105 internal new class Property
107 internal static readonly int ActionPlay = Interop.ImageView.ImageVisualActionPlayGet();
108 internal static readonly int ActionPause = Interop.ImageView.ImageVisualActionPauseGet();
109 internal static readonly int ActionStop = Interop.ImageView.ImageVisualActionStopGet();
115 /// The constructor of Loading.
117 /// <since_tizen> 6 </since_tizen>
118 public Loading() : base()
124 /// Constructor of the Loading class with special style.
126 /// <param name="style">The string to initialize the Loading.</param>
127 /// <since_tizen> 8 </since_tizen>
128 public Loading(string style) : base(style)
134 /// The constructor of the Loading class with specific style.
136 /// <param name="loadingStyle">The style object to initialize the Loading.</param>
137 /// <since_tizen> 8 </since_tizen>
138 public Loading(LoadingStyle loadingStyle) : base(loadingStyle)
144 /// Get style of loading.
145 /// Return a copied Style instance of Loading
148 /// It returns copied Style instance and changing it does not effect to the Loading.
149 /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
151 /// <since_tizen> 8 </since_tizen>
152 public new LoadingStyle Style
156 var result = new LoadingStyle(loadingStyle);
157 result.CopyPropertiesFromView(this);
163 /// Gets or sets loading image resource array.
165 /// <since_tizen> 6 </since_tizen>
166 public string[] ImageArray
170 return (string[])GetValue(ImageArrayProperty);
174 SetValue(ImageArrayProperty, value);
179 /// Gets loading image resource array.
181 [EditorBrowsable(EditorBrowsableState.Never)]
182 public IList<string> ImageList
186 return GetValue(ImageListProperty) as List<string>;
191 /// Gets or sets loading size.
193 /// <since_tizen> 6 </since_tizen>
198 return (Size)GetValue(SizeProperty);
202 SetValue(SizeProperty, value);
207 /// Gets or sets frame rate of loading.
209 /// <since_tizen> 6 </since_tizen>
214 return (int)GetValue(FrameRateProperty);
218 SetValue(FrameRateProperty, value);
223 /// Get Loading style.
225 /// <returns>The default loading style.</returns>
226 /// <since_tizen> 8 </since_tizen>
227 protected override ViewStyle CreateViewStyle()
229 return new LoadingStyle();
235 /// <param name="type">Dispose type.</param>
236 /// <since_tizen> 6 </since_tizen>
237 protected override void Dispose(DisposeTypes type)
244 if (type == DisposeTypes.Explicit)
247 //Release your own managed resources here.
248 //You should release all of your own disposable objects here.
249 RemoveVisual("loadingImageVisual");
252 //You must call base.Dispose(type) just before exit.
256 private void Initialize()
258 imageVisual = new AnimatedImageVisual()
260 URLS = new List<string>(),
263 Position = new Vector2(0, 0),
264 Origin = Visual.AlignType.Center,
265 AnchorPoint = Visual.AlignType.Center,
266 SizePolicy = VisualTransformPolicyType.Relative,
267 Size = new Size2D(1, 1)
272 this.AddVisual("loadingImageVisual", imageVisual);
274 AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "Loading");
277 private void UpdateVisual()
279 if (null != loadingStyle.Images)
281 loadingStyle.ImageList = new List<string>(loadingStyle.Images);
282 imageVisual.URLS = loadingStyle.ImageList as List<string>;
284 if (null != loadingStyle.FrameRate?.All && 0 != loadingStyle.FrameRate.All.Value)
286 imageVisual.FrameDelay = 1000.0f / (float)loadingStyle.FrameRate.All.Value;
291 /// Play Loading Animation.
293 /// This may be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
294 [EditorBrowsable(EditorBrowsableState.Never)]
297 PropertyValue attributes = new PropertyValue(0);
298 this.DoAction(imageVisual.VisualIndex, Property.ActionPlay, attributes);
299 attributes.Dispose();
303 /// Pause Loading Animation.
305 /// This may be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
306 [EditorBrowsable(EditorBrowsableState.Never)]
309 PropertyValue attributes = new PropertyValue(0);
310 this.DoAction(imageVisual.VisualIndex, Property.ActionPause, attributes);
311 attributes.Dispose();
315 /// Stop Loading Animation.
317 /// This may be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
318 [EditorBrowsable(EditorBrowsableState.Never)]
321 PropertyValue attributes = new PropertyValue(0);
322 this.DoAction(imageVisual.VisualIndex, Property.ActionStop, attributes);
323 attributes.Dispose();