2 * Copyright (c) 2016 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>
97 /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
98 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
99 /// <privilege>http://tizen.org/privilege/haptic</privilege>
102 /// Feedback feedback = new Feedback();
107 Pattern[0].PatternNumber = 0;
108 Pattern[0].PatternString = "Tap";
109 Pattern[1].PatternNumber = 1;
110 Pattern[1].PatternString = "SoftInputPanel";
111 Pattern[2].PatternNumber = 6;
112 Pattern[2].PatternString = "Key0";
113 Pattern[3].PatternNumber = 7;
114 Pattern[3].PatternString = "Key1";
115 Pattern[4].PatternNumber = 8;
116 Pattern[4].PatternString = "Key2";
117 Pattern[5].PatternNumber = 9;
118 Pattern[5].PatternString = "Key3";
119 Pattern[6].PatternNumber = 10;
120 Pattern[6].PatternString = "Key4";
121 Pattern[7].PatternNumber = 11;
122 Pattern[7].PatternString = "Key5";
123 Pattern[8].PatternNumber = 12;
124 Pattern[8].PatternString = "Key6";
125 Pattern[9].PatternNumber = 13;
126 Pattern[9].PatternString = "Key7";
127 Pattern[10].PatternNumber = 14;
128 Pattern[10].PatternString = "Key8";
129 Pattern[11].PatternNumber = 15;
130 Pattern[11].PatternString = "Key9";
131 Pattern[12].PatternNumber = 16;
132 Pattern[12].PatternString = "KeyStar";
133 Pattern[13].PatternNumber = 17;
134 Pattern[13].PatternString = "KeySharp";
135 Pattern[14].PatternNumber = 18;
136 Pattern[14].PatternString = "KeyBack";
137 Pattern[15].PatternNumber = 19;
138 Pattern[15].PatternString = "Hold";
139 Pattern[16].PatternNumber = 21;
140 Pattern[16].PatternString = "HardwareKeyPressed";
141 Pattern[17].PatternNumber = 22;
142 Pattern[17].PatternString = "HardwareKeyHold";
143 Pattern[18].PatternNumber = 23;
144 Pattern[18].PatternString = "Message";
145 Pattern[19].PatternNumber = 25;
146 Pattern[19].PatternString = "Email";
147 Pattern[20].PatternNumber = 27;
148 Pattern[20].PatternString = "WakeUp";
149 Pattern[21].PatternNumber = 29;
150 Pattern[21].PatternString = "Schedule";
151 Pattern[22].PatternNumber = 31;
152 Pattern[22].PatternString = "Timer";
153 Pattern[23].PatternNumber = 33;
154 Pattern[23].PatternString = "General";
155 Pattern[24].PatternNumber = 36;
156 Pattern[24].PatternString = "PowerOn";
157 Pattern[25].PatternNumber = 37;
158 Pattern[25].PatternString = "PowerOff";
159 Pattern[26].PatternNumber = 38;
160 Pattern[26].PatternString = "ChargerConnected";
161 Pattern[27].PatternNumber = 40;
162 Pattern[27].PatternString = "ChargingError";
163 Pattern[28].PatternNumber = 42;
164 Pattern[28].PatternString = "FullyCharged";
165 Pattern[29].PatternNumber = 44;
166 Pattern[29].PatternString = "LowBattery";
167 Pattern[30].PatternNumber = 46;
168 Pattern[30].PatternString = "Lock";
169 Pattern[31].PatternNumber = 47;
170 Pattern[31].PatternString = "UnLock";
171 Pattern[32].PatternNumber = 55;
172 Pattern[32].PatternString = "VibrationModeAbled";
173 Pattern[33].PatternNumber = 56;
174 Pattern[33].PatternString = "SilentModeDisabled";
175 Pattern[34].PatternNumber = 57;
176 Pattern[34].PatternString = "BluetoothDeviceConnected";
177 Pattern[35].PatternNumber = 58;
178 Pattern[35].PatternString = "BluetoothDeviceDisconnected";
179 Pattern[36].PatternNumber = 62;
180 Pattern[36].PatternString = "ListReorder";
181 Pattern[37].PatternNumber = 63;
182 Pattern[37].PatternString = "ListSlider";
183 Pattern[38].PatternNumber = 64;
184 Pattern[38].PatternString = "VolumeKeyPressed";
186 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Initialize();
187 if (res != Interop.Feedback.FeedbackError.None)
189 Log.Warn(LogTag, string.Format("Failed to initialize feedback. err = {0}", res));
192 case Interop.Feedback.FeedbackError.NotSupported:
193 throw new NotSupportedException("Device is not supported");
195 throw new InvalidOperationException("Failed to initialize");
201 /// Finalizes an instance of the Feedback class.
205 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Deinitialize();
206 if (res != Interop.Feedback.FeedbackError.None)
208 Log.Warn(LogTag, string.Format("Failed to deinitialize feedback. err = {0}", res));
211 case Interop.Feedback.FeedbackError.NotInitialized:
212 throw new Exception("Not initialized");
214 throw new InvalidOperationException("Failed to initialize");
220 /// Gets the supported information about a specific type and pattern.
223 /// Now, IsSupportedPattern is not working for FeedbackType.All.
224 /// This API is working for FeedbackType.Sound and FeedbackType.Vibration only.
225 /// If you use FeedbackType.All for type parameter, this API will throw ArgumentException.
226 /// To get the supported information for Vibration type, the application should have http://tizen.org/privilege/haptic privilege.
228 /// <since_tizen> 3 </since_tizen>
229 /// <param name="type">The feedback type.</param>
230 /// <param name="pattern">The feedback pattern string.</param>
231 /// <returns>Information whether a pattern is supported.</returns>
232 /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
233 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
234 /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
235 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
236 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
237 /// <privilege>http://tizen.org/privilege/haptic</privilege>
240 /// Feedback feedback = new Feedback();
241 /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
244 public bool IsSupportedPattern(FeedbackType type, String pattern)
246 bool supported = false;
249 Interop.Feedback.FeedbackError res;
251 for (i = 0; i < Constants.NumberOfPattern; i++)
253 if (String.Compare(pattern, Pattern[i].PatternString) == 0)
261 throw new ArgumentException("Invalid Arguments");
263 res = (Interop.Feedback.FeedbackError)Interop.Feedback.IsSupportedPattern((Interop.Feedback.FeedbackType)type, Pattern[i].PatternNumber, out supported);
266 if (res != Interop.Feedback.FeedbackError.None)
268 Log.Warn(LogTag, string.Format("Failed to get supported information. err = {0}", res));
271 case Interop.Feedback.FeedbackError.NotInitialized:
272 throw new Exception("Not initialized");
273 case Interop.Feedback.FeedbackError.InvalidParameter:
274 throw new ArgumentException("Invalid Arguments");
275 case Interop.Feedback.FeedbackError.NotSupported:
276 throw new NotSupportedException("Device is not supported");
277 case Interop.Feedback.FeedbackError.PermissionDenied:
278 throw new UnauthorizedAccessException("Access is not granted");
279 case Interop.Feedback.FeedbackError.OperationFailed:
281 throw new InvalidOperationException("Failed to get supported information");
288 /// Plays a specific feedback pattern.
291 /// To play Vibration type, app should have http://tizen.org/privilege/haptic privilege.
293 /// <since_tizen> 3 </since_tizen>
294 /// <param name="type">The feedback type.</param>
295 /// <param name="pattern">The feedback pattern string.</param>
296 /// <exception cref="Exception">Thrown when failed because feedback is not initialized.</exception>
297 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
298 /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
299 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted(No privilege)</exception>
300 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
301 /// <privilege>http://tizen.org/privilege/haptic</privilege>
304 /// Feedback feedback = new Feedback();
305 /// feedback.Play(FeedbackType.All, "Tap");
308 public void Play(FeedbackType type, String pattern)
312 Interop.Feedback.FeedbackError res;
314 for (i = 0; i < Constants.NumberOfPattern; i++)
316 if (String.Compare(pattern, Pattern[i].PatternString) == 0)
324 throw new ArgumentException("Invalid Arguments");
326 if (type == FeedbackType.All)
327 res = (Interop.Feedback.FeedbackError)Interop.Feedback.Play(Pattern[i].PatternNumber);
329 res = (Interop.Feedback.FeedbackError)Interop.Feedback.PlayType((Interop.Feedback.FeedbackType)type, Pattern[i].PatternNumber);
331 if (res != Interop.Feedback.FeedbackError.None)
333 Log.Warn(LogTag, string.Format("Failed to play feedback. err = {0}", res));
336 case Interop.Feedback.FeedbackError.NotInitialized:
337 throw new Exception("Not initialized");
338 case Interop.Feedback.FeedbackError.InvalidParameter:
339 throw new ArgumentException("Invalid Arguments");
340 case Interop.Feedback.FeedbackError.NotSupported:
341 throw new NotSupportedException("Not supported");
342 case Interop.Feedback.FeedbackError.PermissionDenied:
343 throw new UnauthorizedAccessException("Access is not granted");
344 case Interop.Feedback.FeedbackError.OperationFailed:
346 throw new InvalidOperationException("Failed to play pattern");
352 /// Stops to play the feedback.
355 /// To stop vibration, the application should have http://tizen.org/privilege/haptic privilege.
357 /// <since_tizen> 3 </since_tizen>
358 /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
359 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament</exception>
360 /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
361 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
362 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
363 /// <privilege>http://tizen.org/privilege/haptic</privilege>
366 /// Feedback Feedback1 = new Feedback();
367 /// Feedback1.Stop();
372 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Stop();
374 if (res != Interop.Feedback.FeedbackError.None)
376 Log.Warn(LogTag, string.Format("Failed to stop feedback. err = {0}", res));
379 case Interop.Feedback.FeedbackError.NotInitialized:
380 throw new Exception("Not initialized");
381 case Interop.Feedback.FeedbackError.InvalidParameter:
382 throw new ArgumentException("Invalid Arguments");
383 case Interop.Feedback.FeedbackError.NotSupported:
384 throw new NotSupportedException("Not supported");
385 case Interop.Feedback.FeedbackError.PermissionDenied:
386 throw new UnauthorizedAccessException("Access is not granted");
387 case Interop.Feedback.FeedbackError.OperationFailed:
389 throw new InvalidOperationException("Failed to stop pattern");