[InputDevice] Implementation of (un)registerKeyBatch().
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 4 Sep 2015 11:08:42 +0000 (13:08 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Fri, 11 Sep 2015 06:32:35 +0000 (08:32 +0200)
[Verification] Manually tested:
tizen.inputdevice.registerKeyBatch(['VolumeUp', 'VolumeDown'], function () {console.log('OK');}, function (e) {console.log('error: ' + e);})
tizen.inputdevice.unregisterKeyBatch(['VolumeUp', 'VolumeDown'], function () {console.log('OK');}, function (e) {console.log('error: ' + e);})

Change-Id: Iff64ff419274ee94f5f8e4b9a4559691dca2d3ef
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/inputdevice/inputdevice_api.js

index 8d0a55a..e3c37a2 100644 (file)
@@ -131,6 +131,87 @@ InputDeviceManager.prototype.unregisterKey = function(keyName) {
   }
 };
 
+InputDeviceManager.prototype.registerKeyBatch = function() {
+  var args = validator.validateMethod(arguments, [
+    {
+      name: 'keyNames',
+      type: types.ARRAY,
+      values: types.STRING
+    },
+    {
+      name: 'successCallback',
+      type: types.FUNCTION,
+      optional: true,
+      nullable: true
+    },
+    {
+      name: 'errorCallback',
+      type: types.FUNCTION,
+      optional: true,
+      nullable: true
+    }
+  ]);
+
+  var keysList = "";
+  for (var i = 0; i < args.keyNames.length; ++i) {
+    if (!map[args.keyNames[i]]) {
+      throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR,
+                                'Invalid key name: "' + args.keyNames[i] + '"');
+    }
+    keysList += map[args.keyNames[i]].keyName + ((i < args.keyNames.length - 1) ? "," : "");
+  }
+
+  setTimeout(function() {
+    var ret = native.sendRuntimeSyncMessage('tizen://api/inputdevice/registerKeyBatch', keysList);
+    if (ret === 'error') {
+      native.callIfPossible(args.errorCallback, new WebAPIException(
+          WebAPIException.UNKNOWN_ERR, 'Failed to register keys.'));
+    } else {
+      native.callIfPossible(args.successCallback);
+    }
+  }.bind(this), 0);
+};
+
+InputDeviceManager.prototype.unregisterKeyBatch = function() {
+  var args = validator.validateMethod(arguments, [
+    {
+      name: 'keyNames',
+      type: types.ARRAY,
+      values: types.STRING
+    },
+    {
+      name: 'successCallback',
+      type: types.FUNCTION,
+      optional: true,
+      nullable: true
+    },
+    {
+      name: 'errorCallback',
+      type: types.FUNCTION,
+      optional: true,
+      nullable: true
+    }
+  ]);
+
+  var keysList = "";
+  for (var i = 0; i < args.keyNames.length; ++i) {
+    if (!map[args.keyNames[i]]) {
+      throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR,
+                                'Invalid key name: "' + args.keyNames[i] + '"');
+    }
+    keysList += map[args.keyNames[i]].keyName + ((i < args.keyNames.length - 1) ? "," : "");
+  }
+
+  setTimeout(function() {
+    var ret = native.sendRuntimeSyncMessage('tizen://api/inputdevice/unregisterKeyBatch', keysList);
+    if (ret === 'error') {
+      native.callIfPossible(args.errorCallback, new WebAPIException(
+          WebAPIException.UNKNOWN_ERR, 'Failed to unregister keys.'));
+    } else {
+      native.callIfPossible(args.successCallback);
+    }
+  }.bind(this), 0);
+};
 
 // Exports
 exports = new InputDeviceManager();