[NUI] Fix CA2000 warning issues of Camera / ItemView / Animatable / Animation / Anima...
[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         }
78
79         /// <summary>
80         ///  Image URL list for Image-Array
81         /// </summary>
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
85         {
86             get
87             {
88                 return mResourceURLs;
89             }
90         }
91
92         /// <summary>
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.
95         /// </summary>
96         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
97         [EditorBrowsable(EditorBrowsableState.Never)]
98         public int BatchSize
99         {
100             get
101             {
102                 return mBatchSize;
103             }
104             set
105             {
106                 mDirtyFlag = true;
107                 mBatchSize = value;
108             }
109         }
110
111         /// <summary>
112         /// Defines the cache size for loading images in the Image-Array animation.
113         /// number of images to keep cached ahead during playback. Default value: 1.
114         ///</summary>
115         ///<remarks>
116         /// cacheSize should be >= batchSize. If it isn't, then the cache will automatically be changed to batchSize.
117         /// because of the defaults, it is expected that the application developer tune the batch and cache sizes to their particular use case.
118         /// </remarks>
119         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
120         [EditorBrowsable(EditorBrowsableState.Never)]
121         public int CacheSize
122         {
123             get
124             {
125                 return mCacheSize;
126             }
127             set
128             {
129                 mDirtyFlag = true;
130                 mCacheSize = value;
131             }
132         }
133
134         /// <summary>
135         /// The number of milliseconds between each frame in the Image-Array animation.
136         /// The number of milliseconds between each frame.
137         /// </summary>
138         /// <remarks>
139         /// This is only used when URLs(multiple string) are provided.
140         /// </remarks>
141         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
142         [EditorBrowsable(EditorBrowsableState.Never)]
143         public int FrameDelay
144         {
145             get
146             {
147                 return mFrameDelay;
148             }
149             set
150             {
151                 mDirtyFlag = true;
152                 mFrameDelay = value;
153             }
154         }
155
156         /// <summary>
157         /// The number of looping.
158         /// </summary>
159         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
160         [EditorBrowsable(EditorBrowsableState.Never)]
161         public int LoopCount
162         {
163             get
164             {
165                 return mLoopCount;
166             }
167             set
168             {
169                 mDirtyFlag = true;
170                 mLoopCount = value;
171             }
172         }
173         #endregion Property
174
175         #region Method
176         /// <summary>
177         /// To make the properies be set. This should be called after the properties are set.
178         /// </summary>
179         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
180         [EditorBrowsable(EditorBrowsableState.Never)]
181         public void SetValues()
182         {
183             if (mDirtyFlag == false)
184             {
185                 return;
186             }
187             mDirtyFlag = false;
188
189             PropertyMap tMap = new PropertyMap();
190             PropertyValue animatiedImage = new PropertyValue((int)Visual.Type.AnimatedImage);
191             tMap.Insert(Visual.Property.Type, animatiedImage);
192             if (mResourceURLs?.Count != 0)
193             {
194                 PropertyArray mArray = new PropertyArray();
195                 PropertyArray returnedArr = new PropertyArray();
196                 PropertyValue index = new PropertyValue();
197                 foreach (var iter in mResourceURLs)
198                 {
199                     index = new PropertyValue(iter);
200                     returnedArr = mArray.Add(index);
201                 }
202                 index.Dispose();
203                 returnedArr.Dispose();
204                 PropertyValue array = new PropertyValue(mArray);
205                 tMap.Insert(ImageVisualProperty.URL, array);
206                 PropertyValue batchSize = new PropertyValue(mBatchSize);
207                 tMap.Insert(ImageVisualProperty.BatchSize, batchSize);
208                 PropertyValue cacheSize = new PropertyValue(mCacheSize);
209                 tMap.Insert(ImageVisualProperty.CacheSize, cacheSize);
210                 PropertyValue frameDelay = new PropertyValue(mFrameDelay);
211                 tMap.Insert(ImageVisualProperty.FrameDelay, frameDelay);
212                 PropertyValue loopCount = new PropertyValue(mLoopCount);
213                 tMap.Insert(ImageVisualProperty.LoopCount, loopCount);
214
215                 loopCount.Dispose();
216                 frameDelay.Dispose();
217                 cacheSize.Dispose();
218                 batchSize.Dispose();
219                 mArray.Dispose();
220                 array.Dispose();
221             }
222             else
223             {
224                 PropertyValue url = new PropertyValue(mUrl);
225                 tMap.Insert(ImageVisualProperty.URL, url);
226                 url.Dispose();
227             }
228
229             mMap = tMap;
230             PropertyValue map = new PropertyValue(mMap);
231             SetProperty(ImageView.Property.IMAGE, map);
232             map.Dispose();
233
234             tMap.Dispose();
235             animatiedImage.Dispose();
236         }
237
238         /// <summary>
239         /// Play animation
240         /// </summary>
241         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
242         [EditorBrowsable(EditorBrowsableState.Never)]
243         public new void Play()
244         {
245             SetValues();
246             base.Play();
247         }
248
249         /// <summary>
250         /// Pause animation. Currently pause and stop are same
251         /// </summary>
252         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
253         [EditorBrowsable(EditorBrowsableState.Never)]
254         public new void Pause()
255         {
256             SetValues();
257             base.Pause();
258         }
259
260         /// <summary>
261         /// Stop animation. Currently pause and stop are same
262         /// </summary>
263         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
264         [EditorBrowsable(EditorBrowsableState.Never)]
265         public new void Stop()
266         {
267             SetValues();
268             base.Stop();
269         }
270         #endregion Method
271
272
273         #region Event, Enum, Struct, ETC
274         #endregion Event, Enum, Struct, ETC
275
276
277         #region Internal
278         #endregion Internal
279
280
281         #region Private
282         string mUrl = "";
283         List<string> mResourceURLs = new List<string>();
284         int mBatchSize = 1;
285         int mCacheSize = 1;
286         int mFrameDelay = 0;
287         int mLoopCount = -1;
288         bool mDirtyFlag = false;
289         PropertyMap mMap;
290         #endregion Private
291     }
292 }