Add get/set complication data apis 36/174136/7
authorhyunho <hhstark.kang@samsung.com>
Wed, 28 Mar 2018 11:17:45 +0000 (20:17 +0900)
committerhyunho <hhstark.kang@samsung.com>
Fri, 30 Mar 2018 02:23:11 +0000 (11:23 +0900)
Change-Id: I7f7f03e1abdb847af5308d00470b8b3a9e07898e
Signed-off-by: hyunho <hhstark.kang@samsung.com>
unittest/src/test_editables_container.cc
watchface-complication-provider/include/watchface-complication-provider.h
watchface-complication-provider/watchface-complication-provider.cc
watchface-complication/include/watchface-complication-internal.h
watchface-complication/include/watchface-complication.h
watchface-complication/include/watchface-editable.h
watchface-complication/watchface-complication.cc
watchface-complication/watchface-editable.cc
watchface-editor/include/watchface-editor.h

index 2db5605..d6ef0db 100644 (file)
@@ -141,11 +141,8 @@ TEST_F(EC, GetData)
   bundle* data = nullptr;
   bundle* nthdata = nullptr;
   editable_geo geo;
-  GList* list;
-  const char* set_editable_name = "sample_editor";
   const char* get_editable_name = NULL;
 
-  EXPECT_EQ(editable_set_cur_data_idx(EC::received, idx), 0);
   EXPECT_EQ(editable_get_cur_data_idx(EC::received, &idx_check), 0);
   EXPECT_EQ(idx, idx_check);
 
@@ -155,8 +152,5 @@ TEST_F(EC, GetData)
   EXPECT_EQ(id, 0);
 
   EXPECT_EQ(editable_get_geometry(EC::received, &geo), 0);
-  EXPECT_EQ(editable_get_candidates_list(EC::received, &list), 0);
-
-  EXPECT_EQ(editable_set_editable_name(EC::received, set_editable_name), 0);
   EXPECT_EQ(editable_get_editable_name(EC::received, &get_editable_name), 0);
 }
index e91ef08..0f0ba78 100755 (executable)
@@ -140,6 +140,17 @@ void app_control(app_control_h app_control, void *data)
  */
 int complication_provider_setup_get_context(app_control_h handle, bundle **context);
 
+int complication_provider_set_short_text_data(bundle *shared_data, char *text,
+    char *icon, char *title);
+int complication_provider_set_long_text_data(bundle *shared_data, char *text,
+    char *icon, char *title);
+int complication_provider_set_ranged_value_data(bundle *shared_data,
+    int current, int min, int max, char *text, char *icon, char *title);
+int complication_provider_set_time_value_data(bundle *shared_data, char *time_str,
+    char *icon, char *title);
+int complication_provider_set_icon_value_data(bundle *shared_data, char *icon);
+int complication_provider_set_image_value_data(bundle *shared_data, char *image);
+
 /*
  * @}
  */
index c2bf36f..76712b9 100755 (executable)
@@ -257,3 +257,180 @@ extern "C" EXPORT_API int complication_provider_setup_get_context(
 
   return COMPLICATION_ERROR_NONE;
 }
