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;
21 namespace Tizen.System
24 /// The class for constants.
26 internal static class Constants
28 internal const int NumberOfPattern = 39;
32 /// The Feedback API provides functions to control haptic and sound.
33 /// The Feedback API provides the way to play and stop feedback, and get the information whether a specific pattern is supported.
34 /// Below is the supported pattern string:
51 /// HardwareKeyPressed
67 /// VibrationModeAbled
68 /// SilentModeDisabled
69 /// BluetoothDeviceConnected
70 /// BluetoothDeviceDisconnected
76 /// For controlling the haptic device:
77 /// http://tizen.org/privilege/haptic
78 /// For controlling the sound, privilege is not needed.
82 /// Feedback feedback = new Feedback();
83 /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
86 /// <since_tizen> 3 </since_tizen>
89 private const string LogTag = "Tizen.System.Feedback";
91 private readonly FeedbackPattern[] Pattern = new FeedbackPattern[39];
94 /// Constructor of Feedback class
96 /// <since_tizen> 3 </since_tizen>
98 /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
100 /// <exception cref="NotSupportedException">Thrown when failed because the devices (vibration and sound) are not supported.</exception>
101 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
102 /// <privilege>http://tizen.org/privilege/haptic</privilege>
105 /// Feedback feedback = new Feedback();
110 Pattern[0].PatternNumber = 0;
111 Pattern[0].PatternString = "Tap";
112 Pattern[1].PatternNumber = 1;
113 Pattern[1].PatternString = "SoftInputPanel";
114 Pattern[2].PatternNumber = 6;
115 Pattern[2].PatternString = "Key0";
116 Pattern[3].PatternNumber = 7;
117 Pattern[3].PatternString = "Key1";
118 Pattern[4].PatternNumber = 8;
119 Pattern[4].PatternString = "Key2";
120 Pattern[5].PatternNumber = 9;
121 Pattern[5].PatternString = "Key3";
122 Pattern[6].PatternNumber = 10;
123 Pattern[6].PatternString = "Key4";
124 Pattern[7].PatternNumber = 11;
125 Pattern[7].PatternString = "Key5";
126 Pattern[8].PatternNumber = 12;
127 Pattern[8].PatternString = "Key6";
128 Pattern[9].PatternNumber = 13;
129 Pattern[9].PatternString = "Key7";
130 Pattern[10].PatternNumber = 14;
131 Pattern[10].PatternString = "Key8";
132 Pattern[11].PatternNumber = 15;
133 Pattern[11].PatternString = "Key9";
134 Pattern[12].PatternNumber = 16;
135 Pattern[12].PatternString = "KeyStar";
136 Pattern[13].PatternNumber = 17;
137 Pattern[13].PatternString = "KeySharp";
138 Pattern[14].PatternNumber = 18;
139 Pattern[14].PatternString = "KeyBack";
140 Pattern[15].PatternNumber = 19;
141 Pattern[15].PatternString = "Hold";
142 Pattern[16].PatternNumber = 21;
143 Pattern[16].PatternString = "HardwareKeyPressed";
144 Pattern[17].PatternNumber = 22;
145 Pattern[17].PatternString = "HardwareKeyHold";
146 Pattern[18].PatternNumber = 23;
147 Pattern[18].PatternString = "Message";
148 Pattern[19].PatternNumber = 25;
149 Pattern[19].PatternString = "Email";
150 Pattern[20].PatternNumber = 27;
151 Pattern[20].PatternString = "WakeUp";
152 Pattern[21].PatternNumber = 29;
153 Pattern[21].PatternString = "Schedule";
154 Pattern[22].PatternNumber = 31;
155 Pattern[22].PatternString = "Timer";
156 Pattern[23].PatternNumber = 33;
157 Pattern[23].PatternString = "General";
158 Pattern[24].PatternNumber = 36;
159 Pattern[24].PatternString = "PowerOn";
160 Pattern[25].PatternNumber = 37;
161 Pattern[25].PatternString = "PowerOff";
162 Pattern[26].PatternNumber = 38;
163 Pattern[26].PatternString = "ChargerConnected";
164 Pattern[27].PatternNumber = 40;
165 Pattern[27].PatternString = "ChargingError";
166 Pattern[28].PatternNumber = 42;
167 Pattern[28].PatternString = "FullyCharged";
168 Pattern[29].PatternNumber = 44;
169 Pattern[29].PatternString = "LowBattery";
170 Pattern[30].PatternNumber = 46;
171 Pattern[30].PatternString = "Lock";
172 Pattern[31].PatternNumber = 47;
173 Pattern[31].PatternString = "UnLock";
174 Pattern[32].PatternNumber = 55;
175 Pattern[32].PatternString = "VibrationModeAbled";
176 Pattern[33].PatternNumber = 56;
177 Pattern[33].PatternString = "SilentModeDisabled";
178 Pattern[34].PatternNumber = 57;
179 Pattern[34].PatternString = "BluetoothDeviceConnected";
180 Pattern[35].PatternNumber = 58;
181 Pattern[35].PatternString = "BluetoothDeviceDisconnected";
182 Pattern[36].PatternNumber = 62;
183 Pattern[36].PatternString = "ListReorder";
184 Pattern[37].PatternNumber = 63;
185 Pattern[37].PatternString = "ListSlider";
186 Pattern[38].PatternNumber = 64;
187 Pattern[38].PatternString = "VolumeKeyPressed";
189 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Initialize();
190 if (res != Interop.Feedback.FeedbackError.None)
192 Log.Warn(LogTag, string.Format("Failed to initialize feedback. err = {0}", res));
195 case Interop.Feedback.FeedbackError.NotSupported:
196 throw new NotSupportedException("Device is not supported");
198 throw new InvalidOperationException("Failed to initialize");
204 /// Finalizes an instance of the Feedback class.
208 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Deinitialize();
209 if (res != Interop.Feedback.FeedbackError.None)
211 Log.Warn(LogTag, string.Format("Failed to deinitialize feedback. err = {0}", res));
214 case Interop.Feedback.FeedbackError.NotInitialized:
215 throw new Exception("Not initialized");
217 throw new InvalidOperationException("Failed to initialize");
223 /// Gets the supported information about a specific type and pattern.
226 /// Now, IsSupportedPattern is not working for FeedbackType.All.
227 /// This API is working for FeedbackType.Sound and FeedbackType.Vibration only.
228 /// If you use FeedbackType.All for type parameter, this API will throw ArgumentException.
229 /// To get the supported information for Vibration type, the application should have http://tizen.org/privilege/haptic privilege.
231 /// <since_tizen> 3 </since_tizen>
232 /// <param name="type">The feedback type.</param>
233 /// <param name="pattern">The feedback pattern string.</param>
235 /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
237 /// <returns>Information whether a pattern is supported.</returns>
238 /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
239 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
240 /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
241 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
242 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
243 /// <privilege>http://tizen.org/privilege/haptic</privilege>
246 /// Feedback feedback = new Feedback();
247 /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
250 public bool IsSupportedPattern(FeedbackType type, String pattern)
252 bool supported = false;
255 Interop.Feedback.FeedbackError res;
257 for (i = 0; i < Constants.NumberOfPattern; i++)
259 if (String.Compare(pattern, Pattern[i].PatternString) == 0)
267 throw new ArgumentException("Invalid Arguments");
269 res = (Interop.Feedback.FeedbackError)Interop.Feedback.IsSupportedPattern((Interop.Feedback.FeedbackType)type, Pattern[i].PatternNumber, out supported);
272 if (res != Interop.Feedback.FeedbackError.None)
274 Log.Warn(LogTag, string.Format("Failed to get supported information. err = {0}", res));
277 case Interop.Feedback.FeedbackError.NotInitialized:
278 throw new Exception("Not initialized");
279 case Interop.Feedback.FeedbackError.InvalidParameter:
280 throw new ArgumentException("Invalid Arguments");
281 case Interop.Feedback.FeedbackError.NotSupported:
282 throw new NotSupportedException("Device is not supported");
283 case Interop.Feedback.FeedbackError.PermissionDenied:
284 throw new UnauthorizedAccessException("Access is not granted");
285 case Interop.Feedback.FeedbackError.OperationFailed:
287 throw new InvalidOperationException("Failed to get supported information");
294 /// Plays a specific feedback pattern.
297 /// To play Vibration type, app should have http://tizen.org/privilege/haptic privilege.
299 /// <since_tizen> 3 </since_tizen>
300 /// <param name="type">The feedback type.</param>
301 /// <param name="pattern">The feedback pattern string.</param>
303 /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
305 /// <exception cref="Exception">Thrown when failed because feedback is not initialized.</exception>
306 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
307 /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
308 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted(No privilege)</exception>
309 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
310 /// <privilege>http://tizen.org/privilege/haptic</privilege>
313 /// Feedback feedback = new Feedback();
314 /// feedback.Play(FeedbackType.All, "Tap");
317 public void Play(FeedbackType type, String pattern)
321 Interop.Feedback.FeedbackError res;
323 for (i = 0; i < Constants.NumberOfPattern; i++)
325 if (String.Compare(pattern, Pattern[i].PatternString) == 0)
333 throw new ArgumentException("Invalid Arguments");
335 if (type == FeedbackType.All)
336 res = (Interop.Feedback.FeedbackError)Interop.Feedback.Play(Pattern[i].PatternNumber);
338 res = (Interop.Feedback.FeedbackError)Interop.Feedback.PlayType((Interop.Feedback.FeedbackType)type, Pattern[i].PatternNumber);
340 if (res != Interop.Feedback.FeedbackError.None)
342 Log.Warn(LogTag, string.Format("Failed to play feedback. err = {0}", res));
345 case Interop.Feedback.FeedbackError.NotInitialized:
346 throw new Exception("Not initialized");
347 case Interop.Feedback.FeedbackError.InvalidParameter:
348 throw new ArgumentException("Invalid Arguments");
349 case Interop.Feedback.FeedbackError.NotSupported:
350 throw new NotSupportedException("Not supported");
351 case Interop.Feedback.FeedbackError.PermissionDenied:
352 throw new UnauthorizedAccessException("Access is not granted");
353 case Interop.Feedback.FeedbackError.OperationFailed:
355 throw new InvalidOperationException("Failed to play pattern");
361 /// Stops to play the feedback.
364 /// To stop vibration, the application should have http://tizen.org/privilege/haptic privilege.
366 /// <since_tizen> 3 </since_tizen>
368 /// http://tizen.org/feature/feedback.vibration
370 /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
371 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament</exception>
372 /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
373 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
374 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
375 /// <privilege>http://tizen.org/privilege/haptic</privilege>
378 /// Feedback Feedback1 = new Feedback();
379 /// Feedback1.Stop();
384 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Stop();
386 if (res != Interop.Feedback.FeedbackError.None)
388 Log.Warn(LogTag, string.Format("Failed to stop feedback. err = {0}", res));
391 case Interop.Feedback.FeedbackError.NotInitialized:
392 throw new Exception("Not initialized");
393 case Interop.Feedback.FeedbackError.InvalidParameter:
394 throw new ArgumentException("Invalid Arguments");
395 case Interop.Feedback.FeedbackError.NotSupported:
396 throw new NotSupportedException("Not supported");
397 case Interop.Feedback.FeedbackError.PermissionDenied:
398 throw new UnauthorizedAccessException("Access is not granted");
399 case Interop.Feedback.FeedbackError.OperationFailed:
401 throw new InvalidOperationException("Failed to stop pattern");