2 * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
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.
19 using System.Collections.Generic;
20 using static Interop.StickerData;
22 namespace Tizen.Uix.Sticker
25 /// Enumeration for the URI type.
27 /// <since_tizen> 10 </since_tizen>
41 /// Enumeration for the display type.
43 /// <since_tizen> 10 </since_tizen>
44 public enum DisplayType
57 /// The StickerData provides the methods to get/set the sticker data.
59 /// <since_tizen> 10 </since_tizen>
60 public class StickerData : IDisposable
62 internal SafeStickerDataHandle _handle;
63 private bool _disposed = false;
66 /// The public constructor.
68 /// <since_tizen> 10 </since_tizen>
69 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
70 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
71 /// <exception cref="InvalidOperationException">
72 /// This can occur due to the following reasons:
73 /// 1) This exception can be due to out of memory.
74 /// 2) This exception can be due to operation failed.
78 SafeStickerDataHandle handle;
79 ErrorCode error = StickerDataCreate(out handle);
80 if (error != ErrorCode.None)
82 Log.Error(LogTag, "StickerData Failed with error " + error);
83 throw ExceptionFactory.CreateException(error);
88 internal SafeStickerDataHandle SafeStickerDataHandle
96 internal StickerData(SafeStickerDataHandle handle)
101 internal StickerData(IntPtr handle)
104 ErrorCode error = StickerDataClone(handle, out cloneHandle);
105 if (error != ErrorCode.None)
107 Log.Error(LogTag, "StickerData Failed with error " + error);
108 throw ExceptionFactory.CreateException(error);
111 _handle = new SafeStickerDataHandle(cloneHandle);
115 /// The destructor of the StickerData class.
123 /// Release any unmanaged resources used by this object.
125 /// <since_tizen> 10 </since_tizen>
126 public void Dispose()
129 GC.SuppressFinalize(this);
133 /// Release any unmanaged resources used by this object.
135 /// <param name="disposing">
136 /// If true, disposes any disposable objects. If false, does not dispose disposable objects.
138 /// <since_tizen> 10 </since_tizen>
139 protected virtual void Dispose(bool disposing)
154 /// Gets the name of the sticker provider application from sticker data.
156 /// <since_tizen> 10 </since_tizen>
157 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
158 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
159 /// <exception cref="InvalidOperationException">This exception can be due to no data available.</exception>
165 ErrorCode error = StickerDataGetAppId(_handle, out appId);
166 if (error != ErrorCode.None)
168 Log.Error(LogTag, "GetAppId Failed with error " + error);
169 throw ExceptionFactory.CreateException(error);
177 /// Gets the URI from sticker data.
179 /// <since_tizen> 10 </since_tizen>
180 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
181 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
182 /// <exception cref="InvalidOperationException">This exception can be due to no data available.</exception>
189 ErrorCode error = StickerDataGetUri(_handle, out uriType, out uri);
190 if (error != ErrorCode.None)
192 Log.Error(LogTag, "GetUri Failed with error " + error);
193 throw ExceptionFactory.CreateException(error);
201 /// Gets the URI type from sticker data.
203 /// <since_tizen> 10 </since_tizen>
204 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
205 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
206 /// <exception cref="InvalidOperationException">This exception can be due to no data available.</exception>
207 public UriType UriType
213 ErrorCode error = StickerDataGetUri(_handle, out uriType, out uri);
214 if (error != ErrorCode.None)
216 Log.Error(LogTag, "GetUriType Failed with error " + error);
217 throw ExceptionFactory.CreateException(error);
225 /// Sets the URI of the sticker data.
227 /// <remarks><paramref name="uri"/> must be a path inside the app package directory like 'res/smile.png' when the type of URI is local path.</remarks>
228 /// <since_tizen> 10 </since_tizen>
229 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
230 /// <param name="uriType">The URI type to be saved.</param>
231 /// <param name="uri">The URI to be saved.</param>
232 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
233 /// <exception cref="ArgumentException">This exception can be due to an invalid parameter.</exception>
234 public void SetUri(UriType uriType, string uri)
236 ErrorCode error = StickerDataSetUri(_handle, uriType, uri);
237 if (error != ErrorCode.None)
239 Log.Error(LogTag, "SetUri Failed with error " + error);
240 throw ExceptionFactory.CreateException(error);
245 /// Adds a keyword of the sticker to the list.
247 /// <since_tizen> 10 </since_tizen>
248 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
249 /// <param name="keyword">The keyword to be saved.</param>
250 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
251 /// <exception cref="ArgumentException">This exception can be due to an invalid parameter.</exception>
252 public void AddKeyword(string keyword)
254 ErrorCode error = StickerDataAddKeyword(_handle, keyword);
255 if (error != ErrorCode.None)
257 Log.Error(LogTag, "AddKeyword Failed with error " + error);
258 throw ExceptionFactory.CreateException(error);
263 /// Removes a keyword of the sticker from the list.
265 /// <since_tizen> 10 </since_tizen>
266 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
267 /// <param name="keyword">The keyword to be removed.</param>
268 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
269 /// <exception cref="ArgumentException">This exception can be due to an invalid parameter.</exception>
270 public void RemoveKeyword(string keyword)
272 ErrorCode error = StickerDataRemoveKeyword(_handle, keyword);
273 if (error != ErrorCode.None)
275 Log.Error(LogTag, "RemoveKeyword Failed with error " + error);
276 throw ExceptionFactory.CreateException(error);
281 /// Retrieves all keywords of the sticker data.
283 /// <since_tizen> 10 </since_tizen>
284 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
285 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
286 /// <exception cref="InvalidOperationException">This exception can be due to no data available.</exception>
287 public IEnumerable<string> GetAllKeywords()
289 var keywords = new List<string>();
290 StickerDataKeywordForeachCallback _keywordDelegate = (string keyword, IntPtr userData) =>
292 keywords.Add(keyword);
295 ErrorCode error = StickerDataForeachKeyword(_handle, _keywordDelegate, IntPtr.Zero);
296 if (error != ErrorCode.None)
298 Log.Error(LogTag, "GetAllKeywords Failed with error " + error);
299 throw ExceptionFactory.CreateException(error);
302 return keywords.AsReadOnly();
306 /// Gets/Sets the group name of the sticker data.
308 /// <since_tizen> 10 </since_tizen>
309 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
310 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
311 /// <exception cref="InvalidOperationException">This exception can be due to no data available.</exception>
312 public string GroupName
317 ErrorCode error = StickerDataGetGroupName(_handle, out groupName);
318 if (error != ErrorCode.None)
320 Log.Error(LogTag, "GetGroupName Failed with error " + error);
321 throw ExceptionFactory.CreateException(error);
328 ErrorCode error = StickerDataSetGroupName(_handle, value);
329 if (error != ErrorCode.None)
331 Log.Error(LogTag, "SetGroupName Failed with error " + error);
332 throw ExceptionFactory.CreateException(error);
338 /// Gets/Sets the thumbnail local path of the sticker data.
340 /// <since_tizen> 10 </since_tizen>
341 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
342 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
343 /// <exception cref="ArgumentException">This exception can be due to an invalid parameter.</exception>
344 public string Thumbnail
349 ErrorCode error = StickerDataGetThumbnail(_handle, out thumbnail);
350 if (error != ErrorCode.None)
352 Log.Error(LogTag, "GetThumbnail Failed with error " + error);
353 throw ExceptionFactory.CreateException(error);
360 ErrorCode error = StickerDataSetThumbnail(_handle, value);
361 if (error != ErrorCode.None)
363 Log.Error(LogTag, "SetThumbnail Failed with error " + error);
364 throw ExceptionFactory.CreateException(error);
370 /// Gets/Sets the description of the sticker data.
372 /// <since_tizen> 10 </since_tizen>
373 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
374 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
375 public string Description
380 ErrorCode error = StickerDataGetDescription(_handle, out description);
381 if (error != ErrorCode.None)
383 Log.Error(LogTag, "GetDescription Failed with error " + error);
384 throw ExceptionFactory.CreateException(error);
391 ErrorCode error = StickerDataSetDescription(_handle, value);
392 if (error != ErrorCode.None)
394 Log.Error(LogTag, "SetDescription Failed with error " + error);
395 throw ExceptionFactory.CreateException(error);
401 /// Gets the last update date from sticker data.
403 /// <since_tizen> 10 </since_tizen>
404 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
405 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
406 /// <exception cref="InvalidOperationException">This exception can be due to no data available.</exception>
407 public DateTime LastUpdated
412 ErrorCode error = StickerDataGetDate(_handle, out date);
413 if (error != ErrorCode.None)
415 Log.Error(LogTag, "GetDate Failed with error " + error);
416 throw ExceptionFactory.CreateException(error);
419 return Convert.ToDateTime(date);
424 /// Gets/Sets the display type of the sticker data.
426 /// <since_tizen> 10 </since_tizen>
427 /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
428 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
429 /// <exception cref="ArgumentException">This exception can be due to an invalid parameter.</exception>
430 public DisplayType DisplayType
434 DisplayType displayType;
435 ErrorCode error = StickerDataGetDisplayType(_handle, out displayType);
436 if (error != ErrorCode.None)
438 Log.Error(LogTag, "GetDisplayType Failed with error " + error);
439 throw ExceptionFactory.CreateException(error);
446 ErrorCode error = StickerDataSetDisplayType(_handle, value);
447 if (error != ErrorCode.None)
449 Log.Error(LogTag, "SetDisplayType Failed with error " + error);
450 throw ExceptionFactory.CreateException(error);