[Cordova][Dialog] Add profile feature to divide code (TV and MobileOrWearable)
authorLukasz Bardeli <l.bardeli@samsung.com>
Fri, 1 Apr 2016 15:27:21 +0000 (17:27 +0200)
committerbg.chun <bg.chun@samsung.com>
Mon, 4 Apr 2016 04:23:03 +0000 (13:23 +0900)
Change-Id: I6a1b200ccf8d74bca77b1332cb263bf2b39995e9
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
Signed-off-by: bg.chun <bg.chun@samsung.com>
src/dialog/cordova_dialog.gyp
src/dialog/cordova_dialog_api.js
src/dialog/cordova_dialog_extension.cc
src/dialog/cordova_dialog_extension.h
src/dialog/cordova_dialog_instance.cc [new file with mode: 0644]
src/dialog/cordova_dialog_instance.h [new file with mode: 0644]

index 8f13ec3..9a0f0c7 100644 (file)
@@ -10,6 +10,8 @@
         'cordova_dialog_api.js',
         'cordova_dialog_extension.cc',
         'cordova_dialog_extension.h',
+        'cordova_dialog_instance.cc',
+        'cordova_dialog_instance.h',
       ],
       'include_dirs': [
         '../',
index eb2730f..f2ca43e 100755 (executable)
@@ -14,6 +14,9 @@
  *    limitations under the License.
  */
 
+var utils_ = xwalk.utils;
+var native_ = new utils_.NativeManager(extension);
+
 // TODO: remove when added to public cordova repository -> begin
 var plugin_name = 'cordova-plugin-dialogs.tizen.Notification';
 
@@ -26,16 +29,34 @@ var playback = (function() {
   var soundElement;
   var counter = 1;
 
-  tizen.systemsetting && tizen.systemsetting.getProperty("NOTIFICATION_EMAIL", function(v) {
-    soundElement = new Audio(v);
-    soundElement.addEventListener('ended', function() {
-      if (--counter > 0) {
-        soundElement.play();
-      }
+  var result = native_.callSync('CordovaDialog_getProfile', {});
+
+  result = native_.getResultObject(result);
+
+  if ("TV" == result.profile) {
+    tizen.filesystem.resolve('/usr/share/feedback/sound/operation/operation.wav', function(file) {
+      soundElement = new Audio(file.toURI());
+      soundElement.addEventListener('ended', function() {
+        if (--counter > 0) {
+          soundElement.play();
+        }
+      });
+    }, function(e) {
+      console.error('Failed to get the notification sound: ' + e);
+    }, "r");
+  } else {
+    tizen.systemsetting && tizen.systemsetting.getProperty("NOTIFICATION_EMAIL", function(v) {
+      soundElement = new Audio(v);
+      soundElement.addEventListener('ended', function() {
+        if (--counter > 0) {
+          soundElement.play();
+        }
+      });
+    }, function(e) {
+      console.error('Failed to get the notification sound: ' + e);
     });
-  }, function(e) {
-    console.error('Failed to get the notification sound: ' + e);
-  });
+  }
+
 
   function beep(times) {
     counter = times || 1;
index a375d3a..23c92ee 100755 (executable)
@@ -15,6 +15,7 @@
  */
 
 #include "dialog/cordova_dialog_extension.h"
+#include "dialog/cordova_dialog_instance.h"
 
 // This will be generated from cordova_dialog_api.js
 extern const char kSource_cordova_dialog_api[];
@@ -34,6 +35,11 @@ CordovaDialogExtension::CordovaDialogExtension() {
 
 CordovaDialogExtension::~CordovaDialogExtension() {}
 
+common::Instance* CordovaDialogExtension::CreateInstance() {
+  LoggerD("Entered");
+  return new extension::cordova::dialog::CordovaDialogInstance();
+}
+
 }  // dialog
 }  // cordova
 }  // extension
index 613653b..8d2653b 100755 (executable)
@@ -27,6 +27,10 @@ class CordovaDialogExtension : public common::Extension {
  public:
   CordovaDialogExtension();
   virtual ~CordovaDialogExtension();
+
+ private:
+  // common::Extension implementation.
+  virtual common::Instance* CreateInstance();
 };
 
 }  // dialog
diff --git a/src/dialog/cordova_dialog_instance.cc b/src/dialog/cordova_dialog_instance.cc
new file mode 100644 (file)
index 0000000..58a2b96
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2016 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 "dialog/cordova_dialog_instance.h"
+#include <common/logger.h>
+#include <common/picojson.h>
+#include <common/platform_result.h>
+
+namespace extension {
+namespace cordova {
+namespace dialog {
+
+CordovaDialogInstance::CordovaDialogInstance() {
+  using std::placeholders::_1;
+  using std::placeholders::_2;
+
+  LoggerD("Entered");
+
+#define REGISTER_SYNC(c, x) \
+        RegisterSyncHandler(c, std::bind(&CordovaDialogInstance::x, this, _1, _2));
+
+  REGISTER_SYNC("CordovaDialog_getProfile", GetProfile);
+
+#undef REGISTER_SYNC
+}
+
+CordovaDialogInstance::~CordovaDialogInstance() {
+  LoggerD("Entered");
+}
+
+void CordovaDialogInstance::GetProfile(const picojson::value& args,
+                                    picojson::object& out) {
+  LoggerD("Entered");
+  std::string profile = "MobileOrWearable";
+#ifdef TIZEN_TV
+  profile = "TV";
+#endif
+  picojson::value result = picojson::value(picojson::object());
+  picojson::object& result_obj = result.get<picojson::object>();
+  result_obj.insert(std::make_pair("profile", picojson::value(profile)));
+
+  ReportSuccess(result, out);
+}
+
+}  // dialog
+}  // cordova
+}  // extension
diff --git a/src/dialog/cordova_dialog_instance.h b/src/dialog/cordova_dialog_instance.h
new file mode 100644 (file)
index 0000000..1d71a0f
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016 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 DIALOG_CORDOVA_DIALOG_INSTANCE_H_
+#define DIALOG_CORDOVA_DIALOG_INSTANCE_H_
+
+#include <common/extension.h>
+#include <common/picojson.h>
+
+namespace extension {
+namespace cordova {
+namespace dialog {
+
+class CordovaDialogInstance : public common::ParsedInstance {
+ public:
+  CordovaDialogInstance();
+  virtual ~CordovaDialogInstance();
+
+ private:
+  void GetProfile(const picojson::value& args, picojson::object& out);
+};
+}  // dialog
+}  // cordova
+}  // extension
+
+#endif  // DIALOG_CORDOVA_DIALOG_INSTANCE_H_