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;
22 using tlog = Tizen.Log;
25 namespace Tizen.NUI.BaseComponents
28 /// AnimatedImageView is a class for displaying Animated-GIF and Image-Array
30 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
31 [EditorBrowsable(EditorBrowsableState.Never)]
32 public class AnimatedImageView : ImageView
34 #region Constructor, Destructor, Dispose
36 /// Construct AnimatedImageView
38 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
39 [EditorBrowsable(EditorBrowsableState.Never)]
40 public AnimatedImageView() : base()
46 /// You can override it to clean-up your own resources
48 /// <param name="type">DisposeTypes</param>
49 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
50 [EditorBrowsable(EditorBrowsableState.Never)]
51 protected override void Dispose(DisposeTypes type)
58 //Release your own unmanaged resources here.
59 //You should not access any managed member here except static instance.
60 //because the execution order of Finalizes is non-deterministic.
63 #endregion Constructor, Destructor, Dispose
67 /// Image URL for Animated-GIF
69 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public new string ResourceUrl
85 /// Image URL list for Image-Array
87 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
88 [EditorBrowsable(EditorBrowsableState.Never)]
89 public List<string> URLs
98 /// Defines the batch size for pre-loading images in the Image-Array animation.
99 /// number of images to pre-load before starting to play. Default value: 1.
101 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
102 [EditorBrowsable(EditorBrowsableState.Never)]
117 /// Defines the cache size for loading images in the Image-Array animation.
118 /// number of images to keep cached ahead during playback. Default value: 1.
121 /// cacheSize should be >= batchSize. If it isn't, then the cache will automatically be changed to batchSize.
122 /// because of the defaults, it is expected that the application developer tune the batch and cache sizes to their particular use case.
124 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
125 [EditorBrowsable(EditorBrowsableState.Never)]
140 /// The number of milliseconds between each frame in the Image-Array animation.
141 /// The number of milliseconds between each frame.
144 /// This is only used when URLs(multiple string) are provided.
146 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
147 [EditorBrowsable(EditorBrowsableState.Never)]
148 public int FrameDelay
162 /// The number of looping.
164 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
165 [EditorBrowsable(EditorBrowsableState.Never)]
180 /// Sets or gets the stop behavior.
182 [EditorBrowsable(EditorBrowsableState.Never)]
183 public StopBehaviorType StopBehavior
187 stopBehavior = (StopBehaviorType)value;
197 /// Get the number of total frames
199 [EditorBrowsable(EditorBrowsableState.Never)]
200 public int TotalFrame
205 PropertyMap map = Image;
208 PropertyValue val = map.Find(ImageVisualProperty.TotalFrameNumber);
211 if (val.Get(out ret))
222 /// Set or get the current frame. When setting a specific frame, it is displayed as a still image.
225 /// Gets the value set by a user. If the setting value is out-ranged, it is reset as a minimum frame or a maximum frame.
227 [EditorBrowsable(EditorBrowsableState.Never)]
228 public int CurrentFrame
232 DoAction(ImageView.Property.IMAGE, (int)ActionType.jumpTo, new PropertyValue(value));
237 PropertyMap map = Image;
240 PropertyValue val = map.Find(ImageVisualProperty.CurrentFrameNumber);
243 if (val.Get(out ret))
256 /// To make the properies be set. This should be called after the properties are set.
258 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
259 [EditorBrowsable(EditorBrowsableState.Never)]
260 public void SetValues()
262 if (dirtyFlag == false)
268 PropertyMap tMap = new PropertyMap();
269 PropertyValue animatiedImage = new PropertyValue((int)Visual.Type.AnimatedImage);
270 tMap.Insert(Visual.Property.Type, animatiedImage);
271 if (resourceURLs?.Count != 0)
273 PropertyArray indexPropertyArray = new PropertyArray();
274 PropertyArray returnedArr = new PropertyArray();
275 PropertyValue index = new PropertyValue();
276 foreach (var iter in resourceURLs)
278 index = new PropertyValue(iter);
279 returnedArr = indexPropertyArray.Add(index);
282 returnedArr.Dispose();
283 PropertyValue arrayProperty = new PropertyValue(indexPropertyArray);
284 tMap.Insert(ImageVisualProperty.URL, arrayProperty);
285 PropertyValue frameDelayProperty = new PropertyValue(frameDelay);
286 tMap.Insert(ImageVisualProperty.FrameDelay, frameDelayProperty);
288 arrayProperty.Dispose();
289 indexPropertyArray.Dispose();
290 frameDelayProperty.Dispose();
294 PropertyValue urlProperty = new PropertyValue(url);
295 tMap.Insert(ImageVisualProperty.URL, urlProperty);
296 urlProperty.Dispose();
299 PropertyValue batchSizeProperty = new PropertyValue(batchSize);
300 tMap.Insert(ImageVisualProperty.BatchSize, batchSizeProperty);
301 PropertyValue cacheSizeProperty = new PropertyValue(cacheSize);
302 tMap.Insert(ImageVisualProperty.CacheSize, cacheSizeProperty);
303 PropertyValue loopCountProperty = new PropertyValue(loopCount);
304 tMap.Insert(ImageVisualProperty.LoopCount, loopCountProperty);
305 PropertyValue stopBehaviorProperty = new PropertyValue((int)stopBehavior);
306 tMap.Insert(ImageVisualProperty.StopBehavior, stopBehaviorProperty);
308 loopCountProperty.Dispose();
309 cacheSizeProperty.Dispose();
310 batchSizeProperty.Dispose();
311 stopBehaviorProperty.Dispose();
314 PropertyValue mapProperty = new PropertyValue(propertyMap);
315 SetProperty(ImageView.Property.IMAGE, mapProperty);
316 mapProperty.Dispose();
319 animatiedImage.Dispose();
325 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
326 [EditorBrowsable(EditorBrowsableState.Never)]
327 public new void Play()
334 /// Pause animation. Currently pause and stop are same
336 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
337 [EditorBrowsable(EditorBrowsableState.Never)]
338 public new void Pause()
345 /// Stop animation. Currently pause and stop are same
347 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
348 [EditorBrowsable(EditorBrowsableState.Never)]
349 public new void Stop()
357 #region Event, Enum, Struct, ETC
360 /// Enumeration for what to do when the animation is stopped.
362 [EditorBrowsable(EditorBrowsableState.Never)]
363 public enum StopBehaviorType
366 /// When the animation is stopped, the current frame is shown.
368 [EditorBrowsable(EditorBrowsableState.Never)]
371 /// When the animation is stopped, the min frame (first frame) is shown.
373 [EditorBrowsable(EditorBrowsableState.Never)]
376 /// When the animation is stopped, the max frame (last frame) is shown.
378 [EditorBrowsable(EditorBrowsableState.Never)]
382 private enum ActionType
389 #endregion Event, Enum, Struct, ETC
397 private string url = "";
398 private List<string> resourceURLs = new List<string>();
399 private int batchSize = 1;
400 private int cacheSize = 1;
401 private int frameDelay = 0;
402 private int loopCount = -1;
403 private bool dirtyFlag = false;
404 private StopBehaviorType stopBehavior;
405 private PropertyMap propertyMap;