From: Myungki Lee Date: Wed, 21 Sep 2016 04:13:16 +0000 (+0900) Subject: Add new api for direct reply X-Git-Tag: submit/tizen/20160922.051802~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=51252bff3893353d9386db86cdce77c25c3cc29f;p=platform%2Fcore%2Fapi%2Fnotification.git Add new api for direct reply Change-Id: I0944647478f8ef7ee0f1cb60da038054b6531037 Signed-off-by: Myungki Lee --- diff --git a/include/notification.h b/include/notification.h index 74babf55..ed95895d 100755 --- a/include/notification.h +++ b/include/notification.h @@ -1556,6 +1556,110 @@ notification_h notification_create_from_template(const char *template_name); */ int notification_get_noti_block_state(notification_block_state_e *state); +/** + * @brief Sets a text input box to reply directly on the notification. + * @details When you add a text input to the active notification, the notification UI will show a text input with a button. + * So, the user can enter any text and press the button to confirm the text as a input. + * You can edit some UI component that is related to the text input. + * First, you can add placeholder text to guide the user using notification_set_text() with #NOTIFICATION_TEXT_TYPE_TEXT_INPUT_PLACEHOLDER type. + * You also can edit button for the text input. + * For setting just a text to the button, you can set the text using notification_set_text() with #NOTIFICATION_TEXT_TYPE_TEXT_INPUT_BUTTON type. + * If you want to show image button, you can set an image for the button using notification_set_image() with #NOTIFICATION_IMAGE_TYPE_TEXT_INPUT_BUTTON type. + * + * Note that You should set an app_control for handling the event for user input using notification_set_event_handler(). + * #NOTIFICATION_EVENT_TYPE_CLICK_ON_TEXT_INPUT_BUTTON is the event type for the text input. + * You can get the text the user enters in the app_control handle that is passed as a result of the event. + * The app_control will contain APP_CONTROL_DATA_TEXT key, so you can get the text using app_control_get_extra_data() using APP_CONTROL_DATA_TEXT key. + * The value will contain the text user enters. + * @since_tizen 3.0 + * @return #NOTIFICATION_ERROR_NONE on success, + * otherwise any other value on failure + * @retval #NOTIFICATION_ERROR_NONE Success + * @retval #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter + * @par Sample code: + * @code +#include +... +{ + notification_h noti = NULL; + int noti_err = NOTIFICATION_ERROR_NONE; + app_control = NULL; + + noti = notification_create(NOTIFICATION_TYPE_NOTI); + if (noti == NULL) { + return; + } + ... + + noti_err = notification_set_text_input(noti, 160); + if (noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + noti_err = notification_set_text(noti, + NOTIFICATION_TEXT_TYPE_TEXT_INPUT_PLACEHOLDER, + "Text message", + NULL, + NOTIFICATION_VARIABLE_TYPE_NONE); + if (noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + noti_err = notification_set_text(noti, + NOTIFICATION_TEXT_TYPE_TEXT_INPUT_BUTTON, + "SEND", + NULL, + NOTIFICATION_VARIABLE_TYPE_NONE); + if (noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + noti_err = notification_set_image(noti, + NOTIFICATION_IMAGE_TYPE_TEXT_INPUT_BUTTON, + TEXT_INPUT_BUTTON_PATH); + if (noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + ... + + + noti_err = app_control_create(&app_control); + if (noti_err != APP_CONTROL_ERROR_NONE) { + return; + } + + noti_err = app_control_set_app_id(app_contorl, appid); + if (noti_err != APP_CONTROL_ERROR_NONE) { + return; + } + + noti_err = app_control_set_operation(app_contorl, APP_CONTROL_OPERATION_DEFAULT); + if (noti_err != APP_CONTROL_ERROR_NONE) { + return; + } + + noti_err = notification_set_event_handler(noti, + NOTIFICATION_EVENT_TYPE_CLICK_ON_TEXT_INPUT_BUTTON, + app_control); + if (noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + noti_err = app_control_destroy(app_control); + if (noti_err != APP_CONTROL_ERROR_NONE) { + return; + } + + noti_err = notification_post(noti); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + +} + * @endcode + */ +int notification_set_text_input(notification_h noti, int text_input_max_length); + /** * @} */ diff --git a/include/notification_internal.h b/include/notification_internal.h index 1af1b405..0b4d31d5 100644 --- a/include/notification_internal.h +++ b/include/notification_internal.h @@ -1054,6 +1054,30 @@ int notification_delete_all_for_uid(notification_type_e type, uid_t uid); notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid); notification_h notification_create_from_package_template(const char *pkgname, const char *template_name); +/** + * @brief Gets a max length of text input. + * @since_tizen 3.0 + * @return #NOTIFICATION_ERROR_NONE on success, + * otherwise any other value on failure + * @retval #NOTIFICATION_ERROR_NONE Success + * @retval #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter + * @par Sample code: + * @code +#include +... +{ + int noti_err = NOTIFICATION_ERROR_NONE; + int text_input_max_length; + + noti_err = notification_get_text_input_max_length(noti, &text_input_max_length); + if (noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + ... + } + * @endcode + */ +int notification_get_text_input_max_length(notification_h noti, int *text_input_max_length); /** * @} diff --git a/include/notification_private.h b/include/notification_private.h index 167b1c56..e7ac1195 100644 --- a/include/notification_private.h +++ b/include/notification_private.h @@ -95,6 +95,7 @@ struct _notification { bool auto_remove; notification_button_index_e default_button_index; int timeout; + int text_input_max_length; uid_t uid; }; @@ -153,6 +154,7 @@ typedef enum notification_data_type { NOTIFICATION_DATA_TYPE_AUTO_REMOVE, NOTIFICATION_DATA_TYPE_DEFAULT_BUTTON, NOTIFICATION_DATA_TYPE_TIMEOUT, + NOTIFICATION_DATA_TYPE_TEXT_INPUT_MAX_LENGTH, NOTIFICATION_DATA_TYPE_UID, } notification_data_type_e; diff --git a/include/notification_type.h b/include/notification_type.h index 3d572828..dc6738ed 100644 --- a/include/notification_type.h +++ b/include/notification_type.h @@ -84,6 +84,7 @@ typedef enum _notification_event_type { NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6 = 5, /**< Event type : Click on button 6 */ NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON = 6, /**< Event type : Click on icon */ NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL = 7, /**< Event type : Click on thumbnail */ + NOTIFICATION_EVENT_TYPE_CLICK_ON_TEXT_INPUT_BUTTON = 8, /**< Event type : Click on text_input button(Since 3.0) */ NOTIFICATION_EVENT_TYPE_MAX, } notification_event_type_e; @@ -197,6 +198,11 @@ typedef enum _notification_text_type { /**< Text on button 5 */ NOTIFICATION_TEXT_TYPE_BUTTON_6, /**< Text on button 6 */ + NOTIFICATION_TEXT_TYPE_TEXT_INPUT_PLACEHOLDER, + /**< Guide text on the message reply box(Since 3.0) */ + NOTIFICATION_TEXT_TYPE_TEXT_INPUT_BUTTON, + /**< Text on button the on message reply box(Since 3.0) */ + NOTIFICATION_TEXT_TYPE_MAX, } notification_text_type_e; @@ -242,6 +248,8 @@ typedef enum _notification_image_type { /**< Image for button 5 */ NOTIFICATION_IMAGE_TYPE_BUTTON_6, /**< Image for button 6 */ + NOTIFICATION_IMAGE_TYPE_TEXT_INPUT_BUTTON, + /**< Image for message reply(Since 3.0) */ NOTIFICATION_IMAGE_TYPE_MAX, } notification_image_type_e; diff --git a/src/notification.c b/src/notification.c index 30fbf9b9..eacf9078 100755 --- a/src/notification.c +++ b/src/notification.c @@ -1645,7 +1645,7 @@ EXPORT_API int notification_clone(notification_h noti, notification_h *clone) new_noti->auto_remove = noti->auto_remove; new_noti->default_button_index = noti->default_button_index; new_noti->timeout = noti->timeout; - + new_noti->text_input_max_length = noti->text_input_max_length; new_noti->uid = noti->uid; new_noti->app_icon_path = NULL; @@ -1906,3 +1906,23 @@ EXPORT_API int notification_get_noti_block_state(notification_block_state_e *sta return ret; } + +EXPORT_API int notification_set_text_input(notification_h noti, int text_input_max_length) +{ + if (noti == NULL) + return NOTIFICATION_ERROR_INVALID_PARAMETER; + + noti->text_input_max_length = text_input_max_length; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API int notification_get_text_input_max_length(notification_h noti, int *text_input_max_length) +{ + if (noti == NULL || text_input_max_length == NULL) + return NOTIFICATION_ERROR_INVALID_PARAMETER; + + *text_input_max_length = noti->text_input_max_length; + + return NOTIFICATION_ERROR_NONE; +} diff --git a/src/notification_db.c b/src/notification_db.c index 5c9c414b..725aa683 100755 --- a/src/notification_db.c +++ b/src/notification_db.c @@ -85,6 +85,7 @@ create table if not exists noti_list ( \ auto_remove INTEGER default 1, \ default_button_index INTEGER default 0, \ timeout INTEGER default 0, \ + text_input_max_length INTEGER default 0, \ uid INTEGER \ ); \ create table if not exists noti_group_data ( \ @@ -205,6 +206,7 @@ create table if not exists noti_list ( \ auto_remove INTEGER default 1, \ default_button_index INTEGER default 0, \ timeout INTEGER default 0, \ + text_input_max_length INTEGER default 0, \ uid INTEGER, \ template_name TEXT, \ UNIQUE (caller_pkgname, template_name) \ diff --git a/src/notification_noti.c b/src/notification_noti.c index 902b11d7..186bb3fa 100755 --- a/src/notification_noti.c +++ b/src/notification_noti.c @@ -263,7 +263,7 @@ static int _insertion_query_create(notification_h noti, char **query) "flags_for_property, flag_simmode, display_applist, " "progress_size, progress_percentage, " "ongoing_flag, ongoing_value_type, ongoing_current, ongoing_duration, " - "auto_remove, default_button_index, timeout, uid) values (" + "auto_remove, default_button_index, timeout, text_input_max_length, uid) values (" "%d, " "%d, " "'%s', '%s', " @@ -282,7 +282,7 @@ static int _insertion_query_create(notification_h noti, char **query) "%d, '%s', %d, '%s', %d, %d, %d, %d," "%d, %d, %d, " "$progress_size, $progress_percentage, " - "%d, %d, %d, %d, %d, %d, %d, %d)", + "%d, %d, %d, %d, %d, %d, %d, %d, %d)", noti->type, noti->layout, NOTIFICATION_CHECK_STR(noti->caller_pkgname), @@ -322,6 +322,7 @@ static int _insertion_query_create(notification_h noti, char **query) noti->auto_remove, noti->default_button_index, noti->timeout, + noti->text_input_max_length, noti->uid); /* Free decoded data */ @@ -459,7 +460,7 @@ static int _update_query_create(notification_h noti, char **query) "display_applist = %d, " "progress_size = $progress_size, progress_percentage = $progress_percentage, " "ongoing_flag = %d, ongoing_value_type = %d, ongoing_current = %d, ongoing_duration = %d, " - "auto_remove = %d, default_button_index = %d, timeout = %d " + "auto_remove = %d, default_button_index = %d, timeout = %d, text_input_max_length = %d " "where priv_id = %d ", noti->type, noti->layout, @@ -494,7 +495,7 @@ static int _update_query_create(notification_h noti, char **query) noti->ongoing_flag, noti->ongoing_value_type, noti->ongoing_current, noti->ongoing_duration, noti->auto_remove, noti->default_button_index, - noti->timeout, noti->priv_id); + noti->timeout, noti->text_input_max_length, noti->priv_id); /* Free decoded data */ if (args) @@ -893,6 +894,24 @@ out: return ret; } +static int _check_text_input(notification_h noti) +{ + int err; + int text_input_max_length; + app_control_h app_control = NULL; + + err = notification_get_text_input_max_length(noti, &text_input_max_length); + if (err == NOTIFICATION_ERROR_NONE && text_input_max_length != 0) { + err = notification_get_event_handler(noti, NOTIFICATION_EVENT_TYPE_CLICK_ON_TEXT_INPUT_BUTTON, &app_control); + if (err != NOTIFICATION_ERROR_NONE || app_control == NULL) { + NOTIFICATION_ERR("Event handler for text_input is not set"); + return -1; + } + } + + return NOTIFICATION_ERROR_NONE; +} + EXPORT_API int notification_noti_insert(notification_h noti) { int ret = 0; @@ -920,6 +939,11 @@ EXPORT_API int notification_noti_insert(notification_h noti) NOTIFICATION_DBG("notification display applist - pkgname [%s], applist [%d]", noti->caller_pkgname, noti->display_applist); } + if (_check_text_input(noti) != NOTIFICATION_ERROR_NONE) + return NOTIFICATION_ERROR_INVALID_PARAMETER; + + //get_event_handler + db = notification_db_open(DBPATH); if (!db) return get_last_result(); @@ -1033,7 +1057,7 @@ EXPORT_API int notification_noti_get_by_priv_id(notification_h noti, char *pkgna "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, " "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, " "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, " - "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout " + "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout, text_input_max_length " "from noti_list "; if (pkgname != NULL && strlen(pkgname) != 0) @@ -1104,7 +1128,7 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, " "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, " "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, " - "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout " + "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout, text_input_max_length " "from noti_list where caller_pkgname = ? and tag = ? and uid = ?", -1, &stmt, NULL); if (ret != SQLITE_OK) { NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db)); @@ -1140,7 +1164,7 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, " "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, " "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, " - "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout " + "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout, text_input_max_length " "from noti_list where tag = ? and uid = ?", -1, &stmt, NULL); if (ret != SQLITE_OK) { NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db)); @@ -1599,7 +1623,7 @@ EXPORT_API int notification_noti_get_grouping_list(notification_type_e type, "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, " "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, " "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, " - "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout " + "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout, text_input_max_length " "from noti_list where 1 > 0 "); if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) { @@ -1701,7 +1725,7 @@ EXPORT_API int notification_noti_get_detail_list(const char *pkgname, "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, " "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, " "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, " - "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout " + "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout, text_input_max_length " "from noti_list "); if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) { @@ -1961,7 +1985,7 @@ static int _template_query_create(notification_h noti, char *template_name, char "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, " "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, " "flags_for_property, flag_simmode, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, " - "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout, uid, template_name) values (" + "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout, text_input_max_length, uid, template_name) values (" "%d, " "%d, " "'%s', '%s', " @@ -1980,7 +2004,7 @@ static int _template_query_create(notification_h noti, char *template_name, char "%d, '%s', %d, '%s', %d, %d, %d, %d, " "%d, %d, %d, " "$progress_size, $progress_percentage, " - "%d, %d, %d, %d, %d, %d, %d, %d, '%s')", + "%d, %d, %d, %d, %d, %d, %d, %d, %d, '%s')", noti->type, noti->layout, NOTIFICATION_CHECK_STR(noti->caller_pkgname), @@ -2020,6 +2044,7 @@ static int _template_query_create(notification_h noti, char *template_name, char noti->auto_remove, noti->default_button_index, noti->timeout, + noti->text_input_max_length, noti->uid, template_name); @@ -2185,7 +2210,7 @@ EXPORT_API int notification_noti_get_package_template(notification_h noti, char "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, " "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, " "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, ongoing_value_type, " - "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout " + "ongoing_current, ongoing_duration, auto_remove, default_button_index, timeout, text_input_max_length " "from noti_template where caller_pkgname = ? and template_name = ?", -1, &stmt, NULL); if (ret != SQLITE_OK) { NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));