['tizen == 1', {
'variables': {
'packages': [
- 'notification'
+ 'notification',
+ 'capi-system-device',
]
},
}],
var types_ = validator_.Types;
var native_ = new xwalk.utils.NativeManager(extension);
+function convertColorToInt(rgbaColor) {
+ var color = rgbaColor.length === 7 ? rgbaColor + 'ff' : rgbaColor;
+ var isLengthOk = color.length === 9;
+ var isHash = color.substr(0, 1) === '#';
+ var hex = '0123456789abcdefABCDEF';
+ var isHex = true;
+ var c = color.replace('#', '');
+
+ for (var i = 0; i < c.length; i++) {
+ if (hex.indexOf(c[i]) < 0) {
+ isHex = false;
+ }
+ }
+
+ if (!isLengthOk || !isHash || !isHex) {
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR, 'invalid value');
+ }
+
+ return parseInt('0x' + c);
+}
+
var EditManager = function() {
this.canEdit = false;
};
BYTE: 'BYTE'
};
+var LEDCustomFlags = {
+ LED_CUSTOM_DUTY_ON: 'LED_CUSTOM_DUTY_ON',
+ LED_CUSTOM_DEFAULT: 'LED_CUSTOM_DEFAULT'
+};
+
function NotificationManager() {}
return notifications;
};
+/**
+ * Plays the custom effect of the service LED that is located to the front of a device.
+ *
+ * @param timeOn Number
+ * @param timeOff Number
+ * @param color String
+ * @param flags Array
+ */
+NotificationManager.prototype.playLEDCustomEffect = function(timeOn, timeOff, color, flags) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'timeOn', type: types_.LONG},
+ {name: 'timeOff', type: types_.LONG},
+ {name: 'color', type: types_.STRING},
+ {name: 'flags', type: types_.ARRAY, values: types_.STRING}
+ ]);
+
+ for (var i = 0; i < args.flags.length; ++i) {
+ if (Object.keys(LEDCustomFlags).indexOf(args.flags[i]) < 0) {
+ throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'invalid value');
+ }
+ }
+
+ args.color = convertColorToInt(args.color);
+ var result = native_.callSync('NotificationManager_playLEDCustomEffect', args);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+};
+
+/**
+ * Stops the custom effect of the service LED that is located to the front of a device.
+ */
+NotificationManager.prototype.stopLEDCustomEffect = function() {
+ var result = native_.callSync('NotificationManager_stopLEDCustomEffect');
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+};
+
+
function NotificationInitDict(data) {
var _iconPath = null;
var _soundPath = null;
REGISTER_SYNC("NotificationManager_getAll", NotificationManagerGetAll);
REGISTER_SYNC("NotificationManager_post", NotificationManagerPost);
REGISTER_SYNC("NotificationManager_removeAll", NotificationManagerRemoveAll);
+ REGISTER_SYNC("NotificationManager_playLEDCustomEffect",
+ NotificationManagerPlayLEDCustomEffect);
+ REGISTER_SYNC("NotificationManager_stopLEDCustomEffect",
+ NotificationManagerStopLEDCustomEffect);
#undef REGISTER_SYNC
manager_ = NotificationManager::GetInstance();
ReportError(status, &out);
}
+void NotificationInstance::NotificationManagerPlayLEDCustomEffect(
+ const picojson::value& args, picojson::object& out) {
+
+ PlatformResult status = manager_->PlayLEDCustomEffect(args.get<picojson::object>());
+
+ if (status.IsSuccess())
+ ReportSuccess(out);
+ else
+ ReportError(status, &out);
+}
+
+void NotificationInstance::NotificationManagerStopLEDCustomEffect(
+ const picojson::value& /*args*/, picojson::object& out) {
+
+ PlatformResult status = manager_->StopLEDCustomEffect();
+
+ if (status.IsSuccess())
+ ReportSuccess(out);
+ else
+ ReportError(status, &out);
+}
+
#undef CHECK_EXIST
} // namespace notification
picojson::object& out);
void NotificationManagerGetAll(const picojson::value& args,
picojson::object& out);
+
+ void NotificationManagerPlayLEDCustomEffect(const picojson::value& args,
+ picojson::object& out);
+ void NotificationManagerStopLEDCustomEffect(const picojson::value& args,
+ picojson::object& out);
};
} // namespace notification
#include "notification/notification_manager.h"
-#include <notification_internal.h>
#include <app_control_internal.h>
+#include <device/led.h>
+#include <notification_internal.h>
#include "common/converter.h"
#include "common/logger.h"
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult NotificationManager::PlayLEDCustomEffect(
+ const picojson::object& args) {
+ LOGGER(DEBUG) << "entered";
+
+ int timeOn = FromJson<double>(args, "timeOn");
+ int timeOff = FromJson<double>(args, "timeOff");
+ unsigned int color = FromJson<double>(args, "color");
+
+ auto& flags = FromJson<picojson::array>(args, "flags");
+ unsigned int platformFlags = 0;
+ for (auto flag : flags) {
+ std::string flagStr = JsonCast<std::string>(flag);
+ if (flagStr == "LED_CUSTOM_DEFAULT")
+ platformFlags |= LED_CUSTOM_DEFAULT;
+ else if (flagStr == "LED_CUSTOM_DUTY_ON")
+ platformFlags |= LED_CUSTOM_DUTY_ON;
+ }
+
+ int ret;
+ ret = device_led_play_custom(timeOn, timeOff, color, platformFlags);
+ if (ret != DEVICE_ERROR_NONE) {
+ LOGGER(ERROR) << "Cannot play LED custom effect: " << ret;
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot play LED custom effect");
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult NotificationManager::StopLEDCustomEffect() {
+ LOGGER(DEBUG) << "entered";
+
+ int ret = DEVICE_ERROR_NONE;
+ ret = device_led_stop_custom();
+ if (ret != DEVICE_ERROR_NONE) {
+ LOGGER(ERROR) << "Cannot stop LED custom effect: " << ret;
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot stop LED custom effect");
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
} // namespace notification
} // namespace extension
picojson::object& out);
common::PlatformResult GetAll(picojson::array& out);
+ common::PlatformResult PlayLEDCustomEffect(const picojson::object& args);
+ common::PlatformResult StopLEDCustomEffect();
+
private:
NotificationManager();
virtual ~NotificationManager();