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 partial 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
75 return GetValue(ResourceUrlProperty) as string;
79 SetValue(ResourceUrlProperty, value);
80 NotifyPropertyChanged();
84 private string InternalResourceUrl
98 /// Image URL list for Image-Array
100 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
101 [EditorBrowsable(EditorBrowsableState.Never)]
102 public List<string> URLs
111 /// Defines the batch size for pre-loading images in the Image-Array animation.
112 /// number of images to pre-load before starting to play. Default value: 1.
114 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
115 [EditorBrowsable(EditorBrowsableState.Never)]
120 return (int)GetValue(BatchSizeProperty);
124 SetValue(BatchSizeProperty, value);
125 NotifyPropertyChanged();
129 private int InternalBatchSize
143 /// Defines the cache size for loading images in the Image-Array animation.
144 /// number of images to keep cached ahead during playback. Default value: 1.
147 /// cacheSize should be >= batchSize. If it isn't, then the cache will automatically be changed to batchSize.
148 /// because of the defaults, it is expected that the application developer tune the batch and cache sizes to their particular use case.
150 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
151 [EditorBrowsable(EditorBrowsableState.Never)]
156 return (int)GetValue(CacheSizeProperty);
160 SetValue(CacheSizeProperty, value);
161 NotifyPropertyChanged();
165 private int InternalCacheSize
179 /// The number of milliseconds between each frame in the Image-Array animation.
180 /// The number of milliseconds between each frame.
183 /// This is only used when URLs(multiple string) are provided.
185 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
186 [EditorBrowsable(EditorBrowsableState.Never)]
187 public int FrameDelay
191 return (int)GetValue(FrameDelayProperty);
195 SetValue(FrameDelayProperty, value);
196 NotifyPropertyChanged();
200 private int InternalFrameDelay
214 /// The number of looping.
216 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
217 [EditorBrowsable(EditorBrowsableState.Never)]
222 return (int)GetValue(LoopCountProperty);
226 SetValue(LoopCountProperty, value);
227 NotifyPropertyChanged();
231 private int InternalLoopCount
245 /// Sets or gets the stop behavior.
247 [EditorBrowsable(EditorBrowsableState.Never)]
248 public StopBehaviorType StopBehavior
252 return (StopBehaviorType)GetValue(StopBehaviorProperty);
256 SetValue(StopBehaviorProperty, value);
257 NotifyPropertyChanged();
261 private StopBehaviorType InternalStopBehavior
265 stopBehavior = (StopBehaviorType)value;
275 /// Get the number of total frames
277 [EditorBrowsable(EditorBrowsableState.Never)]
278 public int TotalFrame
283 PropertyMap map = Image;
286 PropertyValue val = map.Find(ImageVisualProperty.TotalFrameNumber);
289 if (val.Get(out ret))
300 /// Set or get the current frame. When setting a specific frame, it is displayed as a still image.
303 /// 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.
305 [EditorBrowsable(EditorBrowsableState.Never)]
306 public int CurrentFrame
310 return (int)GetValue(CurrentFrameProperty);
314 SetValue(CurrentFrameProperty, value);
315 NotifyPropertyChanged();
319 private int InternalCurrentFrame
323 DoAction(ImageView.Property.IMAGE, (int)ActionType.jumpTo, new PropertyValue(value));
328 PropertyMap map = Image;
331 PropertyValue val = map.Find(ImageVisualProperty.CurrentFrameNumber);
334 if (val.Get(out ret))
347 /// To make the properies be set. This should be called after the properties are set.
349 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
350 [EditorBrowsable(EditorBrowsableState.Never)]
351 public void SetValues()
353 if (dirtyFlag == false)
359 PropertyMap tMap = new PropertyMap();
360 PropertyValue animatiedImage = new PropertyValue((int)Visual.Type.AnimatedImage);
361 tMap.Insert(Visual.Property.Type, animatiedImage);
362 if (resourceURLs?.Count != 0)
364 PropertyArray indexPropertyArray = new PropertyArray();
365 PropertyArray returnedArr = new PropertyArray();
366 PropertyValue index = new PropertyValue();
367 foreach (var iter in resourceURLs)
369 index = new PropertyValue(iter);
370 returnedArr = indexPropertyArray.Add(index);
373 returnedArr.Dispose();
374 PropertyValue arrayProperty = new PropertyValue(indexPropertyArray);
375 tMap.Insert(ImageVisualProperty.URL, arrayProperty);
376 PropertyValue frameDelayProperty = new PropertyValue(frameDelay);
377 tMap.Insert(ImageVisualProperty.FrameDelay, frameDelayProperty);
379 arrayProperty.Dispose();
380 indexPropertyArray.Dispose();
381 frameDelayProperty.Dispose();
385 PropertyValue urlProperty = new PropertyValue(url);
386 tMap.Insert(ImageVisualProperty.URL, urlProperty);
387 urlProperty.Dispose();
390 PropertyValue batchSizeProperty = new PropertyValue(batchSize);
391 tMap.Insert(ImageVisualProperty.BatchSize, batchSizeProperty);
392 PropertyValue cacheSizeProperty = new PropertyValue(cacheSize);
393 tMap.Insert(ImageVisualProperty.CacheSize, cacheSizeProperty);
394 PropertyValue loopCountProperty = new PropertyValue(loopCount);
395 tMap.Insert(ImageVisualProperty.LoopCount, loopCountProperty);
396 PropertyValue stopBehaviorProperty = new PropertyValue((int)stopBehavior);
397 tMap.Insert(ImageVisualProperty.StopBehavior, stopBehaviorProperty);
399 loopCountProperty.Dispose();
400 cacheSizeProperty.Dispose();
401 batchSizeProperty.Dispose();
402 stopBehaviorProperty.Dispose();
405 PropertyValue mapProperty = new PropertyValue(propertyMap);
406 SetProperty(ImageView.Property.IMAGE, mapProperty);
407 mapProperty.Dispose();
410 animatiedImage.Dispose();
416 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
417 [EditorBrowsable(EditorBrowsableState.Never)]
418 public new void Play()
425 /// Pause animation. Currently pause and stop are same
427 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
428 [EditorBrowsable(EditorBrowsableState.Never)]
429 public new void Pause()
436 /// Stop animation. Currently pause and stop are same
438 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
439 [EditorBrowsable(EditorBrowsableState.Never)]
440 public new void Stop()
448 #region Event, Enum, Struct, ETC
451 /// Enumeration for what to do when the animation is stopped.
453 [EditorBrowsable(EditorBrowsableState.Never)]
454 public enum StopBehaviorType
457 /// When the animation is stopped, the current frame is shown.
459 [EditorBrowsable(EditorBrowsableState.Never)]
462 /// When the animation is stopped, the min frame (first frame) is shown.
464 [EditorBrowsable(EditorBrowsableState.Never)]
467 /// When the animation is stopped, the max frame (last frame) is shown.
469 [EditorBrowsable(EditorBrowsableState.Never)]
473 private enum ActionType
480 #endregion Event, Enum, Struct, ETC
488 private string url = "";
489 private List<string> resourceURLs = new List<string>();
490 private int batchSize = 1;
491 private int cacheSize = 1;
492 private int frameDelay = 0;
493 private int loopCount = -1;
494 private bool dirtyFlag = false;
495 private StopBehaviorType stopBehavior;
496 private PropertyMap propertyMap;