2 * Copyright (c) 2018 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.
18 using System.Collections.Generic;
19 using System.ComponentModel;
22 namespace Tizen.System
25 /// The Feedback API provides functions to control haptic and sound.
26 /// The Feedback API provides the way to play and stop feedback, and get the information whether a specific pattern is supported.
27 /// Below is the supported pattern string:
44 /// HardwareKeyPressed
60 /// VibrationModeAbled
61 /// SilentModeDisabled
62 /// BluetoothDeviceConnected
63 /// BluetoothDeviceDisconnected
69 /// For controlling the haptic device:
70 /// http://tizen.org/privilege/haptic
71 /// For controlling the sound, privilege is not needed.
75 /// Feedback feedback = new Feedback();
76 /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
79 /// <since_tizen> 3 </since_tizen>
82 private const string LogTag = "Tizen.System.Feedback";
84 private readonly Dictionary<string, int> Pattern = new Dictionary<string, int>
87 {"SoftInputPanel", 1},
102 {"HardwareKeyPressed", 21},
103 {"HardwareKeyHold", 22},
112 {"ChargerConnected", 38},
113 {"ChargingError", 40},
114 {"FullyCharged", 42},
118 {"VibrationModeAbled", 55},
119 {"SilentModeDisabled", 56},
120 {"BluetoothDeviceConnected", 57},
121 {"BluetoothDeviceDisconnected", 58},
124 {"VolumeKeyPressed", 64},
127 {"ToggleOff", 40003},
128 {"LongPressOn", 40004},
129 {"LongPressOff", 40005},
133 {"PreheatEnding", 40009},
134 {"TaskEnding", 40010},
141 {"DefaultLeve1", 40017},
152 {"TimerEnding", 40028},
153 {"BurnerDetected", 40029},
154 {"BurnerMoved", 40030},
155 {"Connected", 40031},
156 {"Disconnected", 40032},
160 /// Constructor of Feedback class
162 /// <since_tizen> 3 </since_tizen>
164 /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
166 /// <exception cref="NotSupportedException">Thrown when failed because the devices (vibration and sound) are not supported.</exception>
167 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
168 /// <privilege>http://tizen.org/privilege/haptic</privilege>
171 /// Feedback feedback = new Feedback();
176 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Initialize();
177 if (res != Interop.Feedback.FeedbackError.None)
179 Log.Warn(LogTag, string.Format("Failed to initialize feedback. err = {0}", res));
182 case Interop.Feedback.FeedbackError.NotSupported:
183 throw new NotSupportedException("Device is not supported");
185 throw new InvalidOperationException("Failed to initialize");
191 /// Finalizes an instance of the Feedback class.
195 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Deinitialize();
196 if (res != Interop.Feedback.FeedbackError.None)
198 Log.Warn(LogTag, string.Format("Failed to deinitialize feedback. err = {0}", res));
203 /// Gets the supported information about a specific type and pattern.
206 /// Now, IsSupportedPattern is not working for FeedbackType.All.
207 /// This API is working for FeedbackType.Sound and FeedbackType.Vibration only.
208 /// If you use FeedbackType.All for type parameter, this API will throw ArgumentException.
209 /// To get the supported information for Vibration type, the application should have http://tizen.org/privilege/haptic privilege.
211 /// <since_tizen> 3 </since_tizen>
212 /// <param name="type">The feedback type.</param>
213 /// <param name="pattern">The feedback pattern string.</param>
215 /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
217 /// <returns>Information whether a pattern is supported.</returns>
218 /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
219 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
220 /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
221 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
222 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
223 /// <privilege>http://tizen.org/privilege/haptic</privilege>
226 /// Feedback feedback = new Feedback();
227 /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
230 public bool IsSupportedPattern(FeedbackType type, String pattern)
232 bool supported = false;
234 Interop.Feedback.FeedbackError res;
236 if (!Pattern.TryGetValue(pattern, out number))
237 throw new ArgumentException($"Not supported pattern string : {pattern}", nameof(pattern));
239 res = (Interop.Feedback.FeedbackError)Interop.Feedback.IsSupportedPattern((Interop.Feedback.FeedbackType)type, number, out supported);
241 if (res != Interop.Feedback.FeedbackError.None)
243 Log.Warn(LogTag, string.Format("Failed to get supported information. err = {0}", res));
246 case Interop.Feedback.FeedbackError.NotInitialized:
247 throw new Exception("Not initialized");
248 case Interop.Feedback.FeedbackError.InvalidParameter:
249 throw new ArgumentException("Invalid Arguments");
250 case Interop.Feedback.FeedbackError.NotSupported:
251 throw new NotSupportedException("Device is not supported");
252 case Interop.Feedback.FeedbackError.PermissionDenied:
253 throw new UnauthorizedAccessException("Access is not granted");
254 case Interop.Feedback.FeedbackError.OperationFailed:
256 throw new InvalidOperationException("Failed to get supported information");
263 /// Plays a specific feedback pattern.
266 /// To play Vibration type, app should have http://tizen.org/privilege/haptic privilege.
268 /// <since_tizen> 3 </since_tizen>
269 /// <param name="type">The feedback type.</param>
270 /// <param name="pattern">The feedback pattern string.</param>
272 /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
274 /// <exception cref="Exception">Thrown when failed because feedback is not initialized.</exception>
275 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
276 /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
277 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted(No privilege)</exception>
278 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
279 /// <privilege>http://tizen.org/privilege/haptic</privilege>
282 /// Feedback feedback = new Feedback();
283 /// feedback.Play(FeedbackType.All, "Tap");
286 public void Play(FeedbackType type, String pattern)
289 Interop.Feedback.FeedbackError res;
291 if (!Pattern.TryGetValue(pattern, out number))
292 throw new ArgumentException($"Not supported pattern string : {pattern}", nameof(pattern));
294 if (type == FeedbackType.All)
295 res = (Interop.Feedback.FeedbackError)Interop.Feedback.Play(number);
297 res = (Interop.Feedback.FeedbackError)Interop.Feedback.PlayType((Interop.Feedback.FeedbackType)type, number);
299 if (res != Interop.Feedback.FeedbackError.None)
301 Log.Warn(LogTag, string.Format("Failed to play feedback. err = {0}", res));
304 case Interop.Feedback.FeedbackError.NotInitialized:
305 throw new Exception("Not initialized");
306 case Interop.Feedback.FeedbackError.InvalidParameter:
307 throw new ArgumentException("Invalid Arguments");
308 case Interop.Feedback.FeedbackError.NotSupported:
309 throw new NotSupportedException("Not supported");
310 case Interop.Feedback.FeedbackError.PermissionDenied:
311 throw new UnauthorizedAccessException("Access is not granted");
312 case Interop.Feedback.FeedbackError.OperationFailed:
314 throw new InvalidOperationException("Failed to play pattern");
320 /// Stops to play the feedback.
323 /// To stop vibration, the application should have http://tizen.org/privilege/haptic privilege.
325 /// <since_tizen> 3 </since_tizen>
327 /// http://tizen.org/feature/feedback.vibration
329 /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
330 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament</exception>
331 /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
332 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
333 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
334 /// <privilege>http://tizen.org/privilege/haptic</privilege>
337 /// Feedback Feedback1 = new Feedback();
338 /// Feedback1.Stop();
343 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Stop();
345 if (res != Interop.Feedback.FeedbackError.None)
347 Log.Warn(LogTag, string.Format("Failed to stop feedback. err = {0}", res));
350 case Interop.Feedback.FeedbackError.NotInitialized:
351 throw new Exception("Not initialized");
352 case Interop.Feedback.FeedbackError.InvalidParameter:
353 throw new ArgumentException("Invalid Arguments");
354 case Interop.Feedback.FeedbackError.NotSupported:
355 throw new NotSupportedException("Not supported");
356 case Interop.Feedback.FeedbackError.PermissionDenied:
357 throw new UnauthorizedAccessException("Access is not granted");
358 case Interop.Feedback.FeedbackError.OperationFailed:
360 throw new InvalidOperationException("Failed to stop pattern");
366 /// Gets the count of theme can be used according to feedback type.
369 /// Now this internal API works for FeedbackType.Sound only, FeedbackType.Vibration is not supported.
371 /// <since_tizen> 10 </since_tizen>
372 /// <param name="type">The feedback type.</param>
373 /// <returns>The counf of theme can be used according to feedback type.</returns>
374 /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
375 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
376 /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
377 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
380 /// Feedback feedback = new Feedback();
381 /// uint coundOfTheme = feedback.GetCountOfThemeInternal(FeedbackType.Sound);
384 [EditorBrowsable(EditorBrowsableState.Never)]
385 public uint GetCountOfThemeInternal(FeedbackType type)
387 uint countOfTheme = 0;
388 Interop.Feedback.FeedbackError res;
390 res = (Interop.Feedback.FeedbackError)Interop.Feedback.GetCountOfThemeInternal((Interop.Feedback.FeedbackType)type, out countOfTheme);
392 if (res != Interop.Feedback.FeedbackError.None)
394 Log.Warn(LogTag, string.Format("Failed to get count of theme internal. err = {0}", res));
397 case Interop.Feedback.FeedbackError.NotInitialized:
398 throw new Exception("Not initialized");
399 case Interop.Feedback.FeedbackError.InvalidParameter:
400 throw new ArgumentException("Invalid Arguments");
401 case Interop.Feedback.FeedbackError.NotSupported:
402 throw new NotSupportedException("Device is not supported");
403 case Interop.Feedback.FeedbackError.OperationFailed:
405 throw new InvalidOperationException("Failed to get count of theme internal");
412 /// Gets the index of theme selected.
415 /// Now this internal API works for FeedbackType.Sound only, FeedbackType.Vibration is not supported.
417 /// <since_tizen> 10 </since_tizen>
418 /// <param name="type">The feedback type.</param>
419 /// <returns>The index of theme selected as default theme according to feedback type.</returns>
420 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
421 /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
422 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
425 /// Feedback feedback = new Feedback();
426 /// uint indexOfTheme = feedback. GetThemeIndexInternal(FeedbackType.Sound);
429 [EditorBrowsable(EditorBrowsableState.Never)]
430 public uint GetThemeIndexInternal(FeedbackType type)
432 uint countOfTheme = 0;
433 Interop.Feedback.FeedbackError res;
435 res = (Interop.Feedback.FeedbackError)Interop.Feedback.GetThemeIndexInternal((Interop.Feedback.FeedbackType)type, out countOfTheme);
437 if (res != Interop.Feedback.FeedbackError.None)
439 Log.Warn(LogTag, string.Format("Failed to get index of theme internal. err = {0}", res));
442 case Interop.Feedback.FeedbackError.InvalidParameter:
443 throw new ArgumentException("Invalid Arguments");
444 case Interop.Feedback.FeedbackError.NotSupported:
445 throw new NotSupportedException("Device is not supported");
446 case Interop.Feedback.FeedbackError.OperationFailed:
448 throw new InvalidOperationException("Failed to get index of theme internal");
455 /// Sets the index of theme according to feedback type.
458 /// Now this internal API works for FeedbackType.Sound only, FeedbackType.Vibration is not supported.
459 /// To set the index of theme for Sound type, the application should have http://tizen.org/privilege/systemsettings.admin privilege.
461 /// <since_tizen> 10 </since_tizen>
462 /// <param name="type">The feedback type.</param>
463 /// <param name="indexOfTheme">The index of theme will be set.</param>
464 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
465 /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
466 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted(No privilege)</exception>
467 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
470 /// Feedback feedback = new Feedback();
471 /// uint indexOfTheme = 0;
472 /// feedback.SetThemeIndexInternal(FeedbackType.Sound, indexOfTheme);
475 [EditorBrowsable(EditorBrowsableState.Never)]
476 public void SetThemeIndexInternal(FeedbackType type, uint indexOfTheme)
478 Interop.Feedback.FeedbackError res;
480 res = (Interop.Feedback.FeedbackError)Interop.Feedback.SetThemeIndexInternal((Interop.Feedback.FeedbackType)type, indexOfTheme);
482 if (res != Interop.Feedback.FeedbackError.None)
484 Log.Warn(LogTag, string.Format("Failed to set index of theme internal. err = {0}", res));
487 case Interop.Feedback.FeedbackError.InvalidParameter:
488 throw new ArgumentException("Invalid Arguments");
489 case Interop.Feedback.FeedbackError.NotSupported:
490 throw new NotSupportedException("Device is not supported");
491 case Interop.Feedback.FeedbackError.PermissionDenied:
492 throw new UnauthorizedAccessException("Access is not granted");
493 case Interop.Feedback.FeedbackError.OperationFailed:
495 throw new InvalidOperationException("Failed to set index of theme internal");