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 /// 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 specific pattern is supported.
34 /// Below is supported pattern string.
51 /// HardwareKeyPressed
67 /// VibrationModeAbled
68 /// SilentModeDisabled
69 /// BluetoothDeviceConnected
70 /// BluetoothDeviceDisconnected
76 /// For controlling haptic device:
77 /// http://tizen.org/privilege/haptic
78 /// For controlling sound, previlege is not needed.
81 /// Feedback feedback = new Feedback();
82 /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
86 private const string LogTag = "Tizen.System.Feedback";
88 private readonly FeedbackPattern[] Pattern = new FeedbackPattern[39];
91 Pattern[0].PatternNumber = 0;
92 Pattern[0].PatternString = "Tap";
93 Pattern[1].PatternNumber = 1;
94 Pattern[1].PatternString = "SoftInputPanel";
95 Pattern[2].PatternNumber = 6;
96 Pattern[2].PatternString = "Key0";
97 Pattern[3].PatternNumber = 7;
98 Pattern[3].PatternString = "Key1";
99 Pattern[4].PatternNumber = 8;
100 Pattern[4].PatternString = "Key2";
101 Pattern[5].PatternNumber = 9;
102 Pattern[5].PatternString = "Key3";
103 Pattern[6].PatternNumber = 10;
104 Pattern[6].PatternString = "Key4";
105 Pattern[7].PatternNumber = 11;
106 Pattern[7].PatternString = "Key5";
107 Pattern[8].PatternNumber = 12;
108 Pattern[8].PatternString = "Key6";
109 Pattern[9].PatternNumber = 13;
110 Pattern[9].PatternString = "Key7";
111 Pattern[10].PatternNumber = 14;
112 Pattern[10].PatternString = "Key8";
113 Pattern[11].PatternNumber = 15;
114 Pattern[11].PatternString = "Key9";
115 Pattern[12].PatternNumber = 16;
116 Pattern[12].PatternString = "KeyStar";
117 Pattern[13].PatternNumber = 17;
118 Pattern[13].PatternString = "KeySharp";
119 Pattern[14].PatternNumber = 18;
120 Pattern[14].PatternString = "KeyBack";
121 Pattern[15].PatternNumber = 19;
122 Pattern[15].PatternString = "Hold";
123 Pattern[16].PatternNumber = 21;
124 Pattern[16].PatternString = "HardwareKeyPressed";
125 Pattern[17].PatternNumber = 22;
126 Pattern[17].PatternString = "HardwareKeyHold";
127 Pattern[18].PatternNumber = 23;
128 Pattern[18].PatternString = "Message";
129 Pattern[19].PatternNumber = 25;
130 Pattern[19].PatternString = "Email";
131 Pattern[20].PatternNumber = 27;
132 Pattern[20].PatternString = "WakeUp";
133 Pattern[21].PatternNumber = 29;
134 Pattern[21].PatternString = "Schedule";
135 Pattern[22].PatternNumber = 31;
136 Pattern[22].PatternString = "Timer";
137 Pattern[23].PatternNumber = 33;
138 Pattern[23].PatternString = "General";
139 Pattern[24].PatternNumber = 36;
140 Pattern[24].PatternString = "PowerOn";
141 Pattern[25].PatternNumber = 37;
142 Pattern[25].PatternString = "PowerOff";
143 Pattern[26].PatternNumber = 38;
144 Pattern[26].PatternString = "ChargerConnected";
145 Pattern[27].PatternNumber = 40;
146 Pattern[27].PatternString = "ChargingError";
147 Pattern[28].PatternNumber = 42;
148 Pattern[28].PatternString = "FullyCharged";
149 Pattern[29].PatternNumber = 44;
150 Pattern[29].PatternString = "LowBattery";
151 Pattern[30].PatternNumber = 46;
152 Pattern[30].PatternString = "Lock";
153 Pattern[31].PatternNumber = 47;
154 Pattern[31].PatternString = "UnLock";
155 Pattern[32].PatternNumber = 55;
156 Pattern[32].PatternString = "VibrationModeAbled";
157 Pattern[33].PatternNumber = 56;
158 Pattern[33].PatternString = "SilentModeDisabled";
159 Pattern[34].PatternNumber = 57;
160 Pattern[34].PatternString = "BluetoothDeviceConnected";
161 Pattern[35].PatternNumber = 58;
162 Pattern[35].PatternString = "BluetoothDeviceDisconnected";
163 Pattern[36].PatternNumber = 62;
164 Pattern[36].PatternString = "ListReorder";
165 Pattern[37].PatternNumber = 63;
166 Pattern[37].PatternString = "ListSlider";
167 Pattern[38].PatternNumber = 64;
168 Pattern[38].PatternString = "VolumeKeyPressed";
170 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Initialize();
171 if (res != Interop.Feedback.FeedbackError.None)
173 Log.Warn(LogTag, string.Format("Failed to initialize feedback. err = {0}", res));
176 case Interop.Feedback.FeedbackError.NotSupported:
177 throw new NotSupportedException("Device is not supported");
179 throw new InvalidOperationException("Failed to initialize");
186 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Deinitialize();
187 if (res != Interop.Feedback.FeedbackError.None)
189 Log.Warn(LogTag, string.Format("Failed to deinitialize feedback. err = {0}", res));
192 case Interop.Feedback.FeedbackError.NotInitialized:
193 throw new Exception("Not initialized");
195 throw new InvalidOperationException("Failed to initialize");
201 /// Get supported information about specific type and pattern
204 /// Now, IsSupportedPattern is not working for FeedbackType.All.
205 /// This API is working for FeedbackType.Sound and FeedbackType.Vibration only.
206 /// If you use FeedbackType.All for type parameter, this API will throw ArgumentException.
207 /// To get supported information for Vibration type, app should have http://tizen.org/privilege/haptic privilege.
209 /// <since_tizen> 3 </since_tizen>
210 /// <param name="type">Feedback type</param>
211 /// <param name="pattern">Feedback pattern string</param>
212 /// <returns>Information whether pattern is supported</returns>
213 /// <exception cref="Exception">Thrown when failed because feedback is not initialized</exception>
214 /// <exception cref="ArgumentException">Thrown when failed because of a invalid arguament</exception>
215 /// <exception cref="NotSupportedException">Thrown when failed becuase device(haptic, sound) is not supported</exception>
216 /// <exception cref="UnauthorizedAccessException">Thrown when failed because access is not granted(No privilege)</exception>
217 /// <exception cref="InvalidOperationException">Thrown when failed because of system error</exception>
218 /// <privilege>http://tizen.org/privilege/haptic</privilege>
221 /// Feedback feedback = new Feedback();
222 /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
225 public bool IsSupportedPattern(FeedbackType type, String pattern)
227 bool supported = false;
230 Interop.Feedback.FeedbackError res;
232 for (i = 0; i < Constants.NumberOfPattern; i++)
234 if (String.Compare(pattern, Pattern[i].PatternString) == 0)
242 throw new ArgumentException("Invalid Arguments");
244 res = (Interop.Feedback.FeedbackError)Interop.Feedback.IsSupportedPattern((Interop.Feedback.FeedbackType)type, Pattern[i].PatternNumber, out supported);
247 if (res != Interop.Feedback.FeedbackError.None)
249 Log.Warn(LogTag, string.Format("Failed to get supported information. err = {0}", res));
252 case Interop.Feedback.FeedbackError.NotInitialized:
253 throw new Exception("Not initialized");
254 case Interop.Feedback.FeedbackError.InvalidParameter:
255 throw new ArgumentException("Invalid Arguments");
256 case Interop.Feedback.FeedbackError.NotSupported:
257 throw new NotSupportedException("Device is not supported");
258 case Interop.Feedback.FeedbackError.PermissionDenied:
259 throw new UnauthorizedAccessException("Access is not granted");
260 case Interop.Feedback.FeedbackError.OperationFailed:
262 throw new InvalidOperationException("Failed to get supported information");
269 /// Play specific feedback pattern
272 /// To play Vibration type, app should have http://tizen.org/privilege/haptic privilege.
274 /// <since_tizen> 3 </since_tizen>
275 /// <param name="type">Feedback type</param>
276 /// <param name="pattern">Feedback pattern string</param>
277 /// <exception cref="Exception">Thrown when failed because feedback is not initialized</exception>
278 /// <exception cref="ArgumentException">Thrown when failed because of a invalid arguament</exception>
279 /// <exception cref="NotSupportedException">Thrown when failed because device(haptic, sound) or specific pattern is not supported</exception>
280 /// <exception cref="UnauthorizedAccessException">Thrown when failed because access is not granted(No privilege)</exception>
281 /// <exception cref="InvalidOperationException">Thrown when failed because of system error</exception>
282 /// <privilege>http://tizen.org/privilege/haptic</privilege>
285 /// Feedback feedback = new Feedback();
286 /// feedback.Play(FeedbackType.All, "Tap");
289 public void Play(FeedbackType type, String pattern)
293 Interop.Feedback.FeedbackError res;
295 for (i = 0; i < Constants.NumberOfPattern; i++)
297 if (String.Compare(pattern, Pattern[i].PatternString) == 0)
305 throw new ArgumentException("Invalid Arguments");
307 if (type == FeedbackType.All)
308 res = (Interop.Feedback.FeedbackError)Interop.Feedback.Play(Pattern[i].PatternNumber);
310 res = (Interop.Feedback.FeedbackError)Interop.Feedback.PlayType((Interop.Feedback.FeedbackType)type, Pattern[i].PatternNumber);
312 if (res != Interop.Feedback.FeedbackError.None)
314 Log.Warn(LogTag, string.Format("Failed to play feedback. err = {0}", res));
317 case Interop.Feedback.FeedbackError.NotInitialized:
318 throw new Exception("Not initialized");
319 case Interop.Feedback.FeedbackError.InvalidParameter:
320 throw new ArgumentException("Invalid Arguments");
321 case Interop.Feedback.FeedbackError.NotSupported:
322 throw new NotSupportedException("Not supported");
323 case Interop.Feedback.FeedbackError.PermissionDenied:
324 throw new UnauthorizedAccessException("Access is not granted");
325 case Interop.Feedback.FeedbackError.OperationFailed:
327 throw new InvalidOperationException("Failed to play pattern");
333 /// Stop to play feedback
336 /// To stop vibration, app should have http://tizen.org/privilege/haptic privilege.
338 /// <since_tizen> 3 </since_tizen>
339 /// <exception cref="Exception">Thrown when failed because feedback is not initialized</exception>
340 /// <exception cref="ArgumentException">Thrown when failed because of a invalid arguament</exception>
341 /// <exception cref="NotSupportedException">Thrown when failed because device(haptic, sound) or specific pattern is not supported</exception>
342 /// <exception cref="UnauthorizedAccessException">Thrown when failed because access is not granted(No privilege)</exception>
343 /// <exception cref="InvalidOperationException">Thrown when failed because of system error</exception>
344 /// <privilege>http://tizen.org/privilege/haptic</privilege>
347 /// Feedback Feedback1 = new Feedback();
348 /// Feedback1.Stop();
353 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Stop();
355 if (res != Interop.Feedback.FeedbackError.None)
357 Log.Warn(LogTag, string.Format("Failed to stop feedback. err = {0}", res));
360 case Interop.Feedback.FeedbackError.NotInitialized:
361 throw new Exception("Not initialized");
362 case Interop.Feedback.FeedbackError.InvalidParameter:
363 throw new ArgumentException("Invalid Arguments");
364 case Interop.Feedback.FeedbackError.NotSupported:
365 throw new NotSupportedException("Not supported");
366 case Interop.Feedback.FeedbackError.PermissionDenied:
367 throw new UnauthorizedAccessException("Access is not granted");
368 case Interop.Feedback.FeedbackError.OperationFailed:
370 throw new InvalidOperationException("Failed to stop pattern");