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 ImageArrayProperty = BindableProperty.Create(nameof(ImageArray), 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).ViewStyle.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
135 return (string[])GetValue(ImageArrayProperty);
139 SetValue(ImageArrayProperty, value);
144 /// Gets or sets loading size.
146 /// <since_tizen> 6 </since_tizen>
151 return (Size)GetValue(SizeProperty);
155 SetValue(SizeProperty, value);
160 /// Gets or sets frame rate of loading.
162 /// <since_tizen> 6 </since_tizen>
167 return (int)GetValue(FrameRateProperty);
171 SetValue(FrameRateProperty, value);
176 /// Get Loading style.
178 /// <returns>The default loading style.</returns>
179 /// <since_tizen> 8 </since_tizen>
180 protected override ViewStyle CreateViewStyle()
182 return new LoadingStyle();
188 /// <param name="type">Dispose type.</param>
189 /// <since_tizen> 6 </since_tizen>
190 protected override void Dispose(DisposeTypes type)
197 if (type == DisposeTypes.Explicit)
200 //Release your own managed resources here.
201 //You should release all of your own disposable objects here.
202 RemoveVisual("loadingImageVisual");
205 //You must call base.Dispose(type) just before exit.
209 private void Initialize()
211 imageVisual = new AnimatedImageVisual()
213 URLS = new List<string>(),
216 Position = new Vector2(0, 0),
217 Origin = Visual.AlignType.Center,
218 AnchorPoint = Visual.AlignType.Center
223 this.AddVisual("loadingImageVisual", imageVisual);
226 private void UpdateVisual()
228 if (null != Style.Images)
230 imageVisual.URLS = new List<string>(Style.Images);
232 if (null != Style.FrameRate?.All && 0 != Style.FrameRate.All.Value)
234 imageVisual.FrameDelay = 1000.0f / (float)Style.FrameRate.All.Value;
236 if (null != Style.LoadingSize)
238 this.Size = new Size2D((int)Style.LoadingSize.Width, (int)Style.LoadingSize.Height);