Merge "[Application] Fixed path of getAppSharedURI" into tizen_5.0
[platform/core/api/webapi-plugins.git] / src / feedback / feedback_api.js
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 var JSON_ = xwalk.JSON;
18 var validator_ = xwalk.utils.validator;
19 var types_ = validator_.Types;
20 var type_ = xwalk.utils.type;
21 var native_ = new xwalk.utils.NativeManager(extension);
22
23 var FeedbackType = {
24     TYPE_SOUND: 'TYPE_SOUND',
25     TYPE_VIBRATION: 'TYPE_VIBRATION'
26 };
27
28 var FeedbackPattern = {
29   TAP: 'TAP',
30   SIP: 'SIP',
31   KEY0: 'KEY0',
32   KEY1: 'KEY1',
33   KEY2: 'KEY2',
34   KEY3: 'KEY3',
35   KEY4: 'KEY4',
36   KEY5: 'KEY5',
37   KEY6: 'KEY6',
38   KEY7: 'KEY7',
39   KEY8: 'KEY8',
40   KEY9: 'KEY9',
41   KEY_STAR: 'KEY_STAR',
42   KEY_SHARP: 'KEY_SHARP',
43   KEY_BACK: 'KEY_BACK',
44   HOLD: 'HOLD',
45   HW_TAP: 'HW_TAP',
46   HW_HOLD: 'HW_HOLD',
47   MESSAGE: 'MESSAGE',
48   EMAIL: 'EMAIL',
49   WAKEUP: 'WAKEUP',
50   SCHEDULE: 'SCHEDULE',
51   TIMER: 'TIMER',
52   GENERAL: 'GENERAL',
53   POWERON: 'POWERON',
54   POWEROFF: 'POWEROFF',
55   CHARGERCONN: 'CHARGERCONN',
56   CHARGING_ERROR: 'CHARGING_ERROR',
57   FULLCHARGED: 'FULLCHARGED',
58   LOWBATT: 'LOWBATT',
59   LOCK: 'LOCK',
60   UNLOCK: 'UNLOCK',
61   VIBRATION_ON: 'VIBRATION_ON',
62   SILENT_OFF: 'SILENT_OFF',
63   BT_CONNECTED: 'BT_CONNECTED',
64   BT_DISCONNECTED: 'BT_DISCONNECTED',
65   LIST_REORDER: 'LIST_REORDER',
66   LIST_SLIDER: 'LIST_SLIDER',
67   VOLUME_KEY: 'VOLUME_KEY'
68 };
69
70 function FeedbackManager() {
71   // constructor of FeedbackManager
72 }
73
74
75 FeedbackManager.prototype.isPatternSupported = function(pattern, type) {
76   var args = validator_.validateArgs(arguments, [
77     {name: 'pattern', type: types_.ENUM, values: Object.keys(FeedbackPattern)},
78     {name: 'type', type: types_.ENUM, values: Object.keys(FeedbackType)},
79   ]);
80
81   var result = native_.callSync('FeedbackManager_isPatternSupported', args);
82   if (native_.isFailure(result)) {
83     throw native_.getErrorObject(result);
84   }
85   return native_.getResultObject(result);
86 };
87
88 FeedbackManager.prototype.play = function(pattern, type) {
89   var args = validator_.validateArgs(arguments, [
90     {
91       name: 'pattern',
92       type: types_.ENUM,
93       values: Object.keys(FeedbackPattern)
94     },
95     {
96       name: 'type',
97       type: types_.ENUM,
98       values: Object.keys(FeedbackType),
99       optional : true,
100       nullable : true
101     },
102   ]);
103
104   var nativeParam = {
105     'pattern': args.pattern,
106     'type': args.type ? args.type : 'any'
107   };
108
109   var result = native_.callSync('FeedbackManager_play', nativeParam);
110   if (native_.isFailure(result)) {
111     throw native_.getErrorObject(result);
112   }
113 };
114
115 FeedbackManager.prototype.stop = function() {
116   var args = validator_.validateArgs(arguments, []);
117
118   var result = native_.callSync('FeedbackManager_stop', args);
119   if (native_.isFailure(result)) {
120     throw native_.getErrorObject(result);
121   }
122 };
123
124 exports = new FeedbackManager();