2 using System.Collections.Generic;
8 /// Class for constants
10 internal static class Constants
12 internal const int NumberOfPattern = 39;
16 /// The Feedback API provides functions to control haptic and sound.
17 /// The Feedback API provides the way to play and stop feedback and get the information whether specific pattern is supported.
18 /// Below is supported pattern string.
35 /// HardwareKeyPressed
51 /// VibrationModeAbled
52 /// SilentModeDisabled
53 /// BluetoothDeviceConnected
54 /// BluetoothDeviceDisconnected
60 /// For controlling haptic device:
61 /// http://tizen.org/privilege/haptic
62 /// For controlling sound, previlege is not needed.
65 /// Feedback feedback = new Feedback();
66 /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
70 private const string LogTag = "Tizen.System.Feedback";
72 private readonly FeedbackPattern[] Pattern = new FeedbackPattern[39];
75 Pattern[0].PatternNumber = 0;
76 Pattern[0].PatternString = "Tap";
77 Pattern[1].PatternNumber = 1;
78 Pattern[1].PatternString = "SoftInputPanel";
79 Pattern[2].PatternNumber = 6;
80 Pattern[2].PatternString = "Key0";
81 Pattern[3].PatternNumber = 7;
82 Pattern[3].PatternString = "Key1";
83 Pattern[4].PatternNumber = 8;
84 Pattern[4].PatternString = "Key2";
85 Pattern[5].PatternNumber = 9;
86 Pattern[5].PatternString = "Key3";
87 Pattern[6].PatternNumber = 10;
88 Pattern[6].PatternString = "Key4";
89 Pattern[7].PatternNumber = 11;
90 Pattern[7].PatternString = "Key5";
91 Pattern[8].PatternNumber = 12;
92 Pattern[8].PatternString = "Key6";
93 Pattern[9].PatternNumber = 13;
94 Pattern[9].PatternString = "Key7";
95 Pattern[10].PatternNumber = 14;
96 Pattern[10].PatternString = "Key8";
97 Pattern[11].PatternNumber = 15;
98 Pattern[11].PatternString = "Key9";
99 Pattern[12].PatternNumber = 16;
100 Pattern[12].PatternString = "KeyStar";
101 Pattern[13].PatternNumber = 17;
102 Pattern[13].PatternString = "KeySharp";
103 Pattern[14].PatternNumber = 18;
104 Pattern[14].PatternString = "KeyBack";
105 Pattern[15].PatternNumber = 19;
106 Pattern[15].PatternString = "Hold";
107 Pattern[16].PatternNumber = 21;
108 Pattern[16].PatternString = "HardwareKeyPressed";
109 Pattern[17].PatternNumber = 22;
110 Pattern[17].PatternString = "HardwareKeyHold";
111 Pattern[18].PatternNumber = 23;
112 Pattern[18].PatternString = "Message";
113 Pattern[19].PatternNumber = 25;
114 Pattern[19].PatternString = "Email";
115 Pattern[20].PatternNumber = 27;
116 Pattern[20].PatternString = "WakeUp";
117 Pattern[21].PatternNumber = 29;
118 Pattern[21].PatternString = "Schedule";
119 Pattern[22].PatternNumber = 31;
120 Pattern[22].PatternString = "Timer";
121 Pattern[23].PatternNumber = 33;
122 Pattern[23].PatternString = "General";
123 Pattern[24].PatternNumber = 36;
124 Pattern[24].PatternString = "PowerOn";
125 Pattern[25].PatternNumber = 37;
126 Pattern[25].PatternString = "PowerOff";
127 Pattern[26].PatternNumber = 38;
128 Pattern[26].PatternString = "ChargerConnected";
129 Pattern[27].PatternNumber = 40;
130 Pattern[27].PatternString = "ChargingError";
131 Pattern[28].PatternNumber = 42;
132 Pattern[28].PatternString = "FullyCharged";
133 Pattern[29].PatternNumber = 44;
134 Pattern[29].PatternString = "LowBattery";
135 Pattern[30].PatternNumber = 46;
136 Pattern[30].PatternString = "Lock";
137 Pattern[31].PatternNumber = 47;
138 Pattern[31].PatternString = "UnLock";
139 Pattern[32].PatternNumber = 55;
140 Pattern[32].PatternString = "VibrationModeAbled";
141 Pattern[33].PatternNumber = 56;
142 Pattern[33].PatternString = "SilentModeDisabled";
143 Pattern[34].PatternNumber = 57;
144 Pattern[34].PatternString = "BluetoothDeviceConnected";
145 Pattern[35].PatternNumber = 58;
146 Pattern[35].PatternString = "BluetoothDeviceDisconnected";
147 Pattern[36].PatternNumber = 62;
148 Pattern[36].PatternString = "ListReorder";
149 Pattern[37].PatternNumber = 63;
150 Pattern[37].PatternString = "ListSlider";
151 Pattern[38].PatternNumber = 64;
152 Pattern[38].PatternString = "VolumeKeyPressed";
154 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Initialize();
155 if (res != Interop.Feedback.FeedbackError.None)
157 Log.Warn(LogTag, string.Format("Failed to initialize feedback. err = {0}", res));
160 case Interop.Feedback.FeedbackError.NotSupported:
161 throw new NotSupportedException("Device is not supported");
163 throw new InvalidOperationException("Failed to initialize");
170 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Deinitialize();
171 if (res != Interop.Feedback.FeedbackError.None)
173 Log.Warn(LogTag, string.Format("Failed to deinitialize feedback. err = {0}", res));
176 case Interop.Feedback.FeedbackError.NotInitialized:
177 throw new Exception("Not initialized");
179 throw new InvalidOperationException("Failed to initialize");
185 /// Get supported information about specific type and pattern
188 /// Now, IsSupportedPattern is not working for FeedbackType.All.
189 /// This API is working for FeedbackType.Sound and FeedbackType.Vibration only.
190 /// If you use FeedbackType.All for type parameter, this API will throw ArgumentException.
191 /// To get supported information for Vibration type, app should have http://tizen.org/privilege/haptic privilege.
193 /// <param name="type">Feedback type</param>
194 /// <param name="pattern">Feedback pattern string</param>
195 /// <returns>Information whether pattern is supported</returns>
196 /// <exception cref="Exception">Thrown when failed because feedback is not initialized</exception>
197 /// <exception cref="ArgumentException">Thrown when failed because of a invalid arguament</exception>
198 /// <exception cref="NotSupportedException">Thrown when failed becuase device(haptic, sound) is not supported</exception>
199 /// <exception cref="UnauthorizedAccessException">Thrown when failed because access is not granted(No privilege)</exception>
200 /// <exception cref="InvalidOperationException">Thrown when failed because of system error</exception>
201 /// <privilege>http://tizen.org/privilege/haptic</privilege>
204 /// Feedback feedback = new Feedback();
205 /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
208 public bool IsSupportedPattern(FeedbackType type, String pattern)
210 bool supported = false;
213 Interop.Feedback.FeedbackError res;
215 for (i = 0; i < Constants.NumberOfPattern; i++)
217 if (String.Compare(pattern, Pattern[i].PatternString) == 0)
225 throw new ArgumentException("Invalid Arguments");
227 res = (Interop.Feedback.FeedbackError)Interop.Feedback.IsSupportedPattern((Interop.Feedback.FeedbackType)type, Pattern[i].PatternNumber, out supported);
230 if (res != Interop.Feedback.FeedbackError.None)
232 Log.Warn(LogTag, string.Format("Failed to get supported information. err = {0}", res));
235 case Interop.Feedback.FeedbackError.NotInitialized:
236 throw new Exception("Not initialized");
237 case Interop.Feedback.FeedbackError.InvalidParameter:
238 throw new ArgumentException("Invalid Arguments");
239 case Interop.Feedback.FeedbackError.NotSupported:
240 throw new NotSupportedException("Device is not supported");
241 case Interop.Feedback.FeedbackError.PermissionDenied:
242 throw new UnauthorizedAccessException("Access is not granted");
243 case Interop.Feedback.FeedbackError.OperationFailed:
245 throw new InvalidOperationException("Failed to get supported information");
252 /// Play specific feedback pattern
255 /// To play Vibration type, app should have http://tizen.org/privilege/haptic privilege.
257 /// <param name="type">Feedback type</param>
258 /// <param name="pattern">Feedback pattern string</param>
259 /// <exception cref="Exception">Thrown when failed because feedback is not initialized</exception>
260 /// <exception cref="ArgumentException">Thrown when failed because of a invalid arguament</exception>
261 /// <exception cref="NotSupportedException">Thrown when failed because device(haptic, sound) or specific pattern is not supported</exception>
262 /// <exception cref="UnauthorizedAccessException">Thrown when failed because access is not granted(No privilege)</exception>
263 /// <exception cref="InvalidOperationException">Thrown when failed because of system error</exception>
264 /// <privilege>http://tizen.org/privilege/haptic</privilege>
267 /// Feedback feedback = new Feedback();
268 /// feedback.Play(FeedbackType.All, "Tap");
271 public void Play(FeedbackType type, String pattern)
275 Interop.Feedback.FeedbackError res;
277 for (i = 0; i < Constants.NumberOfPattern; i++)
279 if (String.Compare(pattern, Pattern[i].PatternString) == 0)
287 throw new ArgumentException("Invalid Arguments");
289 if (type == FeedbackType.All)
290 res = (Interop.Feedback.FeedbackError)Interop.Feedback.Play(Pattern[i].PatternNumber);
292 res = (Interop.Feedback.FeedbackError)Interop.Feedback.PlayType((Interop.Feedback.FeedbackType)type, Pattern[i].PatternNumber);
294 if (res != Interop.Feedback.FeedbackError.None)
296 Log.Warn(LogTag, string.Format("Failed to play feedback. err = {0}", res));
299 case Interop.Feedback.FeedbackError.NotInitialized:
300 throw new Exception("Not initialized");
301 case Interop.Feedback.FeedbackError.InvalidParameter:
302 throw new ArgumentException("Invalid Arguments");
303 case Interop.Feedback.FeedbackError.NotSupported:
304 throw new NotSupportedException("Not supported");
305 case Interop.Feedback.FeedbackError.PermissionDenied:
306 throw new UnauthorizedAccessException("Access is not granted");
307 case Interop.Feedback.FeedbackError.OperationFailed:
309 throw new InvalidOperationException("Failed to play pattern");
315 /// Stop to play feedback
318 /// To stop vibration, app should have http://tizen.org/privilege/haptic privilege.
320 /// <exception cref="Exception">Thrown when failed because feedback is not initialized</exception>
321 /// <exception cref="ArgumentException">Thrown when failed because of a invalid arguament</exception>
322 /// <exception cref="NotSupportedException">Thrown when failed because device(haptic, sound) or specific pattern is not supported</exception>
323 /// <exception cref="UnauthorizedAccessException">Thrown when failed because access is not granted(No privilege)</exception>
324 /// <exception cref="InvalidOperationException">Thrown when failed because of system error</exception>
325 /// <privilege>http://tizen.org/privilege/haptic</privilege>
328 /// Feedback Feedback1 = new Feedback();
329 /// Feedback1.Stop();
334 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Stop();
336 if (res != Interop.Feedback.FeedbackError.None)
338 Log.Warn(LogTag, string.Format("Failed to stop feedback. err = {0}", res));
341 case Interop.Feedback.FeedbackError.NotInitialized:
342 throw new Exception("Not initialized");
343 case Interop.Feedback.FeedbackError.InvalidParameter:
344 throw new ArgumentException("Invalid Arguments");
345 case Interop.Feedback.FeedbackError.NotSupported:
346 throw new NotSupportedException("Not supported");
347 case Interop.Feedback.FeedbackError.PermissionDenied:
348 throw new UnauthorizedAccessException("Access is not granted");
349 case Interop.Feedback.FeedbackError.OperationFailed:
351 throw new InvalidOperationException("Failed to play pattern");