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
32 /// Actions property value to Jump to the specified frame.
34 internal static readonly int ActionJumpTo = Interop.AnimatedImageView.AnimatedImageVisualActionJumpToGet();
38 // Collection of animated-image-sensitive properties.
39 private static readonly List<int> cachedAnimatedImagePropertyKeyList = new List<int> {
40 ImageVisualProperty.BatchSize,
41 ImageVisualProperty.CacheSize,
42 ImageVisualProperty.FrameDelay,
43 ImageVisualProperty.LoopCount,
44 ImageVisualProperty.StopBehavior,
46 private List<string> resourceURLs = new List<string>();
49 #region Constructor, Destructor, Dispose
51 /// Construct AnimatedImageView
53 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
54 [EditorBrowsable(EditorBrowsableState.Never)]
55 public AnimatedImageView() : base()
60 /// You can override it to clean-up your own resources
62 /// <param name="type">DisposeTypes</param>
63 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 protected override void Dispose(DisposeTypes type)
72 //Release your own unmanaged resources here.
73 //You should not access any managed member here except static instance.
74 //because the execution order of Finalizes is non-deterministic.
77 #endregion Constructor, Destructor, Dispose
81 /// Image URL list for Image-Array
83 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
84 [EditorBrowsable(EditorBrowsableState.Never)]
85 public List<string> URLs
94 /// Defines the batch size for pre-loading images in the Image-Array animation.
95 /// number of images to pre-load before starting to play. Default value: 1.
97 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
98 [EditorBrowsable(EditorBrowsableState.Never)]
103 return (int)GetValue(BatchSizeProperty);
107 SetValue(BatchSizeProperty, value);
108 NotifyPropertyChanged();
112 private int InternalBatchSize
118 PropertyValue batchSize = GetCachedImageVisualProperty(ImageVisualProperty.BatchSize);
119 batchSize?.Get(out ret);
120 batchSize?.Dispose();
126 using PropertyValue setValue = new PropertyValue(value);
127 UpdateImage(ImageVisualProperty.BatchSize, setValue);
132 /// Defines the cache size for loading images in the Image-Array animation.
133 /// number of images to keep cached ahead during playback. Default value: 1.
136 /// cacheSize should be >= batchSize. If it isn't, then the cache will automatically be changed to batchSize.
137 /// because of the defaults, it is expected that the application developer tune the batch and cache sizes to their particular use case.
139 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
140 [EditorBrowsable(EditorBrowsableState.Never)]
145 return (int)GetValue(CacheSizeProperty);
149 SetValue(CacheSizeProperty, value);
150 NotifyPropertyChanged();
154 private int InternalCacheSize
160 PropertyValue cacheSize = GetCachedImageVisualProperty(ImageVisualProperty.CacheSize);
161 cacheSize?.Get(out ret);
162 cacheSize?.Dispose();
168 using PropertyValue setValue = new PropertyValue(value);
169 UpdateImage(ImageVisualProperty.CacheSize, setValue);
174 /// The number of milliseconds between each frame in the Image-Array animation.
175 /// The number of milliseconds between each frame.
178 /// This is only used when URLs(multiple string) are provided.
180 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
181 [EditorBrowsable(EditorBrowsableState.Never)]
182 public int FrameDelay
186 return (int)GetValue(FrameDelayProperty);
190 SetValue(FrameDelayProperty, value);
191 NotifyPropertyChanged();
195 private int InternalFrameDelay
201 PropertyValue frameDelay = GetCachedImageVisualProperty(ImageVisualProperty.FrameDelay);
202 frameDelay?.Get(out ret);
203 frameDelay?.Dispose();
209 using PropertyValue setValue = new PropertyValue(value);
210 UpdateImage(ImageVisualProperty.FrameDelay, setValue);
215 /// The number of looping.
217 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
218 [EditorBrowsable(EditorBrowsableState.Never)]
223 return (int)GetValue(LoopCountProperty);
227 SetValue(LoopCountProperty, value);
228 NotifyPropertyChanged();
232 private int InternalLoopCount
238 PropertyValue loopCount = GetCachedImageVisualProperty(ImageVisualProperty.LoopCount);
239 loopCount?.Get(out ret);
240 loopCount?.Dispose();
246 using PropertyValue setValue = new PropertyValue(value);
247 UpdateImage(ImageVisualProperty.LoopCount, setValue);
252 /// Sets or gets the stop behavior.
254 [EditorBrowsable(EditorBrowsableState.Never)]
255 public StopBehaviorType StopBehavior
259 return (StopBehaviorType)GetValue(StopBehaviorProperty);
263 SetValue(StopBehaviorProperty, value);
264 NotifyPropertyChanged();
268 private StopBehaviorType InternalStopBehavior
274 PropertyValue stopBehavior = GetCachedImageVisualProperty(ImageVisualProperty.StopBehavior);
275 stopBehavior?.Get(out ret);
276 stopBehavior?.Dispose();
278 return (StopBehaviorType)ret;
282 using PropertyValue setValue = new PropertyValue((int)value);
283 UpdateImage(ImageVisualProperty.StopBehavior, setValue);
288 /// Get the number of total frames
290 [EditorBrowsable(EditorBrowsableState.Never)]
291 public int TotalFrame
296 PropertyMap map = base.Image;
299 PropertyValue val = map.Find(ImageVisualProperty.TotalFrameNumber);
302 if (val.Get(out ret))
313 /// Set or get the current frame. When setting a specific frame, it is displayed as a still image.
316 /// 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.
318 [EditorBrowsable(EditorBrowsableState.Never)]
319 public int CurrentFrame
323 return (int)GetValue(CurrentFrameProperty);
327 SetValue(CurrentFrameProperty, value);
328 NotifyPropertyChanged();
332 private int InternalCurrentFrame
336 // Sync as current properties
339 DoAction(ImageView.Property.IMAGE, ActionJumpTo, new PropertyValue(value));
344 PropertyMap map = base.Image;
347 PropertyValue val = map.Find(ImageVisualProperty.CurrentFrameNumber);
350 if (val.Get(out ret))
363 /// To make the properies be set. This should be called after the properties are set.
365 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
366 [EditorBrowsable(EditorBrowsableState.Never)]
367 public void SetValues()
369 // This API assume that Animated relative properties setuped forcely.
370 imagePropertyUpdatedFlag = true;
372 // Sync as current properties
377 /// Update animated-image-relative properties synchronously.
378 /// After call this API, All image properties updated.
380 [EditorBrowsable(EditorBrowsableState.Never)]
381 protected override void UpdateImage()
383 if (!imagePropertyUpdatedFlag) return;
385 // Assume that we are using standard Image at first.
386 // (Since we might cache Visual.Property.Type as Visual.Type.AnimatedImage even we don't use URLs.)
387 using (PropertyValue imageType = new PropertyValue((int)Visual.Type.Image))
389 UpdateImage(Visual.Property.Type, imageType, false);
392 if (resourceURLs != null && resourceURLs.Count != 0)
394 using (PropertyArray indexPropertyArray = new PropertyArray())
396 PropertyArray returnedArr = new PropertyArray();
397 foreach (var iter in resourceURLs)
399 using (PropertyValue index = new PropertyValue(iter))
401 returnedArr = indexPropertyArray.Add(index);
404 returnedArr.Dispose();
405 using PropertyValue arrayProperty = new PropertyValue(indexPropertyArray);
407 // Trigger the ImageView so that we have something update
408 UpdateImage(ImageVisualProperty.URL, arrayProperty, false);
411 // Trick that we are using resourceURLs without ResourceUrl API.
412 using PropertyValue animatiedImage = new PropertyValue((int)Visual.Type.AnimatedImage);
413 UpdateImage(Visual.Property.Type, animatiedImage, false);
420 /// Update NUI cached animated image visual property map by inputed property map.
421 /// And call base.MergeCachedImageVisualProperty()
424 /// For performance issue, we will collect only "cachedAnimatedImagePropertyKeyList" hold in this class.
426 [EditorBrowsable(EditorBrowsableState.Never)]
427 protected override void MergeCachedImageVisualProperty(PropertyMap map)
429 if (map == null) return;
430 if (cachedImagePropertyMap == null)
432 cachedImagePropertyMap = new PropertyMap();
434 foreach (var key in cachedAnimatedImagePropertyKeyList)
436 PropertyValue value = map.Find(key);
439 // Update-or-Insert new value
440 cachedImagePropertyMap[key] = value;
443 base.MergeCachedImageVisualProperty(map);
447 #region Event, Enum, Struct, ETC
450 /// Enumeration for what to do when the animation is stopped.
452 [EditorBrowsable(EditorBrowsableState.Never)]
453 public enum StopBehaviorType
456 /// When the animation is stopped, the current frame is shown.
458 [EditorBrowsable(EditorBrowsableState.Never)]
461 /// When the animation is stopped, the min frame (first frame) is shown.
463 [EditorBrowsable(EditorBrowsableState.Never)]
466 /// When the animation is stopped, the max frame (last frame) is shown.
468 [EditorBrowsable(EditorBrowsableState.Never)]
472 #endregion Event, Enum, Struct, ETC