From: Pawel Andruszkiewicz
Date: Fri, 4 Sep 2015 11:08:42 +0000 (+0200)
Subject: [InputDevice] Implementation of (un)registerKeyBatch().
X-Git-Tag: accepted/tizen/mobile/20151026.233336^2^2~112
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b4c96383996ba49ff7c565ea722a491c9b4a3f7c;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[InputDevice] Implementation of (un)registerKeyBatch().
[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
---
diff --git a/src/inputdevice/inputdevice_api.js b/src/inputdevice/inputdevice_api.js
index 8d0a55a..e3c37a2 100644
--- a/src/inputdevice/inputdevice_api.js
+++ b/src/inputdevice/inputdevice_api.js
@@ -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();