[Events] Code structure changed to match cordova architecture.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 7 Apr 2016 12:11:14 +0000 (14:11 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 7 Apr 2016 12:11:14 +0000 (14:11 +0200)
Change-Id: I148576302885da489c84490ddcc0ac0fb6743e48
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/cordova-api.gyp
src/events/cordova_events.gyp [deleted file]
src/events/cordova_events_api.js [deleted file]
src/events/cordova_events_extension.cc [deleted file]
src/events/cordova_events_extension.h [deleted file]
src/lib/cordova_plugins.js
src/lib/plugins/cordova-plugin-events/tizen/Events.js [new file with mode: 0755]

index 21eb7669ef8cd1ebc4fa9a9652551f9078ab8e64..970edd715709f47ba5da8c93823030eb2d6d86d9 100644 (file)
@@ -9,7 +9,6 @@
       'type': 'none',
       'dependencies': [
         'cordova/cordova.gyp:*',
-        'events/cordova_events.gyp:*',
         'file/cordova_file.gyp:*',
         'globalization/cordova_globalization.gyp:*',
         'networkinformation/cordova_networkinformation.gyp:*',
diff --git a/src/events/cordova_events.gyp b/src/events/cordova_events.gyp
deleted file mode 100644 (file)
index a269cd9..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-{
-  'includes':[
-    '/usr/include/webapi-plugins/src/common/common.gypi',
-  ],
-  'targets': [
-    {
-      'target_name': 'tizen_cordova_events',
-      'type': 'loadable_module',
-      'sources': [
-        'cordova_events_api.js',
-        'cordova_events_extension.cc',
-        'cordova_events_extension.h',
-      ],
-      'include_dirs': [
-        '../',
-        '<(SHARED_INTERMEDIATE_DIR)',
-      ],
-      'variables': {
-        'packages': [
-          'webapi-plugins',
-        ],
-      },
-    },
-  ],
-}
diff --git a/src/events/cordova_events_api.js b/src/events/cordova_events_api.js
deleted file mode 100755 (executable)
index a407271..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-
-// TODO: remove when added to public cordova repository -> begin
-var plugin_name = 'cordova-plugin-events.tizen.Events';
-
-cordova.define(plugin_name, function(require, exports, module) {
-// TODO: remove -> end
-
-//////////////////////////// EventHandler
-function EventHandler(name) {
-  this.name = name;
-}
-
-EventHandler.prototype.startListener = function(l) {
-  console.error('Event \"' + this.name + '\" is not suported.');
-};
-
-EventHandler.prototype.stopListener = function() {
-  console.error('Event \"' + this.name + '\" is not suported.');
-};
-
-//////////////////////////// WindowEventHandler
-function WindowEventHandler(name, event_type, callback, target) {
-  EventHandler.call(this, name);
-  this.event_type = event_type;
-  this.callback = callback;
-  this.target = target || window;
-}
-
-WindowEventHandler.prototype = Object.create(EventHandler.prototype);
-WindowEventHandler.prototype.constructor = WindowEventHandler;
-
-WindowEventHandler.prototype.startListener = function(l) {
-  if (this.callback) {
-    this.listener = l;
-    this.target.addEventListener(this.event_type, this.callback);
-  } else {
-    Object.getPrototypeOf(WindowEventHandler.prototype).startListener.call(this, l);
-  }
-};
-
-WindowEventHandler.prototype.stopListener = function() {
-  if (this.callback) {
-    this.target.removeEventListener(this.event_type, this.callback);
-    this.listener = undefined;
-  } else {
-    Object.getPrototypeOf(WindowEventHandler.prototype).stopListener.call(this);
-  }
-};
-
-//////////////////////////// HwKeyEventHandler
-function HwKeyEventHandler(name, type) {
-  var that = this;
-  var callback = function(e) {
-    if (type === e.keyName && that.listener) {
-      that.listener(that.name);
-    }
-  };
-  WindowEventHandler.call(this, name, 'tizenhwkey', callback);
-}
-
-HwKeyEventHandler.prototype = Object.create(WindowEventHandler.prototype);
-HwKeyEventHandler.prototype.constructor = HwKeyEventHandler;
-
-//////////////////////////// VisibilityEventHandler
-function VisibilityEventHandler(name, hidden) {
-  var prop, visibility_event, callback;
-
-  if (typeof document.hidden !== 'undefined') {
-    prop = 'hidden';
-    visibility_event = 'visibilitychange';
-  } else if (typeof document.webkitHidden !== 'undefined') {
-    prop = 'webkitHidden';
-    visibility_event = 'webkitvisibilitychange';
-  }
-
-  if (prop) {
-    var that = this;
-    callback = function() {
-      if (hidden === document[prop] && that.listener) {
-        that.listener(that.name);
-      }
-    };
-  }
-
-  WindowEventHandler.call(this, name, visibility_event, callback, document);
-}
-
-VisibilityEventHandler.prototype = Object.create(WindowEventHandler.prototype);
-VisibilityEventHandler.prototype.constructor = VisibilityEventHandler;
-
-//////////////////////////// InputDeviceEventHandler
-function InputDeviceEventHandler(name, type) {
-  var callback;
-
-  try {
-    this.key = tizen.inputdevice.getKey(type);
-
-    var that = this;
-    callback = function(e) {
-      if (that.key.code === e.keyCode && that.listener) {
-        that.listener(that.name);
-      }
-    };
-  } catch (e) {
-    console.error('Exception: ' + e.message);
-  }
-
-  WindowEventHandler.call(this, name, 'keydown', callback);
-}
-
-InputDeviceEventHandler.prototype = Object.create(WindowEventHandler.prototype);
-InputDeviceEventHandler.prototype.constructor = InputDeviceEventHandler;
-
-InputDeviceEventHandler.prototype.startListener = function(l) {
-  if (this.key) {
-    try {
-      tizen.inputdevice.registerKey(this.key.name);
-    } catch (e) {
-      console.error('Exception: ' + e.message);
-    }
-  }
-
-  Object.getPrototypeOf(InputDeviceEventHandler.prototype).startListener.call(this, l);
-};
-
-InputDeviceEventHandler.prototype.stopListener = function() {
-  if (this.key) {
-    try {
-      tizen.inputdevice.unregisterKey(this.key.name);
-    } catch (e) {
-      console.error('Exception: ' + e.message);
-    }
-  }
-
-  Object.getPrototypeOf(InputDeviceEventHandler.prototype).stopListener.call(this);
-};
-
-//////////////////////////// all handlers
-var handlers = {
-  backbutton: new HwKeyEventHandler('backbutton', 'back'),
-  menubutton: new HwKeyEventHandler('menubutton', 'menu'),
-  searchbutton: new EventHandler('searchbutton'),
-  startcallbutton: new EventHandler('startcallbutton'),
-  endcallbutton: new EventHandler('endcallbutton'),
-  volumedownbutton: new InputDeviceEventHandler('volumedownbutton', 'VolumeDown'),
-  volumeupbutton: new InputDeviceEventHandler('volumeupbutton', 'VolumeUp'),
-  pause: new VisibilityEventHandler('pause', true),
-  resume: new VisibilityEventHandler('resume', false)
-};
-
-exports = {
-  startListener: function(successCallback, errorCallback, args) {
-    var e = args[0];
-    if (handlers[e]) {
-      handlers[e].startListener(successCallback);
-    } else {
-      console.error('Unknown event: ' + e);
-    }
-  },
-  stopListener: function(successCallback, errorCallback, args) {
-    var e = args[0];
-    if (handlers[e]) {
-      handlers[e].stopListener();
-    } else {
-      console.error('Unknown event: ' + e);
-    }
-  }
-};
-
-require('cordova/exec/proxy').add('Events', exports);
-
-console.log('Loaded cordova.events API');
-
-// TODO: remove when added to public cordova repository -> begin
-});
-
-exports = function(require) {
-  require('cordova-tizen').addPlugin('cordova-plugin-events.register', plugin_name, 'runs');
-};
-// TODO: remove -> end
diff --git a/src/events/cordova_events_extension.cc b/src/events/cordova_events_extension.cc
deleted file mode 100755 (executable)
index 0f59ffe..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-
-#include "events/cordova_events_extension.h"
-
-// This will be generated from cordova_events_api.js
-extern const char kSource_cordova_events_api[];
-
-common::Extension* CreateExtension() {
-  return new extension::cordova::events::CordovaEventsExtension();
-}
-
-namespace extension {
-namespace cordova {
-namespace events {
-
-CordovaEventsExtension::CordovaEventsExtension() {
-  SetExtensionName("tizen.cordova.events");
-  SetJavaScriptAPI(kSource_cordova_events_api);
-}
-
-CordovaEventsExtension::~CordovaEventsExtension() {}
-
-}  // events
-}  // cordova
-}  // extension
diff --git a/src/events/cordova_events_extension.h b/src/events/cordova_events_extension.h
deleted file mode 100755 (executable)
index 6d85a7a..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-
-#ifndef EVENTS_CORDOVA_EVENTS_EXTENSION_H_
-#define EVENTS_CORDOVA_EVENTS_EXTENSION_H_
-
-#include <common/extension.h>
-
-namespace extension {
-namespace cordova {
-namespace events {
-
-class CordovaEventsExtension : public common::Extension {
- public:
-  CordovaEventsExtension();
-  virtual ~CordovaEventsExtension();
-};
-
-}  // events
-}  // cordova
-}  // extension
-
-#endif // EVENTS_CORDOVA_EVENTS_EXTENSION_H_
index c2ef0cf315c05069ad3be9624672a8ca89e00787..699af6ecc32ef40c2619b6521308731007795c93 100644 (file)
@@ -62,6 +62,11 @@ module.exports = [
       "id": "cordova-plugin-events.register",
       "runs": true
     },
+    {
+      "file": "plugins/cordova-plugin-events/tizen/Events.js",
+      "id": "cordova-plugin-events.tizen.Events",
+      "runs": true
+    },
     {
         "file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
         "id": "cordova-plugin-file.DirectoryEntry",
diff --git a/src/lib/plugins/cordova-plugin-events/tizen/Events.js b/src/lib/plugins/cordova-plugin-events/tizen/Events.js
new file mode 100755 (executable)
index 0000000..6c4f048
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+// TODO: remove when added to public cordova repository -> begin
+var plugin_name = 'cordova-plugin-events.tizen.Events';
+
+cordova.define(plugin_name, function(require, exports, module) {
+// TODO: remove -> end
+
+//////////////////////////// EventHandler
+function EventHandler(name) {
+  this.name = name;
+}
+
+EventHandler.prototype.startListener = function(l) {
+  console.error('Event \"' + this.name + '\" is not suported.');
+};
+
+EventHandler.prototype.stopListener = function() {
+  console.error('Event \"' + this.name + '\" is not suported.');
+};
+
+//////////////////////////// WindowEventHandler
+function WindowEventHandler(name, event_type, callback, target) {
+  EventHandler.call(this, name);
+  this.event_type = event_type;
+  this.callback = callback;
+  this.target = target || window;
+}
+
+WindowEventHandler.prototype = Object.create(EventHandler.prototype);
+WindowEventHandler.prototype.constructor = WindowEventHandler;
+
+WindowEventHandler.prototype.startListener = function(l) {
+  if (this.callback) {
+    this.listener = l;
+    this.target.addEventListener(this.event_type, this.callback);
+  } else {
+    Object.getPrototypeOf(WindowEventHandler.prototype).startListener.call(this, l);
+  }
+};
+
+WindowEventHandler.prototype.stopListener = function() {
+  if (this.callback) {
+    this.target.removeEventListener(this.event_type, this.callback);
+    this.listener = undefined;
+  } else {
+    Object.getPrototypeOf(WindowEventHandler.prototype).stopListener.call(this);
+  }
+};
+
+//////////////////////////// HwKeyEventHandler
+function HwKeyEventHandler(name, type) {
+  var that = this;
+  var callback = function(e) {
+    if (type === e.keyName && that.listener) {
+      that.listener(that.name);
+    }
+  };
+  WindowEventHandler.call(this, name, 'tizenhwkey', callback);
+}
+
+HwKeyEventHandler.prototype = Object.create(WindowEventHandler.prototype);
+HwKeyEventHandler.prototype.constructor = HwKeyEventHandler;
+
+//////////////////////////// VisibilityEventHandler
+function VisibilityEventHandler(name, hidden) {
+  var prop, visibility_event, callback;
+
+  if (typeof document.hidden !== 'undefined') {
+    prop = 'hidden';
+    visibility_event = 'visibilitychange';
+  } else if (typeof document.webkitHidden !== 'undefined') {
+    prop = 'webkitHidden';
+    visibility_event = 'webkitvisibilitychange';
+  }
+
+  if (prop) {
+    var that = this;
+    callback = function() {
+      if (hidden === document[prop] && that.listener) {
+        that.listener(that.name);
+      }
+    };
+  }
+
+  WindowEventHandler.call(this, name, visibility_event, callback, document);
+}
+
+VisibilityEventHandler.prototype = Object.create(WindowEventHandler.prototype);
+VisibilityEventHandler.prototype.constructor = VisibilityEventHandler;
+
+//////////////////////////// InputDeviceEventHandler
+function InputDeviceEventHandler(name, type) {
+  var callback;
+
+  try {
+    this.key = tizen.inputdevice.getKey(type);
+
+    var that = this;
+    callback = function(e) {
+      if (that.key.code === e.keyCode && that.listener) {
+        that.listener(that.name);
+      }
+    };
+  } catch (e) {
+    console.error('Exception: ' + e.message);
+  }
+
+  WindowEventHandler.call(this, name, 'keydown', callback);
+}
+
+InputDeviceEventHandler.prototype = Object.create(WindowEventHandler.prototype);
+InputDeviceEventHandler.prototype.constructor = InputDeviceEventHandler;
+
+InputDeviceEventHandler.prototype.startListener = function(l) {
+  if (this.key) {
+    try {
+      tizen.inputdevice.registerKey(this.key.name);
+    } catch (e) {
+      console.error('Exception: ' + e.message);
+    }
+  }
+
+  Object.getPrototypeOf(InputDeviceEventHandler.prototype).startListener.call(this, l);
+};
+
+InputDeviceEventHandler.prototype.stopListener = function() {
+  if (this.key) {
+    try {
+      tizen.inputdevice.unregisterKey(this.key.name);
+    } catch (e) {
+      console.error('Exception: ' + e.message);
+    }
+  }
+
+  Object.getPrototypeOf(InputDeviceEventHandler.prototype).stopListener.call(this);
+};
+
+//////////////////////////// all handlers
+var handlers = {
+  backbutton: new HwKeyEventHandler('backbutton', 'back'),
+  menubutton: new HwKeyEventHandler('menubutton', 'menu'),
+  searchbutton: new EventHandler('searchbutton'),
+  startcallbutton: new EventHandler('startcallbutton'),
+  endcallbutton: new EventHandler('endcallbutton'),
+  volumedownbutton: new InputDeviceEventHandler('volumedownbutton', 'VolumeDown'),
+  volumeupbutton: new InputDeviceEventHandler('volumeupbutton', 'VolumeUp'),
+  pause: new VisibilityEventHandler('pause', true),
+  resume: new VisibilityEventHandler('resume', false)
+};
+
+exports = {
+  startListener: function(successCallback, errorCallback, args) {
+    var e = args[0];
+    if (handlers[e]) {
+      handlers[e].startListener(successCallback);
+    } else {
+      console.error('Unknown event: ' + e);
+    }
+  },
+  stopListener: function(successCallback, errorCallback, args) {
+    var e = args[0];
+    if (handlers[e]) {
+      handlers[e].stopListener();
+    } else {
+      console.error('Unknown event: ' + e);
+    }
+  }
+};
+
+require('cordova/exec/proxy').add('Events', exports);
+
+console.log('Loaded cordova.events API');
+
+// TODO: remove when added to public cordova repository -> begin
+});
+// TODO: remove -> end