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.loadingStyle.Images = (string[])newValue;
39 instance.imageVisual.URLS = new List<string>((string[])newValue);
42 defaultValueCreator: (bindable) =>
44 var instance = (Loading)bindable;
45 return instance.loadingStyle.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 = (View)bindable;
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.loadingStyle.FrameRate.All = frameRate;
78 instance.imageVisual.FrameDelay = 1000.0f / frameRate;
82 defaultValueCreator: (bindable) =>
84 var instance = (Loading)bindable;
85 return instance.loadingStyle.FrameRate?.All ?? (int)(1000/16.6f);
88 private AnimatedImageVisual imageVisual = null;
89 private LoadingStyle loadingStyle => ViewStyle as LoadingStyle;
94 /// The constructor of Loading.
96 /// <since_tizen> 6 </since_tizen>
97 public Loading() : base()
103 /// Constructor of the Loading class with special style.
105 /// <param name="style">The string to initialize the Loading.</param>
106 /// <since_tizen> 8 </since_tizen>
107 public Loading(string style) : base(style)
113 /// The constructor of the Loading class with specific style.
115 /// <param name="loadingStyle">The style object to initialize the Loading.</param>
116 /// <since_tizen> 8 </since_tizen>
117 public Loading(LoadingStyle loadingStyle) : base(loadingStyle)
123 /// Get style of loading.
124 /// Return a copied Style instance of Loading
127 /// It returns copied Style instance and changing it does not effect to the Loading.
128 /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
130 /// <since_tizen> 8 </since_tizen>
131 public new LoadingStyle Style
135 var result = new LoadingStyle(loadingStyle);
136 result.CopyPropertiesFromView(this);
142 /// Gets or sets loading image resource array.
144 /// <since_tizen> 6 </since_tizen>
145 public string[] ImageArray
149 return (string[])GetValue(ImageArrayProperty);
153 SetValue(ImageArrayProperty, value);
158 /// Gets or sets loading size.
160 /// <since_tizen> 6 </since_tizen>
165 return (Size)GetValue(SizeProperty);
169 SetValue(SizeProperty, value);
174 /// Gets or sets frame rate of loading.
176 /// <since_tizen> 6 </since_tizen>
181 return (int)GetValue(FrameRateProperty);
185 SetValue(FrameRateProperty, value);
190 /// Get Loading style.
192 /// <returns>The default loading style.</returns>
193 /// <since_tizen> 8 </since_tizen>
194 protected override ViewStyle CreateViewStyle()
196 return new LoadingStyle();
202 /// <param name="type">Dispose type.</param>
203 /// <since_tizen> 6 </since_tizen>
204 protected override void Dispose(DisposeTypes type)
211 if (type == DisposeTypes.Explicit)
214 //Release your own managed resources here.
215 //You should release all of your own disposable objects here.
216 RemoveVisual("loadingImageVisual");
219 //You must call base.Dispose(type) just before exit.
223 private void Initialize()
225 imageVisual = new AnimatedImageVisual()
227 URLS = new List<string>(),
230 Position = new Vector2(0, 0),
231 Origin = Visual.AlignType.Center,
232 AnchorPoint = Visual.AlignType.Center
237 this.AddVisual("loadingImageVisual", imageVisual);
240 private void UpdateVisual()
242 if (null != loadingStyle.Images)
244 imageVisual.URLS = new List<string>(loadingStyle.Images);
246 if (null != loadingStyle.FrameRate?.All && 0 != loadingStyle.FrameRate.All.Value)
248 imageVisual.FrameDelay = 1000.0f / (float)loadingStyle.FrameRate.All.Value;
250 if (null != loadingStyle.LoadingSize)
252 this.Size = new Size2D((int)loadingStyle.LoadingSize.Width, (int)loadingStyle.LoadingSize.Height);