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 System.Collections.Generic;
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Binding;
23 namespace Tizen.NUI.Components
26 /// The Loading class of nui component. It's used to indicate informs users of the ongoing operation.
28 /// <since_tizen> 6 </since_tizen>
29 public class Loading : Control
31 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
32 [EditorBrowsable(EditorBrowsableState.Never)]
33 public static readonly BindableProperty ImagesProperty = BindableProperty.Create(nameof(Images), typeof(string[]), typeof(Loading), null, propertyChanged: (bindable, oldValue, newValue) =>
35 var instance = (Loading)bindable;
38 instance.Style.Images = (string[])newValue;
39 instance.imageVisual.URLS = new List<string>((string[])newValue);
42 defaultValueCreator: (bindable) =>
44 var instance = (Loading)bindable;
45 return instance.Style.Images;
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 new static readonly BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(Size), typeof(Loading), new Size(0,0), propertyChanged: (bindable, oldValue, newValue) =>
51 var instance = (Loading)bindable;
54 Size size = (Size)newValue;
55 ((View)bindable).Size = size;
56 if (null != instance.imageVisual)
58 instance.imageVisual.Size = new Size2D((int)size.Width, (int)size.Height);
62 defaultValueCreator: (bindable) =>
64 var instance = (Loading)bindable;
65 return instance.Style.Size;
67 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
68 [EditorBrowsable(EditorBrowsableState.Never)]
69 public static readonly BindableProperty FrameRateProperty = BindableProperty.Create(nameof(FrameRate), typeof(int), typeof(Loading), (int)(1000/16.6f), propertyChanged: (bindable, oldValue, newValue) =>
71 var instance = (Loading)bindable;
74 int frameRate = (int)newValue;
75 if (0 != frameRate) //It will crash if 0
77 instance.Style.FrameRate.All = frameRate;
78 instance.imageVisual.FrameDelay = 1000.0f / frameRate;
82 defaultValueCreator: (bindable) =>
84 var instance = (Loading)bindable;
85 return instance.Style.FrameRate?.All ?? (int)(1000/16.6f);
88 private AnimatedImageVisual imageVisual = null;
93 /// The constructor of Loading.
95 /// <since_tizen> 6 </since_tizen>
96 public Loading() : base()
102 /// Constructor of the Loading class with special style.
104 /// <param name="style">The string to initialize the Loading.</param>
105 /// <since_tizen> 8 </since_tizen>
106 public Loading(string style) : base(style)
112 /// The constructor of the Loading class with specific style.
114 /// <param name="loadingStyle">The style object to initialize the Loading.</param>
115 /// <since_tizen> 8 </since_tizen>
116 public Loading(LoadingStyle loadingStyle) : base(loadingStyle)
122 /// Get style of loading.
124 /// <since_tizen> 8 </since_tizen>
125 public new LoadingStyle Style => ViewStyle as LoadingStyle;
128 /// Gets or sets loading image resource array.
130 /// <since_tizen> 6 </since_tizen>
131 public string[] ImageArray
144 /// Gets or sets loading image resources.
146 /// <since_tizen> 6 </since_tizen>
147 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
148 [EditorBrowsable(EditorBrowsableState.Never)]
149 public string[] Images
153 return (string[])GetValue(ImagesProperty);
157 SetValue(ImagesProperty, value);
162 /// Gets or sets loading size.
164 /// <since_tizen> 6 </since_tizen>
169 return (Size)GetValue(SizeProperty);
173 SetValue(SizeProperty, value);
178 /// Gets or sets frame rate of loading.
180 /// <since_tizen> 6 </since_tizen>
185 return (int)GetValue(FrameRateProperty);
189 SetValue(FrameRateProperty, value);
194 /// Get Loading style.
196 /// <returns>The default loading style.</returns>
197 /// <since_tizen> 8 </since_tizen>
198 protected override ViewStyle CreateViewStyle()
200 return new LoadingStyle();
206 /// <param name="type">Dispose type.</param>
207 /// <since_tizen> 6 </since_tizen>
208 protected override void Dispose(DisposeTypes type)
215 if (type == DisposeTypes.Explicit)
218 //Release your own managed resources here.
219 //You should release all of your own disposable objects here.
220 RemoveVisual("loadingImageVisual");
223 //You must call base.Dispose(type) just before exit.
227 private void Initialize()
229 imageVisual = new AnimatedImageVisual()
231 URLS = new List<string>(),
234 Position = new Vector2(0, 0),
235 Origin = Visual.AlignType.Center,
236 AnchorPoint = Visual.AlignType.Center
241 this.AddVisual("loadingImageVisual", imageVisual);
244 private void UpdateVisual()
246 if (null != Style.Images)
248 imageVisual.URLS = new List<string>(Style.Images);
250 if (null != Style.FrameRate?.All && 0 != Style.FrameRate.All.Value)
252 imageVisual.FrameDelay = 1000.0f / (float)Style.FrameRate.All.Value;
254 if (null != Style.LoadingSize)
256 this.Size = new Size2D((int)Style.LoadingSize.Width, (int)Style.LoadingSize.Height);