/* * Copyright (c) 2018 Samsung Electronics Co., Ltd. * * 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 #include "view/view_base.h" #include "view/view_car_selection.h" #include "controller/controller_car_selection.h" #include "view_manager/view_manager.h" #include "cloud/car_info.h" #include "log.h" #define START_LIST_ITEMS_NUMBER 3 typedef enum _e_scroll_cb_type { SCROLL_EDGE_TOP, SCROLL_EDGE_BOTTOM, SCROLL_DRAG_START_UP, SCROLL_DRAG_START_DOWN, SCROLL_DRAG_STOP, } e_scroll_cb_type; typedef struct _s_connect_to_car { s_view_base view_base; Evas_Object *genlist; Elm_Object_Item *first; Elm_Object_Item *refresh; Elm_Object_Item *last; Elm_Genlist_Item_Class *car_itc; } s_connect_to_car; static s_connect_to_car s_info = { {0,}, }; static void _create_default_genlist_items(); static void _layout_back_cb(void *data, Evas_Object *obj, void *event_info) { elm_win_lower(view_manager_get_win()); } static char *_genlist_set_text_cb(void *data, Evas_Object *obj, const char *part) { const char *name = (const char *)data; if (name) { char *ret = strdup(name); return ret; } return NULL; } static char *_genlist_car_set_text_cb(void *data, Evas_Object *obj, const char *part) { car_info_t *car = (car_info_t*)data; const char *name = car_info_get_car_name(car); if (name) { char *ret = strdup(name); return ret; } return NULL; } Elm_Genlist_Item_Class *_create_genlist_item_class(char *style, Elm_Gen_Item_Text_Get_Cb text_get_cb, Elm_Gen_Item_Content_Get_Cb content_get_cb, Elm_Gen_Item_Del_Cb del_cb) { Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new(); ASSERT_MEMORY(!itc); itc->item_style = style; itc->func.text_get = text_get_cb; itc->func.content_get = content_get_cb; itc->func.del = del_cb; return itc; } static void _create_guard_items(void) { Elm_Gengrid_Item_Class* itc1 = _create_genlist_item_class("title", _genlist_set_text_cb, NULL, NULL); s_info.first = elm_genlist_item_append(s_info.genlist, itc1, "Select a car", NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); s_info.last = elm_genlist_item_append(s_info.genlist, itc1, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); elm_genlist_item_select_mode_set(s_info.first, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); elm_genlist_item_select_mode_set(s_info.last, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); } static void _refresh_button_clicked(void *data, Evas_Object *obj, void *event_info) { elm_genlist_clear(s_info.genlist); _create_default_genlist_items(); controller_car_selection_start_get_car_names(); } static Evas_Object *_full_content_get_cb(void *data, Evas_Object *obj, const char *part) { Evas_Object *button = view_base_create_button(obj, NULL, "Refresh", NULL, "racing_middle", _refresh_button_clicked, NULL); evas_object_size_hint_min_set(button, 0, 80); return button; } static void _create_refresh_item(void) { Elm_Gengrid_Item_Class* itc = _create_genlist_item_class("full", NULL, _full_content_get_cb, NULL); s_info.refresh = elm_genlist_item_insert_before(s_info.genlist, itc, NULL, NULL, s_info.last, ELM_GENLIST_ITEM_NONE, NULL, NULL); } static void _job_cb(void *data) { Elm_Object_Item *central = elm_genlist_at_xy_item_get(s_info.genlist, 180, 180, NULL); if (central == s_info.last || central == s_info.first || elm_genlist_item_next_get(s_info.first) == s_info.last) { return; } elm_genlist_item_bring_in(central, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE); } static void _genlist_scroll_cb(void *data, Evas_Object *obj, void *event_info) { e_scroll_cb_type scroll_cb_type = (e_scroll_cb_type)data; char *scroll_type_text = ""; static Elm_Object_Item *central_item = NULL; switch (scroll_cb_type) { case SCROLL_EDGE_TOP: scroll_type_text = "SCROLL_EDGE_TOP"; ecore_job_add(_job_cb, NULL); break; case SCROLL_EDGE_BOTTOM: scroll_type_text = "SCROLL_EDGE_BOTTOM"; ecore_job_add(_job_cb, NULL); break; case SCROLL_DRAG_START_UP: scroll_type_text = "SCROLL_DRAG_START_UP"; central_item = elm_genlist_at_xy_item_get(s_info.genlist, 180, 180, NULL); if (central_item != elm_genlist_item_prev_get(s_info.last)) { central_item = NULL; } break; case SCROLL_DRAG_START_DOWN: scroll_type_text = "SCROLL_DRAG_START_DOWN"; central_item = elm_genlist_at_xy_item_get(s_info.genlist, 180, 180, NULL); if (central_item != elm_genlist_item_next_get(s_info.first)) { central_item = NULL; } break; case SCROLL_DRAG_STOP: scroll_type_text = "SCROLL_DRAG_STOP"; if (central_item && central_item == elm_genlist_at_xy_item_get(s_info.genlist, 180, 180, NULL)) { ecore_job_add(_job_cb, NULL); } central_item = NULL; break; default: break; } } static void _add_scroll_end_callbacks(void) { evas_object_smart_callback_add(s_info.genlist, "edge,top", _genlist_scroll_cb, (void *)SCROLL_EDGE_TOP); evas_object_smart_callback_add(s_info.genlist, "edge,bottom", _genlist_scroll_cb, (void *)SCROLL_EDGE_BOTTOM); evas_object_smart_callback_add(s_info.genlist, "drag,start,up", _genlist_scroll_cb, (void *)SCROLL_DRAG_START_UP); evas_object_smart_callback_add(s_info.genlist, "drag,start,down", _genlist_scroll_cb, (void *)SCROLL_DRAG_START_DOWN); evas_object_smart_callback_add(s_info.genlist, "drag,stop", _genlist_scroll_cb, (void *)SCROLL_DRAG_STOP); } static void _create_default_genlist_items() { _create_guard_items(); _create_refresh_item(); _add_scroll_end_callbacks(); } static void _set_circular_parameters(Eext_Circle_Surface* circle_surface) { bool is_circular = false; system_info_get_platform_bool("http://tizen.org/feature/screen.shape.circle", &is_circular); if (!is_circular) { _D("Circular screen shape is not supported"); return; } Evas_Object* circle_genlist = eext_circle_object_genlist_add(s_info.genlist, circle_surface); ASSERT_MEMORY(!circle_genlist); eext_circle_object_genlist_scroller_policy_set(circle_genlist, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_AUTO); eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE); evas_object_size_hint_weight_set(circle_genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); eext_circle_object_item_color_set(circle_genlist, "default", 255, 0, 0, 128); eext_circle_object_item_color_set(circle_genlist, "vertical,scroll,bg", 255, 255, 255, 15); eext_circle_object_line_width_set(circle_genlist, 5); } static void _create_genlist(Eext_Circle_Surface *circle_surface) { s_info.genlist = elm_genlist_add(s_info.view_base.view); ASSERT_MEMORY(!s_info.genlist); _set_circular_parameters(circle_surface); s_info.car_itc = _create_genlist_item_class("racing_list_item", _genlist_car_set_text_cb, NULL, NULL); elm_layout_content_set(s_info.view_base.view, "list", s_info.genlist); _create_default_genlist_items(); } static void _genlist_item_selected_cb(void *data, Evas_Object *obj, void *event_info) { controller_car_selection_select_car((int)data); controller_car_selection_next(); } static void _controller_car_selection_cb(void *data) { if (!data) { elm_layout_signal_emit(s_info.view_base.view, "no.cars.found", ""); } else { elm_layout_signal_emit(s_info.view_base.view, "cars.found", ""); int ind = elm_genlist_items_count(s_info.genlist) - START_LIST_ITEMS_NUMBER; elm_genlist_item_insert_before(s_info.genlist, s_info.car_itc, data, NULL, s_info.refresh, ELM_GENLIST_ITEM_NONE, _genlist_item_selected_cb, (void *)ind); } } static void _car_selection_create_gui(Evas_Object *parent, Eext_Circle_Surface *circle_surface) { s_info.view_base.view = view_base_create_layout(parent, "edje/car_selection.edj", GRP_MAIN); eext_object_event_callback_add(s_info.view_base.view, EEXT_CALLBACK_BACK, _layout_back_cb, NULL); elm_layout_text_set(s_info.view_base.view, "txt_title", "Car selection"); _create_genlist(circle_surface); view_base_create_button(s_info.view_base.view, "no.car.refresh.button", "Refresh", NULL, "racing_bottom", _refresh_button_clicked, NULL); } static void _show_cb(void) { controller_car_selection_init(_controller_car_selection_cb); controller_car_selection_start_get_car_names(); } static void _hide_cb(void) { controller_car_selection_destroy(); } s_view_base *view_car_selection_init(Evas_Object *parent, Eext_Circle_Surface *circle_surface) { s_info.view_base.show_cb = _show_cb; s_info.view_base.hide_cb = _hide_cb; _car_selection_create_gui(parent, circle_surface); return &s_info.view_base; }