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 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
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 = new List<string>((string[])newValue);
43 defaultValueCreator: (bindable) =>
45 var instance = (Loading)bindable;
46 return instance.loadingStyle.Images;
48 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
49 [EditorBrowsable(EditorBrowsableState.Never)]
50 public new static readonly BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(Size), typeof(Loading), new Size(0, 0), propertyChanged: (bindable, oldValue, newValue) =>
52 var instance = (Loading)bindable;
55 Size size = (Size)newValue;
56 ((View)bindable).Size = size;
57 instance.loadingStyle.LoadingSize = size;
60 defaultValueCreator: (bindable) =>
62 var instance = (View)bindable;
65 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
66 [EditorBrowsable(EditorBrowsableState.Never)]
67 public static readonly BindableProperty FrameRateProperty = BindableProperty.Create(nameof(FrameRate), typeof(int), typeof(Loading), (int)(1000 / 16.6f), propertyChanged: (bindable, oldValue, newValue) =>
69 var instance = (Loading)bindable;
72 int frameRate = (int)newValue;
73 if (0 != frameRate) //It will crash if 0
75 instance.loadingStyle.FrameRate = frameRate;
76 instance.imageVisual.FrameDelay = 1000.0f / frameRate;
80 defaultValueCreator: (bindable) =>
82 var instance = (Loading)bindable;
83 return instance.loadingStyle.FrameRate?.All ?? (int)(1000 / 16.6f);
86 private AnimatedImageVisual imageVisual = null;
87 private LoadingStyle loadingStyle => ViewStyle as LoadingStyle;
89 internal new class Property
91 internal static readonly int ActionPlay = Interop.ImageView.ImageVisualActionPlayGet();
92 internal static readonly int ActionPause = Interop.ImageView.ImageVisualActionPauseGet();
93 internal static readonly int ActionStop = Interop.ImageView.ImageVisualActionStopGet();
99 /// The constructor of Loading.
101 /// <since_tizen> 6 </since_tizen>
102 public Loading() : base()
108 /// Constructor of the Loading class with special style.
110 /// <param name="style">The string to initialize the Loading.</param>
111 /// <since_tizen> 8 </since_tizen>
112 public Loading(string style) : base(style)
118 /// The constructor of the Loading class with specific style.
120 /// <param name="loadingStyle">The style object to initialize the Loading.</param>
121 /// <since_tizen> 8 </since_tizen>
122 public Loading(LoadingStyle loadingStyle) : base(loadingStyle)
128 /// Get style of loading.
129 /// Return a copied Style instance of Loading
132 /// It returns copied Style instance and changing it does not effect to the Loading.
133 /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
135 /// <since_tizen> 8 </since_tizen>
136 public new LoadingStyle Style
140 var result = new LoadingStyle(loadingStyle);
141 result.CopyPropertiesFromView(this);
147 /// Gets or sets loading image resource array.
149 /// <since_tizen> 6 </since_tizen>
150 public string[] ImageArray
154 return (string[])GetValue(ImageArrayProperty);
158 SetValue(ImageArrayProperty, value);
163 /// Gets or sets loading size.
165 /// <since_tizen> 6 </since_tizen>
170 return (Size)GetValue(SizeProperty);
174 SetValue(SizeProperty, value);
179 /// Gets or sets frame rate of loading.
181 /// <since_tizen> 6 </since_tizen>
186 return (int)GetValue(FrameRateProperty);
190 SetValue(FrameRateProperty, value);
195 /// Get Loading style.
197 /// <returns>The default loading style.</returns>
198 /// <since_tizen> 8 </since_tizen>
199 protected override ViewStyle CreateViewStyle()
201 return new LoadingStyle();
207 /// <param name="type">Dispose type.</param>
208 /// <since_tizen> 6 </since_tizen>
209 protected override void Dispose(DisposeTypes type)
216 if (type == DisposeTypes.Explicit)
219 //Release your own managed resources here.
220 //You should release all of your own disposable objects here.
221 RemoveVisual("loadingImageVisual");
224 //You must call base.Dispose(type) just before exit.
228 private void Initialize()
230 imageVisual = new AnimatedImageVisual()
232 URLS = new List<string>(),
235 Position = new Vector2(0, 0),
236 Origin = Visual.AlignType.Center,
237 AnchorPoint = Visual.AlignType.Center,
238 SizePolicy = VisualTransformPolicyType.Relative,
239 Size = new Size2D(1, 1)
244 this.AddVisual("loadingImageVisual", imageVisual);
246 AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "Loading");
249 private void UpdateVisual()
251 if (null != loadingStyle.Images)
253 imageVisual.URLS = new List<string>(loadingStyle.Images);
255 if (null != loadingStyle.FrameRate?.All && 0 != loadingStyle.FrameRate.All.Value)
257 imageVisual.FrameDelay = 1000.0f / (float)loadingStyle.FrameRate.All.Value;
262 /// Play Loading Animation.
264 /// This may be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
265 [EditorBrowsable(EditorBrowsableState.Never)]
268 PropertyValue attributes = new PropertyValue(0);
269 this.DoAction(imageVisual.VisualIndex, Property.ActionPlay, attributes);
270 attributes.Dispose();
274 /// Pause Loading Animation.
276 /// This may be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
277 [EditorBrowsable(EditorBrowsableState.Never)]
280 PropertyValue attributes = new PropertyValue(0);
281 this.DoAction(imageVisual.VisualIndex, Property.ActionPause, attributes);
282 attributes.Dispose();
286 /// Stop Loading Animation.
288 /// This may be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
289 [EditorBrowsable(EditorBrowsableState.Never)]
292 PropertyValue attributes = new PropertyValue(0);
293 this.DoAction(imageVisual.VisualIndex, Property.ActionStop, attributes);
294 attributes.Dispose();