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 // Collection of animated-image-sensitive properties.
35 private static readonly List<int> cachedAnimatedImagePropertyKeyList = new List<int> {
36 ImageVisualProperty.BatchSize,
37 ImageVisualProperty.CacheSize,
38 ImageVisualProperty.FrameDelay,
39 ImageVisualProperty.LoopCount,
40 ImageVisualProperty.StopBehavior,
42 private List<string> resourceURLs = new List<string>();
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();
59 /// You can override it to clean-up your own resources
61 /// <param name="type">DisposeTypes</param>
62 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
63 [EditorBrowsable(EditorBrowsableState.Never)]
64 protected override void Dispose(DisposeTypes type)
71 //Release your own unmanaged resources here.
72 //You should not access any managed member here except static instance.
73 //because the execution order of Finalizes is non-deterministic.
76 #endregion Constructor, Destructor, Dispose
80 /// Image URL list for Image-Array
82 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
83 [EditorBrowsable(EditorBrowsableState.Never)]
84 public List<string> URLs
93 /// Defines the batch size for pre-loading images in the Image-Array animation.
94 /// number of images to pre-load before starting to play. Default value: 1.
96 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
97 [EditorBrowsable(EditorBrowsableState.Never)]
102 return (int)GetValue(BatchSizeProperty);
106 SetValue(BatchSizeProperty, value);
107 NotifyPropertyChanged();
111 private int InternalBatchSize
117 PropertyValue batchSize = GetCachedImageVisualProperty(ImageVisualProperty.BatchSize);
118 batchSize?.Get(out ret);
119 batchSize?.Dispose();
125 using PropertyValue setValue = new PropertyValue(value);
126 UpdateImage(ImageVisualProperty.BatchSize, setValue);
131 /// Defines the cache size for loading images in the Image-Array animation.
132 /// number of images to keep cached ahead during playback. Default value: 1.
135 /// cacheSize should be >= batchSize. If it isn't, then the cache will automatically be changed to batchSize.
136 /// because of the defaults, it is expected that the application developer tune the batch and cache sizes to their particular use case.
138 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
139 [EditorBrowsable(EditorBrowsableState.Never)]
144 return (int)GetValue(CacheSizeProperty);
148 SetValue(CacheSizeProperty, value);
149 NotifyPropertyChanged();
153 private int InternalCacheSize
159 PropertyValue cacheSize = GetCachedImageVisualProperty(ImageVisualProperty.CacheSize);
160 cacheSize?.Get(out ret);
161 cacheSize?.Dispose();
167 using PropertyValue setValue = new PropertyValue(value);
168 UpdateImage(ImageVisualProperty.CacheSize, setValue);
173 /// The number of milliseconds between each frame in the Image-Array animation.
174 /// The number of milliseconds between each frame.
177 /// This is only used when URLs(multiple string) are provided.
179 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
180 [EditorBrowsable(EditorBrowsableState.Never)]
181 public int FrameDelay
185 return (int)GetValue(FrameDelayProperty);
189 SetValue(FrameDelayProperty, value);
190 NotifyPropertyChanged();
194 private int InternalFrameDelay
200 PropertyValue frameDelay = GetCachedImageVisualProperty(ImageVisualProperty.FrameDelay);
201 frameDelay?.Get(out ret);
202 frameDelay?.Dispose();
208 using PropertyValue setValue = new PropertyValue(value);
209 UpdateImage(ImageVisualProperty.FrameDelay, setValue);
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
237 PropertyValue loopCount = GetCachedImageVisualProperty(ImageVisualProperty.LoopCount);
238 loopCount?.Get(out ret);
239 loopCount?.Dispose();
245 using PropertyValue setValue = new PropertyValue(value);
246 UpdateImage(ImageVisualProperty.LoopCount, setValue);
251 /// Sets or gets the stop behavior.
253 [EditorBrowsable(EditorBrowsableState.Never)]
254 public StopBehaviorType StopBehavior
258 return (StopBehaviorType)GetValue(StopBehaviorProperty);
262 SetValue(StopBehaviorProperty, value);
263 NotifyPropertyChanged();
267 private StopBehaviorType InternalStopBehavior
273 PropertyValue stopBehavior = GetCachedImageVisualProperty(ImageVisualProperty.StopBehavior);
274 stopBehavior?.Get(out ret);
275 stopBehavior?.Dispose();
277 return (StopBehaviorType)ret;
281 using PropertyValue setValue = new PropertyValue((int)value);
282 UpdateImage(ImageVisualProperty.StopBehavior, setValue);
287 /// Get the number of total frames
289 [EditorBrowsable(EditorBrowsableState.Never)]
290 public int TotalFrame
295 PropertyMap map = base.Image;
298 PropertyValue val = map.Find(ImageVisualProperty.TotalFrameNumber);
301 if (val.Get(out ret))
312 /// Set or get the current frame. When setting a specific frame, it is displayed as a still image.
315 /// 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.
317 [EditorBrowsable(EditorBrowsableState.Never)]
318 public int CurrentFrame
322 return (int)GetValue(CurrentFrameProperty);
326 SetValue(CurrentFrameProperty, value);
327 NotifyPropertyChanged();
331 private int InternalCurrentFrame
335 // Sync as current properties
338 DoAction(ImageView.Property.IMAGE, ActionJumpTo, new PropertyValue(value));
343 PropertyMap map = base.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 [EditorBrowsable(EditorBrowsableState.Never)]
364 protected int ActionJumpTo { get; set; } = Interop.AnimatedImageView.AnimatedImageVisualActionJumpToGet();
369 /// To make the properies be set. This should be called after the properties are set.
371 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
372 [EditorBrowsable(EditorBrowsableState.Never)]
373 public void SetValues()
375 // This API assume that Animated relative properties setuped forcely.
376 imagePropertyUpdatedFlag = true;
378 // Sync as current properties
383 /// Update animated-image-relative properties synchronously.
384 /// After call this API, All image properties updated.
386 [EditorBrowsable(EditorBrowsableState.Never)]
387 protected override void UpdateImage()
389 if (!imagePropertyUpdatedFlag) return;
391 if (resourceURLs != null && resourceURLs.Count != 0)
393 using (PropertyArray indexPropertyArray = new PropertyArray())
395 PropertyArray returnedArr = new PropertyArray();
396 foreach (var iter in resourceURLs)
398 using (PropertyValue index = new PropertyValue(iter))
400 returnedArr = indexPropertyArray.Add(index);
403 returnedArr.Dispose();
404 using PropertyValue arrayProperty = new PropertyValue(indexPropertyArray);
406 // Trigger the ImageView so that we have something update
407 UpdateImage(ImageVisualProperty.URL, arrayProperty);
411 using PropertyValue animatiedImage = new PropertyValue((int)Visual.Type.AnimatedImage);
412 UpdateImage(Visual.Property.Type, animatiedImage);
418 /// Update NUI cached animated image visual property map by inputed property map.
419 /// And call base.MergeCachedImageVisualProperty()
422 /// For performance issue, we will collect only "cachedAnimatedImagePropertyKeyList" hold in this class.
424 [EditorBrowsable(EditorBrowsableState.Never)]
425 protected override void MergeCachedImageVisualProperty(PropertyMap map)
427 if (map == null) return;
428 if (cachedImagePropertyMap == null)
430 cachedImagePropertyMap = new PropertyMap();
432 foreach (var key in cachedAnimatedImagePropertyKeyList)
434 PropertyValue value = map.Find(key);
437 // Update-or-Insert new value
438 cachedImagePropertyMap[key] = value;
441 base.MergeCachedImageVisualProperty(map);
445 #region Event, Enum, Struct, ETC
448 /// Enumeration for what to do when the animation is stopped.
450 [EditorBrowsable(EditorBrowsableState.Never)]
451 public enum StopBehaviorType
454 /// When the animation is stopped, the current frame is shown.
456 [EditorBrowsable(EditorBrowsableState.Never)]
459 /// When the animation is stopped, the min frame (first frame) is shown.
461 [EditorBrowsable(EditorBrowsableState.Never)]
464 /// When the animation is stopped, the max frame (last frame) is shown.
466 [EditorBrowsable(EditorBrowsableState.Never)]
470 #endregion Event, Enum, Struct, ETC