From acf3652f92a9e08879bd2479d89d79b969725c0b Mon Sep 17 00:00:00 2001 From: "mk5004.lee" Date: Tue, 24 Jul 2018 19:31:07 +0900 Subject: [PATCH] Add apis for screen reader text - watchface_complication_data_get_screen_reader_text watchface_complication_provider_data_set_screen_reader_text Change-Id: I0f4c68d843f3171a2012a8a9338f920546e05f0f Signed-off-by: mk5004.lee --- .../include/watchface-complication-provider.h | 27 ++++++++++++++++++ .../watchface-complication-provider.cc | 12 +++++++- .../include/watchface-complication-internal.h | 1 + .../include/watchface-complication.h | 32 ++++++++++++++++++++++ watchface-complication/watchface-complication.cc | 25 +++++++++++++++++ 5 files changed, 96 insertions(+), 1 deletion(-) diff --git a/watchface-complication-provider/include/watchface-complication-provider.h b/watchface-complication-provider/include/watchface-complication-provider.h index e19dd5b..5d29ff6 100644 --- a/watchface-complication-provider/include/watchface-complication-provider.h +++ b/watchface-complication-provider/include/watchface-complication-provider.h @@ -562,6 +562,33 @@ int watchface_complication_provider_data_set_extra_data(bundle *shared_data, const char *extra_data); /** + * @brief Sets screen reader text for shared data. + * @since_tizen 5.0 + * @remarks @a screen_reader_text can be added to every type of shared data. + * @param[in] shared_data The data which will be shared with watch application + * @param[in] screen_reader_text The screen reader text + * @return #WATCHFACE_COMPLICATION_ERROR_NONE on success, + * otherwise an error code (see #watchface_complication_error_e) on failure + * @retval #WATCHFACE_COMPLICATION_ERROR_NONE Successful + * @retval #WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WATCHFACE_COMPLICATION_ERROR_IO_ERROR I/O error + * @retval #WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED Not supported + * @par Sample code: + * @code +#include +void _watchface_complication_provider_update_requested_cb(const char *provider_id, + const char *req_appid, watchface_complication_type_e type, + const bundle *context, bundle *shared_data, void *user_data) +{ + watchface_complication_provider_data_set_screen_reader_text(shared_data, "screen reader text"); +} + * @endcode + */ +int watchface_complication_provider_data_set_screen_reader_text( + bundle *shared_data, const char *screen_reader_text); + +/** * @brief Checks whether app is launched by complication touch or not. * @since_tizen 5.0 * @remarks @a is_touch_launch is true when provider app is launched by watchface_complication_touch_launch(). diff --git a/watchface-complication-provider/watchface-complication-provider.cc b/watchface-complication-provider/watchface-complication-provider.cc index 18c7a54..d891d64 100644 --- a/watchface-complication-provider/watchface-complication-provider.cc +++ b/watchface-complication-provider/watchface-complication-provider.cc @@ -560,11 +560,21 @@ extern "C" EXPORT_API int watchface_complication_provider_data_set_extra_data( ret = _add_bundle_data(shared_data, EXTRA_DATA_KEY, extra_data); if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) - return ret; + return ret; return WATCHFACE_COMPLICATION_ERROR_NONE; } +extern "C" EXPORT_API int watchface_complication_provider_data_set_screen_reader_text( + bundle* shared_data, const char* screen_reader_text) { + if (shared_data == NULL || screen_reader_text == NULL) { + LOGE("Invalid param"); + return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; + } + + return _add_bundle_data(shared_data, SCREEN_READER_TEXT_KEY, screen_reader_text); +} + extern "C" EXPORT_API int watchface_complication_provider_is_touch_launch( app_control_h handle, bool* is_touch_launch) { int ret; diff --git a/watchface-complication/include/watchface-complication-internal.h b/watchface-complication/include/watchface-complication-internal.h index 2497951..327c391 100644 --- a/watchface-complication/include/watchface-complication-internal.h +++ b/watchface-complication/include/watchface-complication-internal.h @@ -32,6 +32,7 @@ #define IMAGE_KEY "__IMAGE_KEY__" #define DATA_TYPE_KEY "__DATA_TYPE_KEY__" #define EXTRA_DATA_KEY "__EXTRA_DATA_KEY__" +#define SCREEN_READER_TEXT_KEY "__SCREEN_READER_TEXT_KEY__" #define TOUCH_LAUNCH_CONTEXT_KEY "__TOUCH_LAUNCH_CONTEXT_KEY__" #define TOUCH_LAUNCH_PROVIDER_ID_KEY "__TOUCH_LAUNCH_PROVIDER_ID_KEY__" #define TOUCH_LAUNCH_TYPE_KEY "__TOUCH_LAUNCH_TYPE_KEY__" diff --git a/watchface-complication/include/watchface-complication.h b/watchface-complication/include/watchface-complication.h index 7a43347..01fda7f 100644 --- a/watchface-complication/include/watchface-complication.h +++ b/watchface-complication/include/watchface-complication.h @@ -627,6 +627,38 @@ int watchface_complication_data_get_extra_data(const bundle *data, char **extra_data); /** + * @brief Gets screen reader text from complication data. + * @since_tizen 5.0 + * @remarks The @a screen_reader_text should be freed using free(). + * @param[in] data The data received from complication provider app + * @param[out] screen_reader_text The screen reader text + * @return #WATCHFACE_COMPLICATION_ERROR_NONE on success, + * otherwise an error code (see #watchface_complication_error_e) on failure + * @retval #WATCHFACE_COMPLICATION_ERROR_NONE Successful + * @retval #WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #WATCHFACE_COMPLICATION_ERROR_NO_DATA No data + * @retval #WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED Not supported + * @see watchface_complication_updated_cb() + * @par Sample code: + * @code +#include +void _on_complication_update(int complication_id, + const char *provider_id, + watchface_complication_type_e type, + const bundle *data, void *user_data) +{ + char *screen_reader_text; + watchface_complication_data_get_screen_reader_text(data, &screen_reader_text); + ... + free(screen_reader_text); +} + * @endcode + */ +int watchface_complication_data_get_screen_reader_text(const bundle *data, + char **screen_reader_text); + +/** * @brief Launches current complication's provider application. * @details This function launchs the provider application with extra data, * so that provider can tell it is launched by touching. diff --git a/watchface-complication/watchface-complication.cc b/watchface-complication/watchface-complication.cc index 5caeb07..d420e4b 100644 --- a/watchface-complication/watchface-complication.cc +++ b/watchface-complication/watchface-complication.cc @@ -455,6 +455,31 @@ extern "C" EXPORT_API int watchface_complication_data_get_extra_data( return WATCHFACE_COMPLICATION_ERROR_NONE; } +extern "C" EXPORT_API int watchface_complication_data_get_screen_reader_text( + const bundle *data, char **screen_reader_text) { + int ret; + char *value; + + if (data == NULL || screen_reader_text == NULL) { + LOGE("Invalid data !!"); + return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER; + } + + ret = bundle_get_str(const_cast(data), SCREEN_READER_TEXT_KEY, &value); + if (ret != BUNDLE_ERROR_NONE) { + LOGE("Invalid data !!"); + return WATCHFACE_COMPLICATION_ERROR_NO_DATA; + } + + *screen_reader_text = strdup(value); + if (*screen_reader_text == NULL) { + LOGE("Out of memory"); + return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY; + } + + return WATCHFACE_COMPLICATION_ERROR_NONE; +} + extern "C" EXPORT_API int watchface_complication_touch_launch( complication_h handle) { if (handle == NULL) -- 2.7.4