[NUI] Fix to restore setter of AnimatedImageView.ResourceUrl
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / AnimatedImageView.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System.Collections.Generic;
19 using System.ComponentModel;
20
21 #if (NUI_DEBUG_ON)
22 using tlog = Tizen.Log;
23 #endif
24
25 namespace Tizen.NUI.BaseComponents
26 {
27     /// <summary>
28     /// AnimatedImageView is a class for displaying Animated-GIF and Image-Array
29     /// </summary>
30     // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
31     [EditorBrowsable(EditorBrowsableState.Never)]
32     public class AnimatedImageView : ImageView
33     {
34         #region Constructor, Distructor, Dispose
35         /// <summary>
36         /// Construct AnimatedImageView
37         /// </summary>
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()
41         {
42             mDirtyFlag = true;
43         }
44
45         /// <summary>
46         /// You can override it to clean-up your own resources
47         /// </summary>
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)
52         {
53             if (disposed)
54             {
55                 return;
56             }
57
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.
61             base.Dispose(type);
62         }
63         #endregion Constructor, Distructor, Dispose
64
65         #region Property
66         /// <summary>
67         /// Image URL for Animated-GIF
68         /// </summary>
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
72         {
73             get
74             {
75                 return mUrl;
76             }
77             set
78             {
79                 mDirtyFlag = true;
80                 mUrl = value;
81             }
82         }
83
84         /// <summary>
85         ///  Image URL list for Image-Array
86         /// </summary>
87         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
88         [EditorBrowsable(EditorBrowsableState.Never)]
89         public List<string> URLs
90         {
91             get
92             {
93                 return mResourceURLs;
94             }
95         }
96
97         /// <summary>
98         /// Defines the batch size for pre-loading images in the Image-Array animation.
99         /// number of images to pre-load before starting to play. Default value: 1.
100         /// </summary>
101         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
102         [EditorBrowsable(EditorBrowsableState.Never)]
103         public int BatchSize
104         {
105             get
106             {
107                 return mBatchSize;
108             }
109             set
110             {
111                 mDirtyFlag = true;
112                 mBatchSize = value;
113             }
114         }
115
116         /// <summary>
117         /// Defines the cache size for loading images in the Image-Array animation.
118         /// number of images to keep cached ahead during playback. Default value: 1.
119         ///</summary>
120         ///<remarks>
121         /// cacheSize should be >= batchSize. If it isn't, then the cache will automatically be changed to batchSize.
122         /// because of the defaults, it is expected that the application developer tune the batch and cache sizes to their particular use case.
123         /// </remarks>
124         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
125         [EditorBrowsable(EditorBrowsableState.Never)]
126         public int CacheSize
127         {
128             get
129             {
130                 return mCacheSize;
131             }
132             set
133             {
134                 mDirtyFlag = true;
135                 mCacheSize = value;
136             }
137         }
138
139         /// <summary>
140         /// The number of milliseconds between each frame in the Image-Array animation.
141         /// The number of milliseconds between each frame.
142         /// </summary>
143         /// <remarks>
144         /// This is only used when URLs(multiple string) are provided.
145         /// </remarks>
146         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
147         [EditorBrowsable(EditorBrowsableState.Never)]
148         public int FrameDelay
149         {
150             get
151             {
152                 return mFrameDelay;
153             }
154             set
155             {
156                 mDirtyFlag = true;
157                 mFrameDelay = value;
158             }
159         }
160
161         /// <summary>
162         /// The number of looping.
163         /// </summary>
164         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
165         [EditorBrowsable(EditorBrowsableState.Never)]
166         public int LoopCount
167         {
168             get
169             {
170                 return mLoopCount;
171             }
172             set
173             {
174                 mDirtyFlag = true;
175                 mLoopCount = value;
176             }
177         }
178         #endregion Property
179
180         #region Method
181         /// <summary>
182         /// To make the properies be set. This should be called after the properties are set.
183         /// </summary>
184         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
185         [EditorBrowsable(EditorBrowsableState.Never)]
186         public void SetValues()
187         {
188             if (mDirtyFlag == false)
189             {
190                 return;
191             }
192             mDirtyFlag = false;
193
194             PropertyMap tMap = new PropertyMap();
195             PropertyValue animatiedImage = new PropertyValue((int)Visual.Type.AnimatedImage);
196             tMap.Insert(Visual.Property.Type, animatiedImage);
197             if (mResourceURLs?.Count != 0)
198             {
199                 PropertyArray mArray = new PropertyArray();
200                 PropertyArray returnedArr = new PropertyArray();
201                 PropertyValue index = new PropertyValue();
202                 foreach (var iter in mResourceURLs)
203                 {
204                     index = new PropertyValue(iter);
205                     returnedArr = mArray.Add(index);
206                 }
207                 index.Dispose();
208                 returnedArr.Dispose();
209                 PropertyValue array = new PropertyValue(mArray);
210                 tMap.Insert(ImageVisualProperty.URL, array);
211                 PropertyValue batchSize = new PropertyValue(mBatchSize);
212                 tMap.Insert(ImageVisualProperty.BatchSize, batchSize);
213                 PropertyValue cacheSize = new PropertyValue(mCacheSize);
214                 tMap.Insert(ImageVisualProperty.CacheSize, cacheSize);
215                 PropertyValue frameDelay = new PropertyValue(mFrameDelay);
216                 tMap.Insert(ImageVisualProperty.FrameDelay, frameDelay);
217                 PropertyValue loopCount = new PropertyValue(mLoopCount);
218                 tMap.Insert(ImageVisualProperty.LoopCount, loopCount);
219
220                 loopCount.Dispose();
221                 frameDelay.Dispose();
222                 cacheSize.Dispose();
223                 batchSize.Dispose();
224                 mArray.Dispose();
225                 array.Dispose();
226             }
227             else
228             {
229                 PropertyValue url = new PropertyValue(mUrl);
230                 tMap.Insert(ImageVisualProperty.URL, url);
231                 url.Dispose();
232             }
233
234             mMap = tMap;
235             PropertyValue map = new PropertyValue(mMap);
236             SetProperty(ImageView.Property.IMAGE, map);
237             map.Dispose();
238
239             tMap.Dispose();
240             animatiedImage.Dispose();
241         }
242
243         /// <summary>
244         /// Play animation
245         /// </summary>
246         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
247         [EditorBrowsable(EditorBrowsableState.Never)]
248         public new void Play()
249         {
250             SetValues();
251             base.Play();
252         }
253
254         /// <summary>
255         /// Pause animation. Currently pause and stop are same
256         /// </summary>
257         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
258         [EditorBrowsable(EditorBrowsableState.Never)]
259         public new void Pause()
260         {
261             SetValues();
262             base.Pause();
263         }
264
265         /// <summary>
266         /// Stop animation. Currently pause and stop are same
267         /// </summary>
268         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
269         [EditorBrowsable(EditorBrowsableState.Never)]
270         public new void Stop()
271         {
272             SetValues();
273             base.Stop();
274         }
275         #endregion Method
276
277
278         #region Event, Enum, Struct, ETC
279         #endregion Event, Enum, Struct, ETC
280
281
282         #region Internal
283         #endregion Internal
284
285
286         #region Private
287         string mUrl = "";
288         List<string> mResourceURLs = new List<string>();
289         int mBatchSize = 1;
290         int mCacheSize = 1;
291         int mFrameDelay = 0;
292         int mLoopCount = -1;
293         bool mDirtyFlag = false;
294         PropertyMap mMap;
295         #endregion Private
296     }
297 }