using System.Collections.Generic;
using System.ComponentModel;
-#if (NUI_DEBUG_ON)
-using tlog = Tizen.Log;
-#endif
-
namespace Tizen.NUI.BaseComponents
{
/// <summary>
/// </summary>
// This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
[EditorBrowsable(EditorBrowsableState.Never)]
- public class AnimatedImageView : ImageView
+ public partial class AnimatedImageView : ImageView
{
+ #region Internal
+ /// <summary>
+ /// Actions property value to Jump to the specified frame.
+ /// </summary>
+ internal static readonly int ActionJumpTo = Interop.AnimatedImageView.AnimatedImageVisualActionJumpToGet();
+ #endregion Internal
+
+ #region Private
+ // Collection of animated-image-sensitive properties.
+ private static readonly List<int> cachedAnimatedImagePropertyKeyList = new List<int> {
+ ImageVisualProperty.BatchSize,
+ ImageVisualProperty.CacheSize,
+ ImageVisualProperty.FrameDelay,
+ ImageVisualProperty.LoopCount,
+ ImageVisualProperty.StopBehavior,
+ };
+ private List<string> resourceURLs = new List<string>();
+ #endregion Private
+
#region Constructor, Destructor, Dispose
/// <summary>
/// Construct AnimatedImageView
[EditorBrowsable(EditorBrowsableState.Never)]
public AnimatedImageView() : base()
{
- dirtyFlag = true;
}
/// <summary>
#region Property
/// <summary>
- /// Image URL for Animated-GIF
- /// </summary>
- // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
- [EditorBrowsable(EditorBrowsableState.Never)]
- public new string ResourceUrl
- {
- get
- {
- return url;
- }
- set
- {
- dirtyFlag = true;
- url = value;
- }
- }
-
- /// <summary>
/// Image URL list for Image-Array
/// </summary>
// This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
{
get
{
- return batchSize;
+ return (int)GetValue(BatchSizeProperty);
+ }
+ set
+ {
+ SetValue(BatchSizeProperty, value);
+ NotifyPropertyChanged();
+ }
+ }
+
+ private int InternalBatchSize
+ {
+ get
+ {
+ int ret = 1;
+
+ PropertyValue batchSize = GetCachedImageVisualProperty(ImageVisualProperty.BatchSize);
+ batchSize?.Get(out ret);
+ batchSize?.Dispose();
+
+ return ret;
}
set
{
- dirtyFlag = true;
- batchSize = value;
+ using PropertyValue setValue = new PropertyValue(value);
+ UpdateImage(ImageVisualProperty.BatchSize, setValue);
}
}
{
get
{
- return cacheSize;
+ return (int)GetValue(CacheSizeProperty);
}
set
{
- dirtyFlag = true;
- cacheSize = value;
+ SetValue(CacheSizeProperty, value);
+ NotifyPropertyChanged();
+ }
+ }
+
+ private int InternalCacheSize
+ {
+ get
+ {
+ int ret = 1;
+
+ PropertyValue cacheSize = GetCachedImageVisualProperty(ImageVisualProperty.CacheSize);
+ cacheSize?.Get(out ret);
+ cacheSize?.Dispose();
+
+ return ret;
+ }
+ set
+ {
+ using PropertyValue setValue = new PropertyValue(value);
+ UpdateImage(ImageVisualProperty.CacheSize, setValue);
}
}
{
get
{
- return frameDelay;
+ return (int)GetValue(FrameDelayProperty);
+ }
+ set
+ {
+ SetValue(FrameDelayProperty, value);
+ NotifyPropertyChanged();
+ }
+ }
+
+ private int InternalFrameDelay
+ {
+ get
+ {
+ int ret = 0;
+
+ PropertyValue frameDelay = GetCachedImageVisualProperty(ImageVisualProperty.FrameDelay);
+ frameDelay?.Get(out ret);
+ frameDelay?.Dispose();
+
+ return ret;
}
set
{
- dirtyFlag = true;
- frameDelay = value;
+ using PropertyValue setValue = new PropertyValue(value);
+ UpdateImage(ImageVisualProperty.FrameDelay, setValue);
}
}
{
get
{
- return loopCount;
+ return (int)GetValue(LoopCountProperty);
+ }
+ set
+ {
+ SetValue(LoopCountProperty, value);
+ NotifyPropertyChanged();
+ }
+ }
+
+ private int InternalLoopCount
+ {
+ get
+ {
+ int ret = -1;
+
+ PropertyValue loopCount = GetCachedImageVisualProperty(ImageVisualProperty.LoopCount);
+ loopCount?.Get(out ret);
+ loopCount?.Dispose();
+
+ return ret;
}
set
{
- dirtyFlag = true;
- loopCount = value;
+ using PropertyValue setValue = new PropertyValue(value);
+ UpdateImage(ImageVisualProperty.LoopCount, setValue);
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
public StopBehaviorType StopBehavior
{
+ get
+ {
+ return (StopBehaviorType)GetValue(StopBehaviorProperty);
+ }
set
{
- stopBehavior = (StopBehaviorType)value;
- dirtyFlag = true;
+ SetValue(StopBehaviorProperty, value);
+ NotifyPropertyChanged();
}
+ }
+
+ private StopBehaviorType InternalStopBehavior
+ {
get
{
- return stopBehavior;
+ int ret = 0;
+
+ PropertyValue stopBehavior = GetCachedImageVisualProperty(ImageVisualProperty.StopBehavior);
+ stopBehavior?.Get(out ret);
+ stopBehavior?.Dispose();
+
+ return (StopBehaviorType)ret;
+ }
+ set
+ {
+ using PropertyValue setValue = new PropertyValue((int)value);
+ UpdateImage(ImageVisualProperty.StopBehavior, setValue);
}
}
get
{
int ret = -1;
- PropertyMap map = Image;
+ PropertyMap map = base.Image;
if (map != null)
{
PropertyValue val = map.Find(ImageVisualProperty.TotalFrameNumber);
[EditorBrowsable(EditorBrowsableState.Never)]
public int CurrentFrame
{
+ get
+ {
+ return (int)GetValue(CurrentFrameProperty);
+ }
set
{
- DoAction(ImageView.Property.IMAGE, (int)ActionType.jumpTo, new PropertyValue(value));
+ SetValue(CurrentFrameProperty, value);
+ NotifyPropertyChanged();
+ }
+ }
+
+ private int InternalCurrentFrame
+ {
+ set
+ {
+ // Sync as current properties
+ UpdateImage();
+
+ DoAction(ImageView.Property.IMAGE, ActionJumpTo, new PropertyValue(value));
}
get
{
int ret = -1;
- PropertyMap map = Image;
+ PropertyMap map = base.Image;
if (map != null)
{
PropertyValue val = map.Find(ImageVisualProperty.CurrentFrameNumber);
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetValues()
{
- if (dirtyFlag == false)
- {
- return;
- }
- dirtyFlag = false;
-
- PropertyMap tMap = new PropertyMap();
- PropertyValue animatiedImage = new PropertyValue((int)Visual.Type.AnimatedImage);
- tMap.Insert(Visual.Property.Type, animatiedImage);
- if (resourceURLs?.Count != 0)
- {
- PropertyArray indexPropertyArray = new PropertyArray();
- PropertyArray returnedArr = new PropertyArray();
- PropertyValue index = new PropertyValue();
- foreach (var iter in resourceURLs)
- {
- index = new PropertyValue(iter);
- returnedArr = indexPropertyArray.Add(index);
- }
- index.Dispose();
- returnedArr.Dispose();
- PropertyValue arrayProperty = new PropertyValue(indexPropertyArray);
- tMap.Insert(ImageVisualProperty.URL, arrayProperty);
- PropertyValue frameDelayProperty = new PropertyValue(frameDelay);
- tMap.Insert(ImageVisualProperty.FrameDelay, frameDelayProperty);
-
- arrayProperty.Dispose();
- indexPropertyArray.Dispose();
- frameDelayProperty.Dispose();
- }
- else
- {
- PropertyValue urlProperty = new PropertyValue(url);
- tMap.Insert(ImageVisualProperty.URL, urlProperty);
- urlProperty.Dispose();
- }
+ // This API assume that Animated relative properties setuped forcely.
+ imagePropertyUpdatedFlag = true;
- PropertyValue batchSizeProperty = new PropertyValue(batchSize);
- tMap.Insert(ImageVisualProperty.BatchSize, batchSizeProperty);
- PropertyValue cacheSizeProperty = new PropertyValue(cacheSize);
- tMap.Insert(ImageVisualProperty.CacheSize, cacheSizeProperty);
- PropertyValue loopCountProperty = new PropertyValue(loopCount);
- tMap.Insert(ImageVisualProperty.LoopCount, loopCountProperty);
- PropertyValue stopBehaviorProperty = new PropertyValue((int)stopBehavior);
- tMap.Insert(ImageVisualProperty.StopBehavior, stopBehaviorProperty);
-
- loopCountProperty.Dispose();
- cacheSizeProperty.Dispose();
- batchSizeProperty.Dispose();
- stopBehaviorProperty.Dispose();
-
- propertyMap = tMap;
- PropertyValue mapProperty = new PropertyValue(propertyMap);
- SetProperty(ImageView.Property.IMAGE, mapProperty);
- mapProperty.Dispose();
-
- tMap.Dispose();
- animatiedImage.Dispose();
+ // Sync as current properties
+ UpdateImage();
}
/// <summary>
- /// Play animation
+ /// Update animated-image-relative properties synchronously.
+ /// After call this API, All image properties updated.
/// </summary>
- // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
[EditorBrowsable(EditorBrowsableState.Never)]
- public new void Play()
+ protected override void UpdateImage()
{
- SetValues();
- base.Play();
- }
+ if (!imagePropertyUpdatedFlag) return;
- /// <summary>
- /// Pause animation. Currently pause and stop are same
- /// </summary>
- // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
- [EditorBrowsable(EditorBrowsableState.Never)]
- public new void Pause()
- {
- SetValues();
- base.Pause();
+ // Assume that we are using standard Image at first.
+ // (Since we might cache Visual.Property.Type as Visual.Type.AnimatedImage even we don't use URLs.)
+ using (PropertyValue imageType = new PropertyValue((int)Visual.Type.Image))
+ {
+ UpdateImage(Visual.Property.Type, imageType, false);
+ }
+
+ if (resourceURLs != null && resourceURLs.Count != 0)
+ {
+ using (PropertyArray indexPropertyArray = new PropertyArray())
+ {
+ PropertyArray returnedArr = new PropertyArray();
+ foreach (var iter in resourceURLs)
+ {
+ using (PropertyValue index = new PropertyValue(iter))
+ {
+ returnedArr = indexPropertyArray.Add(index);
+ }
+ }
+ returnedArr.Dispose();
+ using PropertyValue arrayProperty = new PropertyValue(indexPropertyArray);
+
+ // Trigger the ImageView so that we have something update
+ UpdateImage(ImageVisualProperty.URL, arrayProperty, false);
+ }
+
+ // Trick that we are using resourceURLs without ResourceUrl API.
+ using PropertyValue animatiedImage = new PropertyValue((int)Visual.Type.AnimatedImage);
+ UpdateImage(Visual.Property.Type, animatiedImage, false);
+ }
+
+ base.UpdateImage();
}
/// <summary>
- /// Stop animation. Currently pause and stop are same
+ /// Update NUI cached animated image visual property map by inputed property map.
+ /// And call base.MergeCachedImageVisualProperty()
/// </summary>
- // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+ /// <remarks>
+ /// For performance issue, we will collect only "cachedAnimatedImagePropertyKeyList" hold in this class.
+ /// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
- public new void Stop()
+ protected override void MergeCachedImageVisualProperty(PropertyMap map)
{
- SetValues();
- base.Stop();
+ if (map == null) return;
+ if (cachedImagePropertyMap == null)
+ {
+ cachedImagePropertyMap = new PropertyMap();
+ }
+ foreach (var key in cachedAnimatedImagePropertyKeyList)
+ {
+ PropertyValue value = map.Find(key);
+ if (value != null)
+ {
+ // Update-or-Insert new value
+ cachedImagePropertyMap[key] = value;
+ }
+ }
+ base.MergeCachedImageVisualProperty(map);
}
#endregion Method
-
#region Event, Enum, Struct, ETC
/// <summary>
MaximumFrame
}
- private enum ActionType
- {
- play,
- pause,
- stop,
- jumpTo,
- };
#endregion Event, Enum, Struct, ETC
-
-
- #region Internal
- #endregion Internal
-
-
- #region Private
- private string url = "";
- private List<string> resourceURLs = new List<string>();
- private int batchSize = 1;
- private int cacheSize = 1;
- private int frameDelay = 0;
- private int loopCount = -1;
- private bool dirtyFlag = false;
- private StopBehaviorType stopBehavior;
- private PropertyMap propertyMap;
- #endregion Private
}
}