From e52f820e1a4027f8a9df4c2e652bb228f377e6c8 Mon Sep 17 00:00:00 2001 From: Lukasz Bardeli Date: Fri, 1 Apr 2016 17:27:21 +0200 Subject: [PATCH] [Cordova][Dialog] Add profile feature to divide code (TV and MobileOrWearable) Change-Id: I6a1b200ccf8d74bca77b1332cb263bf2b39995e9 Signed-off-by: Lukasz Bardeli Signed-off-by: bg.chun --- src/dialog/cordova_dialog.gyp | 2 + src/dialog/cordova_dialog_api.js | 39 +++++++++++++---- src/dialog/cordova_dialog_extension.cc | 6 +++ src/dialog/cordova_dialog_extension.h | 4 ++ src/dialog/cordova_dialog_instance.cc | 60 ++++++++++++++++++++++++++ src/dialog/cordova_dialog_instance.h | 39 +++++++++++++++++ 6 files changed, 141 insertions(+), 9 deletions(-) create mode 100644 src/dialog/cordova_dialog_instance.cc create mode 100644 src/dialog/cordova_dialog_instance.h diff --git a/src/dialog/cordova_dialog.gyp b/src/dialog/cordova_dialog.gyp index 8f13ec3..9a0f0c7 100644 --- a/src/dialog/cordova_dialog.gyp +++ b/src/dialog/cordova_dialog.gyp @@ -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': [ '../', diff --git a/src/dialog/cordova_dialog_api.js b/src/dialog/cordova_dialog_api.js index eb2730f..f2ca43e 100755 --- a/src/dialog/cordova_dialog_api.js +++ b/src/dialog/cordova_dialog_api.js @@ -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; diff --git a/src/dialog/cordova_dialog_extension.cc b/src/dialog/cordova_dialog_extension.cc index a375d3a..23c92ee 100755 --- a/src/dialog/cordova_dialog_extension.cc +++ b/src/dialog/cordova_dialog_extension.cc @@ -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 diff --git a/src/dialog/cordova_dialog_extension.h b/src/dialog/cordova_dialog_extension.h index 613653b..8d2653b 100755 --- a/src/dialog/cordova_dialog_extension.h +++ b/src/dialog/cordova_dialog_extension.h @@ -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 index 0000000..58a2b96 --- /dev/null +++ b/src/dialog/cordova_dialog_instance.cc @@ -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 +#include +#include + +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(); + 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 index 0000000..1d71a0f --- /dev/null +++ b/src/dialog/cordova_dialog_instance.h @@ -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 +#include + +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_ -- 2.34.1