Divide code regarding view into view_xx
authorjunkyu han <junkyu.han@samsung.com>
Tue, 9 Jan 2018 08:48:11 +0000 (17:48 +0900)
committerjunkyu han <junkyu.han@samsung.com>
Tue, 9 Jan 2018 08:48:11 +0000 (17:48 +0900)
inc/view.h [new file with mode: 0644]
res/edje/app.edc
res/images/BG_preview_02.png [new file with mode: 0755]
res/images/BG_preview_03.png [new file with mode: 0755]
src/view.c [new file with mode: 0644]

diff --git a/inc/view.h b/inc/view.h
new file mode 100644 (file)
index 0000000..67a4dca
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 __CAR_CONTROLLER_VIEW__
+#define __CAR_CONTROLLER_VIEW__
+
+int view_create_controller_view(char *package_name);
+void view_destroy_controller_view(void);
+void view_update_view_with_data(void *user_data);
+
+#endif /* __CAR_CONTROLLER_VIEW__ */
index 4d977f8..0d52601 100644 (file)
  * limitations under the License.
  */ 
 
+images {
+       image: "BG_preview_02.png" COMP;
+       image: "BG_preview_03.png" COMP;
+}
+
 collections {
        group {
                name: "main_page";
                parts {
                        part {
                                name: "center_bg";
-                               type: RECT;
+                               type: IMAGE;
                                description {
                                        state: "default" 0.0;
                                        align: 0.5 0.5;
                                        rel1 { relative: 0.0 0.0; }
                                        rel2 { relative: 1.0 1.0; }
-                                       color : 0 0 0 255;
+                                       image {
+                                               normal: "BG_preview_02.png";
+                                       }
+                               }
+                               description {
+                                       state: "stop" 0.0;
+                                       inherit: "default" 0.0;
+                                       image {
+                                               normal: "BG_preview_03.png";
+                                       }
                                }
                        }
                        part {
@@ -34,8 +48,8 @@ collections {
                                type: TEXT;
                                description {
                                        state: "default" 0.0;
-                                       rel1 { relative: 0.3 0.2; to: "center_bg"; }
-                                       rel2 { relative: 0.45 0.4; to: "center_bg"; }
+                                       rel1 { relative: 0.25 0.3; to: "center_bg"; }
+                                       rel2 { relative: 0.4 0.5; to: "center_bg"; }
                                        text {
                                                                                                                                                                                                                                                                                                                                                                                                                                                text: "X: ";
                                                font: "Tizen:style=regular"; size: 30; align: 0.5 0.5;
@@ -50,8 +64,8 @@ collections {
                                description {
                                        state: "default" 0.0;
                                        align: 0.0 0.5;
-                                       rel1 { relative: 0.4 0.2; to: "center_bg"; }
-                                       rel2 { relative: 0.8 0.4; to: "center_bg"; }
+                                       rel1 { relative: 0.35 0.3; to: "center_bg"; }
+                                       rel2 { relative: 0.75 0.5; to: "center_bg"; }
                                        text {
                                                text: "x-value";
                                                font: "Tizen:style=regular"; size: 30; align: 0.5 0.5;
@@ -65,8 +79,8 @@ collections {
                                type: TEXT;
                                description {
                                        state: "default" 0.0;
-                                       rel1 { relative: 0.3 0.4; to: "center_bg"; }
-                                       rel2 { relative: 0.45 0.6; to: "center_bg"; }
+                                       rel1 { relative: 0.25 0.5; to: "center_bg"; }
+                                       rel2 { relative: 0.4 0.7; to: "center_bg"; }
                                        text {
                                                text: "Y: ";
                                                font: "Tizen:style=regular"; size: 30; align: 0.5 0.5;
@@ -81,8 +95,8 @@ collections {
                                description {
                                        state: "default" 0.0;
                                        align: 0.0 0.5;
-                                       rel1 { relative: 0.4 0.4; to: "center_bg"; }
-                                       rel2 { relative: 0.8 0.6; to: "center_bg"; }
+                                       rel1 { relative: 0.35 0.5; to: "center_bg"; }
+                                       rel2 { relative: 0.75 0.7; to: "center_bg"; }
                                        text {
                                                text: "y-value";
                                                font: "Tizen:style=regular"; size: 30; align: 0.5 0.5;
@@ -92,36 +106,29 @@ collections {
                                }
                        }
                        part {
-                               name: "z_title";
-                               type: TEXT;
+                               name: "start_stop_button";
+                               type: SWALLOW;
                                description {
                                        state: "default" 0.0;
-                                       rel1 { relative: 0.3 0.6; to: "center_bg"; }
-                                       rel2 { relative: 0.45 0.8; to: "center_bg"; }
-                                       text {
-                                               text: "Z: ";
-                                               font: "Tizen:style=regular"; size: 30; align: 0.5 0.5;
-                                       }
-                                       color : 250 250 250 255;
-                                       min: 72 72;
-                               }
-                       }
-                       part {
-                               name: "z_value";
-                               type: TEXT;
-                               description {
-                                       state: "default" 0.0;
-                                       align: 0.0 0.5;
-                                       rel1 { relative: 0.4 0.6; to: "center_bg"; }
-                                       rel2 { relative: 0.8 0.8; to: "center_bg"; }
-                                       text {
-                                               text: "z-value";
-                                               font: "Tizen:style=regular"; size: 30; align: 0.5 0.5;
-                                       }
-                                       color : 250 250 250 255;
-                                       min: 100 72;
+                                       align: 0.5 0.5;
+                                       rel1 { relative: 0.5 0.5; to: "center_bg"; }
+                                       rel2 { relative: 0.5 0.5; to: "center_bg"; }
+                                       min: 360 360;
                                }
                        }
                }
+               programs {
+                       program {
+                               signal: "start";
+                               source: "car";
+                               action: STATE_SET "stop" 0.0;
+                               target: "center_bg";
+                       }
+                       program {
+                               signal: "stop";
+                               source: "car";
+                               action: STATE_SET "default" 0.0;
+                               target: "center_bg";
+                       }
        }
 }
diff --git a/res/images/BG_preview_02.png b/res/images/BG_preview_02.png
new file mode 100755 (executable)
index 0000000..aa82a58
Binary files /dev/null and b/res/images/BG_preview_02.png differ
diff --git a/res/images/BG_preview_03.png b/res/images/BG_preview_03.png
new file mode 100755 (executable)
index 0000000..ba38c2f
Binary files /dev/null and b/res/images/BG_preview_03.png differ
diff --git a/src/view.c b/src/view.c
new file mode 100644 (file)
index 0000000..3660983
--- /dev/null
@@ -0,0 +1,210 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 <stdio.h>
+#include <Elementary.h>
+#include <efl_extension.h>
+#include <app.h>
+
+#include "communication_center.h"
+#include "resource.h"
+#include "log.h"
+
+static struct {
+       Evas_Object *win;
+       Evas_Object *conform;
+       Evas_Object *layout;
+       Evas_Object *start_stop_btn;
+} view_info = {
+       .win = NULL,
+       .conform = NULL,
+       .layout = NULL,
+       .start_stop_btn = NULL,
+};
+
+static void __start_stop_button_clicked(void *data, Evas_Object *obj, void *event_info);
+static void __win_delete_request_cb(void *data, Evas_Object *obj, void *event_info);
+static void __back_button_cb(void *data, Evas_Object *obj, void *event_info);
+static int __create_start_stop_button(void);
+static int __create_window(char *pkg_name);
+static int __create_layout(void);
+
+int view_create_controller_view(char *pkg_name)
+{
+       int ret = 0;
+       ret = __create_window(pkg_name);
+       if (ret < 0) {
+               _E("Failed to create window");
+               return -1;
+       }
+
+       ret = __create_layout();
+       if (ret < 0) {
+               _E("Failed to create layout");
+               return -1;
+       }
+
+       ret = __create_start_stop_button();
+       if (ret < 0) {
+               _E("Failed to create layout");
+               return -1;
+       }
+
+       return 0;
+}
+
+void view_destroy_controller_view(void)
+{
+       if (view_info.start_stop_btn)
+               evas_object_del(view_info.start_stop_btn);
+       view_info.start_stop_btn = NULL;
+
+       if (view_info.layout)
+               evas_object_del(view_info.layout);
+       view_info.layout = NULL;
+
+       if (view_info.conform)
+               evas_object_del(view_info.conform);
+       view_info.conform = NULL;
+
+       if (view_info.win)
+               evas_object_del(view_info.win);
+       view_info.win = NULL;
+}
+
+void view_update_view_with_data(void *user_data)
+{
+       commu_data_s data = *(commu_data_s *)user_data;
+       char x_value[1024];
+       char y_value[1024];
+
+       snprintf(x_value, 1024, "%d", data.x);
+       snprintf(y_value, 1024, "%d", data.y);
+
+       elm_object_part_text_set(view_info.layout, "x_value", x_value);
+       elm_object_part_text_set(view_info.layout, "y_value", y_value);
+}
+
+static void __win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       ui_app_exit();
+}
+
+static void __back_button_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       ui_app_exit();
+}
+
+static int __create_window(char *pkg_name)
+{
+       Evas_Object *win = NULL;
+       Evas_Object *conform = NULL;
+
+       win = elm_win_util_standard_add(pkg_name, pkg_name);
+       if (win == NULL) {
+               _E("Failed to create window");
+               return -1;
+       }
+       elm_win_conformant_set(win, EINA_TRUE);
+       elm_win_autodel_set(win, EINA_TRUE);
+       evas_object_smart_callback_add(win, "delete,request", __win_delete_request_cb, NULL);
+       evas_object_show(win);
+
+       conform = elm_conformant_add(win);
+       if (conform == NULL) {
+               _E("Failed to create conformant");
+               return -1;
+       }
+       evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       elm_win_resize_object_add(win, conform);
+       evas_object_show(conform);
+
+       view_info.win = win;
+       view_info.conform = conform;
+
+       return 0;
+}
+
+static int __create_layout(void)
+{
+       Evas_Object *layout = NULL;
+       Evas_Object *conform = view_info.conform;
+       char *res_path = NULL;
+       char file_path[1024];
+
+       res_path = app_get_resource_path();
+       if (res_path == NULL) {
+               _E("Failed to get resource path");
+               return -1;
+       }
+       snprintf(file_path, 1024, "%s%s", res_path, "edje/app.edj");
+       free(res_path);
+
+       layout = elm_layout_add(conform);
+       if (layout == NULL) {
+               _E("Failed to create layout");
+               return -1;
+       }
+       elm_layout_file_set(layout, file_path, "main_page");
+
+       /* Layout size setting */
+       evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       eext_object_event_callback_add(layout, EEXT_CALLBACK_BACK, __back_button_cb, NULL);
+       elm_object_content_set(conform, layout);
+       evas_object_show(layout);
+
+       view_info.layout = layout;
+
+       return 0;
+}
+
+static void __start_stop_button_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+       _D("Start / Stop button clicked");
+       Evas_Object *layout = view_info.layout;
+       double val = 0.0;
+
+       if (!strcmp("default", edje_object_part_state_get(elm_layout_edje_get(layout), "center_bg", &val))) {
+               elm_object_signal_emit(layout, "start", "car");
+               resource_start_sensing();
+       } else {
+               elm_object_signal_emit(layout, "stop", "car");
+               resource_stop_sensing();
+       }
+}
+
+static int __create_start_stop_button(void)
+{
+       Evas_Object *button = NULL;
+       Evas_Object *layout = view_info.layout;
+
+       button = elm_button_add(layout);
+       if (button == NULL) {
+               _E("Failed to create button");
+               return -1;
+       }
+       elm_object_style_set(button, "circle");
+       evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       elm_object_part_content_set(layout, "start_stop_button", button);
+       evas_object_smart_callback_add(button, "clicked", __start_stop_button_clicked, NULL);
+
+       view_info.start_stop_btn = button;
+
+       return 0;
+}
+