+
+static int _add_bundle_data(bundle* shared_data, const char* key, char* value) {
+  int ret;
+
+  ret = bundle_add_str(shared_data, key, value);
+  if (ret == BUNDLE_ERROR_KEY_EXISTS) {
+    bundle_del(shared_data, TEXT_KEY);
+    ret = bundle_add_str(shared_data, key, value);
+  }
+
+  if (ret == BUNDLE_ERROR_OUT_OF_MEMORY) {
+    LOGE("Out of memory : %s, %s fail", key, value);
+    return COMPLICATION_ERROR_OUT_OF_MEMORY;
+  } else if (ret != BUNDLE_ERROR_NONE) {
+    LOGE("IO error : %s, %s fail(%d)", key, value, ret);
+    return COMPLICATION_ERROR_IO_ERROR;
+  }
+
+  return COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int complication_provider_set_short_text_data(
+    bundle* shared_data, char* text, char* icon, char* title) {
+
+  int ret;
+  if (shared_data == NULL || text == NULL) {
+    LOGE("Text value is NULL");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  ret = _add_bundle_data(shared_data, TEXT_KEY, text);
+  if (ret != COMPLICATION_ERROR_NONE)
+    return ret;
+
+  if (icon) {
+    ret = _add_bundle_data(shared_data, ICON_KEY, icon);
+    if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+  }
+  if (title) {
+    ret = _add_bundle_data(shared_data, TITLE_KEY, title);
+    if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+  }
+
+  return COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int complication_provider_set_long_text_data(
+    bundle* shared_data, char* text, char* icon, char* title) {
+
+  int ret;
+  if (shared_data == NULL || text == NULL) {
+    LOGE("Text value is NULL");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  ret = _add_bundle_data(shared_data, TEXT_KEY, text);
+  if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+  if (icon) {
+    ret = _add_bundle_data(shared_data, ICON_KEY, icon);
+    if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+  }
+
+  if (title) {
+    ret = _add_bundle_data(shared_data, TITLE_KEY, title);
+    if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+  }
+
+  return COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int complication_provider_set_ranged_value_data(
+    bundle* shared_data, int current, int min, int max, char* text, char* icon,
+    char* title) {
+
+  int ret;
+  char num_str[32] = {0,};
+  if (shared_data == NULL || current < min || current > max || min > max) {
+    LOGE("wrong range %d, %d, %d", current, min, max);
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  snprintf(num_str, sizeof(num_str), "%d", current);
+  ret = _add_bundle_data(shared_data, RANGE_CUR_KEY, num_str);
+  if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+
+  snprintf(num_str, sizeof(num_str), "%d", min);
+  ret = _add_bundle_data(shared_data, RANGE_MIN_KEY, num_str);
+  if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+
+  snprintf(num_str, sizeof(num_str), "%d", max);
+  ret = _add_bundle_data(shared_data, RANGE_MAX_KEY, num_str);
+  if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+
+  if (text) {
+    ret = _add_bundle_data(shared_data, TEXT_KEY, text);
+    if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+  }
+
+  if (icon) {
+    ret = _add_bundle_data(shared_data, ICON_KEY, icon);
+    if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+  }
+
+  if (title) {
+    ret = _add_bundle_data(shared_data, TITLE_KEY, title);
+    if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+  }
+
+  return COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int complication_provider_set_time_value_data(
+    bundle* shared_data, char* time_str, char* icon, char* title) {
+
+  int ret;
+  if (shared_data == NULL || time_str == NULL) {
+    LOGE("Time value is NULL");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  ret = _add_bundle_data(shared_data, TIME_KEY, time_str);
+  if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+  if (icon) {
+    ret = _add_bundle_data(shared_data, ICON_KEY, icon);
+  }
+
+  if (title) {
+    ret = _add_bundle_data(shared_data, TITLE_KEY, title);
+    if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+  }
+
+  return COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int complication_provider_set_icon_value_data(
+    bundle* shared_data, char* icon) {
+
+  int ret;
+  if (shared_data == NULL || icon == NULL) {
+    LOGE("Time value is NULL");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  ret = _add_bundle_data(shared_data, ICON_KEY, icon);
+  if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+
+  return COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int complication_provider_set_image_value_data(
+    bundle* shared_data, char* image) {
+
+  int ret;
+  if (shared_data == NULL || image == NULL) {
+    LOGE("Image value is NULL");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  ret = _add_bundle_data(shared_data, IMAGE_KEY, image);
+  if (ret != COMPLICATION_ERROR_NONE)
+      return ret;
+
+  return COMPLICATION_ERROR_NONE;
+}
+
index f8a2388..c84798a 100755 (executable)
 #define SETUP_EDITOR_APPID_KEY "__SETUP_EDITOR_APPID_KEY__"
 #define SETUP_EDITABLE_ID_KEY "__SETUP_EDITABLE_ID_KEY__"
 #define SETUP_CONTEXT_DATA_KEY "__SETUP_CONTEXT_DATA_KEY__"
+#define TEXT_KEY "__TEXT_KEY__"
+#define ICON_KEY "__ICON_KEY__"
+#define TITLE_KEY "__TITLE_KEY__"
+#define TIME_KEY "__TIME_KEY__"
+#define RANGE_CUR_KEY "__MAX_KEY__"
+#define RANGE_MAX_KEY "__MAX_KEY__"
+#define RANGE_MIN_KEY "__MIN_KEY__"
+#define IMAGE_KEY "__IMAGE_KEY__"
 
 namespace watchface_complication {
 
index 39caffe..cab3492 100755 (executable)
@@ -58,7 +58,6 @@ int complication_update_cb_add(complication_h handle, on_complication_update cb,
 int complication_update_cb_del(complication_h handle,
                                on_complication_update cb);
 int complication_send_update_request(complication_h handle);
-int complication_set_provider(const char *provider_id);
 int complication_create(int complication_id, const char *default_provider_id,
                         complication_type default_type, int support_types,
                         complication_shape_type type,
@@ -68,6 +67,16 @@ int complication_get_provider_id(const bundle *candidate,
     const char **provider_id);
 int complication_get_type(const bundle *candidate,
     complication_type *cur_type);
+int complication_get_short_text_data(bundle *data, char **text, char **icon,
+    char **title);
+int complication_get_long_text_data(bundle *data, char **text, char **icon,
+    char **title);
+int complication_get_ranged_value_data(bundle *data, int *current, int *min,
+    int *max, char **text, char **icon, char **title);
+int complication_get_time_value_data(bundle *data, char **time_str, char **icon,
+    char **title);
+int complication_get_icon_value_data(bundle *data, char **icon);
+int complication_get_image_value_data(bundle *data, char **image);
 
 /**
  * @}
index 757663a..da42a56 100755 (executable)
@@ -84,6 +84,9 @@ int editable_request_edit(editable_container_h handle, const char *editor_appid,
 int editable_on_edit_ready_cb_add(on_edit_ready cb, void *user_data);
 int editable_on_edit_ready_cb_del(on_edit_ready cb);
 int editable_load_current_data(int editable_id, bundle **current_data);
+int editable_get_editable_name(const editable_h handle,
+    const char **editable_name);
+int editable_get_geometry(const editable_h handle, editable_geo *geo);
 
 /**
  * @}
index b26d9a1..66f409a 100755 (executable)
@@ -225,3 +225,148 @@ extern "C" EXPORT_API int complication_get_type(const bundle* candidate,
 
   return COMPLICATION_ERROR_NONE;
 }
+
+extern "C" EXPORT_API int complication_get_short_text_data(bundle* data,
+    char** text, char** icon, char** title) {
+
+  int ret;
+  if (data == NULL || text == NULL) {
+    LOGE("Invalid param !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  ret = bundle_get_str(data, TEXT_KEY, text);
+  if (ret != BUNDLE_ERROR_NONE) {
+    LOGE("Invalid data !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  if (icon)
+    bundle_get_str(data, ICON_KEY, icon);
+  if (title)
+    bundle_get_str(data, TITLE_KEY, title);
+
+  return COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int complication_get_long_text_data(bundle* data,
+    char** text, char** icon, char** title) {
+
+  int ret;
+  if (data == NULL || text == NULL) {
+    LOGE("Invalid param !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  ret = bundle_get_str(data, TEXT_KEY, text);
+  if (ret != BUNDLE_ERROR_NONE) {
+    LOGE("Invalid data !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  if (icon)
+    bundle_get_str(data, ICON_KEY, icon);
+  if (title)
+    bundle_get_str(data, TITLE_KEY, title);
+
+  return COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int complication_get_ranged_value_data(bundle* data,
+    int* current_val, int* min_val, int* max_val, char** text, char** icon,
+    char** title) {
+
+  int ret;
+  if (data == NULL || current_val == NULL || min_val == NULL
+      || max_val == NULL) {
+    LOGE("Invalid param !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  char* num_str;
+  ret = bundle_get_str(data, RANGE_CUR_KEY, &num_str);
+  if (ret != BUNDLE_ERROR_NONE) {
+    LOGE("Invalid data !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  *current_val = atoi(num_str);
+
+  ret = bundle_get_str(data, RANGE_MIN_KEY, &num_str);
+  if (ret != BUNDLE_ERROR_NONE) {
+    LOGE("Invalid data !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  *min_val = atoi(num_str);
+
+  ret = bundle_get_str(data, RANGE_MAX_KEY, &num_str);
+  if (ret != BUNDLE_ERROR_NONE) {
+    LOGE("Invalid data !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  *max_val = atoi(num_str);
+
+  if (text)
+    bundle_get_str(data, TEXT_KEY, text);
+  if (icon)
+    bundle_get_str(data, ICON_KEY, icon);
+  if (title)
+    bundle_get_str(data, TITLE_KEY, title);
+
+  return COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int complication_get_time_value_data(bundle* data,
+    char** time_str, char** icon, char** title) {
+
+  int ret;
+  if (data == NULL || time_str == NULL) {
+    LOGE("Invalid param !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  ret = bundle_get_str(data, TIME_KEY, time_str);
+  if (ret != BUNDLE_ERROR_NONE) {
+    LOGE("Invalid data !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  if (icon)
+    bundle_get_str(data, ICON_KEY, icon);
+  if (title)
+    bundle_get_str(data, TITLE_KEY, title);
+
+  return COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int complication_get_icon_value_data(bundle* data,
+    char** icon) {
+
+  int ret;
+  if (data == NULL || icon == NULL) {
+    LOGE("Invalid param !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  ret = bundle_get_str(data, ICON_KEY, icon);
+  if (ret != BUNDLE_ERROR_NONE) {
+    LOGE("Invalid data !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  return COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int complication_get_image_value_data(bundle* data,
+    char** image)  {
+
+  int ret;
+  if (data == NULL || image == NULL) {
+    LOGE("Invalid param !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  ret = bundle_get_str(data, IMAGE_KEY, image);
+  if (ret != BUNDLE_ERROR_NONE) {
+    LOGE("Invalid data !!");
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  return COMPLICATION_ERROR_NONE;
+}
\ No newline at end of file
index c6fb954..a408e4f 100755 (executable)
@@ -322,6 +322,5 @@ extern "C" EXPORT_API int editable_load_current_data(int editable_id,
     *selected_data = bundle_dup(setting_data.get()->GetRaw());
   else
     return COMPLICATION_ERROR_NO_DATA;
-
   return COMPLICATION_ERROR_NONE;
 }
index ada2d4b..e2c7e3d 100755 (executable)
@@ -46,8 +46,6 @@ typedef int (*editable_list_foreach_cb)(const editable_h handle,
                                         void *user_data);
 int editor_on_request_edit_cb_add(on_request_edit cb, void *user_data);
 int editor_on_request_edit_cb_del(on_request_edit cb);
-int editor_update_cur_data(const editable_h handle, int cur_data_idx,
-                           editable_edit_state state);
 int editor_edit_complete();
 int editor_edit_preview(const editable_h handle, int cur_data_idx);
 int editor_edit_cancel();