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;
21 namespace Tizen.NUI.BaseComponents
24 /// AnimatedImageView is a class for displaying Animated-GIF and Image-Array
26 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public partial class AnimatedImageView : ImageView
34 private string url = "";
35 private List<string> resourceURLs = new List<string>();
36 private int batchSize = 1;
37 private int cacheSize = 1;
38 private int frameDelay = 0;
39 private int loopCount = -1;
40 private bool dirtyFlag = false;
41 private StopBehaviorType stopBehavior;
42 private PropertyMap propertyMap;
45 #region Constructor, Destructor, Dispose
47 /// Construct AnimatedImageView
49 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
50 [EditorBrowsable(EditorBrowsableState.Never)]
51 public AnimatedImageView() : base()
53 ActionPlay = Interop.AnimatedImageView.AnimatedImageVisualActionPlayGet();
54 ActionPause = Interop.AnimatedImageView.AnimatedImageVisualActionPauseGet();
55 ActionStop = Interop.AnimatedImageView.AnimatedImageVisualActionStopGet();
61 /// You can override it to clean-up your own resources
63 /// <param name="type">DisposeTypes</param>
64 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
65 [EditorBrowsable(EditorBrowsableState.Never)]
66 protected override void Dispose(DisposeTypes type)
73 //Release your own unmanaged resources here.
74 //You should not access any managed member here except static instance.
75 //because the execution order of Finalizes is non-deterministic.
78 #endregion Constructor, Destructor, Dispose
82 /// Image URL for Animated-GIF
84 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
85 [EditorBrowsable(EditorBrowsableState.Never)]
86 public new string ResourceUrl
90 return GetValue(ResourceUrlProperty) as string;
94 SetValue(ResourceUrlProperty, value);
95 NotifyPropertyChanged();
99 private string InternalResourceUrl
113 /// Image URL list for Image-Array
115 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
116 [EditorBrowsable(EditorBrowsableState.Never)]
117 public List<string> URLs
126 /// Defines the batch size for pre-loading images in the Image-Array animation.
127 /// number of images to pre-load before starting to play. Default value: 1.
129 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
130 [EditorBrowsable(EditorBrowsableState.Never)]
135 return (int)GetValue(BatchSizeProperty);
139 SetValue(BatchSizeProperty, value);
140 NotifyPropertyChanged();
144 private int InternalBatchSize
158 /// Defines the cache size for loading images in the Image-Array animation.
159 /// number of images to keep cached ahead during playback. Default value: 1.
162 /// cacheSize should be >= batchSize. If it isn't, then the cache will automatically be changed to batchSize.
163 /// because of the defaults, it is expected that the application developer tune the batch and cache sizes to their particular use case.
165 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
166 [EditorBrowsable(EditorBrowsableState.Never)]
171 return (int)GetValue(CacheSizeProperty);
175 SetValue(CacheSizeProperty, value);
176 NotifyPropertyChanged();
180 private int InternalCacheSize
194 /// The number of milliseconds between each frame in the Image-Array animation.
195 /// The number of milliseconds between each frame.
198 /// This is only used when URLs(multiple string) are provided.
200 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
201 [EditorBrowsable(EditorBrowsableState.Never)]
202 public int FrameDelay
206 return (int)GetValue(FrameDelayProperty);
210 SetValue(FrameDelayProperty, value);
211 NotifyPropertyChanged();
215 private int InternalFrameDelay
229 /// The number of looping.
231 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
232 [EditorBrowsable(EditorBrowsableState.Never)]
237 return (int)GetValue(LoopCountProperty);
241 SetValue(LoopCountProperty, value);
242 NotifyPropertyChanged();
246 private int InternalLoopCount
260 /// Sets or gets the stop behavior.
262 [EditorBrowsable(EditorBrowsableState.Never)]
263 public StopBehaviorType StopBehavior
267 return (StopBehaviorType)GetValue(StopBehaviorProperty);
271 SetValue(StopBehaviorProperty, value);
272 NotifyPropertyChanged();
276 private StopBehaviorType InternalStopBehavior
280 stopBehavior = (StopBehaviorType)value;
290 /// Get the number of total frames
292 [EditorBrowsable(EditorBrowsableState.Never)]
293 public int TotalFrame
298 PropertyMap map = Image;
301 PropertyValue val = map.Find(ImageVisualProperty.TotalFrameNumber);
304 if (val.Get(out ret))
315 /// Set or get the current frame. When setting a specific frame, it is displayed as a still image.
318 /// 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.
320 [EditorBrowsable(EditorBrowsableState.Never)]
321 public int CurrentFrame
325 return (int)GetValue(CurrentFrameProperty);
329 SetValue(CurrentFrameProperty, value);
330 NotifyPropertyChanged();
334 private int InternalCurrentFrame
338 DoAction(ImageView.Property.IMAGE, ActionJumpTo, new PropertyValue(value));
343 PropertyMap map = Image;
346 PropertyValue val = map.Find(ImageVisualProperty.CurrentFrameNumber);
349 if (val.Get(out ret))
360 /// Actions property value to Jump to the specified frame.
361 /// This property can be redefined by child class if it use different value.
363 protected internal int ActionJumpTo { get; set; } = Interop.AnimatedImageView.AnimatedImageVisualActionJumpToGet();
368 /// To make the properies be set. This should be called after the properties are set.
370 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
371 [EditorBrowsable(EditorBrowsableState.Never)]
372 public void SetValues()
374 if (dirtyFlag == false)
380 PropertyMap tMap = new PropertyMap();
381 PropertyValue animatiedImage = new PropertyValue((int)Visual.Type.AnimatedImage);
382 tMap.Insert(Visual.Property.Type, animatiedImage);
383 if (resourceURLs?.Count != 0)
385 PropertyArray indexPropertyArray = new PropertyArray();
386 PropertyArray returnedArr = new PropertyArray();
387 PropertyValue index = new PropertyValue();
388 foreach (var iter in resourceURLs)
390 index = new PropertyValue(iter);
391 returnedArr = indexPropertyArray.Add(index);
394 returnedArr.Dispose();
395 PropertyValue arrayProperty = new PropertyValue(indexPropertyArray);
396 tMap.Insert(ImageVisualProperty.URL, arrayProperty);
397 PropertyValue frameDelayProperty = new PropertyValue(frameDelay);
398 tMap.Insert(ImageVisualProperty.FrameDelay, frameDelayProperty);
400 arrayProperty.Dispose();
401 indexPropertyArray.Dispose();
402 frameDelayProperty.Dispose();
406 PropertyValue urlProperty = new PropertyValue(url);
407 tMap.Insert(ImageVisualProperty.URL, urlProperty);
408 urlProperty.Dispose();
411 PropertyValue batchSizeProperty = new PropertyValue(batchSize);
412 tMap.Insert(ImageVisualProperty.BatchSize, batchSizeProperty);
413 PropertyValue cacheSizeProperty = new PropertyValue(cacheSize);
414 tMap.Insert(ImageVisualProperty.CacheSize, cacheSizeProperty);
415 PropertyValue loopCountProperty = new PropertyValue(loopCount);
416 tMap.Insert(ImageVisualProperty.LoopCount, loopCountProperty);
417 PropertyValue stopBehaviorProperty = new PropertyValue((int)stopBehavior);
418 tMap.Insert(ImageVisualProperty.StopBehavior, stopBehaviorProperty);
420 loopCountProperty.Dispose();
421 cacheSizeProperty.Dispose();
422 batchSizeProperty.Dispose();
423 stopBehaviorProperty.Dispose();
426 PropertyValue mapProperty = new PropertyValue(propertyMap);
427 SetProperty(ImageView.Property.IMAGE, mapProperty);
428 mapProperty.Dispose();
431 animatiedImage.Dispose();
437 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
438 [EditorBrowsable(EditorBrowsableState.Never)]
439 public new void Play()
446 /// Pause animation. Currently pause and stop are same
448 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
449 [EditorBrowsable(EditorBrowsableState.Never)]
450 public new void Pause()
457 /// Stop animation. Currently pause and stop are same
459 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
460 [EditorBrowsable(EditorBrowsableState.Never)]
461 public new void Stop()
469 #region Event, Enum, Struct, ETC
472 /// Enumeration for what to do when the animation is stopped.
474 [EditorBrowsable(EditorBrowsableState.Never)]
475 public enum StopBehaviorType
478 /// When the animation is stopped, the current frame is shown.
480 [EditorBrowsable(EditorBrowsableState.Never)]
483 /// When the animation is stopped, the min frame (first frame) is shown.
485 [EditorBrowsable(EditorBrowsableState.Never)]
488 /// When the animation is stopped, the max frame (last frame) is shown.
490 [EditorBrowsable(EditorBrowsableState.Never)]
494 #endregion Event, Enum, Struct, ETC